Commit edbe8234 authored by SAINT-MARCEL Frederic's avatar SAINT-MARCEL Frederic
Browse files

contrainte+update

:wq
parent 55a53e4a
/**
* $Id: FCMarqueeHandler.java,v 1.3 2002-05-14 16:17:07 gchomat Exp $
* $Id: FCMarqueeHandler.java,v 1.4 2002-05-16 14:12:55 frederic Exp $
*
* Transmorpher
*
......@@ -176,48 +176,31 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
super.mouseMoved(event);
}
public void doConnectionSet(Object firstCell,Object secondCell) {
Point p=null;
Point p2=null;
Rectangle beginRect,endRect;
int beginPorts=((ProcessGraph)currentProcess).getNumberPorts(firstCell,"output");
System.out.println(beginPorts);
int secondPorts=((ProcessGraph)currentProcess).getNumberPorts(secondCell,"input");
System.out.println(secondPorts);
beginRect=currentProcess.getCellBounds(firstCell);
endRect=currentProcess.getCellBounds(secondCell);
if ((firstCell instanceof SerializeCell)||(secondCell instanceof GenerateCell))
public void doConnectionSet(Object cell,Object cell2) {
Point p,p2 = null;
Rectangle rect,rect2;
rect=currentProcess.getCellBounds(cell);
rect2=currentProcess.getCellBounds(cell2);
int port = (((ProcessGraph)currentProcess).getPorts(cell,"output")).size();
int port2 = (((ProcessGraph)currentProcess).getPorts(cell2,"input")).size();
System.out.println(port+"premier");
System.out.println(port2+"deuxieme");
if ((cell instanceof SerializeCell)||(cell2 instanceof GenerateCell))
System.out.println("pas de port en entre (resp. sortie)");
else if ((beginPorts>1)&&((firstCell instanceof MergeCell)||(firstCell instanceof ApplyRulesetCell)
||(firstCell instanceof ApplyQueryCell)||(firstCell instanceof GenerateCell)))
else if ((port==1)&&((cell instanceof MergeCell)||(cell instanceof ApplyRulesetCell)
||(cell instanceof ApplyQueryCell)||(cell instanceof GenerateCell)))
System.out.println("1 seul port d'entre pour la connection");
else if ((secondPorts>1)&&((secondCell instanceof DispatchCell)||(secondCell instanceof ApplyRulesetCell)
||(secondCell instanceof ApplyQueryCell)||(secondCell instanceof SerializeCell)))
else if ((port2==1)&&((cell2 instanceof DispatchCell)||(cell2 instanceof ApplyRulesetCell)
||(cell2 instanceof ApplyQueryCell)||(cell2 instanceof SerializeCell)))
System.out.println("1 seul port de sortie pour la connection");
else {
if ((firstCell instanceof GenerateCell)||(firstCell instanceof ApplyRulesetCell)||(firstCell instanceof MergeCell)||(firstCell instanceof ApplyQueryCell))
{
p = new Point(beginRect.x+beginRect.width,beginRect.y+(beginRect.height/2));
}
else {
((ProcessGraph)currentProcess).addDynamicPort("output",(DefaultGraphCell)firstCell,beginPorts);
p = new Point(beginRect.x+beginRect.width,beginRect.y+((beginRect.height*(beginPorts+1))/(beginPorts+2)));
}
if ((secondCell instanceof SerializeCell)||(secondCell instanceof ApplyRulesetCell)||(secondCell instanceof DispatchCell)||(secondCell instanceof ApplyQueryCell))
{
p2 = new Point(endRect.x,endRect.y+(endRect.height/2));
}
else {
((ProcessGraph)currentProcess).addDynamicPort("input",(DefaultGraphCell)secondCell,secondPorts);
p2 = new Point(endRect.x,endRect.y+((endRect.height*(secondPorts+1))/(secondPorts+2)));
}
((ProcessGraph)currentProcess).addPort("output",(DefaultGraphCell)cell);
((ProcessGraph)currentProcess).addPort("input",(DefaultGraphCell)cell2);
p= new Point(rect.x+rect.width,rect.y+((rect.height*(port+1))/(port+2)));
p2= new Point(rect2.x,rect2.y+((rect2.height*(port2+1))/(port2+2)));
Point p3 = currentProcess.fromScreen(new Point(p));
Point p4 = currentProcess.fromScreen(new Point(p2));
......@@ -227,19 +210,15 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
Map map = GraphConstants.createMap();
GraphConstants.setPoints(map, list);
Map viewMap = new Hashtable();
NormalEdge cell = new NormalEdge();
viewMap.put(cell, map);
Object[] insert = new Object[]{cell};
NormalEdge edge = new NormalEdge();
viewMap.put(edge, map);
Object[] insert = new Object[]{edge};
ConnectionSet cs = new ConnectionSet();
System.out.println("currentProcess.getPortForLocation(p.x,p.y) "+currentProcess.getPortForLocation(p.x,p.y));
System.out.println("currentProcess.getPortForLocation(p.x,p.y) "+currentProcess.getPortForLocation(p2.x,p2.y));
System.out.println("firstcell.getChildCount "+((DefaultGraphCell)firstCell).getChildCount());
System.out.println("secondcell.getChildCount "+((DefaultGraphCell)secondCell).getChildCount());
cs.connect(cell,currentProcess.getPortForLocation(p.x,p.y), true);
cs.connect(cell,currentProcess.getPortForLocation(p2.x,p2.y), false);
cs.connect(edge,currentProcess.getPortForLocation(p.x,p.y), true);
cs.connect(edge,currentProcess.getPortForLocation(p2.x,p2.y), false);
currentProcess.getModel().insert(insert, cs, null, viewMap);
((ProcessGraph)currentProcess).layoutPorts(cell,"output");
((ProcessGraph)currentProcess).layoutPorts(cell2,"input");
}
}
......
/**
* $Id: ProcessGraph.java,v 1.3 2002-05-14 16:17:07 gchomat Exp $
* $Id: ProcessGraph.java,v 1.4 2002-05-16 14:12:55 frederic Exp $
*
* Transmorpher
*
......@@ -358,48 +358,67 @@ public class ProcessGraph extends JGraph implements Comparator{
return result.toArray();
}
/**
/**
*
*
*/
public Object[] getCells(Object vertex1,boolean source) {
public ArrayList getPorts(Object vertex1,Object userObject) {
ArrayList result = new ArrayList();
if (!((DefaultGraphCell)vertex1).isLeaf()) {
java.util.List children = ((DefaultGraphCell)vertex1).getChildren();
Iterator it = children.iterator();
while (it.hasNext()) {
Object port = it.next();
//System.out.println(((DefaultPort)port).getUserObject());
if (userObject.equals(((DefaultPort)port).getUserObject()))
result.add(port);
}
}
return result;
}
public void layoutPorts(Object vertex1,Object userObject) {
GraphView v = getView();
ArrayList result = new ArrayList();
Map port = new Hashtable();
Set edges = DefaultGraphModel.getEdges(graphModel, new Object[]{vertex1});
Iterator it = edges.iterator();
while (it.hasNext()) {
Object edge = it.next();
if ((source)&&(getSourceVertex(edge)==vertex1))
result.add(getTargetVertex(edge));
else if (getTargetVertex(edge)==vertex1)
result.add(getSourceVertex(edge));
if ((userObject.equals("output"))&&(getSourceVertex(edge)==vertex1)){
result.add(graphModel.getTarget(edge));
port.put(graphModel.getTarget(edge),edge);}
else if (getTargetVertex(edge)==vertex1){
result.add(graphModel.getSource(edge));
port.put(graphModel.getSource(edge),edge);}
}
Collections.sort(result,this);
for (int i=0;i<result.size();i++) {
Rectangle rect = getCellBounds((Object)result.get(i));
System.out.println(rect.y);
}
return result.toArray();
}
/**
*
*
*/
public int getNumberPorts(Object vertex1,Object userObject) {
ArrayList result = new ArrayList();
if (((DefaultGraphCell)vertex1).isLeaf())
return 0;
else {
java.util.List children = ((DefaultGraphCell)vertex1).getChildren();
Iterator it = children.iterator();
while (it.hasNext()) {
Object port = it.next();
if (userObject.equals(((DefaultPort)port).getUserObject()))
result.add(port);
}
return result.size();
}
}
for (int i=0;i<result.size();i++) {
Map map = GraphConstants.createMap();
Map attributes = new Hashtable();
int u = GraphConstants.PERCENT;
Object edge = port.get(result.get(i));
if (userObject.equals("input")){
GraphConstants.setOffset(map,new Point(0,(u*(i+1))/(result.size()+1)));
CellView cellView = v.getMapping(graphModel.getTarget(edge),false);
attributes.put(cellView,map);
}
else {
GraphConstants.setOffset(map,new Point(u,(u*(i+1))/(result.size()+1)));
CellView cellView = v.getMapping(graphModel.getSource(edge),false);
attributes.put(cellView,map);
}
v.edit(attributes);
}
}
/** add a Cell to the Graph
......@@ -417,25 +436,21 @@ public class ProcessGraph extends JGraph implements Comparator{
cell = new MergeCell(userObject);
bounds = new Rectangle(point,boundsCube);
addCell(cell,viewMap,bounds);
addStaticPort("output",cell,viewMap);
break;
case GENERATE :
cell = new GenerateCell(userObject);
bounds = new Rectangle(point,boundsRect);
addCell(cell,viewMap,bounds);
addStaticPort("output",cell,viewMap);
break;
case SERIALYSE :
cell = new SerializeCell(userObject);
bounds = new Rectangle(point,boundsRect);
addCell(cell,viewMap,bounds);
addStaticPort("input",cell,viewMap);
break;
case DISPATCH :
cell = new DispatchCell(userObject);
bounds = new Rectangle(point,boundsCube);
addCell(cell,viewMap,bounds);
addStaticPort("input",cell,viewMap);
break;
case APPLYEXTERNAL :
cell = new ApplyExternalCell(userObject);
......@@ -451,15 +466,11 @@ public class ProcessGraph extends JGraph implements Comparator{
cell = new ApplyRulesetCell(userObject);
bounds = new Rectangle(point,boundsRect);
addCell(cell,viewMap,bounds);
addStaticPort("input",cell,viewMap);
addStaticPort("output",cell,viewMap);
break;
case APPLYQUERY :
cell = new ApplyQueryCell(userObject);
bounds = new Rectangle(point,boundsCube);
addCell(cell,viewMap,bounds);
addStaticPort("input",cell,viewMap);
addStaticPort("output",cell,viewMap);
break;
default: System.out.println("pas de vertex correspondant la string : FlowComposerGraph+meth addCell");break;
}
......@@ -481,38 +492,38 @@ public class ProcessGraph extends JGraph implements Comparator{
*
*/
public void addStaticPort(Object userObject,DefaultGraphCell cell, Map viewMap) {
Map map = GraphConstants.createMap();
int u = GraphConstants.PERCENT;
if (userObject.equals("input"))
GraphConstants.setOffset(map, new Point(0, (int) (u/2)));
else
GraphConstants.setOffset(map, new Point(u, (int) (u/2)));
DefaultPort port = new DefaultPort(userObject);
cell.add(port);
viewMap.put(port,map);
}
public void addDynamicPort(Object userObject,DefaultGraphCell cell,int number) {
public void addPort(Object userObject,DefaultGraphCell cell) {
int nb = (getPorts(cell,userObject)).size();
Map map = GraphConstants.createMap();
int u = GraphConstants.PERCENT;
if (userObject.equals("input"))
GraphConstants.setOffset(map, new Point(0, (int) ((u*(number+1))/(number+2))));
else
GraphConstants.setOffset(map, new Point(u, (int) ((u*(number+1))/(number+2))));
DefaultPort port = new DefaultPort(userObject);
ParentMap parent = new ParentMap();
parent.addEntry(port,cell);
GraphConstants.setOffset(map,new Point(0,getFactor(nb)));
else
GraphConstants.setOffset(map,new Point(u,getFactor(nb)));
DefaultPort port = new DefaultPort(userObject);
ParentMap parent = new ParentMap();
parent.addEntry(port,cell);
Map viewMap = new Hashtable();
viewMap.put(port,map);
getModel().insert(new Object[]{port},null,parent,viewMap);
}
Map viewMap = new Hashtable();
viewMap.put(port,map);
getModel().insert(new Object[]{port},null,parent,viewMap);
public int getFactor(int nb) {
int u = GraphConstants.PERCENT;
// System.out.println(nb);
return (int)(u*(nb+1))/(nb+2);
}
/* Show a dialog with the given error message. */
public void error(String message) {
JOptionPane.showMessageDialog(this, message,"FlowComposer", JOptionPane.ERROR_MESSAGE);
}
/* Show a dialog with the given error message. */
public void error(String message) {
JOptionPane.showMessageDialog(this, message,"FlowComposer", JOptionPane.ERROR_MESSAGE);
}
}
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