01: package org.enhydra.jawe.components.graph;
02:
03: import java.awt.Dimension;
04: import java.awt.geom.Rectangle2D;
05: import java.util.HashMap;
06: import java.util.Map;
07:
08: import org.jgraph.graph.AttributeMap;
09: import org.jgraph.graph.CellViewRenderer;
10: import org.jgraph.graph.GraphConstants;
11:
12: /**
13: * Represents a view for a Port object.
14: *
15: * @author Sasa Bojanic
16: */
17: public class DefaultGraphPortView extends GraphPortViewInterface {
18:
19: protected static Map renderers = new HashMap();
20:
21: public DefaultGraphPortView(Object cell) {
22: super (cell);
23: AttributeMap map = new AttributeMap();
24: GraphConstants.setSize(map, new Dimension(30, 30));
25: super .setAttributes(map);
26: }
27:
28: /**
29: * Sets size of all ports to given value.
30: */
31: public void setPortSize(Dimension d) {
32: if (SIZE < 2)
33: SIZE = 2;
34: AttributeMap map = new AttributeMap();
35: GraphConstants.setSize(map, d);
36: super .setAttributes(map);
37: }
38:
39: /**
40: * Returns port's size.
41: */
42: public Dimension getPortSize() {
43: return (Dimension) getAttributes().get(GraphConstants.SIZE);
44: }
45:
46: public GraphActivityInterface getGraphActivity() {
47: return (GraphActivityInterface) getParentView().getCell();
48: }
49:
50: public CellViewRenderer getRenderer() {
51: String type = ((GraphPortInterface) super .getCell()).getType();
52: GraphPortRendererInterface gprenderer = (GraphPortRendererInterface) renderers
53: .get(type);
54: if (gprenderer == null) {
55: gprenderer = createRenderer(type);
56: renderers.put(type, gprenderer);
57: }
58: return gprenderer;
59: }
60:
61: public Rectangle2D getBounds() {
62: AttributeMap map = new AttributeMap();
63: Rectangle2D bounds = map.createRect(getLocation());
64: bounds.setFrame(bounds.getX() - getPortSize().width / 2, bounds
65: .getY()
66: - getPortSize().height / 2, bounds.getWidth()
67: + getPortSize().width, bounds.getHeight()
68: + getPortSize().height);
69: return bounds;
70: }
71:
72: protected GraphPortRendererInterface createRenderer(String type) {
73: return GraphUtilities.getGraphController()
74: .getGraphObjectRendererFactory().createPortRenderer(
75: type);
76: }
77:
78: }
|