Commit 64973676 authored by Guillaume Chomat's avatar Guillaume Chomat
Browse files

implemented the load rdf

parent 251a29ca
/**
* $Id: FCMarqueeHandler.java,v 1.40 2002-07-01 13:11:18 gchomat Exp $
* $Id: FCMarqueeHandler.java,v 1.41 2002-07-02 13:46:43 gchomat Exp $
*
* Transmorpher
......@@ -56,8 +56,9 @@ import java.io.*;
*/
public class FCMarqueeHandler extends BasicMarqueeHandler {
protected ProcessGraph currentProcess;
protected Process currentTransformation;
//protected ProcessGraph currentProcess;
//protected Process currentTransformation;
protected FlowComposer flowcomposer;
protected PortView port, firstPort, lastPort;
......@@ -88,25 +89,26 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
gt = new FCGraphTools();
}
public void setCurrentProcess(Object process){
/*public void setCurrentProcess(Object process){
if(process instanceof ProcessGraph){
currentProcess = (ProcessGraph)process;
if(currentProcess.getUserObject()!=null && currentProcess.getUserObject() instanceof Process){
currentTransformation = (Process)currentProcess.getUserObject();
}
}
}
}*/
public void update() {
if (currentProcess.canConnect())
if (flowcomposer.getCurrentProcess().canConnect())
edgeNormal.setEnabled(true);
else edgeNormal.setEnabled(false);
}
public JGraph getCurrentProcess(){
return currentProcess;
}
/*
public JGraph getCurrentProcess(){
return currentProcess;
}
*/
public Point getCurrentPoint(){
return current;
......@@ -126,6 +128,8 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
public String getTrueName(String name,int count){
Process currentTransformation = (Process)flowcomposer.getCurrentProcess().getUserObject();
Enumeration e = currentTransformation.getCalls().getKeys();
String trueName = name+"-"+count;
......@@ -156,7 +160,7 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
{
if (!e.isConsumed() && marquee.isSelected()) {
current = currentProcess.snap(e.getPoint());
current = flowcomposer.getCurrentProcess().snap(e.getPoint());
flowcomposer.showPopup(e);
return;
......@@ -171,13 +175,13 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
}*/
else{
if(currentProcess != null){
if(flowcomposer.getCurrentProcess() != null){
if (!e.isConsumed() && !marquee.isSelected()) {
start = currentProcess.snap(e.getPoint());
start = flowcomposer.getCurrentProcess().snap(e.getPoint());
firstPort = port;
if ((edgeNormal.isSelected())&&(firstPort != null)) {
double scale = currentProcess.getScale();
double scale = flowcomposer.getCurrentProcess().getScale();
start = firstPort.getLocation(null);
start = new Point((int)(start.x*scale),(int)(start.y*scale));
}
......@@ -194,18 +198,18 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
public void mouseDragged(MouseEvent event) {
//System.out.println("MouseDragged Start...");
if(currentProcess != null){
if(flowcomposer.getCurrentProcess() != null){
if (!event.isConsumed() && !marquee.isSelected()) {
Graphics g = currentProcess.getGraphics();
Color bg = currentProcess.getBackground();
Graphics g = flowcomposer.getCurrentProcess().getGraphics();
Color bg = flowcomposer.getCurrentProcess().getBackground();
Color fg = Color.black;
g.setColor(fg);
g.setXORMode(bg);
overlay(g);
current = currentProcess.snap(event.getPoint());
current = flowcomposer.getCurrentProcess().snap(event.getPoint());
if (edgeNormal.isSelected()){
double scale = currentProcess.getScale();
port = currentProcess.getPortViewAt((int)(event.getX()/scale),(int)(event.getY()/scale));
double scale = flowcomposer.getCurrentProcess().getScale();
port = flowcomposer.getCurrentProcess().getPortViewAt((int)(event.getX()/scale),(int)(event.getY()/scale));
if ( port != null ) {
current = port.getLocation(null);
current = new Point((int)(current.x*scale),(int)(current.y*scale));
......@@ -227,6 +231,9 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
public void mouseReleased(MouseEvent event) {
Call call;
ProcessGraph currentProcess = flowcomposer.getCurrentProcess();
Process currentTransformation = (Process)currentProcess.getUserObject();
current = currentProcess.snap(event.getPoint());
String tmpName,name;
......@@ -373,8 +380,10 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
}
public void mouseMoved(MouseEvent event) {
//System.out.println("currentProcess " + currentProcess);
if(currentProcess!=null){
//System.out.println("currentProcess " + flowcomposer.getCurrentProcess());
ProcessGraph currentProcess = flowcomposer.getCurrentProcess();
if(currentProcess!=null){
if (!marquee.isSelected() && !event.isConsumed()) {
currentProcess.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
event.consume();
......@@ -404,12 +413,16 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
public void updateGraphics(){
if(currentProcess != null)
currentProcess.getModel().insert(null,null,null,null);
if(flowcomposer.getCurrentProcess() != null)
flowcomposer.getCurrentProcess().getModel().insert(null,null,null,null);
}
public void doConnection(PortView firstPort,PortView port) {
Channel channel;
ProcessGraph currentProcess = flowcomposer.getCurrentProcess();
Process currentTransformation = (Process)currentProcess.getUserObject();
Channel channel;
DefaultGraphCell c = (DefaultGraphCell)(port.getParentView()).getCell();
String name;
if((c!=null)&&(c.getUserObject() instanceof Call)){
......@@ -417,7 +430,7 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
name = "C"+ca.getId()+"-"+countChannel;
}
else{ name = "C"+countChannel;}
channel = new Channel( name, (fr.fluxmedia.transmorpher.Graph.Process)currentTransformation );
channel = new Channel( name,currentTransformation );
DefaultGraphCell portOut = (DefaultGraphCell)firstPort.getCell();
DefaultGraphCell portIn = (DefaultGraphCell)port.getCell();
channel.setOut((Port)portOut.getUserObject());
......@@ -425,11 +438,11 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
((Port)portIn.getUserObject()).setChannel(channel);
((Port)portOut.getUserObject()).setChannel(channel);
channel.setName(name);
((Process)currentTransformation).addChannel(channel);
currentTransformation.addChannel(channel);
// Object[] tmp = gt.getSpanningTree(currentProcess,null);
// currentProcess.setSelectionCells(tmp);
// Object[] all = currentProcess.getAll();
// Object[] tmp = gt.getSpanningTree(flowcomposer.getCurrentProcess(),null);
// flowcomposer.getCurrentProcess().setSelectionCells(tmp);
// Object[] all = flowcomposer.getCurrentProcess().getAll();
// if (tmp.length!=all.length)
// System.out.println("le graphe comporte un circuit");
countChannel++;
......@@ -438,7 +451,7 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
public void overlay(Graphics g) {
super.overlay(g);
previewPort(currentProcess.getGraphics());
previewPort(flowcomposer.getCurrentProcess().getGraphics());
if (start != null) {
if ((edgeNormal.isSelected()) && current != null)
g.drawLine(start.x, start.y, current.x, current.y);
......@@ -479,11 +492,11 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
protected void paintPort(Graphics g) {
boolean offset = (GraphConstants.getOffset(port.getAttributes()) != null);
Rectangle r = (offset) ? port.getBounds(): port.getParentView().getBounds();
r = currentProcess.toScreen(new Rectangle(r));
r = flowcomposer.getCurrentProcess().toScreen(new Rectangle(r));
int s = 3;
r.translate(-s, -s);
r.setSize(r.width+2*s, r.height+2*s);
currentProcess.getUI().paintCell(g, port, r, true);
flowcomposer.getCurrentProcess().getUI().paintCell(g, port, r, true);
}
}
......
/**
* $Id: FCProcessFactory.java,v 1.14 2002-07-01 13:11:18 gchomat Exp $
* $Id: FCProcessFactory.java,v 1.15 2002-07-02 13:46:43 gchomat Exp $
*
* Transmorpher
*
......@@ -54,6 +54,8 @@ public class FCProcessFactory implements ProcessFactory,Observer{
protected FlowComposer flowcomposer;
boolean create = true;
public FCProcessFactory( FlowComposer flowcomposer){
this.flowcomposer = flowcomposer;
......@@ -88,12 +90,17 @@ public class FCProcessFactory implements ProcessFactory,Observer{
{
//throw new SingleMainProcessException("single main");
mainProcess.setUserObject(userObject);
//decide if the flowcomposer.createProcess() method must be call
create = false;
}
else{
model = new ProcessGraphModel();
process = new ProcessGraph(model,null,userObject);
mainProcess = process;
listProcess.add(process);
create = true;
}
process = mainProcess;
}
......@@ -114,8 +121,9 @@ public class FCProcessFactory implements ProcessFactory,Observer{
process.update((Process)userObject,((Process)userObject).outPorts().getPort(j));
}
}
listProcess.add(process);
}
listProcess.add(process);
create = true;
}
((Process)userObject).addObserver(process);
......@@ -156,8 +164,6 @@ public class FCProcessFactory implements ProcessFactory,Observer{
}
return null;
}
public boolean validateProcess(Object process){
// not yet implemented
......@@ -180,25 +186,19 @@ public class FCProcessFactory implements ProcessFactory,Observer{
}
return null;
}
}
public List getAllProcess(){
return listProcess;
}
public void generateFileRDF(ReadWrite file) {
file.Writeln("<?xml version=\"1.0\" standalone=\"yes\"?>");
file.Writeln("<rdf:RDF");
file.Writeln(4,"xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns\"");
file.Writeln(4,"xmlns:s=\"http://www.w3.org/2000/01/rdf-schema\">");
Iterator it = getAllProcess().iterator();
Iterator it = getAllProcess().iterator();
while (it.hasNext()) {
Object process = it.next();
((ProcessGraph)process).generateRDF(file);
}
file.Writeln("</rdf:RDF>");
}
public static final Call newCall(String type, Object[] params) {
......@@ -217,9 +217,10 @@ public class FCProcessFactory implements ProcessFactory,Observer{
public void update(Observable observable, Object arg){
System.out.println("update "+ arg);
if(observable instanceof Transmorpher)
{
if(arg instanceof TmAction)
{
TmAction action = (TmAction)arg;
......@@ -244,8 +245,9 @@ public class FCProcessFactory implements ProcessFactory,Observer{
{
return;
}
flowcomposer.createProcess(process);
if(create)
flowcomposer.createProcess(process);
break;
case TmAction.REMOVE :
......
/**
*
*$Id: FlowComposer.java,v 1.59 2002-07-01 13:11:18 gchomat Exp $
*$Id: FlowComposer.java,v 1.60 2002-07-02 13:46:43 gchomat Exp $
*
* Transmorpher
*
......@@ -83,8 +83,6 @@ public class FlowComposer extends JPanel implements GraphModelListener,
//Used only if FlowComposer is an applet
//private boolean inAnApplet = true;
protected ParserRDF parser;
//Process Factory allow to create new Process
protected FCProcessFactory processFactory;
......@@ -97,7 +95,7 @@ public class FlowComposer extends JPanel implements GraphModelListener,
//Array of all Flowcomposer instance
protected static ArrayList instances = new ArrayList();
//The current Process of our Transmorpher.Warning!!! This reference must be sync whith marqueeHandler.currentProcess.
//The current Process of our Transmorpher.
protected ProcessGraph currentProcess;
protected FlowLayout flow;
......@@ -125,7 +123,10 @@ public class FlowComposer extends JPanel implements GraphModelListener,
//The window listener.
protected static FCWindowListener windowListener;
// The current file name
//File
protected File file;
//The current file name
protected String filename;
// Temporary filename
......@@ -261,7 +262,6 @@ public class FlowComposer extends JPanel implements GraphModelListener,
touchLayout = new Layout(currentProcess);
parser = new ParserRDF();
}
public static void init() {
......@@ -339,14 +339,13 @@ public class FlowComposer extends JPanel implements GraphModelListener,
public void stateChanged(ChangeEvent e) {
SingleSelectionModel model = (SingleSelectionModel) e.getSource();
if(model.getSelectedIndex() != -1) {
currentProcess = processFactory.getProcess(tabProcess.getTitleAt(model.getSelectedIndex()));
setCurrentProcess(processFactory.getProcess(tabProcess.getTitleAt(model.getSelectedIndex())));
if(currentProcess== null)
{
System.out.println("currentProcess is null");
}
else
{
marqueeHandler.setCurrentProcess(currentProcess);
touchLayout = new Layout(currentProcess);
update();
}
......@@ -441,6 +440,20 @@ public class FlowComposer extends JPanel implements GraphModelListener,
public Transmorpher getTransmorpher(){
return transmorpher;
}
/**
* Get the value of currentProcess.
* @return value of currentProcess.
*/
public ProcessGraph getCurrentProcess() {return currentProcess;}
/**
* Set the value of currentProcess.
* @param v Value to assign to currentProcess.
*/
public void setCurrentProcess(ProcessGraph v) {this.currentProcess = v;}
/**
* Find the hosting frame, for the file-chooser dialog.
......@@ -474,6 +487,20 @@ public class FlowComposer extends JPanel implements GraphModelListener,
return result;
}
public void generateFileRDF(ReadWrite file) {
if(file != null){
file.Writeln("<?xml version=\"1.0\" standalone=\"yes\"?>");
file.Writeln("<rdf:RDF");
file.Writeln(4,"xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns\"");
file.Writeln(4,"xmlns:s=\"http://www.w3.org/2000/01/rdf-schema\">");
file.Writeln(6,"<rdf:Description about=\""+transmorpher.getName()+"\">");
((FCProcessFactory)processFactory).generateFileRDF(file);
file.Writeln(6,"</rdf:Description>");
file.Writeln(4,"</rdf:RDF>");
}
}
public void newProcess(String name, int type){
Transformation process = null;
......@@ -540,8 +567,7 @@ public class FlowComposer extends JPanel implements GraphModelListener,
sp.setCorner(JScrollPane.LOWER_RIGHT_CORNER,buttonView);
ActionListener buttonListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("ca passe ici");
JDialog overviewDlg = new JDialog(getFrame(),"GeneralView", false);
JDialog overviewDlg = new JDialog(getFrame(),"GeneralView", false);
Container fContentPane = overviewDlg.getContentPane();
fContentPane.setLayout(new BorderLayout());
FCOverviewPanel overviewPanel = new FCOverviewPanel(currentProcess);
......@@ -1027,8 +1053,6 @@ public class FlowComposer extends JPanel implements GraphModelListener,
}
//
// Listeners
//
......@@ -1069,16 +1093,17 @@ public class FlowComposer extends JPanel implements GraphModelListener,
//not yet implemented
return true;
}
//Component Listener
public void componentHidden(ComponentEvent e) { }
public void componentMoved(ComponentEvent e) { }
public void componentResized(ComponentEvent e) {
viewPortRect = sp.getViewport().getBounds();
List processList = processFactory.getAllProcess();
java.util.Iterator it = processList.iterator();
viewPortRect = sp.getViewport().getBounds();
List processList = processFactory.getAllProcess();
java.util.Iterator it = processList.iterator();
while (it.hasNext()) {
ProcessGraph process = (ProcessGraph)it.next();
Rectangle processRect = process.getBounds();
......@@ -1181,14 +1206,12 @@ public class FlowComposer extends JPanel implements GraphModelListener,
undoAction.update();
redoAction.update();
}
public void setProcess(ProcessGraph process){
this.process = process;
public void setProcess(ProcessGraph process){
this.process = process;
}
public ProcessGraph getProcess(){
return process;
}
......@@ -1262,7 +1285,7 @@ public class FlowComposer extends JPanel implements GraphModelListener,
JFileChooser f = new JFileChooser();
f.setDialogType(mode);
int returnVal = f.showOpenDialog(this);
int returnVal = (mode ==JFileChooser.OPEN_DIALOG)? f.showOpenDialog(this) :f.showSaveDialog(this) ;
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = f.getSelectedFile();
......@@ -1627,9 +1650,6 @@ public class FlowComposer extends JPanel implements GraphModelListener,
}
class CloseAction extends AbstractAction {
CloseAction() {
......@@ -1744,10 +1764,13 @@ public class FlowComposer extends JPanel implements GraphModelListener,
}
else
{
ProcessParser parser = new ProcessParser(2,new Object[]{processFactory});
transmorpher = parser.Newparse(file.getAbsolutePath());
ProcessParser processParser = new ProcessParser(2,new Object[]{processFactory});
transmorpher = processParser.Newparse(file.getAbsolutePath());
processFactory.createAllChannels();
setTitle(file.getAbsolutePath());
filename = file.getAbsolutePath();
setTitle(filename);
ParserRDF rdfParser = new ParserRDF(processFactory);
rdfParser.newParse(filename.substring(0,filename.lastIndexOf('.'))+".rdf");
editing = true;
}
}
......@@ -1971,24 +1994,29 @@ public class FlowComposer extends JPanel implements GraphModelListener,
PrintStream out = System.out;
String directory = new File(filename).getParentFile().getAbsolutePath();
try{
out = new PrintStream(new BufferedOutputStream(new FileOutputStream(filename)));
}
catch(FileNotFoundException ex)
{
System.out.println("file not found "+ filename);
return;
}
System.setOut(out);
System.setErr(out);
transmorpher.generateXML();
out.close();
//generating RDF
ReadWrite file = new ReadWrite(transmorpher.getName()+".rdf",ReadWrite.WRITE);
((FCProcessFactory)processFactory).generateFileRDF(file);
ReadWrite file = new ReadWrite(directory+""+File.separator+""+transmorpher.getName()+".rdf",ReadWrite.WRITE);
generateFileRDF(file);
file.Close();
//parser.newParse(file.getName());
//parser.print();
}
}
......
......@@ -9,7 +9,6 @@
package fr.fluxmedia.flowcomposer;
// Imported SAX Classes
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXException ;
......@@ -20,33 +19,52 @@ import org.xml.sax.helpers.XMLFilterImpl;
import java.util.*;
import java.io.*;
import java.util.Stack ;
import java.lang.Integer;
import java.awt.Point;
public class ParserRDF extends DefaultHandler {
/** The XML Parser class */
private static final String
protected static final String
DEFAULT_PARSER_NAME = "org.apache.xerces.parsers.SAXParser";
private static final int DEFAULT=0;
private static final int COLOR=1;
private static final int X=2;
private static final int Y=3;
private int mode = DEFAULT;
protected static final int DEFAULT=0;
protected static final int PROCESS=1;
protected static final int COMPONENT=2;
protected static final int CHANNEL=3;
protected int mode = DEFAULT;
protected static final int COLOR=0;
protected static final int X=1;
protected static final int Y=2;
protected static final int NO = -1;
protected int parameter = NO;
protected int x = -1;
protected int y = -1;
public Vector process = new Vector();
/** XML Parser */
javax.xml.parsers.SAXParser iParser = null;
public FCProcessFactory processFactory;
public ProcessGraph currentProcess;
public FCGraphCell currentCall;
public Object currentChannel ;
/** XML Parser */
javax.xml.parsers.SAXParser iParser = null;
/*------------------------------------------ CONSTRUCTOR -----------------------------*/
/** The constructor, build the XML Parser but not parse the document */
public ParserRDF() {
try {
public ParserRDF(FCProcessFactory factory) {
processFactory = factory;