|
1 /*************************************************************************** |
|
2 Title: GraphBrowser/Vertex.java |
|
3 ID: $Id$ |
|
4 Author: Stefan Berghofer, TU Muenchen |
|
5 Copyright 1997 TU Muenchen |
|
6 |
|
7 This class contains attributes and methods common to all kinds of |
|
8 vertices (e.g. coordinates, successors, predecessors). |
|
9 ***************************************************************************/ |
|
10 |
|
11 package GraphBrowser; |
|
12 |
|
13 import java.util.*; |
|
14 import java.awt.*; |
|
15 import java.io.*; |
|
16 |
|
17 abstract class Vertex { |
|
18 protected static final Font font=new Font("Helvetica",Font.PLAIN,12); |
|
19 |
|
20 Vector children=new Vector(10,10); |
|
21 Vector parents=new Vector(10,10); |
|
22 int degree=0; |
|
23 int number=-1; |
|
24 double weight=0; |
|
25 int x,y; |
|
26 Graph gra; |
|
27 |
|
28 public abstract Object clone(); |
|
29 |
|
30 public void setGraph(Graph g) { gra=g; } |
|
31 |
|
32 public int countChildren() { return children.size(); } |
|
33 |
|
34 /** getInflate returns a vector of vertices which get **/ |
|
35 /** inflated again if the user clicks on this vertex **/ |
|
36 |
|
37 public void setInflate(Vector v) {} |
|
38 |
|
39 public Vector getInflate() { return null; } |
|
40 |
|
41 /** getUp returns a vector of vertices which get inflated **/ |
|
42 /** again, if the user clicks on this vertex's upward arrow **/ |
|
43 |
|
44 public Vector getUp() { return null; } |
|
45 |
|
46 public void setUp(Vector v) {} |
|
47 |
|
48 /** getUp returns a vector of vertices which get inflated **/ |
|
49 /** again, if the user clicks on this vertex's downward arrow **/ |
|
50 |
|
51 public Vector getDown() { return null; } |
|
52 |
|
53 public void setDown(Vector v) {} |
|
54 |
|
55 /** internal number, for decoding / encoding etc. **/ |
|
56 |
|
57 public int getNumber() { return number; } |
|
58 |
|
59 public void setNumber(int n) { number=n; } |
|
60 |
|
61 public String getLabel() {return "";} |
|
62 |
|
63 public void setLabel(String s) {} |
|
64 |
|
65 /** unique identifier **/ |
|
66 |
|
67 public String getID() {return "";} |
|
68 |
|
69 public void setID(String s) {} |
|
70 |
|
71 public Dimension getLabelSize(Graphics g) { |
|
72 FontMetrics fm=g.getFontMetrics(font); |
|
73 |
|
74 return new Dimension( |
|
75 Math.max(fm.stringWidth("[. . . .]"),fm.stringWidth(getLabel())), |
|
76 fm.getAscent()+fm.getDescent()); |
|
77 } |
|
78 |
|
79 public String getPath() { return "";} |
|
80 |
|
81 public void setPath(String p) {} |
|
82 |
|
83 public String getDir() { return ""; } |
|
84 |
|
85 public void setDir(String d) {} |
|
86 |
|
87 public void setWeight(double w) {weight=w;} |
|
88 |
|
89 public double getWeight() {return weight;} |
|
90 |
|
91 public void setDegree(int d) { degree=d; } |
|
92 |
|
93 public int getDegree() { return degree; } |
|
94 |
|
95 public boolean isDummy() { return false; } |
|
96 |
|
97 public Enumeration getChildren() { |
|
98 return ((Vector)(children.clone())).elements(); |
|
99 } |
|
100 |
|
101 public void addChild(Vertex v) { |
|
102 children.addElement(v); |
|
103 v.parents.addElement(this); |
|
104 } |
|
105 |
|
106 public void removeChild(Vertex v) { |
|
107 children.removeElement(v); |
|
108 v.parents.removeElement(this); |
|
109 } |
|
110 |
|
111 public boolean isChild(Vertex v) { |
|
112 return children.indexOf(v)>=0; |
|
113 } |
|
114 |
|
115 public boolean isParent(Vertex v) { |
|
116 return parents.indexOf(v)>=0; |
|
117 } |
|
118 |
|
119 public Enumeration getParents() { |
|
120 return ((Vector)(parents.clone())).elements(); |
|
121 } |
|
122 |
|
123 public void addParent(Vertex v) { |
|
124 parents.addElement(v); |
|
125 v.children.addElement(this); |
|
126 } |
|
127 |
|
128 public void removeParent(Vertex v) { |
|
129 parents.removeElement(v); |
|
130 v.children.removeElement(this); |
|
131 } |
|
132 |
|
133 /********************************************************************/ |
|
134 /* get all predecessor vertices */ |
|
135 /********************************************************************/ |
|
136 |
|
137 public Vector getPreds() { |
|
138 Vector v1=new Vector(10,10); |
|
139 Vertex vx1,vx2; |
|
140 Enumeration e1,e2; |
|
141 |
|
142 e1=getParents(); |
|
143 while (e1.hasMoreElements()) { |
|
144 vx1=(Vertex)(e1.nextElement()); |
|
145 if (v1.indexOf(vx1)<0) v1.addElement(vx1); |
|
146 e2=vx1.getPreds().elements(); |
|
147 while (e2.hasMoreElements()) { |
|
148 vx2=(Vertex)(e2.nextElement()); |
|
149 if (v1.indexOf(vx2)<0) v1.addElement(vx2); |
|
150 } |
|
151 } |
|
152 |
|
153 return v1; |
|
154 } |
|
155 |
|
156 /********************************************************************/ |
|
157 /* get all successor vertices */ |
|
158 /********************************************************************/ |
|
159 |
|
160 public Vector getSuccs() { |
|
161 Vector v1=new Vector(10,10); |
|
162 Vertex vx1,vx2; |
|
163 Enumeration e1,e2; |
|
164 |
|
165 e1=getChildren(); |
|
166 while (e1.hasMoreElements()) { |
|
167 vx1=(Vertex)(e1.nextElement()); |
|
168 if (v1.indexOf(vx1)<0) v1.addElement(vx1); |
|
169 e2=vx1.getSuccs().elements(); |
|
170 while (e2.hasMoreElements()) { |
|
171 vx2=(Vertex)(e2.nextElement()); |
|
172 if (v1.indexOf(vx2)<0) v1.addElement(vx2); |
|
173 } |
|
174 } |
|
175 |
|
176 return v1; |
|
177 } |
|
178 |
|
179 public void setX(int x) {this.x=x;} |
|
180 |
|
181 public void setY(int y) {this.y=y;} |
|
182 |
|
183 public int getX() {return x;} |
|
184 |
|
185 public int getY() {return y;} |
|
186 |
|
187 public abstract int leftX(); |
|
188 |
|
189 public abstract int rightX(); |
|
190 |
|
191 public abstract void draw(Graphics g); |
|
192 |
|
193 public void drawButtons(Graphics g) {} |
|
194 |
|
195 public void drawBox(Graphics g,Color boxColor) {} |
|
196 |
|
197 public void removeButtons(Graphics g) {} |
|
198 |
|
199 public boolean contains(int x,int y) { return false; } |
|
200 |
|
201 public boolean leftButton(int x,int y) { return false; } |
|
202 |
|
203 public boolean rightButton(int x,int y) { return false; } |
|
204 |
|
205 public void PS(PrintStream p) {} |
|
206 } |