Source code: com/port80/graph/impl/DirectedVertexFactory.java
1 //
2 // Copyright(c) 2002, Chris Leung
3 //
4
5 package com.port80.graph.impl;
6
7 import java.awt.Color;
8
9 import com.port80.graph.GraphException;
10 import com.port80.graph.IGraph;
11 import com.port80.graph.IVertex;
12 import com.port80.graph.IVertexFactory;
13 import com.port80.graph.dot.impl.RouteFactory;
14 import com.port80.util.msg;
15 import com.port80.util.attr.AttrRegistry;
16 import com.port80.util.attr.AttrTable;
17 import com.port80.util.attr.ColorFactory;
18 import com.port80.util.attr.DoubleAttrFactory;
19 import com.port80.util.attr.FontFactory;
20 import com.port80.util.attr.IAttrRegistry;
21 import com.port80.util.attr.IntAttrFactory;
22 import com.port80.util.attr.PointFactory;
23 import com.port80.util.attr.RectFactory;
24 import com.port80.util.attr.StringAttrFactory;
25
26 /** Factory class that produce vertex for directed graph. The factory
27 * also holds default attributes for vertices and IAttrRegistry interface for
28 * client to check for unqiue attribute names.
29 */
30 public class DirectedVertexFactory extends AttrTable implements IVertexFactory {
31
32 private static final String NAME="DirectedVertexFactory";
33
34 // Instance feilds /////////////////////////////////////////////////////
35 //
36
37 // Constructors ////////////////////////////////////////////////////////
38 //
39
40 public DirectedVertexFactory() {
41 super(null, new AttrRegistry());
42 //
43 StringAttrFactory aString = StringAttrFactory.getInstance();
44 IntAttrFactory aInt = IntAttrFactory.getInstance();
45 DoubleAttrFactory aDouble = DoubleAttrFactory.getInstance();
46 RectFactory aRect = RectFactory.getInstance();
47 ColorFactory aColor = ColorFactory.getInstance();
48 StrokeFactory aStroke = StrokeFactory.getInstance();
49 FontFactory aFont = FontFactory.getInstance();
50 PointFactory aPoint = PointFactory.getInstance();
51 ShapeFactory aShape = ShapeFactory.getInstance();
52 RouteFactory aRoute = RouteFactory.getInstance();
53 //
54 super.initAttr("shape", aString, "box");
55 super.initAttr("style", aString, "filled");
56 super.initAttr("color", aColor, Color.BLACK);
57 super.initAttr("fillcolor", aColor, Color.WHITE);
58 //FIXME: Java doesn't seems to be able to use the X11 fonts.
59 super.initAttr("fontname", "verdana");
60 super.initAttr("fontsize", 11.0);
61 super.initAttr("fontcolor", aColor,Color.BLACK);
62 super.initAttr("fontstyle", aString);
63 //
64 super.initAttr("layer", aString);
65 super.initAttr("url", aString);
66 super.initAttr("pos", aPoint);
67 super.initAttr("label", aString);
68 super.initAttr("height", aDouble);
69 // 'top' to pull vertex to top rank if vertex has no input edge.
70 // 'min', 'max' to put vertex at the min/max rank (regardless of number of input edges).
71 super.initAttr("rank", aString);
72 //
73 // Added attributes not in 'dot'.
74 //
75 super.initAttr("inthreshold", 8);
76 super.initAttr("outthreshold", 8);
77 super.initAttr("ibuscolor", aColor, Color.BLUE);
78 super.initAttr("obuscolor", aColor, Color.BLACK);
79 super.initAttr("minwidth", 48);
80 super.initAttr("minheight", 24);
81 //
82 super.initAttr("tobus", aString);
83 super.initAttr("frombus", aString);
84 super.initAttr("inbus", aString);
85 super.initAttr("outbus", aString);
86 super.initAttr("exclude", aInt);
87 super.initAttr("alt1", aString);
88 super.initAttr("alt2", aString);
89 super.initAttr("alt3", aString);
90 //
91 // Transient attributes.
92 //
93 super.initAttr("-font", aFont); // Owned by renderer.
94 super.initAttr("-style", aStroke); // Jointly owned by renderer and layout manager.
95 super.initAttr("-shape", aShape); // Jointly owned by renderer and layout manager.
96 super.initAttr("-rank", aInt);
97 super.initAttr("-bounds", aRect);
98 super.initAttr("-tobus", aRoute);
99 super.initAttr("-frombus", aRoute);
100 super.initAttr("-inbus", aRoute);
101 super.initAttr("-outbus", aRoute);
102 }
103
104 // IAttrTable interface ////////////////////////////////////////////////
105 //
106
107 /**
108 * Factory tables are read only. Override setAttr methods to warn user.
109 */
110
111 public Object setAttrFromString(String name, String value) {
112 msg.err(NAME+".setAttrFromString(): Factory table is read only: attrname="+name);
113 return null;
114 }
115 public Object setAttr(String name, Object value) {
116 msg.err(NAME+".setAttr(Object): Factory table is read only: attrname="+name);
117 return null;
118 }
119 public Object setAttr(String name, boolean value) {
120 msg.err(NAME+".setAttr(boolean): Factory table is read only: attrname="+name);
121 return null;
122 }
123 public Object setAttr(String name, int value) {
124 msg.err(NAME+".setAttr(int): Factory table is read only: attrname="+name);
125 return null;
126 }
127 public Object setAttr(String name, long value) {
128 msg.err(NAME+".setAttr(long): Factory table is read only: attrname="+name);
129 return null;
130 }
131 public Object setAttr(String name, float value) {
132 msg.err(NAME+".setAttr(float): Factory table is read only: attrname="+name);
133 return null;
134 }
135 public Object setAttr(String name, double value) {
136 msg.err(NAME+".setAttr(double): Factory table is read only: attrname="+name);
137 return null;
138 }
139 public Object setAttrFromString(String name, double value) {
140 msg.err(NAME+".setAttr(double): Factory table is read only: attrname="+name);
141 return null;
142 }
143 public Object removeAttr(String name) {
144 msg.err(NAME+".removeAttr(String): Factory table is read only: attrname="+name);
145 return null;
146 }
147 public void removeUnregistered() {
148 msg.err(NAME+".removeUnregistered(): Factory table is read only");
149 }
150 public void clearAttrs() {
151 msg.err(NAME+".clearAttrs(): Factory table is read only");
152 }
153
154 // IAttrFactory interface //////////////////////////////////////////////
155 //
156
157 public IVertex newVertex(String name, Object data, IGraph parent) throws GraphException {
158 return newVertex(name, null, data, parent);
159 }
160
161 public IVertex newVertex(String name, String port, Object data, IGraph parent) throws GraphException {
162 if (parent.containsVertex(name))
163 throw new GraphException("Duplicated vertex", parent.getVertex(name), parent);
164 return new Vertex(name, port, data, parent);
165 }
166
167 ////////////////////////////////////////////////////////////////////////
168
169 }