author | haftmann |
Mon, 10 May 2010 13:58:18 +0200 | |
changeset 36798 | 3981db162131 |
parent 33686 | 8e33ca8832b1 |
child 50473 | ca4088bf8365 |
permissions | -rw-r--r-- |
3599 | 1 |
/*************************************************************************** |
2 |
Title: GraphBrowser/TreeBrowser.java |
|
3 |
Author: Stefan Berghofer, TU Muenchen |
|
4 |
||
5 |
This class defines the browser window which is used to display directory |
|
6 |
trees. It contains methods for handling events. |
|
7 |
***************************************************************************/ |
|
8 |
||
9 |
package GraphBrowser; |
|
10 |
||
11 |
import java.awt.*; |
|
6541 | 12 |
import java.awt.event.*; |
3599 | 13 |
import java.util.*; |
14 |
||
15 |
||
6541 | 16 |
public class TreeBrowser extends Canvas implements MouseListener |
3599 | 17 |
{ |
18 |
TreeNode t; |
|
19 |
TreeNode selected; |
|
20 |
GraphView gv; |
|
21 |
long timestamp; |
|
6541 | 22 |
Dimension size; |
23 |
boolean parent_needs_layout; |
|
11873
38dc46b55d7e
Moved font settings from TreeNode to TreeBrowser.
berghofe
parents:
6541
diff
changeset
|
24 |
Font font; |
3599 | 25 |
|
11873
38dc46b55d7e
Moved font settings from TreeNode to TreeBrowser.
berghofe
parents:
6541
diff
changeset
|
26 |
public TreeBrowser(TreeNode tn, GraphView gr, Font f) { |
38dc46b55d7e
Moved font settings from TreeNode to TreeBrowser.
berghofe
parents:
6541
diff
changeset
|
27 |
t = tn; gv = gr; font = f; |
6541 | 28 |
size = new Dimension(0, 0); |
29 |
parent_needs_layout = true; |
|
30 |
addMouseListener(this); |
|
3599 | 31 |
} |
32 |
||
6541 | 33 |
public Dimension getPreferredSize() { |
34 |
return size; |
|
35 |
} |
|
36 |
||
37 |
public void mouseEntered(MouseEvent evt) {} |
|
38 |
||
39 |
public void mouseExited(MouseEvent evt) {} |
|
40 |
||
41 |
public void mouseReleased(MouseEvent evt) {} |
|
42 |
||
43 |
public void mousePressed(MouseEvent evt) {} |
|
44 |
||
45 |
public void mouseClicked(MouseEvent e) |
|
3599 | 46 |
{ |
6541 | 47 |
TreeNode l=t.lookup(e.getY()); |
3599 | 48 |
|
49 |
if (l!=null) |
|
50 |
{ |
|
51 |
if (l.select()) { |
|
52 |
Vector v=new Vector(10,10); |
|
53 |
t.collapsedDirectories(v); |
|
54 |
gv.collapseDir(v); |
|
55 |
gv.relayout(); |
|
56 |
} else { |
|
57 |
Vertex vx=gv.getGraph().getVertexByNum(l.getNumber()); |
|
58 |
gv.focusToVertex(l.getNumber()); |
|
59 |
vx=gv.getOriginalGraph().getVertexByNum(l.getNumber()); |
|
6541 | 60 |
if (e.getWhen()-timestamp < 400 && !(vx.getPath().equals(""))) |
3599 | 61 |
gv.getBrowser().viewFile(vx.getPath()); |
6541 | 62 |
timestamp=e.getWhen(); |
3599 | 63 |
|
64 |
} |
|
6541 | 65 |
selected=l; |
66 |
parent_needs_layout = true; |
|
67 |
repaint(); |
|
3599 | 68 |
} |
69 |
} |
|
70 |
||
71 |
public void selectNode(TreeNode nd) { |
|
72 |
Vector v=new Vector(10,10); |
|
73 |
nd.select(); |
|
74 |
t.collapsedDirectories(v); |
|
75 |
gv.collapseDir(v); |
|
76 |
gv.relayout(); |
|
6541 | 77 |
selected=nd; |
78 |
parent_needs_layout = true; |
|
79 |
repaint(); |
|
3599 | 80 |
} |
81 |
||
6541 | 82 |
public void paint(Graphics g) |
3599 | 83 |
{ |
11873
38dc46b55d7e
Moved font settings from TreeNode to TreeBrowser.
berghofe
parents:
6541
diff
changeset
|
84 |
g.setFont(font); |
6541 | 85 |
Dimension d = t.draw(g,5,5,selected); |
86 |
if (parent_needs_layout) { |
|
87 |
size = new Dimension(5+d.width, 5+d.height); |
|
88 |
parent_needs_layout = false; |
|
89 |
getParent().doLayout(); |
|
90 |
} |
|
3599 | 91 |
} |
92 |
} |
|
93 |