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

update

parent 23f87aec
/**
* $Id: FCMarqueeHandler.java,v 1.26 2002-06-10 11:48:44 gchomat Exp $
* $Id: FCMarqueeHandler.java,v 1.27 2002-06-10 13:53:00 frederic Exp $
*
* Transmorpher
*
......@@ -116,9 +116,9 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
if (!e.isConsumed() && !marquee.isSelected()) {
start = currentProcess.snap(e.getPoint());
firstPort = port;
//beginCell = currentProcess.getFirstCellForLocation(e.getX(), e.getY());
e.consume();
}
}
......@@ -138,8 +138,8 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
overlay(g);
if (edgeNormal.isSelected())
port = currentProcess.getPortViewAt(event.getX(), event.getY());
current = currentProcess.snap(event.getPoint());
current = currentProcess.snap(event.getPoint());
g.setColor(bg);
g.setXORMode(fg);
overlay(g);
......@@ -161,10 +161,10 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
if(currentProcess != null){
//endCell= currentProcess.getFirstCellForLocation(event.getX(), event.getY());
if (event != null && !event.isConsumed() && !marquee.isSelected()) {
if (merge.isSelected())
{
{
call = new Merge(FCConstants.NMERGE+"-"+count,(String)FCConstants.MERGETYPE[0],currentTransformation);
currentTransformation.addCall(call);
}
......@@ -205,48 +205,48 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
//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);
//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)(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);
else if (edgeNormal.isSelected())
{
if ((firstPort!=null)&&(port!=null)) {
java.util.Iterator itFirst = ((DefaultPort)firstPort.getCell()).edges();
java.util.Iterator it = ((DefaultPort)port.getCell()).edges();
if ((lenght(itFirst)<1)&&(lenght(it)<1)) {
DefaultGraphCell c = (DefaultGraphCell)(port.getParentView()).getCell();
Call ca = (Call)(c.getUserObject());
String name = "C"+ca.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);
//a voir absolument?????????
//((Port)portIn.getUserObject()).setName(name);
//((Port)portOut.getUserObject()).setName(name);
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();
cs.connect(cell, firstPort.getCell(), true);
cs.connect(cell, port.getCell(), false);
currentProcess.getModel().insert(insert, cs, null, viewMap);
}
}
}
event.consume();
}
......@@ -262,19 +262,19 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
}
public void mouseMoved(MouseEvent event) {
//System.out.println("currentProcess " + currentProcess);
if(currentProcess!=null){
if (!marquee.isSelected() && !event.isConsumed()) {
currentProcess.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
event.consume();
if (edgeNormal.isSelected()) {
PortView oldPort = port;
PortView newPort = currentProcess.getPortViewAt(event.getX(), event.getY());
if (oldPort != newPort) {
Graphics g = currentProcess.getGraphics();
Color bg = currentProcess.getBackground();
......@@ -299,6 +299,16 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
currentProcess.getModel().insert(null,null,null,null);
}
public int lenght(java.util.Iterator it) {
int compteur = 0;
while (it.hasNext()){
it.next();
compteur++;
}
return compteur;
}
/*
public void doConnectionSet(Object cell,Object cell2) {
......@@ -417,10 +427,10 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
currentProcess.getUI().paintCell(g, port, r, true);
}
}
}
/**
* $Id: ProcessGraph.java,v 1.23 2002-06-10 11:48:44 gchomat Exp $
* $Id: ProcessGraph.java,v 1.24 2002-06-10 13:53:00 frederic Exp $
*
* Transmorpher
*
......@@ -57,10 +57,10 @@ import fr.fluxmedia.transmorpher.Files.*;
public class ProcessGraph extends JGraph implements Comparator, Observer{
Object userObject;
// 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
......@@ -68,13 +68,13 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
static Dimension boundsCube = new Dimension(70,70);
static Dimension boundsPort = new Dimension(15,15);
static Dimension boundsPortCell = new Dimension(30,30);
/** boundsRect define the dimension of a rectangle form composant such as ApplyProcess, Serialize,...
* ie: this composant are included in rectangle boxe
*/
static Dimension boundsRect = new Dimension(70,50);
ArrayList tmp =null;
public ProcessGraph() {
......@@ -131,11 +131,11 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
}
public String getName(){
if(userObject instanceof Process){
return ((Process)userObject).getName();
}
return "";
return "";
}
......@@ -185,31 +185,33 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
/** interface Observer*/
public void update(Observable observable, Object arg){
if(observable instanceof Process)
{
if(arg instanceof Call)
{
if(arg instanceof Dispatch)
addVertex(arg,FCConstants.DISPATCH);
addVertex(arg,FCConstants.DISPATCH);
else if(arg instanceof Merge)
addVertex(arg,FCConstants.MERGE);
else if(arg instanceof ApplyProcess)
addVertex(arg,FCConstants.APPLYPROCESS);
else if(arg instanceof ApplyExternal)
addVertex(arg,FCConstants.APPLYEXTERNAL);
else if(arg instanceof Generate)
addVertex(arg,FCConstants.GENERATE);
else if(arg instanceof Serialize)
addVertex(arg,FCConstants.SERIALIZE);
else if(arg instanceof ApplyQuery)
addVertex(arg,FCConstants.APPLYQUERY);
else if(arg instanceof ApplyRuleset)
addVertex(arg,FCConstants.MERGE);
else if(arg instanceof ApplyProcess)
addVertex(arg,FCConstants.APPLYPROCESS);
else if(arg instanceof ApplyExternal)
addVertex(arg,FCConstants.APPLYEXTERNAL);
else if(arg instanceof Generate)
addVertex(arg,FCConstants.GENERATE);
else if(arg instanceof Serialize)
addVertex(arg,FCConstants.SERIALIZE);
else if(arg instanceof ApplyQuery)
addVertex(arg,FCConstants.APPLYQUERY);
else if(arg instanceof ApplyRuleset)
addVertex(arg,FCConstants.APPLYRULESET);
}
}
}
/** implementation insertion sort */
public boolean inferieur(Object o1, Object o2) {
......@@ -475,6 +477,23 @@ 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,9 +557,9 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
/**
create a channel in the graph.
*/
public void createChannel(){}
/**
create a call in the graph.
......@@ -548,24 +567,24 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
/* public void createCall(int type, Object[] parameters, Point position){
call = FCProcessFactory.createCall(type,parameters);
if(userObject != null && userObject instanceof Transformation)
((Transformation)userObject).addCall(call);
else
{
// traitement erreur
}
addVertex(call, position,FCConstants.MERGE);
}*/
/**
remove a channel in the graph.
*/
public void removeChannel(){}
/**
remove a call in the graph.
*/
......@@ -573,7 +592,7 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
/**
/**
* add a Cell to the Graph
public void updateProcess() {
......@@ -592,13 +611,13 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
/** add a Cell to the Graph
*
*/
public void addVertex(Object userObject,int type) {
public DefaultGraphCell addVertex(Object userObject,int type) {
int u = GraphConstants.PERCENT;
Rectangle bounds;
Point position = new Point(10,10);
if(marquee instanceof FCMarqueeHandler)
position = new Point(((FCMarqueeHandler)marquee).getCurrentPoint());
Point position = new Point(10,10);
if(marquee instanceof FCMarqueeHandler)
position = new Point(((FCMarqueeHandler)marquee).getCurrentPoint());
DefaultGraphCell cell = null;
Map viewMap = new Hashtable();
......@@ -635,8 +654,8 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
cell = new ApplyExternalCell(userObject);
bounds = new Rectangle(position,boundsRect);
addCell(cell,viewMap,bounds);
Call call = (Call)userObject;
Call call = (Call)userObject;
if(call.getType().equals("xslt")){
addPort(cell,viewMap,FCConstants.PORTINPUT);
addPort(cell,viewMap,FCConstants.PORTOUTPUT);
......@@ -648,7 +667,7 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
GraphConstants.setForeground(map, Color.white);
GraphConstants.setBackground(map, Color.lightGray);
viewMap.put(cell, map);*/
break;
case FCConstants.APPLYPROCESS :
cell = new ApplyProcessCell(userObject);
......@@ -670,33 +689,33 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
addPort(cell,viewMap,FCConstants.PORTOUTPUT);
break;
case FCConstants.PORTPROCESS :
bounds = new Rectangle(position,boundsCube);
cell = new PortProcessCell(userObject);
bounds = new Rectangle(new Point(50,50),boundsPort);
addCell(cell,viewMap,bounds);
addPort(cell,viewMap,FCConstants.PORTOUTPUT);
break;
break;
default: System.out.println("pas de vertex correspondant la string : FlowComposerGraph+meth addCell");break;
}
getModel().insert(new Object[]{cell}, null, null, viewMap);
FlowComposer.editing=true;
// updateProcess();
return cell;
}
public void addCell(DefaultGraphCell cell,Map viewMap, Rectangle 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);
viewMap.put(cell, map);
}
......@@ -711,7 +730,7 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
Map map = GraphConstants.createMap();
}
}
public void addPort(DefaultGraphCell cell,Map viewMap, int type) {
int index;
fr.fluxmedia.transmorpher.Graph.Port port=null;
......@@ -731,7 +750,9 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
break;
case FCConstants.PORTOUTPUT :
GraphConstants.setOffset(map, new Point(u,(int) (u/2)));
if(call!=null){
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);
......@@ -744,8 +765,138 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
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",type);
else cell= addVertex("POutput",type);
addPortRL(cell,portLocation);
updateCellProcess(portLocation);
}
}
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 updateCellProcess(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 updatePort(DefaultGraphCell cell,int type){
GraphView v = getView();
ArrayList children = getPorts(cell,type);
for (int i=0;i<children.size();i++) {
Map map = GraphConstants.createMap();
int u = GraphConstants.PERCENT;
Map attributes = new Hashtable();
if (type==FCConstants.PORTINPUT){
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 {
GraphConstants.setOffset(map,new Point(u,(int)(u*(i+1))/(children.size()+1)));
System.out.println(children.get(i));
CellView cellView = v.getMapping(children.get(i),false);
attributes.put(cellView,map);
}
v.edit(attributes);
}
}
/*
public void updatePorts(int type,DefaultGraphCell cell){