Commit 3c8ce10a authored by Guillaume Chomat's avatar Guillaume Chomat
Browse files

implemented the observer/observable model

parent d55201f7
/**
* $Id: FCMarqueeHandler.java,v 1.24 2002-06-10 10:58:40 frederic Exp $
* $Id: FCMarqueeHandler.java,v 1.25 2002-06-10 11:36:52 gchomat Exp $
*
* Transmorpher
*
......@@ -80,6 +80,8 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
protected Point start, current;
protected Object beginCell, endCell;
int count = 0;
public FCMarqueeHandler(FlowComposer flowcomposer){
this.flowcomposer = flowcomposer;
......@@ -146,94 +148,113 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
}
public void mouseReleased(MouseEvent event) {
Call call;
Channel channel;
//count++;
count++;
current = currentProcess.snap(event.getPoint());
if(currentProcess != null){
//endCell= currentProcess.getFirstCellForLocation(event.getX(), event.getY());
if (event != null && !event.isConsumed() && !marquee.isSelected()) {
if (merge.isSelected())
{
Call call = new Dispatch("dispatch","broadcast");
{
call = new Merge(FCConstants.NMERGE+"-"+count,(String)FCConstants.MERGETYPE[0],currentTransformation);
currentTransformation.addCall(call);
}
else if (generate.isSelected())
{
///dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.GENERATE);
}
{
call = new Generate(FCConstants.NGENERATE+"-"+count,(String)FCConstants.GENERATETYPE[0],currentTransformation);
currentTransformation.addCall(call);
///dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.GENERATE);
}
else if (serialize.isSelected())
{
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.SERIALIZE);
}
{
call = new Serialize(FCConstants.NSERIALIZE+"-"+count,(String)FCConstants.SERIALIZETYPE[0],currentTransformation);
currentTransformation.addCall(call);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.SERIALIZE);
}
else if (dispatch.isSelected())
{
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.DISPATCH);
}
{
call = new Dispatch(FCConstants.NDISPATCH+"-"+count,(String)FCConstants.DISPATCHTYPE[0],currentTransformation);
currentTransformation.addCall(call);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.DISPATCH);
}
else if (applyExternal.isSelected())
{
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.APPLYEXTERNAL);
}
{
call = new ApplyExternal(FCConstants.NAPPLYEXTERNAL+"-"+count,(String)FCConstants.APPLYEXTERNALTYPE[0],currentTransformation);
currentTransformation.addCall(call);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.APPLYEXTERNAL);
}
else if (applyProcess.isSelected())
{
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.APPLYPROCESS);
}
{
call = new ApplyProcess(FCConstants.NAPPLYPROCESS+"-"+count,"",currentTransformation);
currentTransformation.addCall(call);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.APPLYPROCESS);
}
else if (applyRuleset.isSelected())
{
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.APPLYRULESET);
}
{
call = new ApplyRuleset(FCConstants.NAPPLYRULESET+"-"+count,"",currentTransformation);
currentTransformation.addCall(call);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.APPLYRULESET);
}
else if (applyQuery.isSelected())
{//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),(ProcessGraph)currentProcess,null,start,FCConstants.APPLYQUERY);}
}
else if (edgeNormal.isSelected()){
//currentProcess.getModel().insert(null,null,null,null);
{
call = new ApplyQuery(FCConstants.NAPPLYQUERY+"-"+count,(String)FCConstants.APPLYQUERYTYPE[0],currentTransformation);
currentTransformation.addCall(call);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),(ProcessGraph)currentProcess,null,start,FCConstants.APPLYQUERY);}
}
else if (edgeNormal.isSelected()){
//currentProcess.getModel().insert(null,null,null,null);
DefaultGraphCell c = (DefaultGraphCell)(port.getParentView()).getCell();
Call call = (Call)(c.getUserObject());
String name = "C"+call.getId();
channel = new Channel( name, (fr.fluxmedia.transmorpher.Graph.Process)currentTransformation );
((Process)currentTransformation).addChannel(channel);
DefaultGraphCell portOut = (DefaultGraphCell)firstPort.getCell();
DefaultGraphCell portIn = (DefaultGraphCell)port.getCell();
channel.setOut((Port)portOut.getUserObject());
channel.setIn((Port)portIn.getUserObject());
((Port)portIn.getUserObject()).setChannel(channel);
((Port)portOut.getUserObject()).setChannel(channel);
//((Port)portIn.getUserObject()).setName(name);
//((Port)portOut.getUserObject()).setName(name);
call = (Call)(c.getUserObject());
String name = "C"+call.getId();
channel = new Channel( name, (fr.fluxmedia.transmorpher.Graph.Process)currentTransformation );
((Process)currentTransformation).addChannel(channel);
DefaultGraphCell portOut = (DefaultGraphCell)firstPort.getCell();
DefaultGraphCell portIn = (DefaultGraphCell)port.getCell();
channel.setOut((Port)portOut.getUserObject());
channel.setIn((Port)portIn.getUserObject());
((Port)portIn.getUserObject()).setChannel(channel);
((Port)portOut.getUserObject()).setChannel(channel);
//((Port)portIn.getUserObject()).setName(name);
//((Port)portOut.getUserObject()).setName(name);
//if ((beginCell!=null)&&(endCell!=null)&&(!beginCell.equals(endCell))) {
//doConnectionSet(beginCell,endCell);}
Point p = currentProcess.fromScreen(new Point(start));
Point p2 = currentProcess.toScreen(new Point(current));
ArrayList list = new ArrayList();
list.add(p);
list.add(p2);
Map map = GraphConstants.createMap();
GraphConstants.setPoints(map, list);
Map viewMap = new Hashtable();
DefaultEdge cell = new DefaultEdge(channel);
viewMap.put(cell, map);
Object[] insert = new Object[]{cell};
ConnectionSet cs = new ConnectionSet();
if (firstPort != null)
cs.connect(cell, firstPort.getCell(), true);
if (port != null)
cs.connect(cell, port.getCell(), false);
currentProcess.getModel().insert(insert, cs, null, viewMap);
Point p = currentProcess.fromScreen(new Point(start));
Point p2 = currentProcess.toScreen(new Point(current));
ArrayList list = new ArrayList();
list.add(p);
list.add(p2);
Map map = GraphConstants.createMap();
GraphConstants.setPoints(map, list);
Map viewMap = new Hashtable();
DefaultEdge cell = new DefaultEdge(channel);
viewMap.put(cell, map);
Object[] insert = new Object[]{cell};
ConnectionSet cs = new ConnectionSet();
if (firstPort != null)
cs.connect(cell, firstPort.getCell(), true);
if (port != null)
cs.connect(cell, port.getCell(), false);
currentProcess.getModel().insert(insert, cs, null, viewMap);
}
event.consume();
}
marquee.doClick();
firstPort = null;
port = null;
start = null;
current = null;
event.consume();
}
marquee.doClick();
firstPort = null;
port = null;
start = null;
current = null;
super.mouseReleased(event);
updateGraphics();
updateGraphics();
//System.out.println("MouseReleased End...");
}
}
}
......
/**
* $Id: ProcessGraph.java,v 1.21 2002-06-10 10:58:40 frederic Exp $
* $Id: ProcessGraph.java,v 1.22 2002-06-10 11:36:52 gchomat Exp $
*
* Transmorpher
*
......@@ -43,6 +43,15 @@ import javax.swing.undo.UndoManager;
import fr.fluxmedia.transmorpher.Graph.Transmorpher;
import fr.fluxmedia.transmorpher.Graph.Process;
import fr.fluxmedia.transmorpher.Graph.Call;
import fr.fluxmedia.transmorpher.Graph.Merge;
import fr.fluxmedia.transmorpher.Graph.Dispatch;
import fr.fluxmedia.transmorpher.Graph.Serialize;
import fr.fluxmedia.transmorpher.Graph.Generate;
import fr.fluxmedia.transmorpher.Graph.ApplyProcess;
import fr.fluxmedia.transmorpher.Graph.ApplyRuleset;
import fr.fluxmedia.transmorpher.Graph.ApplyExternal;
import fr.fluxmedia.transmorpher.Graph.ApplyQuery;
import fr.fluxmedia.transmorpher.Files.*;
public class ProcessGraph extends JGraph implements Comparator, Observer{
......@@ -52,7 +61,7 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
// Undo Manager
protected GraphUndoManager undo;
protected DefaultGraphCell pCell = null;
/** boundsCube define the dimension of a squared form composant such as ApplyQuery, Merge and Dispatch.
* ie: this composant are included in square boxe
*/
......@@ -181,12 +190,26 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
{
if(arg instanceof Call)
{
System.out.println("new call created ");
addVertex(arg,new Point(10,10),FCConstants.DISPATCH);
if(arg instanceof Dispatch)
addVertex(arg,new Point(10,10),FCConstants.DISPATCH);
else if(arg instanceof Merge)
addVertex(arg,new Point(10,10),FCConstants.MERGE);
else if(arg instanceof ApplyProcess)
addVertex(arg,new Point(10,10),FCConstants.APPLYPROCESS);
else if(arg instanceof ApplyExternal)
addVertex(arg,new Point(10,10),FCConstants.APPLYEXTERNAL);
else if(arg instanceof Generate)
addVertex(arg,new Point(10,10),FCConstants.GENERATE);
else if(arg instanceof Serialize)
addVertex(arg,new Point(10,10),FCConstants.SERIALIZE);
else if(arg instanceof ApplyQuery)
addVertex(arg,new Point(10,10),FCConstants.APPLYQUERY);
else if(arg instanceof ApplyRuleset)
addVertex(arg,new Point(10,10),FCConstants.APPLYRULESET);
}
}
}
/** implementation insertion sort */
public boolean inferieur(Object o1, Object o2) {
......@@ -335,7 +358,6 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
return null;
}
/**
* Return the cell Neighboor of the vertex
* @param edge The edge between the vertex and his neighboor
......@@ -387,18 +409,6 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
return getView().getMapping(target, false);
}
public Object[] getSelectionCells() {
Object[] tmp = getSelectionModel().getSelectionCells();
ArrayList list = new ArrayList();
for (int i = 0; i <tmp.length; i++){
DefaultGraphCell cell = (DefaultGraphCell)tmp[i];
if ((!(cell instanceof PortProcessCell))&&(!(cell instanceof PortCell)))
list.add(tmp[i]);
}
return list.toArray();
}
/**
* Return all edges between two vertices.
*
......@@ -420,11 +430,12 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
public boolean isSingleId(String name){
Object[] roots = getAll();
//Observable
DefaultGraphCell cell;
Object userObject;
Call call;
for (int i = 0; i < roots.length; i++){
if (!(roots[i] instanceof Edge))
{
......@@ -435,8 +446,10 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
{
if(call.getId().equals(name))
return false;
}
}
}
}
return true;
}
......@@ -462,22 +475,6 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
return result;
}
public ArrayList getCellProcess(int portLocation) {
Object[] roots = getAll();
String user;
if (portLocation==FCConstants.PORTINPUT)
user="PInput";
else user="POutput";
ArrayList result = new ArrayList();
for (int i = 0; i < roots.length; i++){
if (((DefaultGraphCell)roots[i]).getUserObject().equals(user))
result.add(roots[i]);
}
return result;
}
/*
public void layoutPorts(Object vertex1,Object userObject) {
GraphView v = getView();
......@@ -538,7 +535,6 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
}
*/
/**
create a channel in the graph.
*/
......@@ -592,12 +588,11 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
v.edit(attributes);}
}
*/
/** add a Cell to the Graph
*
*/
public DefaultGraphCell addVertex(Object userObject,Point point,int type) {
public void addVertex(Object userObject,Point point,int number) {
int u = GraphConstants.PERCENT;
Rectangle bounds;
......@@ -605,7 +600,7 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
Map viewMap = new Hashtable();
// Create Vertex
switch (type) {
switch (number) {
case FCConstants.MERGE :
cell = new MergeCell(userObject);
bounds = new Rectangle(point,boundsCube);
......@@ -671,10 +666,9 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
addPort(cell,viewMap,FCConstants.PORTOUTPUT);
break;
case FCConstants.PORTPROCESS :
cell = new PortProcessCell(userObject);
bounds = new Rectangle(new Point(50,50),boundsPort);
bounds = new Rectangle(point,boundsCube);
addCell(cell,viewMap,bounds);
addPort(cell,viewMap,FCConstants.PORTOUTPUT);
break;
default: System.out.println("pas de vertex correspondant la string : FlowComposerGraph+meth addCell");break;
......@@ -682,26 +676,20 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
getModel().insert(new Object[]{cell}, null, null, viewMap);
FlowComposer.editing=true;
return cell;
// updateProcess();
}
public void addCell(DefaultGraphCell cell,Map viewMap, Rectangle bounds) {
Map map = GraphConstants.createMap();
if(cell instanceof PortProcessCell)
{
GraphConstants.setEditable(map,false);
GraphConstants.setMoveable(map, false);
GraphConstants.setSizeable(map, false);
}
GraphConstants.setBounds(map, bounds);
Map map = GraphConstants.createMap();
if(cell instanceof PortProcessCell){
GraphConstants.setMoveable(map, false);
GraphConstants.setSizeable(map, false);
}
GraphConstants.setBounds(map, bounds);
GraphConstants.setOpaque(map, false);
GraphConstants.setBorderColor(map, Color.black);
......@@ -725,134 +713,38 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
fr.fluxmedia.transmorpher.Graph.Port port=null;
int u = GraphConstants.PERCENT;
Map map = GraphConstants.createMap();
Call call = (Call)cell.getUserObject();
Call call = (Call)cell.getUserObject();
switch (type) {
case FCConstants.PORTINPUT :
GraphConstants.setOffset(map, new Point(0,(int) (u/2)));
if(call!=null){
GraphConstants.setOffset(map, new Point(0,(int) (u/2)));
if(call!=null){
index = (call.inPorts().length()==0)?0:call.inPorts().length()-1;
port = new fr.fluxmedia.transmorpher.Graph.Port(null,call,index);
call.inPorts().addPort(port);
}
}
break;
case FCConstants.PORTOUTPUT :
GraphConstants.setOffset(map, new Point(u,(int) (u/2)));
if(call!=null){
index = (call.outPorts().length()==0)?0:call.outPorts().length()-1;
port = new fr.fluxmedia.transmorpher.Graph.Port(null,call,index);
call.outPorts().addPort(port);
}
break;
default : System.out.println("type de port inconnu : meth addPort");
}
PortCell pc = new PortCell(port,type);
PortCell pc = new PortCell("",type);
viewMap.put(pc, map);
cell.add(pc);
}
public void actionRL(int type,int portLocation){
Object[] tmp = getSelectionCells();
DefaultGraphCell cell;
if (tmp.length!=0) {
for (int i = 0; i <tmp.length; i++){
cell = (DefaultGraphCell)tmp[i];
if (!(cell instanceof NormalEdge)){
cell = (DefaultGraphCell)tmp[i];
addPortRL(cell,portLocation);
updatePort(cell,portLocation);
}
}
}
else {
if (portLocation==FCConstants.PORTINPUT)
cell= addVertex("PInput",null,type);
else cell= addVertex("POutput",null,type);
addPortRL(cell,portLocation);
updateCell(portLocation);
}
}
public void updateCell(int portLocation){
GraphView v = getView();
Rectangle rect = getBounds();
System.out.println(rect);
ArrayList cell = getCellProcess(portLocation);
for (int i=0;i<cell.size();i++) {
Map map = GraphConstants.createMap();
Map attributes = new Hashtable();
if (portLocation==FCConstants.PORTINPUT)
GraphConstants.setBounds(map,new Rectangle(new Point(rect.width-15,(int)(rect.height*(i+1))/(cell.size()+1)),boundsPort));
else GraphConstants.setBounds(map,new Rectangle(new Point(0,(int)(rect.height*(i+1))/(cell.size()+1)),boundsPort));
CellView cellView = v.getMapping(cell.get(i),true);
attributes.put(cellView,map);
v.edit(attributes);
}
}
public void addPortRL(DefaultGraphCell cell,int type){
int index;
Call call = null;
fr.fluxmedia.transmorpher.Graph.Port port=null;
GraphView v = getView();
Map map = GraphConstants.createMap();
int u = GraphConstants.PERCENT;
GraphConstants.setOffset(map, new Point((int)(u/2),(int)(u/2)));
switch (type) {
case FCConstants.PORTINPUT :
if (cell.getUserObject().equals("PInput")) {
index = (((Process)userObject).inPorts().length()==0)?0:((Process)userObject).inPorts().length()-1;
port = new fr.fluxmedia.transmorpher.Graph.Port(null,((Process)userObject),index);
((Process)userObject).addIn(index,port);
}
else {
call = (Call)cell.getUserObject();
index = (call.inPorts().length()==0)?0:call.inPorts().length()-1;
port = new fr.fluxmedia.transmorpher.Graph.Port(null,call,index);
call.inPorts().addPort(port);
}
break;
case FCConstants.PORTOUTPUT :
if (cell.getUserObject().equals("POutput")) {
index = (((Process)userObject).outPorts().length()==0)?0:((Process)userObject).outPorts().length()-1;
port = new fr.fluxmedia.transmorpher.Graph.Port(null,((Process)userObject),index);
((Process)userObject).addOut(index,port);
}
else {
call = (Call)cell.getUserObject();
index = (call.outPorts().length()==0)?0:call.outPorts().length()-1;
port = new fr.fluxmedia.transmorpher.Graph.Port(null,call,index);
call.outPorts().addPort(port);
}
break;
default : System.out.println("type de port inconnu : meth addPort");
}
PortCell pc = new PortCell(port,type);
ParentMap parent = new ParentMap();
parent.addEntry(pc,cell);
Map viewMap = new Hashtable();
viewMap.put(pc,map);
getModel().insert(new Object[]{pc},null,parent,viewMap);
}
public void updatePort(DefaultGraphCell cell,int type){
/*
public void updatePorts(int type,DefaultGraphCell cell){
GraphView v = getView();
ArrayList children = getPorts(cell,type);
for (int i=0;i<children.size();i++) {
Map map = GraphConstants.createMap();
int u = GraphConstants.PERCENT;
......@@ -861,6 +753,7 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
GraphConstants.setOffset(map,new Point(0,(int)(u*(i+1))/(children.size()+1)));
System.out.println(children.get(i));
CellView cellView = v.getMapping(children.get(i),true);
attributes.put(cellView,map);
}
else {
......@@ -872,12 +765,7 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
}
v.edit(attributes);
}
}
} */
/** add a Port to the Cell
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment