| [Prior]
[Top] [Next]
7.
Graph Event Handling
Graph
event handling in JFDraw.
We added a new graph event handling mechanism in JFDraw now. So
you can implement you own code while a shape/selection is selected,
moving/moved,moving/moved nodes, changed properties.
Sample
codes of graph event handling.
Method
1: add an Event Listener to current DrawPane.
//Action:
create a draw panel
//Desc: A DrawPane object packaged a vertical ruler, a horizontal
ruler and a drawing canvas
DrawPane
panel =new DrawPane();
//Action: Add a new customized Graph event
listener for JFDraw shapes.
panel.addGraphEventListener(new GraphEventListener(){
public void graphChanged(GraphEvent ge){
Sample5.printGraphChangedEvent(ge);
}
});
Method
2: Create a subclass which extends DrawPane and implements GraphEventListener.
//you
can use method below to create a sub class object of DrawPane
DrawPane panel =new MyDrawPane();
....
class MyDrawPane extends DrawPane implements
GraphEventListener{
public void graphChanged(GraphEvent ge){
Sample5.printGraphChangedEvent(ge);
}
}
Output
samples in Sample5.printGraphChangedEvent method.
Lines below are some sample output for Sample5.printGraphChangedEvent
Method:
.........
Event:
Shape Selected; Shape Count:1; mouse Pos:163,126
Event: Shape Moving; Shape Count:1; mouse Pos:163,124
Event: Shape Moving; Shape Count:1; mouse Pos:163,122
Event: Shape Moving; Shape Count:1; mouse Pos:163,120
Event: Shape Moving; Shape Count:1; mouse Pos:165,120
Event: Shape Moving; Shape Count:1; mouse Pos:165,118
Event: Shape Moving; Shape Count:1; mouse Pos:165,116
Event: Shape Moving; Shape Count:1; mouse Pos:167,116
Event: Shape Moving; Shape Count:1; mouse Pos:167,114
Event: Shape Moved; Shape Count:1; mouse Pos:167,114
Event: Node Selected; Shape Count:1; mouse Pos:203,146
Event: Node Moving; Shape Count:1; mouse Pos:203,144
Event: Node Moving; Shape Count:1; mouse Pos:201,144
Event: Node Moving; Shape Count:1; mouse Pos:199,144
Event: Node Moving; Shape Count:1; mouse Pos:197,144
Event: Node Moving; Shape Count:1; mouse Pos:195,142
Event: Node Moving; Shape Count:1; mouse Pos:193,142
Event: Node Moving; Shape Count:1; mouse Pos:193,140
Event: Node Moving; Shape Count:1; mouse Pos:191,140
Event: Node Moving; Shape Count:1; mouse Pos:191,138
.........
To
get full source code of this sample.
You can download the full sample
source code package here. Then open the file at sample5/Sample5.java
for detail informations.
[Prior]
[Top] [Next]
|