-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestVisitor.java
More file actions
144 lines (117 loc) · 3.32 KB
/
TestVisitor.java
File metadata and controls
144 lines (117 loc) · 3.32 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
package scandirvis;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
/**
* Exemple du parton Visiteur
* @author Vincent Lacasse
*
*/
public class TestVisitor extends JFrame {
private JButton btnChoisir;
private JButton btnFermer;
private JTextArea txtrResultat;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
TestVisitor frame = new TestVisitor();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Constructeur
* construire l'écran principal et assigner des actions
* aux deux boutons
*/
public TestVisitor() {
buildScreen();
btnChoisir.setAction(new ActionChoisir());
btnFermer.setAction(new ActionFermer());
}
/**
* Construire l'écran principal
*/
private void buildScreen() {
JPanel contentPane;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JPanel panel = new JPanel();
contentPane.add(panel, BorderLayout.SOUTH);
panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
btnChoisir = new JButton();
panel.add(btnChoisir);
btnFermer = new JButton();
panel.add(btnFermer);
JScrollPane scrollPane = new JScrollPane();
contentPane.add(scrollPane, BorderLayout.CENTER);
txtrResultat = new JTextArea();
scrollPane.setViewportView(txtrResultat);
}
/**
* Action assignee au bouton "Choisir"
* @author Vincent Lacasse
*
*/
private class ActionChoisir extends AbstractAction {
ActionChoisir() {
super("Choisir");
}
public void actionPerformed(ActionEvent e) {
int returnVal;
File nom;
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
returnVal = fileChooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
nom = new File(fileChooser.getSelectedFile().getPath());
// Créer l'arbre contenant la structure de répertoire
// Utilisation du patron Composite
Noeud base = new Repertoire(nom);
// Créer le visiteur, exécuter le visiteur et afficher le resultat
CompteRepertoire cv = new CompteRepertoire();
base.accept(cv);
txtrResultat.setText("Nombre de réperoire = " + cv.getCompteur());
// // Créer le visiteur, exécuter le visiteur et afficher le resultat
// TrouveFichier tf = new TrouveFichier("fichier4.rtf");
// base.accept(tf);
// txtrResultat.setText("Nombre de fichier = " + tf.getCompteur());
}
}
}
/**
* Action assignee au bouton "Fermer"
* @author Vincent Lacasse
*
*/
private class ActionFermer extends AbstractAction {
ActionFermer() {
super("Fermer");
}
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
}