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