-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClickableDisplay.java
More file actions
211 lines (190 loc) · 4.47 KB
/
ClickableDisplay.java
File metadata and controls
211 lines (190 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import java.awt.event.*;
/**
* Classe de gestion des évènements pour la souris
* @author J. Pallamidessi & S. Andreux
*/
public class ClickableDisplay extends MouseAdapter
{
protected Display attachedDisplay;
/**
* Crée une classe de gestion des evènements souris
*/
public ClickableDisplay()
{
super();
}
/**
* Test si le pointeur de la souris se trouve dans la case
* @param x
* abscisse de la case
* @param y
* ordonnée de la case
* @param edgeLength
* longueur de la case
* @param e
* évènement souris
*/
boolean isCursorInSquare(int x,int y,int edgeLength,MouseEvent e)
{
int xMouse,yMouse;
xMouse=e.getX();
yMouse=e.getY();
return ((x+edgeLength>xMouse
&& x<xMouse)
&& (y+edgeLength>yMouse
&& y<yMouse));
}
/**
* Renvoit le FileNode associé à la case lorsque la souris déclenche un évènement
* @param e
* Evènement souris
* @return
* Filenode associé au fichier
*/
public FileNode getReferenceFromDisplay(MouseEvent e)
{
FileTree t=attachedDisplay.getTree();
FileNode fd=t.getRoot();
return getReferenceFromDisplayAux(e,0,t.getDepth(),fd);
}
/**
* Fonction auxiliaire permettant de récupérer un noeud de l'arbre actuellement affché en fonction d'un évènement souris
* @param e
* évènement souris
* @param depth
* profondeur de l'arbre
* @param maxDepth
* profondeur maximale
* @param f
* racine de l'arbre
* @return
* noeud associé à l'évènement
*/
private FileNode getReferenceFromDisplayAux(MouseEvent e,int depth,int maxDepth,FileNode f)
{
FileNode found;
int i;
if (isCursorInSquare(f.getX(),f.getY(),f.getEdgeSize(),e))
{
if(maxDepth==depth)
return f;
else
{
if(f.isDirectory() && !f.isEmpty())
{
for (i = 0; i <f.nbFiles(); i++)
{
if((found=getReferenceFromDisplayAux(e,depth+1,maxDepth,f.getSon(i)))!=null)
return found;
}
}
return f;
}
}
return null;
}
/**
* Déclenche une modification de l'arbre associé lors d'un clic souris
* @param e
* évènement souris
*/
public void mouseClicked(MouseEvent e)
{
FileNode toDetermined;
if (e.getButton()==MouseEvent.BUTTON1)
{
toDetermined=getReferenceFromDisplay(e);
if (toDetermined==null)
return;
else
{
if(toDetermined.isFile())
{
ControlPanel p=attachedDisplay.getControlPanel();
p.updateFileInfo(toDetermined.getName(),(int) toDetermined.length(),toDetermined.getAbsolutePath());
}
else if(toDetermined.isDirectory())
{
attachedDisplay.getEdgeVector().removeAllElements();
attachedDisplay.setTreeFile(new
FileTree(toDetermined.getAbsolutePath(),attachedDisplay.getDepthLevel(),1) );
attachedDisplay.repaint();
}
}
}
else if (e.getButton()==MouseEvent.BUTTON3)
{
String parent=attachedDisplay.getTree().getRoot().getParent();
if(parent==null)
return;
else
{
ControlPanel p=attachedDisplay.getControlPanel();
attachedDisplay.getEdgeVector().removeAllElements();
attachedDisplay.setTreeFile(new FileTree(parent,attachedDisplay.getDepthLevel(),1));
attachedDisplay.repaint();
}
}
}
/**
* Mutateur: attache un nouveau display
* @param d
* nouveau display
*/
public void setAttachedDisplay(Display d)
{
attachedDisplay=d;
}
/**
* Associe une action lors du déplacement de la souris
* @param e
* évènement souris
*/
public void mouseMoved(MouseEvent e)
{
int x,y;
int i;
FileTree t=attachedDisplay.getTree();
FileNode fd=t.getRoot();
attachedDisplay.getEdgeVector().removeAllElements();
mouseMovedAux(e,0,t.getDepth(),fd,attachedDisplay);
attachedDisplay.repaint();
}
/**
* Fonction auxiliaure lors du déplacement de la souris
* @param e
* évènement souris
* @param depth
* profondeur de l'arbre
* @param maxDepth
* profondeur maximum de l'arbre
* @param f
* noeud du fichier
* @param d
* panneau d'affichage de l'arbre
*/
private void mouseMovedAux(MouseEvent e,int depth,int maxDepth,FileNode f,Display d)
{
int i;
if (isCursorInSquare(f.getX(),f.getY(),f.getEdgeSize(),e))
{
attachedDisplay.setToolTipText(f.getName());
d.addEdge(f.getX(),
f.getY(),
f.getEdgeSize());
if(maxDepth==depth)
return ;
else
{
if(f.isDirectory() && !f.isEmpty())
{
for (i = 0; i <f.nbFiles(); i++)
{
mouseMovedAux(e,depth+1,maxDepth,f.getSon(i),d);
}
}
return;
}
}
}
}