Commit 6f4f4e65 authored by Guillaume Chomat's avatar Guillaume Chomat
Browse files

extends BasicGraphUI in order to change the third mouse button comportement....

extends BasicGraphUI in order to change the third mouse button comportement. Now when you click on a component whith the third mouse button a popupMenu is showing.
parent ba063e4e
......@@ -114,9 +114,11 @@ component=newC - expandC - propertiesC
componentLabel=Component
newCLabel=New
expandCLabel=Expand
PropertiesAction= propertiesC
propertiesCLabel=Properties
propertiesCImage=resources/properties.gif
#
# channel Menu definition
#
......@@ -224,6 +226,11 @@ PortLeftAction=portleft
#OutImage=resources/Out.gif
#OutTooltip=Out
#popup definition
popup1 = propertiesC
# label
EnterName = Enter the name
EnterNameMessage = Please enter the name of this process
......
/**
* $Id: FCConstants.java,v 1.8 2002-06-14 09:26:48 gchomat Exp $
* $Id: FCConstants.java,v 1.9 2002-06-18 15:04:14 gchomat Exp $
*
* Transmorpher
*
......@@ -30,6 +30,7 @@
package fr.fluxmedia.flowcomposer;
import java.util.Hashtable;
import fr.fluxmedia.transmorpher.Graph.*;
public class FCConstants{
......@@ -66,6 +67,31 @@ public class FCConstants{
public static final Object[] STRATEGYRULESET = new Object[]{"top-down"};
public static int getType(Object object){
if(object instanceof Merge)
return MERGE;
else if(object instanceof Generate)
return GENERATE;
else if(object instanceof Dispatch)
return DISPATCH;
else if(object instanceof Serialize)
return SERIALIZE;
else if(object instanceof ApplyExternal)
return APPLYEXTERNAL;
else if(object instanceof ApplyRuleset)
return APPLYRULESET;
else if(object instanceof ApplyQuery)
return APPLYQUERY;
else if(object instanceof ApplyProcess)
return APPLYPROCESS;
else
return -1;
}
public static String getCallClass(int className){
String name;
......
/**
* $Id: FCGraphCell.java,v 1.3 2002-06-14 09:26:48 gchomat Exp $
* $Id: FCGraphCell.java,v 1.4 2002-06-18 15:04:14 gchomat Exp $
*
* Transmorpher
*
......@@ -106,6 +106,7 @@ public class FCGraphCell extends DefaultGraphCell implements Observer{
public void update(Observable obs, Object arg)
{
System.out.println("modify a call + arg "+ arg);
if(obs instanceof Call)
{
......@@ -113,8 +114,6 @@ public class FCGraphCell extends DefaultGraphCell implements Observer{
{
if(process != null)
{
System.out.println("obs "+obs);
PortCell pc = new PortCell((Port)arg,((Port)arg).getType());
......@@ -133,7 +132,6 @@ public class FCGraphCell extends DefaultGraphCell implements Observer{
process.getModel().insert(new Object[]{pc},null,parent,viewMap);
System.out.println("type "+((Port)arg).getType());
process.updatePort(this,((Port)arg).getType());
}
}
......
......@@ -37,11 +37,23 @@ import com.jgraph.plaf.basic.BasicGraphUI;
public class FCGraphUI extends BasicGraphUI{
// FCGraphUI constructors
public static ComponentUI createUI(JComponent x) {
return new FCGraphUI();
}
public FCGraphUI(){
super();
}
/**
* Creates the listener responsible for calling the correct handlers
* based on mouse events, and to select invidual cells.
*/
protected MouseListener createMouseListener() {
return new FCMouseHandler();
}
/**
* Main painting routine.
......@@ -74,7 +86,7 @@ public class FCGraphUI extends BasicGraphUI{
for (int i = 0; i < views.length; i++) {
System.out.println("views["+i+"]="+views[i]);
Rectangle bounds = views[i].getBounds();
if (bounds != null && real != null && bounds.intersects(real))
paintCell(g, views[i], bounds, false);
......@@ -145,9 +157,110 @@ public class FCGraphUI extends BasicGraphUI{
rendererPane.paintComponent(g, component, graph, bounds.x, bounds.y,
bounds.width, bounds.height, true);
}
}
/**
* TreeMouseListener is responsible for updating the selection
* based on mouse events.
*/
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
super.mousePressed(e);
}
public void mouseDragged(MouseEvent e) {
try {
autoscroll(graph, e.getPoint());
if (handler == marquee)
marquee.mouseDragged(e);
else if (handler == null && !isEditing(graph) && focus != null) {
if (!graph.isCellSelected(focus.getCell())) {
selectCellForEvent(focus.getCell(), e);
cell = null;
}
if (handle != null)
handle.mousePressed(e);
handler = handle;
}
if (handle != null && handler == handle)
handle.mouseDragged(e);
} finally {
//cell = null;
}
}
/**
* Invoked when the mouse pointer has been moved on a component
* (with no buttons down).
*/
public void mouseMoved(MouseEvent e) {
if (graph != null && graph.isEnabled()) {
if (marquee != null)
marquee.mouseMoved(e);
if (handle != null)
handle.mouseMoved(e);
if (!e.isConsumed())
graph.setCursor(Cursor.getDefaultCursor());
}
}
public void mouseReleased(MouseEvent e) {
try {
if (!e.isConsumed()) {
if (handler == marquee)
marquee.mouseReleased(e);
else if (handler == handle && handle != null)
handle.mouseReleased(e);
if (isDescendant(cell, focus) && e.getModifiers() != 0) {
// Do not switch to parent if Special Selection
cell = focus;
}
if (!e.isConsumed() && cell != null) {
Object tmp = cell.getCell();
boolean wasSelected = graph.isCellSelected(tmp);
selectCellForEvent(tmp, e);
focus = cell;
if (wasSelected && graph.isCellSelected(tmp))
{
Object root = ((DefaultMutableTreeNode) tmp).getRoot();
selectCellForEvent(root, e);
focus = graphView.getMapping(root, false);
}
}
}
} finally {
insertionLocation = null;
handler = null;
cell = null;
}
}
protected boolean isDescendant(CellView parent, CellView child) {
if (parent != null && parent.getCell() instanceof DefaultMutableTreeNode &&
child != null && child.getCell() instanceof DefaultMutableTreeNode)
{
DefaultMutableTreeNode p = (DefaultMutableTreeNode) parent.getCell();
DefaultMutableTreeNode c = (DefaultMutableTreeNode) child.getCell();
return p.isNodeDescendant(c);
}
return false;
}
} // End of BasicGraphUI.MouseHandler
}
/**
* $Id: FCMarqueeHandler.java,v 1.35 2002-06-14 15:19:21 frederic Exp $
* $Id: FCMarqueeHandler.java,v 1.36 2002-06-18 15:04:14 gchomat Exp $
*
* Transmorpher
*
......@@ -84,7 +85,7 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
public FCMarqueeHandler(FlowComposer flowcomposer){
this.flowcomposer = flowcomposer;
this.flowcomposer = flowcomposer;
gt = new FCGraphTools();
}
......@@ -127,14 +128,15 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
public void mousePressed(MouseEvent e) {
//System.out.println("MousePressed Start...");
if(e.getButton() == MouseEvent.BUTTON3)
{
if(e.isPopupTrigger())
{
if (!e.isConsumed() && marquee.isSelected()) {
System.out.println("MousePressed Start...");
e.consume();
current = currentProcess.snap(e.getPoint());
flowcomposer.showPopup(e);
return;
}
}
else{
......@@ -201,6 +203,7 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
//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);
......@@ -208,13 +211,13 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
}
else if (generate.isSelected())
{
call = new Generate(FCConstants.NGENERATE+"-"+count,(String)FCConstants.GENERATETYPE[0],currentTransformation);
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())
{
call = new Serialize(FCConstants.NSERIALIZE+"-"+count,(String)FCConstants.SERIALIZETYPE[0],currentTransformation);
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);
}
......@@ -226,13 +229,13 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
}
else if (applyExternal.isSelected())
{
call = new ApplyExternal(FCConstants.NAPPLYEXTERNAL+"-"+count,(String)FCConstants.APPLYEXTERNALTYPE[0],currentTransformation);
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())
{
call = new ApplyProcess(FCConstants.NAPPLYPROCESS+"-"+count,"",currentTransformation);
call = new ApplyProcess(FCConstants.NAPPLYPROCESS+"-"+count,"",currentTransformation,"");
currentTransformation.addCall(call);
//dialog = new EditCall((JFrame)(currentProcess.getTopLevelAncestor()),currentProcess,null,start,FCConstants.APPLYPROCESS);
}
......@@ -255,24 +258,24 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
java.util.Iterator itFirst = ((DefaultPort)firstPort.getCell()).edges();
java.util.Iterator it = ((DefaultPort)port.getCell()).edges();
if ((lenght(itFirst)<1)&&(lenght(it)<1)) {
DefaultGraphCell firstCell = (DefaultGraphCell)(firstPort.getParentView()).getCell();
DefaultGraphCell cell = (DefaultGraphCell)(port.getParentView()).getCell();
int firstType = ((PortCell)firstPort.getCell()).getType();
int type = ((PortCell)port.getCell()).getType();
if (!(firstCell instanceof PortProcessCell)){
if (!(cell instanceof PortProcessCell)){
DefaultGraphCell firstCell = (DefaultGraphCell)(firstPort.getParentView()).getCell();
DefaultGraphCell cell = (DefaultGraphCell)(port.getParentView()).getCell();
int firstType = ((PortCell)firstPort.getCell()).getType();
int type = ((PortCell)port.getCell()).getType();
if (!(firstCell instanceof PortProcessCell)){
if (!(cell instanceof PortProcessCell)){
if ((firstType!=type)&&(firstCell!=cell)) {doConnection(firstPort,port);}
}
else if (firstType==type) {doConnection(firstPort,port);}
}
}
else if (firstType==type) {doConnection(firstPort,port);}
}
else if (!(cell instanceof PortProcessCell)){
if (firstType==type) {doConnection(firstPort,port);}
}
}
else if (firstType!=type) {doConnection(firstPort,port);}
}
}
}
}
event.consume();
event.consume();
}
}
......@@ -285,11 +288,10 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
super.mouseReleased(event);
updateGraphics();
//System.out.println("MouseReleased End...");
}
}
public void mouseMoved(MouseEvent event) {
//System.out.println("currentProcess " + currentProcess);
if(currentProcess!=null){
......@@ -326,35 +328,37 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
currentProcess.getModel().insert(null,null,null,null);
}
public void doConnection(PortView firstPort,PortView port) {
Channel channel;
DefaultGraphCell c = (DefaultGraphCell)(port.getParentView()).getCell();
String name;
if((c!=null)&&(c.getUserObject() instanceof Call)){
Call ca = (Call)(c.getUserObject());
name = "C"+ca.getId()+"-"+c.getChildCount();
}
else{ name = "C"+count;}
channel = new Channel( name, (fr.fluxmedia.transmorpher.Graph.Process)currentTransformation );
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);
channel.setName(name);
((Process)currentTransformation).addChannel(channel);
// Object[] tmp = gt.getSpanningTree(currentProcess,null);
// currentProcess.setSelectionCells(tmp);
// Object[] all = currentProcess.getAll();
// if (tmp.length!=all.length)
// System.out.println("le graphe comporte un circuit");
}
public void doConnection(PortView firstPort,PortView port) {
Channel channel;
DefaultGraphCell c = (DefaultGraphCell)(port.getParentView()).getCell();
String name;
if((c!=null)&&(c.getUserObject() instanceof Call)){
Call ca = (Call)(c.getUserObject());
name = "C"+ca.getId()+"-"+count;
}
else{ name = "C"+count;}
count++;
channel = new Channel( name, (fr.fluxmedia.transmorpher.Graph.Process)currentTransformation );
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);
channel.setName(name);
((Process)currentTransformation).addChannel(channel);
// Object[] tmp = gt.getSpanningTree(currentProcess,null);
// currentProcess.setSelectionCells(tmp);
// Object[] all = currentProcess.getAll();
// if (tmp.length!=all.length)
// System.out.println("le graphe comporte un circuit");
}
public int lenght(java.util.Iterator it) {
int compteur = 0;
while (it.hasNext()){
......@@ -376,24 +380,24 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
protected void previewPort(Graphics g) {
if (port != null) {
java.util.Iterator it = ((DefaultPort)port.getCell()).edges();
if ((firstPort!=null)&&(firstPort!=port)){
if ((lenght(it)<1)) {
DefaultGraphCell firstCell = (DefaultGraphCell)(firstPort.getParentView()).getCell();
DefaultGraphCell cell = (DefaultGraphCell)(port.getParentView()).getCell();
int firstType = ((PortCell)firstPort.getCell()).getType();
int type = ((PortCell)port.getCell()).getType();
if (!(firstCell instanceof PortProcessCell)){
if (!(cell instanceof PortProcessCell)){
if ((firstType!=type)&&(firstCell!=cell)) { paintPort(g);}
}
else if (firstType==type) { paintPort(g);}
}
else if (!(cell instanceof PortProcessCell)){
if (firstType==type) { paintPort(g);}
}
else if (firstType!=type) { paintPort(g);}
}
java.util.Iterator it = ((DefaultPort)port.getCell()).edges();
if ((firstPort!=null)&&(firstPort!=port)){
if ((lenght(it)<1)) {
DefaultGraphCell firstCell = (DefaultGraphCell)(firstPort.getParentView()).getCell();
DefaultGraphCell cell = (DefaultGraphCell)(port.getParentView()).getCell();
int firstType = ((PortCell)firstPort.getCell()).getType();
int type = ((PortCell)port.getCell()).getType();
if (!(firstCell instanceof PortProcessCell)){
if (!(cell instanceof PortProcessCell)){
if ((firstType!=type)&&(firstCell!=cell)) { paintPort(g);}
}
else if (firstType==type) { paintPort(g);}
}
else if (!(cell instanceof PortProcessCell)){
if (firstType==type) { paintPort(g);}
}
else if (firstType!=type) { paintPort(g);}
}
}
else {
if ((lenght(it)<1)) {
......@@ -403,18 +407,18 @@ public class FCMarqueeHandler extends BasicMarqueeHandler {
}
}
protected void paintPort(Graphics g) {
boolean offset = (GraphConstants.getOffset(port.getAttributes()) != null);
Rectangle r = (offset) ? port.getBounds(): port.getParentView().getBounds();
r = currentProcess.toScreen(new Rectangle(r));
int s = 3;
r.translate(-s, -s);
r.setSize(r.width+2*s, r.height+2*s);
currentProcess.getUI().paintCell(g, port, r, true);
}
protected void paintPort(Graphics g) {
boolean offset = (GraphConstants.getOffset(port.getAttributes()) != null);
Rectangle r = (offset) ? port.getBounds(): port.getParentView().getBounds();
r = currentProcess.toScreen(new Rectangle(r));
int s = 3;
r.translate(-s, -s);
r.setSize(r.width+2*s, r.height+2*s);
currentProcess.getUI().paintCell(g, port, r, true);
}
}
/**
* $Id: FCProcessFactory.java,v 1.10 2002-06-11 09:42:51 frederic Exp $
* $Id: FCProcessFactory.java,v 1.11 2002-06-18 15:04:14 gchomat Exp $
*
* Transmorpher
*
......@@ -88,6 +88,7 @@ public class FCProcessFactory implements ProcessFactory,Observer{
}
else
mainProcess = process;
}
listProcess.add(process);
......
/**
* $Id: ProcessGraph.java,v 1.34 2002-06-14 15:19:21 frederic Exp $
* $Id: ProcessGraph.java,v 1.35 2002-06-18 15:04:14 gchomat Exp $
*
* Transmorpher
*
......@@ -107,9 +107,10 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
undo = new GraphUndoManager();
setPortsVisible(true);
setSizeable(true);
setSizeable(false);
//setEditable(false);
setAntiAliased(true);
setUI(new FCGraphUI());
this.userObject = userObject;
}
......@@ -232,12 +233,12 @@ public class ProcessGraph extends JGraph implements Comparator, Observer{
/** interface Observer*/
public void update(Observable observable, Object arg){
if(observable instanceof Process)
if(observable instanceof Process)
{
if(arg instanceof Call)
{
if(arg instanceof Dispatch)
if(arg instanceof Dispatch)
addVertex(arg,FCConstants.DISPATCH);
else if(arg instanceof Merge)
addVertex(arg,FCConstants.MERGE);
......
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