Commit 6417ac50 authored by Guillaume Chomat's avatar Guillaume Chomat
Browse files

finish to implement the observer observable model

parent 6f4f4e65
Manifest-Version: 1.0
Created-By: 1.4.0 (Sun Microsystems Inc.)
Class-Path: flowcomposer.jar jgraph.jar transmo.jar
Class-Path: flowcomposer.jar jgraph.jar transmo.jar sax2.jar
Main-Class: fr.fluxmedia.flowcomposer.FCRun
/**
* $Id: ApplyExternalCell.java,v 1.5 2002-06-13 12:04:50 gchomat Exp $
* $Id: ApplyExternalCell.java,v 1.6 2002-06-25 08:23:39 gchomat Exp $
*
* Transmorpher
*
......@@ -39,11 +39,11 @@ public class ApplyExternalCell extends FCGraphCell {
public ApplyExternalCell(Object userObject,ProcessGraph process) {
super(userObject,process);
if(userObject instanceof Call && ((Call)userObject).getType().equals("xslt"))
/* if(userObject instanceof Call && ((Call)userObject).getType().equals("xslt"))
{
newPort(FCConstants.PORTOUTPUT);
newPort(FCConstants.PORTINPUT);
}
}*/
}
public void update(Observable o, Object arg){
......
/**
* $Id: DispatchCell.java,v 1.5 2002-06-13 12:04:50 gchomat Exp $
* $Id: DispatchCell.java,v 1.6 2002-06-25 08:23:39 gchomat Exp $
*
* Transmorpher
*
......@@ -37,7 +37,7 @@ public class DispatchCell extends FCGraphCell{
public DispatchCell(Object userObject,ProcessGraph process) {
super(userObject,process);
newPort(FCConstants.PORTINPUT);
// newPort(FCConstants.PORTINPUT);
}
......
/**
* $Id: FCGraphCell.java,v 1.4 2002-06-18 15:04:14 gchomat Exp $
* $Id: FCGraphCell.java,v 1.5 2002-06-25 08:23:39 gchomat Exp $
*
* Transmorpher
*
......@@ -57,8 +57,18 @@ public class FCGraphCell extends DefaultGraphCell implements Observer{
super(userObject);
this.process = process;
if(userObject instanceof CallImpl)
((CallImpl)userObject).addObserver(this);
if(userObject instanceof CallImpl){
CallImpl call = (CallImpl)userObject;
call.addObserver(this);
for(int i =0; i < call.inPorts().length();i++)
{
createPort(call.inPorts().getPort(i));
}
for(int j =0; j < call.outPorts().length();j++)
{
createPort(call.outPorts().getPort(j));
}
}
}
public String getId(){
......@@ -114,29 +124,32 @@ public class FCGraphCell extends DefaultGraphCell implements Observer{
{
if(process != null)
{
PortCell pc = new PortCell((Port)arg,((Port)arg).getType());
Map map = GraphConstants.createMap();
int u = GraphConstants.PERCENT;
GraphConstants.setOffset(map, new Point((int)(u/2),(int)(u/2)));
ParentMap parent = new ParentMap();
parent.addEntry(pc,this);
//System.out.println("cell "+ this);
Map viewMap = new Hashtable();
viewMap.put(pc,map);
process.getModel().insert(new Object[]{pc},null,parent,viewMap);
process.updatePort(this,((Port)arg).getType());
createPort(arg);
}
}
}
}
private void createPort(Object port){
PortCell pc = new PortCell((Port)port,((Port)port).getType());
Map map = GraphConstants.createMap();
int u = GraphConstants.PERCENT;
GraphConstants.setOffset(map, new Point((int)(u/2),(int)(u/2)));
ParentMap parent = new ParentMap();
parent.addEntry(pc,this);
//System.out.println("cell "+ this);
Map viewMap = new Hashtable();
viewMap.put(pc,map);
process.getModel().insert(new Object[]{pc},null,parent,viewMap);
process.updatePort(this,((Port)port).getType());
}
}
/**
*
*$Id: FCGraphUI.java,v 1.5 2002-06-25 08:23:39 gchomat Exp $
*
* Transmorpher
*
* Copyright (C) 2002 Fluxmedia and INRIA Rhne-Alpes.
*
* http://www.fluxmedia.fr - http://transmorpher.inrialpes.fr
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
*
*
* @version 1.0 29/01/01
* @author Chomat/Saint-Marcel
*/
package fr.fluxmedia.flowcomposer;
import java.io.*;
......
/**
* $Id: FCMarqueeHandler.java,v 1.36 2002-06-18 15:04:14 gchomat Exp $
* $Id: FCMarqueeHandler.java,v 1.37 2002-06-25 08:23:39 gchomat Exp $
*
* Transmorpher
......@@ -118,9 +118,6 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
return port;
}
/* Return true if this handler should be preferred over other handlers. */
public boolean isForceMarqueeEvent(MouseEvent e) {
return !marquee.isSelected() || super.isForceMarqueeEvent(e);
......@@ -185,7 +182,7 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
overlay(g);
event.consume();
}
else System.out.println("ta mere en slip");
else {}
}
......@@ -207,29 +204,38 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
if (merge.isSelected())
{
call = new Merge(FCConstants.NMERGE+"-"+count,(String)FCConstants.MERGETYPE[0],currentTransformation);
currentTransformation.addCall(call);
call.outPorts().setPort(0, new Port("", call, 0 ,Port.OUTPUT));
currentTransformation.addCall(call);
}
else if (generate.isSelected())
{
call = new Generate(FCConstants.NGENERATE+"-"+count,(String)FCConstants.GENERATETYPE[0],"",currentTransformation);
currentTransformation.addCall(call);
call.outPorts().setPort(0, new Port("", call, 0 ,Port.OUTPUT));
currentTransformation.addCall(call);
///dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.GENERATE);
}
else if (serialize.isSelected())
{
call = new Serialize(FCConstants.NSERIALIZE+"-"+count,(String)FCConstants.SERIALIZETYPE[0],"",currentTransformation);
currentTransformation.addCall(call);
call.inPorts().setPort(0, new Port("", call, 0 ,Port.INPUT));
currentTransformation.addCall(call);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.SERIALIZE);
}
else if (dispatch.isSelected())
{
call = new Dispatch(FCConstants.NDISPATCH+"-"+count,(String)FCConstants.DISPATCHTYPE[0],currentTransformation);
currentTransformation.addCall(call);
call.inPorts().setPort(0, new Port("", call, 0 ,Port.INPUT));
currentTransformation.addCall(call);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.DISPATCH);
}
else if (applyExternal.isSelected())
{
call = new ApplyExternal(FCConstants.NAPPLYEXTERNAL+"-"+count,(String)FCConstants.APPLYEXTERNALTYPE[0],"",currentTransformation);
if(((String)FCConstants.APPLYEXTERNALTYPE[0]).equals("xslt")){
call.inPorts().setPort(0, new Port("", call, 0 ,Port.INPUT));
call.outPorts().setPort(0, new Port("", call, 0 ,Port.OUTPUT));
}
currentTransformation.addCall(call);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.APPLYEXTERNAL);
}
......@@ -242,13 +248,17 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
else if (applyRuleset.isSelected())
{
call = new ApplyRuleset(FCConstants.NAPPLYRULESET+"-"+count,"",currentTransformation);
currentTransformation.addCall(call);
call.inPorts().setPort(0, new Port("", call, 0 ,Port.INPUT));
call.outPorts().setPort(0, new Port("", call, 0 ,Port.OUTPUT));
currentTransformation.addCall(call);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.APPLYRULESET);
}
else if (applyQuery.isSelected())
{
call = new ApplyQuery(FCConstants.NAPPLYQUERY+"-"+count,(String)FCConstants.APPLYQUERYTYPE[0],currentTransformation);
currentTransformation.addCall(call);
call.inPorts().setPort(0, new Port("", call, 0 ,Port.INPUT));
call.outPorts().setPort(0, new Port("", call, 0 ,Port.OUTPUT));
currentTransformation.addCall(call);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),(ProcessGraph)currentProcess,null,start,FCConstants.APPLYQUERY);}
}
else if (edgeNormal.isSelected())
......
/**
* $Id: FCProcessFactory.java,v 1.11 2002-06-18 15:04:14 gchomat Exp $
* $Id: FCProcessFactory.java,v 1.12 2002-06-25 08:23:39 gchomat Exp $
*
* Transmorpher
*
......@@ -56,12 +56,12 @@ public class FCProcessFactory implements ProcessFactory,Observer{
public FCProcessFactory( FlowComposer flowcomposer){
this.flowcomposer = flowcomposer;
mainProcess = null;
listProcess = new ArrayList();
listType = new Hashtable();
initFactory();
}
public void initFactory(){
listType.put("broadcast", (Object)"fr.fluxmedia.transmorpher.Graph.Dispatch");
listType.put("concat", (Object)"fr.fluxmedia.transmorpher.Graph.Merge");
......@@ -91,6 +91,19 @@ public class FCProcessFactory implements ProcessFactory,Observer{
}
if(userObject instanceof Process){
for(int i =0; i < ((Process)userObject).inPorts().length();i++)
{
process.update((Process)userObject,((Process)userObject).inPorts().getPort(i));
}
for(int j =0; j < ((Process)userObject).outPorts().length();j++)
{
process.update((Process)userObject,((Process)userObject).outPorts().getPort(j));
}
}
listProcess.add(process);
((Process)userObject).addObserver(process);
......@@ -98,7 +111,39 @@ public class FCProcessFactory implements ProcessFactory,Observer{
}
else return null;
}
public void createAllChannels(){
Iterator it = listProcess.iterator();
while(it.hasNext())
createChannel((Process)((ProcessGraph)it.next()).getUserObject());
}
public void createChannel(Process transformation){
ProcessGraph processGraph = getProcessGraph(transformation);
Enumeration channels = transformation.getChannels();
while(channels.hasMoreElements())
processGraph.update(transformation,channels.nextElement());
}
public ProcessGraph getProcessGraph(Object userObject){
Iterator it = listProcess.iterator();
while(it.hasNext()){
Object process = it.next();
if(process instanceof ProcessGraph && ((ProcessGraph)process).getUserObject().equals(userObject))
return (ProcessGraph)process;
}
return null;
}
public boolean validateProcess(Object process){
// not yet implemented
return true;
......@@ -161,6 +206,8 @@ public class FCProcessFactory implements ProcessFactory,Observer{
{
if(arg instanceof Process)
{
System.out.println("arg "+ arg);
ProcessGraph process ;
try{
......
/**
*
*$Id: FlowComposer.java,v 1.51 2002-06-18 15:04:14 gchomat Exp $
*$Id: FlowComposer.java,v 1.52 2002-06-25 08:23:39 gchomat Exp $
*
* Transmorpher
*
......@@ -42,6 +42,7 @@ import com.jgraph.event.*;
import fr.fluxmedia.transmorpher.Graph.*;
import fr.fluxmedia.transmorpher.Utils.*;
import fr.fluxmedia.transmorpher.Files.*;
import fr.fluxmedia.transmorpher.Parser.ProcessParser;
import java.awt.*;
import java.beans.*;
......@@ -106,7 +107,7 @@ public class FlowComposer extends JPanel implements GraphModelListener,
protected JMenuBar menubar;
// for represent the process notion we dacide to use a tabbed Pane
protected JTabbedPane tabProcess;
protected JTabbedPane tabProcess = new JTabbedPane();
// External resource
protected static ResourceBundle resource;
......@@ -133,6 +134,9 @@ public class FlowComposer extends JPanel implements GraphModelListener,
protected JPopupMenu popupMenu;
protected static boolean isMetric = true;
boolean init_main = true;
/**Default width of the app*/
public static final int PREFERRED_WIDTH =640;
......@@ -200,7 +204,6 @@ public class FlowComposer extends JPanel implements GraphModelListener,
public static final String tipSuffix = "Tooltip";
static {
windowListener = new FCWindowListener();
try {
resource = ResourceBundle.getBundle("resources/FlowComposer_fr",
Locale.getDefault());
......@@ -230,6 +233,8 @@ public class FlowComposer extends JPanel implements GraphModelListener,
System.err.println("Error loading L&F: " + exc);
}
marqueeHandler = new FCMarqueeHandler(this);
// init the transmorpher and processFactory.
initTransmorpher();
......@@ -237,9 +242,9 @@ public class FlowComposer extends JPanel implements GraphModelListener,
initGUI();
//init the Main Process.
initMainProcess();
if(init_main)
initMainProcess();
parser = new ParserRDF();
......@@ -251,13 +256,22 @@ public class FlowComposer extends JPanel implements GraphModelListener,
protected void initTransmorpher(){
transmorpher = new Transmorpher(filename,resource.getString("TRANSMORPHER_VERSION"),0,false);
processFactory = new FCProcessFactory(this);
//proccess Factory listen transmorpher modification.
transmorpher.addObserver(processFactory);
if(filename != null)
{
init_main = false;
ProcessParser parser = new ProcessParser(2,new Object[]{processFactory});
transmorpher = parser.Newparse(filename);
processFactory.createAllChannels();
}
else
{
filename = "Untitled-"+ Integer.toString(instances.size()+1);
transmorpher = new Transmorpher(filename,resource.getString("TRANSMORPHER_VERSION"),0,false);
//proccess Factory listen transmorpher modification.
transmorpher.addObserver(processFactory);
}
}
protected void initGUI(){
......@@ -287,8 +301,6 @@ public class FlowComposer extends JPanel implements GraphModelListener,
}
marqueeHandler = new FCMarqueeHandler(this);
buttons = createButtons();
//createSpecialButtons();
// Add a ToolBar
......@@ -300,8 +312,8 @@ public class FlowComposer extends JPanel implements GraphModelListener,
Border etched = BorderFactory.createRaisedBevelBorder();
center.setBorder(etched);
//Add a JTabbedPane for represnting the process notion.
tabProcess= new JTabbedPane();
//tabProcess= new JTabbedPane();
tabProcess.getModel().addChangeListener(
new ChangeListener() {
......@@ -322,7 +334,7 @@ public class FlowComposer extends JPanel implements GraphModelListener,
}
}
}
}
);
......@@ -338,9 +350,7 @@ public class FlowComposer extends JPanel implements GraphModelListener,
}
protected void initMainProcess(){
newProcess("Main",MAIN);
}
......@@ -364,23 +374,23 @@ public class FlowComposer extends JPanel implements GraphModelListener,
JFrame frame = new JFrame();
frame.addWindowListener(windowListener);
FlowComposer flowComposer = createInstance(filename,null);
frame.setContentPane(flowComposer);
FlowComposer flowComposer = createInstance(filename,model);
instances.add(flowComposer);
frame.setContentPane(flowComposer);
frame.setTitle(title +" "+ version + " -- " + flowComposer.getFileName());
frame.pack();
frame.addWindowListener(flowComposer.createCloser());
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation(
screenSize.width/2 - frame.getSize().width/2 + instances.size()*10,
screenSize.height/2 - frame.getSize().height/2+ instances.size()*10);
frame.show();
instances.add(flowComposer);
return flowComposer;
}
......@@ -402,10 +412,20 @@ public class FlowComposer extends JPanel implements GraphModelListener,
public static FlowComposer createInstance(String filename, GraphModel model)
{
if(filename == null)
return new FlowComposer("Untitled-"+ Integer.toString(instances.size()+1), model);
else
return new FlowComposer(filename, model);
//return new FlowComposer("Untitled-"+ Integer.toString(instances.size()+1), model);
return new FlowComposer(filename, model);
}
/**
* Find the hosting frame, for the file-chooser dialog.
*/
public Frame getFrame() {
for (Container p = getParent(); p != null; p = p.getParent()) {
if (p instanceof Frame) {
return (Frame) p;
}
}
return null;
}
......@@ -434,18 +454,16 @@ public class FlowComposer extends JPanel implements GraphModelListener,
{
process = new fr.fluxmedia.transmorpher.Graph.Main(name,transmorpher);
transmorpher.setMain((MainProcess)process);
}
transmorpher.addTransformation(name,process);
}
break;
case PROCESS:
process = new fr.fluxmedia.transmorpher.Graph.Process(name,transmorpher);
transmorpher.addTransformation(name,process);
break;
}
/*
*/
}
......@@ -456,26 +474,29 @@ public class FlowComposer extends JPanel implements GraphModelListener,
currentProcess = (ProcessGraph)process;
if(tabProcess != null )
{
currentProcess.setMarqueeHandler(marqueeHandler);
undoHandler = new UndoHandler();
registerListeners(currentProcess);
currentProcess.getModel().addUndoableEditListener(undoHandler);
sp = new JScrollPane(currentProcess,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
sp = (JScrollPane)(tabProcess.add(currentProcess.getName(),sp));
tabProcess.setSelectedComponent(sp);
currentProcess = (ProcessGraph)(sp.getViewport().getView());
undoHandler.setProcess(currentProcess);
}
{
if(marqueeHandler == null)
marqueeHandler = new FCMarqueeHandler(this);
currentProcess.setMarqueeHandler(marqueeHandler);
undoHandler = new UndoHandler();
registerListeners(currentProcess);
currentProcess.getModel().addUndoableEditListener(undoHandler);
sp = new JScrollPane(currentProcess,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
sp = (JScrollPane)(tabProcess.add(currentProcess.getName(),sp));
tabProcess.setSelectedComponent(sp);
currentProcess = (ProcessGraph)(sp.getViewport().getView());
undoHandler.setProcess(currentProcess);
}
else
{
System.out.println("The process is not added. Mode multi fentre not yet implemented");
}
{
System.out.println("The process is not added. Mode multi fentre not yet implemented");
}
}
......@@ -682,7 +703,6 @@ public class FlowComposer extends JPanel implements GraphModelListener,
return b;
}
public JPopupMenu createPopupMenu(String popup){
popupMenu = new JPopupMenu();