Source code: com/port80/graph/impl/DefaultGraphAttrTable.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.util.msg;
10 import com.port80.util.attr.AttrRegistry;
11 import com.port80.util.attr.AttrTable;
12 import com.port80.util.attr.BooleanAttrFactory;
13 import com.port80.util.attr.ColorFactory;
14 import com.port80.util.attr.DoubleAttrFactory;
15 import com.port80.util.attr.IntAttrFactory;
16 import com.port80.util.attr.RectFactory;
17 import com.port80.util.attr.StringAttrFactory;
18
19 /**
20 * Place holder for preset default graph attributes.
21 *
22 * . The default values should never be changed.
23 * . Client should never access this class directly, instance of this
24 * class should only be used by vertex factories.
25 */
26 public class DefaultGraphAttrTable extends AttrTable {
27
28 private static final String NAME = "DefaultGraphAttrTable";
29
30 // Static fields ///////////////////////////////////////////////////////
31 //
32 public static final int RANKDIR_TB = 0;
33 public static final int RANKDIR_LR = 1;
34
35 // Instance feilds /////////////////////////////////////////////////////
36 //
37
38 private static DefaultGraphAttrTable instance = null;
39
40 // Static methods //////////////////////////////////////////////////////
41 //
42 public static DefaultGraphAttrTable getInstance() {
43 if (instance == null)
44 instance = new DefaultGraphAttrTable();
45 return instance;
46 }
47
48 // Constructors ////////////////////////////////////////////////////////
49 //
50
51 private DefaultGraphAttrTable() {
52 super(null, new AttrRegistry());
53 //
54 // Init. graph attribute registry.
55 //
56 StringAttrFactory aString = StringAttrFactory.getInstance();
57 BooleanAttrFactory aBoolean = BooleanAttrFactory.getInstance();
58 IntAttrFactory aInt = IntAttrFactory.getInstance();
59 DoubleAttrFactory aDouble = DoubleAttrFactory.getInstance();
60 RectFactory aRect = RectFactory.getInstance();
61 ColorFactory aColor = ColorFactory.getInstance();
62 ArrowFactory aArrow = ArrowFactory.getInstance();
63 //
64 // Unimplemented Graphviz attributes.
65 //
66 super.initAttr("ordering", aString, "out");
67 super.initAttr("rankdir", aString, "TB");
68 super.initAttr("pagedir", aString, "TBLR");
69 super.initAttr("rotate", false);
70 super.initAttr("center", true);
71 super.initAttr("nslimit", 1.0);
72 super.initAttr("mclimit", 1.0);
73 super.initAttr("layers", aString);
74 super.initAttr("url", aString);
75 //
76 super.initAttr("bb", aRect);
77 super.initAttr("bgcolor", aColor, Color.WHITE);
78 super.initAttr("color", aColor, Color.BLACK);
79 super.initAttr("rank", aString); // same,min,max
80 //
81 super.initAttr("margin", 1);
82 super.initAttr("ratio", 1.0);
83 super.initAttr("nodesep", 1.0);
84 super.initAttr("ranksep", 1.0);
85 //
86 // Attribute not in dot.
87 //
88 super.initAttr("inthreshold", 8);
89 // This is for the graph itself, vertices have their own inthreshold attribute.
90 super.initAttr("outthreshold", 8);
91 // This is for the graph itself, vertices have their own outthreshold attribute.
92 super.initAttr("criticaluseinbus", false); // True enable critical edge to use in buses.
93 super.initAttr("criticaluseoutbus", false); // True enable critical edge to use out buses.
94 super.initAttr("bidirectionalusebus", false); // True enable critical edge to use out buses.
95 super.initAttr("seed", 0);
96 //
97 // Layout parameters.
98 //
99 //
100 // Default layout parameters.
101 //
102 // These attributes are in pixels and scaled by nodesep and ranksep.
103 super.initAttr("default_halfwidth", 24);
104 super.initAttr("default_halfheight", 24);
105 super.initAttr("yspacing_xbus", 32);
106 super.initAttr("halfheight_virtualvertex", 3);
107 //
108 // These spacings are in pixels but NOT scaled by nodesep and ranksep.
109 super.initAttr("yspacing_busbus", 8);
110 //
111 // Spacing dividers. xdiv for vertex spacing and ydiv for rank spacing.
112 super.initAttr("xdiv_edges", 2);
113 super.initAttr("xdiv_xedge", 2);
114 //
115 // Mincross
116 super.initAttr("xpenalty_default", 32);
117 super.initAttr("xpenalty_bus", 8);
118 super.initAttr("xpenalty_critical", 32);
119 super.initAttr("xpenalty_stub", 1);
120 super.initAttr("xpenalty_aux", 2);
121 super.initAttr("xpenalty_dist", 1.0);
122 //
123 // Position
124 super.initAttr("virtual_weight_default", 1);
125 super.initAttr("virtual_weight_bus", 1);
126 super.initAttr("virtual_weight_critical", 8);
127 super.initAttr("virtual_weight_stub", 256);
128 // Multiplier for Virtual-Virtual edges.
129 super.initAttr("virtual_weightfactor", 8);
130 //
131 // Anneal
132 super.initAttr("cell_xdiv", 4); // super.getAttrInt("xdiv_edges")*2);
133 super.initAttr("cell_basicfactor", 1);
134 super.initAttr("cell_distfactor", 64);
135 super.initAttr("cell_turnfactor", 4);
136 super.initAttr("ptp_percent", 100);
137 //
138 // Route
139 super.initAttr("box_minoverlap", 4);
140 // super.getAttrInt("default_halfwidth") / super.getAttrInt("xdiv_edges"));
141 super.initAttr("merge_offset", 8);
142 //
143 // Cached attribute objects for layout/rendering.
144 //
145 super.initAttr("-headarrow", aArrow);
146 super.initAttr("-tailarrow", aArrow);
147 super.initAttr("-minrank", aInt);
148 super.initAttr("-maxrank", aInt);
149 }
150
151 ////////////////////////////////////////////////////////////////////////
152
153 /* Make attribute table read only. */
154
155 public Object setAttrFromString(String name, String value) {
156 msg.err(NAME + ".setAttrFromString(): Default table is read only: attrname=" + name);
157 return null;
158 }
159 public Object setAttr(String name, Object value) {
160 msg.err(NAME + ".setAttr(Object): Default table is read only: attrname=" + name);
161 return null;
162 }
163 public Object setAttr(String name, boolean value) {
164 msg.err(NAME + ".setAttr(boolean): Default table is read only: attrname=" + name);
165 return null;
166 }
167 public Object setAttr(String name, int value) {
168 msg.err(NAME + ".setAttr(int): Default table is read only: attrname=" + name);
169 return null;
170 }
171 public Object setAttr(String name, long value) {
172 msg.err(NAME + ".setAttr(long): Default table is read only: attrname=" + name);
173 return null;
174 }
175 public Object setAttr(String name, float value) {
176 msg.err(NAME + ".setAttr(float): Default table is read only: attrname=" + name);
177 return null;
178 }
179 public Object setAttr(String name, double value) {
180 msg.err(NAME + ".setAttr(double): Default table is read only: attrname=" + name);
181 return null;
182 }
183 public Object setAttrFromString(String name, double value) {
184 msg.err(NAME + ".setAttr(double): Default table is read only: attrname=" + name);
185 return null;
186 }
187 public Object removeAttr(String name) {
188 msg.err(NAME + ".removeAttr(String): Default table is read only: attrname=" + name);
189 return null;
190 }
191 public void removeUnregisteredAttrs() {
192 msg.err(NAME + ".removeUnregistered(): Default table is read only");
193 }
194 public void clearAttrs() {
195 msg.err(NAME + ".clearAttrs(): Default table is read only");
196 }
197
198 ////////////////////////////////////////////////////////////////////////
199
200 }