3599
|
1 |
/***************************************************************************
|
|
2 |
Title: GraphBrowser/GraphView.java
|
|
3 |
ID: $Id$
|
|
4 |
Author: Stefan Berghofer, TU Muenchen
|
|
5 |
Copyright 1997 TU Muenchen
|
|
6 |
|
|
7 |
This class defines the window in which the graph is displayed. It
|
|
8 |
contains methods for handling events such as collapsing / uncollapsing
|
|
9 |
nodes of the graph.
|
|
10 |
***************************************************************************/
|
|
11 |
|
|
12 |
package GraphBrowser;
|
|
13 |
|
|
14 |
import java.awt.*;
|
6541
|
15 |
import java.awt.event.*;
|
3599
|
16 |
import java.io.*;
|
|
17 |
import java.util.*;
|
|
18 |
import awtUtilities.*;
|
|
19 |
|
6541
|
20 |
public class GraphView extends Canvas implements MouseListener, MouseMotionListener {
|
|
21 |
Graph gra, gra2;
|
|
22 |
GraphBrowser browser;
|
|
23 |
Vertex v = null;
|
|
24 |
Vector collapsed = new Vector(10,10);
|
|
25 |
Vector collapsedDirs = new Vector(10,10);
|
3599
|
26 |
TreeBrowser tb;
|
|
27 |
long timestamp;
|
6541
|
28 |
Vertex highlighted = null;
|
|
29 |
Dimension size;
|
|
30 |
boolean parent_needs_layout;
|
3599
|
31 |
|
|
32 |
public void setTreeBrowser(TreeBrowser br) {
|
|
33 |
tb=br;
|
|
34 |
}
|
|
35 |
|
6541
|
36 |
public GraphBrowser getBrowser() { return browser; }
|
3599
|
37 |
|
|
38 |
public Graph getGraph() { return gra; }
|
|
39 |
|
|
40 |
public Graph getOriginalGraph() { return gra2; }
|
|
41 |
|
|
42 |
public GraphView(Graph gr,GraphBrowser br) {
|
|
43 |
gra2=gr;
|
6541
|
44 |
browser=br;
|
3599
|
45 |
gra=(Graph)(gra2.clone());
|
6541
|
46 |
parent_needs_layout = true;
|
|
47 |
size = new Dimension(0, 0);
|
|
48 |
addMouseListener(this);
|
|
49 |
addMouseMotionListener(this);
|
3599
|
50 |
}
|
|
51 |
|
|
52 |
public void PS(String fname,boolean printable) throws IOException {
|
|
53 |
gra.PS(fname,printable);
|
|
54 |
}
|
|
55 |
|
6541
|
56 |
public void paint(Graphics g) {
|
3599
|
57 |
gra.draw(g);
|
6541
|
58 |
if (highlighted!=null) highlighted.drawBox(g,Color.white);
|
|
59 |
size = new Dimension(gra.max_x-gra.min_x, gra.max_y-gra.min_y);
|
|
60 |
if (parent_needs_layout) {
|
|
61 |
parent_needs_layout = false;
|
|
62 |
getParent().doLayout();
|
|
63 |
}
|
3599
|
64 |
}
|
|
65 |
|
6541
|
66 |
public Dimension getPreferredSize() {
|
|
67 |
return size;
|
|
68 |
}
|
|
69 |
|
|
70 |
public void mouseMoved(MouseEvent evt) {
|
|
71 |
int x = evt.getX() + gra.min_x;
|
|
72 |
int y = evt.getY() + gra.min_y;
|
3599
|
73 |
|
|
74 |
Vertex v2=gra.vertexAt(x,y);
|
|
75 |
Graphics g=getGraphics();
|
|
76 |
g.translate(-gra.min_x,-gra.min_y);
|
|
77 |
if (highlighted!=null) {
|
|
78 |
highlighted.drawBox(g,Color.lightGray);
|
|
79 |
highlighted=null;
|
|
80 |
}
|
|
81 |
if (v2!=v) {
|
|
82 |
if (v!=null) v.removeButtons(g);
|
|
83 |
if (v2!=null) v2.drawButtons(g);
|
|
84 |
v=v2;
|
|
85 |
}
|
|
86 |
}
|
|
87 |
|
6541
|
88 |
public void mouseDragged(MouseEvent evt) {}
|
|
89 |
|
3599
|
90 |
/*****************************************************************/
|
|
91 |
/* This method is called if successor / predecessor nodes (whose */
|
|
92 |
/* numbers are stored in Vector c) of a certain node should be */
|
|
93 |
/* displayed again */
|
|
94 |
/*****************************************************************/
|
|
95 |
|
|
96 |
void uncollapse(Vector c) {
|
|
97 |
collapsed.removeElement(c);
|
|
98 |
collapseNodes();
|
|
99 |
}
|
|
100 |
|
|
101 |
/*****************************************************************/
|
|
102 |
/* This method is called by class TreeBrowser when directories */
|
|
103 |
/* are collapsed / uncollapsed by the user */
|
|
104 |
/*****************************************************************/
|
|
105 |
|
|
106 |
public void collapseDir(Vector v) {
|
|
107 |
collapsedDirs=v;
|
|
108 |
|
|
109 |
collapseNodes();
|
|
110 |
}
|
|
111 |
|
|
112 |
/*****************************************************************/
|
|
113 |
/* Inflate node again */
|
|
114 |
/*****************************************************************/
|
|
115 |
|
|
116 |
public void inflateNode(Vector c) {
|
|
117 |
Enumeration e1;
|
|
118 |
|
|
119 |
e1=collapsedDirs.elements();
|
|
120 |
while (e1.hasMoreElements()) {
|
|
121 |
Directory d=(Directory)(e1.nextElement());
|
|
122 |
if (d.collapsed==c) {
|
|
123 |
tb.selectNode(d.getNode());
|
|
124 |
return;
|
|
125 |
}
|
|
126 |
}
|
|
127 |
|
|
128 |
collapsed.removeElement(c);
|
|
129 |
e1=gra2.getVertices();
|
|
130 |
while (e1.hasMoreElements()) {
|
|
131 |
Vertex vx=(Vertex)(e1.nextElement());
|
|
132 |
if (vx.getUp()==c) vx.setUp(null);
|
|
133 |
if (vx.getDown()==c) vx.setDown(null);
|
|
134 |
}
|
|
135 |
|
|
136 |
collapseNodes();
|
|
137 |
relayout();
|
|
138 |
}
|
|
139 |
|
|
140 |
public void relayout() {
|
6541
|
141 |
browser.showWaitMessage();
|
3599
|
142 |
highlighted=null;
|
|
143 |
gra.layout(getGraphics());
|
|
144 |
v=null;
|
6541
|
145 |
parent_needs_layout = true;
|
3599
|
146 |
update(getGraphics());
|
6541
|
147 |
browser.showReadyMessage();
|
3599
|
148 |
}
|
|
149 |
|
|
150 |
public void focusToVertex(int n) {
|
|
151 |
Vertex vx=gra.getVertexByNum(n);
|
|
152 |
if (vx!=null) {
|
6541
|
153 |
ScrollPane scrollp = (ScrollPane)(getParent());
|
|
154 |
Dimension vpsize = scrollp.getViewportSize();
|
|
155 |
|
|
156 |
int x = vx.getX()-gra.min_x;
|
|
157 |
int y = vx.getY()-gra.min_y;
|
|
158 |
int offset_x = Math.min(scrollp.getHAdjustable().getMaximum(),
|
|
159 |
Math.max(0,x-vpsize.width/2));
|
|
160 |
int offset_y = Math.min(scrollp.getVAdjustable().getMaximum(),
|
|
161 |
Math.max(0,y-vpsize.height/2));
|
|
162 |
|
3599
|
163 |
Graphics g=getGraphics();
|
|
164 |
g.translate(-gra.min_x,-gra.min_y);
|
6541
|
165 |
if (highlighted!=null) highlighted.drawBox(g,Color.lightGray);
|
3599
|
166 |
vx.drawBox(g,Color.white);
|
6541
|
167 |
highlighted=vx;
|
|
168 |
scrollp.setScrollPosition(offset_x, offset_y);
|
3599
|
169 |
}
|
|
170 |
}
|
|
171 |
|
|
172 |
/*****************************************************************/
|
|
173 |
/* Create new graph with collapsed nodes */
|
|
174 |
/*****************************************************************/
|
|
175 |
|
|
176 |
public void collapseNodes() {
|
|
177 |
Enumeration e1=collapsed.elements();
|
|
178 |
gra=(Graph)(gra2.clone());
|
|
179 |
|
|
180 |
while (e1.hasMoreElements()) {
|
|
181 |
Vector v1=(Vector)(e1.nextElement());
|
|
182 |
Vector v2=gra.decode(v1);
|
|
183 |
if (!v2.isEmpty()) gra.collapse(v2,"[. . . .]",v1);
|
|
184 |
}
|
|
185 |
|
|
186 |
e1=collapsedDirs.elements();
|
|
187 |
|
|
188 |
while (e1.hasMoreElements()) {
|
|
189 |
Directory d=(Directory)(e1.nextElement());
|
|
190 |
Vector v=gra.decode(d.getCollapsed());
|
|
191 |
if (!v.isEmpty())
|
|
192 |
gra.collapse(v,"["+d.getName()+"]",d.getCollapsed());
|
|
193 |
}
|
|
194 |
}
|
|
195 |
|
6541
|
196 |
public void mouseClicked(MouseEvent evt) {
|
|
197 |
Vector code = null;
|
3599
|
198 |
Vertex v2;
|
6541
|
199 |
int x = evt.getX() + gra.min_x;
|
|
200 |
int y = evt.getY() + gra.min_y;
|
3599
|
201 |
|
|
202 |
if (v!=null) {
|
|
203 |
int num=v.getNumber();
|
|
204 |
v2=gra2.getVertexByNum(num);
|
|
205 |
if (v.leftButton(x,y)) {
|
|
206 |
if (v.getUp()!=null) {
|
|
207 |
code=v.getUp();
|
|
208 |
v2.setUp(null);
|
|
209 |
v=null;
|
|
210 |
uncollapse(code);
|
|
211 |
relayout();
|
|
212 |
focusToVertex(num);
|
|
213 |
} else {
|
|
214 |
Vector vs=v2.getPreds();
|
|
215 |
code=gra2.encode(vs);
|
|
216 |
v.setUp(code);v2.setUp(code);
|
|
217 |
v=null;
|
|
218 |
collapsed.insertElementAt(code,0);
|
|
219 |
collapseNodes();
|
|
220 |
relayout();
|
|
221 |
focusToVertex(num);
|
|
222 |
}
|
|
223 |
} else if (v.rightButton(x,y)) {
|
|
224 |
if (v.getDown()!=null) {
|
|
225 |
code=v.getDown();
|
|
226 |
v2.setDown(null);
|
|
227 |
v=null;
|
|
228 |
uncollapse(code);
|
|
229 |
relayout();
|
|
230 |
focusToVertex(num);
|
|
231 |
} else {
|
|
232 |
Vector vs=v2.getSuccs();
|
|
233 |
code=gra2.encode(vs);
|
|
234 |
v.setDown(code);v2.setDown(code);
|
|
235 |
v=null;
|
|
236 |
collapsed.insertElementAt(code,0);
|
|
237 |
collapseNodes();
|
|
238 |
relayout();
|
|
239 |
focusToVertex(num);
|
|
240 |
}
|
|
241 |
} else if (v.getInflate()!=null) {
|
|
242 |
inflateNode(v.getInflate());
|
|
243 |
v=null;
|
|
244 |
} else {
|
6541
|
245 |
if (evt.getWhen()-timestamp < 400 && !(v.getPath().equals("")))
|
|
246 |
browser.viewFile(v.getPath());
|
|
247 |
timestamp=evt.getWhen();
|
3599
|
248 |
}
|
|
249 |
}
|
|
250 |
}
|
|
251 |
|
6541
|
252 |
public void mouseExited(MouseEvent evt) {
|
3599
|
253 |
Graphics g=getGraphics();
|
|
254 |
g.translate(-gra.min_x,-gra.min_y);
|
|
255 |
if (highlighted!=null) {
|
|
256 |
highlighted.drawBox(g,Color.lightGray);
|
|
257 |
highlighted=null;
|
|
258 |
}
|
|
259 |
if (v!=null) v.removeButtons(g);
|
|
260 |
v=null;
|
|
261 |
}
|
6541
|
262 |
|
|
263 |
public void mouseEntered(MouseEvent evt) {}
|
|
264 |
|
|
265 |
public void mousePressed(MouseEvent evt) {}
|
|
266 |
|
|
267 |
public void mouseReleased(MouseEvent evt) {}
|
3599
|
268 |
}
|