-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlPanel.java
More file actions
274 lines (230 loc) · 7.36 KB
/
Copy pathControlPanel.java
File metadata and controls
274 lines (230 loc) · 7.36 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JComponent;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.BorderFactory;
import javax.swing.border.*;
import java.awt.GridLayout;
import java.awt.FlowLayout;
import javax.swing.BoxLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.*;
import java.io.File;
/**
* Panneau de controle
* @author J. Pallamidessi & S. Andreux
*/
public class ControlPanel extends JPanel{
private Display attachedDisplay;
private JPanel file;
private JPanel directory;
private JPanel recursion;
private JTextField currentPath;
private JTextField goTo;
private JLabel sizeOnDiskDir;
private JLabel nbElem;
private JLabel nbFiles,nbDirectory;
private JLabel sizeOnDiskFile;
private JTextField getFilePath;
private JLabel filename;
private JLabel currentDepth;
private JTextField newDepth;
//private JLabel
/**
* Gros constructeur du panneau d'affichage des données générales sur la l'arbre et la navigation dans celui-ci
*/
public ControlPanel()
{
super();
file=new JPanel();
directory=new JPanel();
recursion=new JPanel();
currentPath=new JTextField("",20);
goTo=new JTextField(20);
sizeOnDiskDir=new JLabel();
nbElem=new JLabel();
nbFiles=new JLabel();
nbDirectory=new JLabel();
getFilePath=new JTextField("",20);
filename=new JLabel();
sizeOnDiskFile=new JLabel();
currentDepth=new JLabel();
newDepth=new JTextField("",5);
currentPath.setHorizontalAlignment(JLabel.CENTER);
sizeOnDiskDir.setHorizontalAlignment(JLabel.CENTER);
nbElem.setHorizontalAlignment(JLabel.CENTER);
nbFiles.setHorizontalAlignment(JLabel.CENTER);
nbDirectory.setHorizontalAlignment(JLabel.CENTER);
filename.setHorizontalAlignment(JLabel.CENTER);
sizeOnDiskFile.setHorizontalAlignment(JLabel.CENTER);
currentDepth.setHorizontalAlignment(JLabel.CENTER);
BoxLayout principal=new BoxLayout(this,BoxLayout.Y_AXIS);
//principal.setVgap(50);
setLayout(principal);
JPanel padding=new JPanel();
Dimension d=new Dimension(70,30);
padding.setPreferredSize(d);
padding.setMaximumSize(d);
padding.setMinimumSize(d);
JPanel padding2=new JPanel();
padding2.setPreferredSize(d);
padding2.setMaximumSize(d);
padding2.setMinimumSize(d);
GridLayout secondary=new GridLayout(0,1);
secondary.setVgap(17);
directory.setLayout(secondary);
file.setLayout(secondary);
recursion.setLayout(secondary);
//directory.add(padding);
directory.add(addTitledBorder(currentPath,"Path du repertoire courant"));
directory.add(addTitledBorder(nbElem,"Nombre total d'element"));
directory.add(addTitledBorder(nbFiles,"Nombre de fichier"));
directory.add(addTitledBorder(nbDirectory,"Nombre de dossier"));
directory.add(addTitledBorder(goTo,"Afficher le repertoire de path suivant :"));
file.add(addTitledBorder(filename,"Nom du fichier selectionne"));
file.add(addTitledBorder(getFilePath,"Path du fichier selectionne"));
file.add(addTitledBorder(sizeOnDiskFile,"Taille du fichier selectionne en octets"));
recursion.add(addTitledBorder(currentDepth,"Niveau de recursion actuel"));
recursion.add(addTitledBorder(newDepth,"Nouveaux niveaux de recursion"));
getFilePath.setEditable(false);
currentPath.setEditable(false);
TitledBorder titleDirPanel=BorderFactory.createTitledBorder("Information sur le repertoire courant");
TitledBorder titleFilePanel=BorderFactory.createTitledBorder("Information sur le fichier");
TitledBorder titleControlPanel=BorderFactory.createTitledBorder("Information sur le niveau de recursion");
directory.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10,10,10,10),titleDirPanel));
file.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10,10,10,10),titleFilePanel));
recursion.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10,10,10,10),titleControlPanel));
add(directory);
add(file);
add(recursion);
goTo.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e ){
try{
File test=new File(goTo.getText());
if(test.isDirectory()){
attachedDisplay.setTreeFile(new FileTree(goTo.getText(),attachedDisplay.getDepthLevel(),1));
attachedDisplay.repaint();
}
else
return;
}
catch(NullPointerException ex){
return;
}
}
});
newDepth.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e ){
try{
try{
attachedDisplay.setDepthLevel( Integer.parseInt(newDepth.getText()) );
}
catch(Exception ex2){
attachedDisplay.setDepthLevel(2);
}
if(attachedDisplay.getDepthLevel()==0)
attachedDisplay.setDepthLevel(2);
attachedDisplay.setTreeFile(new FileTree(attachedDisplay.getTree().getRoot().getAbsolutePath(),attachedDisplay.getDepthLevel(),1));
attachedDisplay.repaint();
}
catch(NullPointerException ex){
return;
}
}
});
setBorder(BorderFactory.createLineBorder(Color.black));
}
/**
* Fixe le titre et les options du panneau de controle
* @param c
* composant du panneau
* @param name
* titre du panneau
* @return
* panneau d'affichage
*/
public JComponent addTitledBorder(JComponent c,String name)
{
JPanel p=new JPanel();
Border e=BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
TitledBorder title=BorderFactory.createTitledBorder(e,name);
title.setTitleJustification(TitledBorder.CENTER);
p.setLayout(new FlowLayout());
p.add(c);
p.setBorder(title);
p.validate();
return p;
}
/**
* Met-à-jour les informations concernant répertoire courant en vu de leur affichage
* @param currentDirPath
* Chemin vers le répertoire courant
* @param sizeCurDir
* Taille du répertoire courant
* @param nbNewFile
* Actuel répertoire courant
* @param nbNewDirectory
* Nouveau répertoire courant
*/
public void updateDirInfo(String currentDirPath,int sizeCurDir,int nbNewFile,int nbNewDirectory)
{
currentPath.setText("");
currentPath.setText(currentDirPath);
sizeOnDiskDir.setText("");
sizeOnDiskDir.setText(String.valueOf(sizeCurDir));
nbFiles.setText("");
nbFiles.setText(String.valueOf(nbNewFile));
nbDirectory.setText("");
nbDirectory.setText(String.valueOf(nbNewDirectory));
nbElem.setText("");
nbElem.setText(String.valueOf(nbNewFile+nbNewDirectory));
}
/**
* Met-à-jour les informations relative à un fichier en vu de leur affichage
* @param fileNameClick
* nom du fichier cliqué
* @param size
* taille du fichier
* @param pathFile
* chemin du fichier
*/
public void updateFileInfo(String fileNameClick,int size,String pathFile)
{
sizeOnDiskFile.setText("");
sizeOnDiskFile.setText(String.valueOf(size));
getFilePath.setText("");
getFilePath.setText(pathFile);
filename.setText("");
filename.setText(fileNameClick);
}
/**
*
* @param currentRec
*
*/
public void updateRecInfo(int currentRec)
{
currentDepth.setText("");
currentDepth.setText(String.valueOf(currentRec));
}
/**
* Enlève les infos affichées concernant un fichier
*/
public void flushFileInfo()
{
sizeOnDiskFile.setText("");
getFilePath.setText("");
filename.setText("");
}
/**
* Mutateur: attache une fenêtre au panneau
* @param d
* affichage à attacher au panneau
*/
public void setAttachedElement(Display d)
{
attachedDisplay=d;
}
}