1 package org.glassbox.graphview;
2
3 import java.awt.Color;
4 import java.awt.Point;
5 import java.awt.Rectangle;
6 import java.util.HashMap;
7 import java.util.List;
8 import java.util.Set;
9
10 import de.fzi.wim.guibase.graphview.graph.*;
11 import de.fzi.wim.guibase.graphview.view.*;
12
13 import org.glassbox.Theme;
14
15 /***
16 An extension of <code>JGraphPane</code> for some additional features.<br><br>
17 This class has the following properties which can be configured via the application's theme:
18 <ul>
19 <li>glassbox.graphview.GGraphPane.background.color</li>
20 </ul>
21 */
22 public class GGraphPane extends JGraphPane {
23 protected static final String BACKGROUND_COLOR_KEY = "glassbox.graphview.GGraphPane.background.color";
24 protected static final Color BACKGROUND_COLOR = Theme.getColor(BACKGROUND_COLOR_KEY);
25
26 protected HashMap _nodepainters;
27 protected HashMap _edgepainters;
28
29 public GGraphPane(Graph graph) {
30 super(graph);
31 _nodepainters = new HashMap();
32 _edgepainters = new HashMap();
33 setBackground(BACKGROUND_COLOR);
34 }
35
36 protected void updateNodeScreenPositions() {
37 if (m_graph!=null) {
38 super.updateNodeScreenPositions();
39 }
40 }
41
42 public Node getNodeAtPoint(Point point) {
43 if (m_graph!=null) {
44 return super.getNodeAtPoint(point);
45 } else {
46 return null;
47 }
48 }
49
50 public Set getNodesInRectangle(Rectangle rectangle) {
51 if (m_graph!=null) {
52 return super.getNodesInRectangle(rectangle);
53 } else {
54 return null;
55 }
56 }
57
58 public Edge getNearestEdge(Point point) {
59 if (m_graph!=null) {
60 return super.getNearestEdge(point);
61 } else {
62 return null;
63 }
64 }
65
66 /***
67 Set the painter for a spcific type of node.
68 */
69 public void setNodePainter(Class nodetype, NodePainter painter) {
70 _nodepainters.put(nodetype, painter);
71 }
72
73 /***
74 Set the painter for a spcific type of edge.
75 */
76 public void setEdgePainter(Class edgetype, EdgePainter painter) {
77 _edgepainters.put(edgetype, painter);
78 }
79
80 /***
81 Get the painter for a node.
82 <code>setNodePainter</code> must have been called for the node's class before callling this method,
83 otherwise <code>null</code> will be returned.
84 */
85 public NodePainter getPainterForNode(Node node) {
86 return (NodePainter)_nodepainters.get(node.getClass());
87 }
88
89 /***
90 Get the painter for an edge.
91 <code>setEdgePainter</code> must have been called for the edge's class before callling this method,
92 otherwise <code>null</code> will be returned.
93 */
94 public EdgePainter getPainterForEdge(Edge edge) {
95 return (EdgePainter)_edgepainters.get(edge.getClass());
96 }
97 }