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

implemented model observer/observable with TmAction

parent 30fdd0de
/**
* $Id: FCGraphCell.java,v 1.6 2002-06-28 15:29:31 frederic Exp $
* $Id: FCGraphCell.java,v 1.7 2002-07-01 13:11:18 gchomat Exp $
*
* Transmorpher
*
......@@ -46,6 +46,8 @@ import com.jgraph.graph.*;
import fr.fluxmedia.transmorpher.Graph.Call;
import fr.fluxmedia.transmorpher.Graph.CallImpl;
import fr.fluxmedia.transmorpher.Graph.Port;
import fr.fluxmedia.transmorpher.action.TmAction;
public class FCGraphCell extends DefaultGraphCell implements Observer{
......@@ -56,19 +58,13 @@ public class FCGraphCell extends DefaultGraphCell implements Observer{
public FCGraphCell(Object userObject, ProcessGraph process){
super(userObject);
this.process = process;
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));
}
createPorts();
}
}
public String getId(){
......@@ -91,7 +87,7 @@ public class FCGraphCell extends DefaultGraphCell implements Observer{
public void newPort(int type){
if(userObject != null && userObject instanceof CallImpl)
{
CallImpl call = (CallImpl)userObject;
......@@ -99,7 +95,7 @@ public class FCGraphCell extends DefaultGraphCell implements Observer{
int number;
if(type == FCConstants.PORTOUTPUT)
{
{
number = call.outPorts().length();
port= new Port("",call,number,FCConstants.PORTOUTPUT);
call.addOut(port);
......@@ -116,23 +112,53 @@ public class FCGraphCell extends DefaultGraphCell implements Observer{
public void update(Observable obs, Object arg)
{
if(obs instanceof Call)
{
if(arg instanceof Port)
System.out.println("arg " +arg);
if(arg instanceof TmAction)
{
if(process != null)
TmAction action = (TmAction)arg;
switch(action.getType())
{
createPort(arg);
case TmAction.ADD :
if(action.getTarget() instanceof Port)
if(process != null)
{
createPort(((TmAction)arg).getTarget());
}
break;
case TmAction.REMOVE :
break;
case TmAction.MODIFY :
break;
}
}
}
}
public void createPorts(){
CallImpl call = (CallImpl)userObject;
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));
}
}
private void createPort(Object port){
PortCell pc = new PortCell((Port)port,((Port)port).getType());
Map map = GraphConstants.createMap();
......@@ -142,14 +168,16 @@ public class FCGraphCell extends DefaultGraphCell implements Observer{
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());
//System.out.println("fin port");
}
}
/**
*
*$Id: FCGraphUI.java,v 1.7 2002-06-28 15:29:31 frederic Exp $
*$Id: FCGraphUI.java,v 1.8 2002-07-01 13:11:18 gchomat Exp $
*
* Transmorpher
*
......@@ -169,30 +169,30 @@ public class FCGraphUI extends BasicGraphUI{
*/
public class FCMouseHandler extends BasicGraphUI.MouseHandler
{
/**
* Invoked when a mouse button has been pressed on a component.
*/
public void mousePressed(MouseEvent e) {
if(e.isPopupTrigger())
{
if (marquee!= null)
marquee.mousePressed(e);
super.mousePressed(e);
}
else if(e.getButton() == MouseEvent.BUTTON3 ){
if (marquee!= null)
marquee.mousePressed(e);
super.mousePressed(e);
}
else
super.mousePressed(e);
}
public void mouseDragged(MouseEvent e) {
/**
* Invoked when a mouse button has been pressed on a component.
*/
public void mousePressed(MouseEvent e) {
// System.out.println("e "+e.getButton());
if(e.isPopupTrigger())
{
if (marquee!= null)
marquee.mousePressed(e);
super.mousePressed(e);
}
/*else if(e.getButton() == MouseEvent.BUTTON3 ){
//System.out.println("marquee "+marquee);
if (marquee!= null)
marquee.mousePressed(e);
super.mousePressed(e);
}*/
else
super.mousePressed(e);
}
public void mouseDragged(MouseEvent e) {
try {
autoscroll(graph, e.getPoint());
if (handler == marquee)
......
/**
* $Id: FCMarqueeHandler.java,v 1.39 2002-06-28 15:29:31 frederic Exp $
* $Id: FCMarqueeHandler.java,v 1.40 2002-07-01 13:11:18 gchomat Exp $
*
* Transmorpher
......@@ -81,10 +81,8 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
protected Point start, current;
protected Object beginCell, endCell;
int count = 0;
int countMerge,countGenerate,countSerialize,countDispatch, countAE,countAQ,countAR,countAP,countChannel = 0;
public FCMarqueeHandler(FlowComposer flowcomposer){
this.flowcomposer = flowcomposer;
gt = new FCGraphTools();
......@@ -99,13 +97,13 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
}
}
public void update() {
if (currentProcess.canConnect())
edgeNormal.setEnabled(true);
else edgeNormal.setEnabled(false);
}
public void update() {
if (currentProcess.canConnect())
edgeNormal.setEnabled(true);
else edgeNormal.setEnabled(false);
}
public JGraph getCurrentProcess(){
return currentProcess;
}
......@@ -126,6 +124,26 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
return port;
}
public String getTrueName(String name,int count){
Enumeration e = currentTransformation.getCalls().getKeys();
String trueName = name+"-"+count;
while(e.hasMoreElements()){
String tmpName = (String)e.nextElement();
if(tmpName.equals(trueName))
{
count++;
trueName = getTrueName(name,count);
}
}
return trueName;
}
/* Return true if this handler should be preferred over other handlers. */
public boolean isForceMarqueeEvent(MouseEvent e) {
return !marquee.isSelected() || super.isForceMarqueeEvent(e);
......@@ -137,26 +155,27 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
if(e.isPopupTrigger())
{
if (!e.isConsumed() && marquee.isSelected()) {
current = currentProcess.snap(e.getPoint());
flowcomposer.showPopup(e);
return;
}
}
else if(e.getButton() == MouseEvent.BUTTON3)
{
current = currentProcess.snap(e.getPoint());
flowcomposer.showPopup(e);
return;
}
}
/* else if(e.getButton() == MouseEvent.BUTTON3)
{
current = currentProcess.snap(e.getPoint());
flowcomposer.showPopup(e);
return;
}*/
else{
if(currentProcess != null){
if (!e.isConsumed() && !marquee.isSelected()) {
start = currentProcess.snap(e.getPoint());
firstPort = port;
if ((edgeNormal.isSelected())&&(firstPort != null)) {
double scale = currentProcess.getScale();
start = firstPort.getLocation(null);
......@@ -164,7 +183,7 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
}
e.consume();
}
}
}
......@@ -209,7 +228,7 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
Call call;
current = currentProcess.snap(event.getPoint());
String tmpName,name;
if(currentProcess != null){
//endCell= currentProcess.getFirstCellForLocation(event.getX(), event.getY());
......@@ -218,63 +237,102 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
if (merge.isSelected())
{
call = new Merge(FCConstants.NMERGE+"-"+count,(String)FCConstants.MERGETYPE[0],currentTransformation);
tmpName = FCConstants.NMERGE;
name = getTrueName(tmpName,countMerge);
call = new Merge(name,(String)FCConstants.MERGETYPE[0],currentTransformation);
call.outPorts().setPort(0, new Port("", call, 0 ,Port.OUTPUT));
currentTransformation.addCall(call);
flowcomposer.setEditing(true);
countMerge++;
}
else if (generate.isSelected())
{
call = new Generate(FCConstants.NGENERATE+"-"+count,(String)FCConstants.GENERATETYPE[0],"",currentTransformation);
call.outPorts().setPort(0, new Port("", call, 0 ,Port.OUTPUT));
currentTransformation.addCall(call);
///dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.GENERATE);
}
{
tmpName = FCConstants.NGENERATE;
name = getTrueName(tmpName,countGenerate);
call = new Generate(name,(String)FCConstants.GENERATETYPE[0],"",currentTransformation);
call.outPorts().setPort(0, new Port("", call, 0 ,Port.OUTPUT));
currentTransformation.addCall(call);
flowcomposer.setEditing(true);
countGenerate++;
///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);
call.inPorts().setPort(0, new Port("", call, 0 ,Port.INPUT));
currentTransformation.addCall(call);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.SERIALIZE);
{
tmpName = FCConstants.NSERIALIZE;
name = getTrueName(tmpName,countSerialize);
call = new Serialize(name,(String)FCConstants.SERIALIZETYPE[0],"",currentTransformation);
call.inPorts().setPort(0, new Port("", call, 0 ,Port.INPUT));
currentTransformation.addCall(call);
flowcomposer.setEditing(true);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.SERIALIZE);
countSerialize++;
}
else if (dispatch.isSelected())
{
call = new Dispatch(FCConstants.NDISPATCH+"-"+count,(String)FCConstants.DISPATCHTYPE[0],currentTransformation);
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")){
{
tmpName = FCConstants.NDISPATCH;
name = getTrueName(tmpName,countDispatch);
call = new Dispatch(name,(String)FCConstants.DISPATCHTYPE[0],currentTransformation);
call.inPorts().setPort(0, new Port("", call, 0 ,Port.INPUT));
call.outPorts().setPort(0, new Port("", call, 0 ,Port.OUTPUT));
currentTransformation.addCall(call);
flowcomposer.setEditing(true);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.DISPATCH);
countDispatch++;
}
else if (applyExternal.isSelected())
{
tmpName = FCConstants.NAPPLYEXTERNAL;
name = getTrueName(tmpName,countAE);
call = new ApplyExternal(name,(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);
flowcomposer.setEditing(true);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.APPLYEXTERNAL);
countAE++;
}
currentTransformation.addCall(call);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.APPLYEXTERNAL);
}
else if (applyProcess.isSelected())
{
call = new ApplyProcess(FCConstants.NAPPLYPROCESS+"-"+count,"",currentTransformation,"");
currentTransformation.addCall(call);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.APPLYPROCESS);
}
{
tmpName = FCConstants.NAPPLYPROCESS;
name = getTrueName(tmpName,countAP);
call = new ApplyProcess(name,"",currentTransformation,"");
currentTransformation.addCall(call);
flowcomposer.setEditing(true);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.APPLYPROCESS);
countAP++;
}
else if (applyRuleset.isSelected())
{
call = new ApplyRuleset(FCConstants.NAPPLYRULESET+"-"+count,"",currentTransformation);
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);
}
{
tmpName = FCConstants.NAPPLYRULESET;
name = getTrueName(tmpName,countAR);
call = new ApplyRuleset(name,"",currentTransformation,"");
call.inPorts().setPort(0, new Port("", call, 0 ,Port.INPUT));
call.outPorts().setPort(0, new Port("", call, 0 ,Port.OUTPUT));
currentTransformation.addCall(call);
flowcomposer.setEditing(true);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.APPLYRULESET);
countAR++;
}
else if (applyQuery.isSelected())
{
call = new ApplyQuery(FCConstants.NAPPLYQUERY+"-"+count,(String)FCConstants.APPLYQUERYTYPE[0],currentTransformation);
tmpName = FCConstants.NAPPLYQUERY;
name = getTrueName(tmpName,countAQ);
call = new ApplyQuery(name,(String)FCConstants.APPLYQUERYTYPE[0],currentTransformation,"");
call.inPorts().setPort(0, new Port("", call, 0 ,Port.INPUT));
call.outPorts().setPort(0, new Port("", call, 0 ,Port.OUTPUT));
currentTransformation.addCall(call);
flowcomposer.setEditing(true);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),(ProcessGraph)currentProcess,null,start,FCConstants.APPLYQUERY);}
countAQ++;
}
else if (edgeNormal.isSelected())
{
......@@ -304,8 +362,7 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
}
}
count++;
marquee.doClick();
marquee.doClick();
firstPort = null;
port = null;
start = null;
......@@ -315,8 +372,6 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
//System.out.println("MouseReleased End...");
}
public void mouseMoved(MouseEvent event) {
//System.out.println("currentProcess " + currentProcess);
if(currentProcess!=null){
......@@ -359,10 +414,9 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
String name;
if((c!=null)&&(c.getUserObject() instanceof Call)){
Call ca = (Call)(c.getUserObject());
name = "C"+ca.getId()+"-"+count;
name = "C"+ca.getId()+"-"+countChannel;
}
else{ name = "C"+count;}
count++;
else{ name = "C"+countChannel;}
channel = new Channel( name, (fr.fluxmedia.transmorpher.Graph.Process)currentTransformation );
DefaultGraphCell portOut = (DefaultGraphCell)firstPort.getCell();
DefaultGraphCell portIn = (DefaultGraphCell)port.getCell();
......@@ -378,15 +432,10 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
// Object[] all = currentProcess.getAll();
// if (tmp.length!=all.length)
// System.out.println("le graphe comporte un circuit");
countChannel++;
}
public void overlay(Graphics g) {
super.overlay(g);
previewPort(currentProcess.getGraphics());
......@@ -437,8 +486,5 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
currentProcess.getUI().paintCell(g, port, r, true);
}
}
......@@ -47,7 +47,7 @@ public class FCPortRenderer extends PortRenderer {
int offset = ( GraphConstants.getOffset(attr) != null ) ? 0 : 1;
g.setXORMode(graph.getBackground());
g.setColor(Color.GREEN);
g.setColor(Color.green);
//g.setColor(getBackground());
g.drawRect(0, 0, d.width - offset, d.height - offset);
......
/**
* $Id: FCProcessFactory.java,v 1.13 2002-06-28 15:29:31 frederic Exp $
* $Id: FCProcessFactory.java,v 1.14 2002-07-01 13:11:18 gchomat Exp $
*
* Transmorpher
*
......@@ -39,6 +39,7 @@ import com.jgraph.graph.*;
import fr.fluxmedia.transmorpher.Files.*;
import fr.fluxmedia.transmorpher.Graph.*;
import fr.fluxmedia.transmorpher.Graph.Process;
import fr.fluxmedia.transmorpher.action.*;
public class FCProcessFactory implements ProcessFactory,Observer{
......@@ -75,38 +76,52 @@ public class FCProcessFactory implements ProcessFactory,Observer{
public ProcessGraph createProcess(Object userObject) throws FCException{
ProcessGraph process = null;
GraphModel model = null;
if(userObject != null)
{
GraphModel model = new ProcessGraphModel();
ProcessGraph process = new ProcessGraph(model,null,userObject);
if(userObject instanceof MainProcess)
{
if( mainProcess != null)
{
throw new SingleMainProcessException("single main");
//throw new SingleMainProcessException("single main");
mainProcess.setUserObject(userObject);
}
else
mainProcess = process;
}
if(userObject instanceof Process){
for(int i =0; i < ((Process)userObject).inPorts().length();i++)
{
process.update((Process)userObject,((Process)userObject).inPorts().getPort(i));
else{
model = new ProcessGraphModel();
process = new ProcessGraph(model,null,userObject);
mainProcess = process;
listProcess.add(process);
}
for(int j =0; j < ((Process)userObject).outPorts().length();j++)
{
process.update((Process)userObject,((Process)userObject).outPorts().getPort(j));
process = mainProcess;
}
else
{