1 package org.glassbox.graphview;
2
3 import org.glassbox.gui.*;
4
5 import de.fzi.wim.guibase.graphview.graph.*;
6
7 import javax.swing.*;
8 import java.util.HashMap;
9 import java.util.Iterator;
10 import java.awt.Dimension;
11
12 /***
13 Implementation of a layered group to display graphs.
14 It uses a <code>JLayeredPane</code> as view.
15 The group offers a <code>GGraphPane</code> on the background layer (i.e. the layer with index 0).
16 */
17 public class GraphGroup extends JLayeredGroup implements LayeredGroup.Layer {
18 public static final String IDENTIFIER = "glassbox.GraphGroup";
19 /*** The position of the graph layer (background). */
20 public static final int GRAPH_LAYER = 0;
21 /*** The position of the graph component layer (one above background). */
22 public static final int GRAPH_COMPONENT_LAYER = 1;
23
24 protected GGraphPane _graphpane;
25
26 public GraphGroup() {
27 this(true);
28 }
29
30 public GraphGroup(boolean showgraphpane) {
31 super();
32 _graphpane = new GGraphPane(null);
33 if (showgraphpane) {
34 _view.add(_graphpane, new Integer(0));
35 }
36 addLayer(GRAPH_COMPONENT_LAYER, this);
37 }
38 /***
39 Set the current graph.
40 */
41 public void setGraph(Graph graph) {
42 _graphpane.setGraph(graph);
43 }
44
45 /***
46 Get the current graph.
47 */
48 public Graph getGraph() {
49 return _graphpane.getGraph();
50 }
51
52 /***
53 Get the graph pane.
54 */
55 public GGraphPane getGraphPane() {
56 return _graphpane;
57 }
58
59 /***
60 Add a visible member to the group on the GRAPH_COMPONENT_LAYER and attach it to the specified node.
61 Not implemented yet, simply calls <code>addMember(member, GRAPH_COMPONENT_LAYER)</code>.
62 */
63 public void addMember(VisibleMember member, Node node) {
64 addMember(member, GRAPH_COMPONENT_LAYER);
65 }
66
67 /***
68 Add a visible member to the group on the GRAPH_COMPONENT_LAYER and attach it to the specified edge.
69 Not implemented yet, simply calls <code>addMember(member, GRAPH_COMPONENT_LAYER)</code>.
70 */
71 public void addMember(VisibleMember member, Edge edge) {
72 addMember(member, GRAPH_COMPONENT_LAYER);
73 }
74
75
76
77
78
79 /***
80 Adds the visible's view to the GRAPH_COMPONENT_LAYER.
81 This method should not be used by clients, use <code>addMember(VisibleMember, {Node | Edge})</code> instead.
82 */
83 public void addVisible(Visible view, Object constraints) {
84 addVisible(view);
85 }
86
87 /***
88 Adds the visible's view to the GRAPH_COMPONENT_LAYER.
89 This method should not be used by clients, use <code>addMember(VisibleMember, {Node | Edge})</code> instead.
90 */
91 public void addVisible(Visible view) {
92 _view.add(view.getView(), new Integer(GRAPH_COMPONENT_LAYER));
93 }
94
95 public void removeVisible(Visible view) {
96 _view.remove(view.getView());
97 }
98
99
100
101
102
103 public String getIdentifier() {
104 return IDENTIFIER;
105 }
106
107 /***
108 Add a member to the specified layer.
109 It is not allowed to add a member to the background layer (index 0) or the GRAPH_COMPONENT_LAYER.
110 @exception IllegalArgumentException If the specified layer is <= 0;
111 */
112 public void addMember(VisibleMember member, int position) {
113 if (position<=0)
114 throw new IllegalArgumentException("Can not add member to the background layer.");
115 super.addMember(member, position);
116 }
117
118 /***
119 Add a member to the specified layer.
120 It is not allowed to add a member to the background layer (index 0) or the GRAPH_COMPONENT_LAYER.
121 @exception IllegalArgumentException If the specified layer is <= 0;
122 */
123 public void addMember(VisibleMember member, int position, Object constraints) {
124 if (position<=0)
125 throw new IllegalArgumentException("Can not add member to the background layer.");
126 super.addMember(member, position, constraints);
127 }
128
129 /***
130 Overridden to handle certain property changes within this group.<br>
131 The following properties are interpreted by this method:
132 <table>
133 <tr><td><pre>glassbox.VisibleGroup.modal-member</pre></td><td>Disables and enables the view accordingly.</td></tr>
134 <tr><td><pre>glassbox.VisibleGroup.viewport-size</pre></td><td>Resizes the view.</td></tr>
135 </table>
136 */
137 public void setProperty(String name, Object newvalue) {
138 if (name.equals(VisibleGroup.MODAL_MEMBER_KEY)) {
139 if (newvalue!=this && newvalue!=null) {
140 _graphpane.setEnabled(false);
141 } else if (newvalue==null) {
142 _graphpane.setEnabled(true);
143 }
144 } else if (name.equals(VisibleGroup.VIEWPORT_SIZE_KEY)) {
145 Dimension newsize = (Dimension)newvalue;
146 _graphpane.setSize(newsize);
147 }
148 super.setProperty(name, newvalue);
149 }
150 }
151