01: package com.jgraph.example.groupeditor;
02:
03: import java.net.URL;
04:
05: import javax.swing.ImageIcon;
06: import javax.swing.JFrame;
07:
08: import org.jgraph.JGraph;
09: import org.jgraph.graph.VertexView;
10:
11: import com.jgraph.example.GraphEdX;
12: import com.jgraph.example.GraphEdXMenuBar;
13:
14: /**
15: * A demo based on GraphEdX that demonstrates a simple way of allowing the user
16: * to edit cells inside groups or the groups themselves. NB: in order to have the
17: * edit button displayed in the top layer (not shadowed by child cells), we need
18: * to display them on the border away from the child cells. To do that, we
19: * assume we groups have larger bounds than the union of their child cells, a
20: * feauture implemented in GraphEdX in the group method.
21: *
22: * Remark: using a click system rather than this button system wouldn't work
23: * because the click count is already used to traverse the cell selection.
24: *
25: * @author rvalyi
26: */
27: public class EditableGroupDemo extends GraphEdX {
28:
29: /**
30: * References the folding manager.
31: */
32: protected GroupManager foldingManager;
33:
34: // Override parent method
35: protected void installListeners(JGraph graph) {
36: super .installListeners(graph);
37: // Adds redirector for group collapse/expand
38: foldingManager = new GroupManager();
39: graph.addMouseListener(foldingManager);
40: }
41:
42: protected void uninstallListeners(JGraph graph) {
43: super .uninstallListeners(graph);
44: graph.removeMouseListener(foldingManager);
45: }
46:
47: /**
48: * Constructs a new application
49: */
50: public EditableGroupDemo() {
51: // Overrides the global vertex renderer
52: VertexView.renderer = new EditableGroupRenderer();
53:
54: // Prepares layout actions
55: setJMenuBar(new GraphEdXMenuBar(this , graphFactory));
56: // Initializes actions states
57: valueChanged(null);
58: }
59:
60: /**
61: * Main method
62: */
63: public static void main(String[] args) {
64: try {
65: // Construct Frame
66: JFrame frame = new JFrame("GraphEdX");
67: // Set Close Operation to Exit
68: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
69: // Add an Editor Panel
70: GraphEdX app = new EditableGroupDemo();
71: frame.getContentPane().add(app);
72: // Fetch URL to Icon Resource
73: URL jgraphUrl = GraphEdX.class.getClassLoader()
74: .getResource(
75: "org/jgraph/example/resources/jgraph.gif");
76: // If Valid URL
77: if (jgraphUrl != null) {
78: // Load Icon
79: ImageIcon jgraphIcon = new ImageIcon(jgraphUrl);
80: // Use in Window
81: frame.setIconImage(jgraphIcon.getImage());
82: }
83: // Set Default Size
84: frame.setSize(640, 480);
85: // Show Frame
86: frame.setVisible(true);
87: app.init();
88: } catch (Exception e) {
89: e.printStackTrace();
90: }
91: }
92:
93: }
|