3599
|
1 |
/***************************************************************************
|
|
2 |
Title: GraphBrowser/NormalVertex.java
|
|
3 |
Author: Stefan Berghofer, TU Muenchen
|
|
4 |
|
|
5 |
This class represents an ordinary vertex. It contains methods for
|
|
6 |
drawing and PostScript output.
|
|
7 |
***************************************************************************/
|
|
8 |
|
|
9 |
package GraphBrowser;
|
|
10 |
|
|
11 |
import java.util.*;
|
|
12 |
import java.awt.*;
|
|
13 |
import java.io.*;
|
|
14 |
|
|
15 |
class NormalVertex extends Vertex {
|
|
16 |
String label="",path="",dir="",ID="";
|
|
17 |
Vector up,down,inflate=null;
|
|
18 |
|
|
19 |
public Object clone() {
|
|
20 |
Vertex ve=new NormalVertex(label);
|
|
21 |
ve.setID(ID);
|
|
22 |
ve.setNumber(getNumber());
|
|
23 |
ve.setUp(getUp());ve.setDown(getDown());
|
|
24 |
ve.setX(getX());ve.setY(getY());
|
|
25 |
ve.setPath(getPath());
|
|
26 |
return ve;
|
|
27 |
}
|
|
28 |
|
|
29 |
/*** Constructor ***/
|
|
30 |
|
|
31 |
public NormalVertex(String s) { label=s; }
|
|
32 |
|
|
33 |
public void setInflate(Vector v) { inflate=v; }
|
|
34 |
|
|
35 |
public Vector getInflate() { return inflate; }
|
|
36 |
|
|
37 |
public Vector getUp() { return up; }
|
|
38 |
|
|
39 |
public void setUp(Vector v) { up=v; }
|
|
40 |
|
|
41 |
public Vector getDown() { return down; }
|
|
42 |
|
|
43 |
public void setDown(Vector v) { down=v; }
|
|
44 |
|
|
45 |
public String getLabel() {return label;}
|
|
46 |
|
|
47 |
public void setLabel(String s) {label=s;}
|
|
48 |
|
|
49 |
public void setID(String s) { ID=s; }
|
|
50 |
|
|
51 |
public String getID() { return ID; }
|
|
52 |
|
|
53 |
public String getPath() { return path;}
|
|
54 |
|
|
55 |
public void setPath(String p) { path=p; }
|
|
56 |
|
|
57 |
public String getDir() { return dir; }
|
|
58 |
|
|
59 |
public void setDir(String d) { dir=d; }
|
|
60 |
|
|
61 |
public int leftX() { return getX()-gra.box_width2; }
|
|
62 |
|
|
63 |
public int rightX() { return getX()+gra.box_width2; }
|
|
64 |
|
|
65 |
public void drawBox(Graphics g,Color boxColor) {
|
11872
|
66 |
FontMetrics fm = g.getFontMetrics(g.getFont());
|
3599
|
67 |
int h=fm.getAscent()+fm.getDescent();
|
|
68 |
|
|
69 |
g.setColor(boxColor);
|
|
70 |
g.fillRect(getX()-gra.box_width2,getY(),gra.box_width,gra.box_height);
|
|
71 |
g.setColor(Color.black);
|
|
72 |
g.drawRect(getX()-gra.box_width2,getY(),gra.box_width,gra.box_height);
|
|
73 |
if (getNumber()<0) {
|
|
74 |
g.setColor(Color.red);
|
|
75 |
label=label.substring(1,label.length()-1);
|
|
76 |
while (label.length()>0 && fm.stringWidth("["+label+"]")>gra.box_width-8)
|
|
77 |
label=label.substring(0,label.length()-1);
|
|
78 |
label="["+label+"]";
|
|
79 |
}
|
|
80 |
|
|
81 |
g.drawString(label,
|
|
82 |
(int)Math.round((gra.box_width-fm.stringWidth(label))/2.0)+getX()-gra.box_width2,
|
|
83 |
fm.getAscent()+(int)Math.round((gra.box_height-h)/2.0)+getY());
|
|
84 |
}
|
|
85 |
|
|
86 |
public void removeButtons(Graphics g) {
|
|
87 |
drawBox(g,Color.lightGray);
|
|
88 |
}
|
|
89 |
|
|
90 |
public void draw(Graphics g) {
|
|
91 |
drawBox(g,Color.lightGray);
|
|
92 |
g.setColor(Color.black);
|
|
93 |
Enumeration e1=getChildren();
|
|
94 |
while (e1.hasMoreElements()) {
|
|
95 |
Vertex v=(Vertex)(e1.nextElement());
|
|
96 |
if (!v.isDummy())
|
|
97 |
g.drawLine(getX(),getY()+gra.box_height,v.getX(),v.getY());
|
|
98 |
}
|
|
99 |
}
|
|
100 |
|
|
101 |
public boolean contains(int x,int y) {
|
|
102 |
return (x>=leftX() && x<=rightX() && y>=getY() &&
|
|
103 |
y<=getY()+gra.box_height);
|
|
104 |
}
|
|
105 |
|
|
106 |
public boolean leftButton(int x,int y) {
|
|
107 |
return contains(x,y) && x<=leftX()+gra.box_height && getParents().hasMoreElements() && getNumber()>=0;
|
|
108 |
}
|
|
109 |
|
|
110 |
public boolean rightButton(int x,int y) {
|
|
111 |
return contains(x,y) && x>=rightX()-gra.box_height && getChildren().hasMoreElements() && getNumber()>=0;
|
|
112 |
}
|
|
113 |
|
|
114 |
public void drawButtons(Graphics g) {
|
|
115 |
if (getNumber()<0) return;
|
|
116 |
|
|
117 |
int l=gra.box_height*2/3,d=gra.box_height/6;
|
|
118 |
int up_x[] = { leftX()+d , leftX()+d+l/2 , leftX()+d+l };
|
|
119 |
int up_y[] = { getY()+d+l , getY()+d , getY()+d+l };
|
|
120 |
int down_x[] = { rightX()-d-l , rightX()-d-l/2 , rightX()-d };
|
|
121 |
int down_y[] = { getY()+d , getY()+d+l , getY()+d };
|
|
122 |
|
|
123 |
if (getParents().hasMoreElements()) {
|
|
124 |
g.setColor(Color.gray);
|
|
125 |
g.fillRect(leftX()+1,getY()+1,gra.box_height-1,gra.box_height-1);
|
|
126 |
g.setColor(getUp()!=null ? Color.red : Color.green);
|
|
127 |
g.fillPolygon(up_x,up_y,3);
|
|
128 |
}
|
|
129 |
if (getChildren().hasMoreElements()) {
|
|
130 |
g.setColor(Color.gray);
|
|
131 |
g.fillRect(rightX()+1-gra.box_height,getY()+1,gra.box_height,gra.box_height-1);
|
|
132 |
g.setColor(getDown()!=null ? Color.red : Color.green);
|
|
133 |
g.fillPolygon(down_x,down_y,3);
|
|
134 |
}
|
|
135 |
g.setColor(Color.black);
|
|
136 |
}
|
|
137 |
|
6541
|
138 |
public void PS(PrintWriter p) {
|
3599
|
139 |
p.print(leftX()+" "+getY()+" "+gra.box_width+" "+
|
|
140 |
gra.box_height+" (");
|
|
141 |
for (int i=0;i<label.length();i++)
|
|
142 |
{
|
|
143 |
if (("()\\").indexOf(label.charAt(i))>=0)
|
|
144 |
p.print("\\");
|
|
145 |
p.print(label.charAt(i));
|
|
146 |
}
|
|
147 |
p.println(") b");
|
|
148 |
|
|
149 |
Enumeration e1=getChildren();
|
|
150 |
while (e1.hasMoreElements()) {
|
|
151 |
Vertex v=(Vertex)(e1.nextElement());
|
|
152 |
if (!v.isDummy())
|
|
153 |
p.println("n "+getX()+" "+(getY()+gra.box_height)+
|
|
154 |
" m "+v.getX()+" "+v.getY()+" l s");
|
|
155 |
}
|
|
156 |
}
|
|
157 |
}
|
|
158 |
|