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