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