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 package com.drazzib.netpisteur.ui;
28
29 import java.awt.BorderLayout;
30 import java.awt.Font;
31 import java.awt.GridLayout;
32 import java.awt.event.ActionEvent;
33 import java.awt.event.ActionListener;
34 import java.awt.event.MouseAdapter;
35 import java.awt.event.MouseEvent;
36 import java.net.MalformedURLException;
37 import java.net.URL;
38
39 import javax.swing.JButton;
40 import javax.swing.JComboBox;
41 import javax.swing.JFrame;
42 import javax.swing.JLabel;
43 import javax.swing.JOptionPane;
44 import javax.swing.JPanel;
45 import javax.swing.JTextField;
46
47 import org.apache.commons.logging.Log;
48 import org.apache.commons.logging.LogFactory;
49
50 import com.drazzib.netpisteur.configuration.Configuration;
51 import com.drazzib.netpisteur.configuration.ListUtilisateurs;
52 import com.drazzib.netpisteur.configuration.Utilisateur;
53 import com.drazzib.netpisteur.util.Messages;
54
55 /**
56 * This class open a frame wich allows to change the banner page and the
57 * separator of a user.
58 *
59 * @author Netpisteur v.2 Team
60 */
61 public class AdvancedOptionsFrame extends JFrame {
62
63 private static Log log = LogFactory.getLog(AdvancedOptionsFrame.class);
64
65 /**
66 *
67 */
68 private static final long serialVersionUID = 2509402800493155326L;
69
70 private JPanel saisieSeparateur, panelAll, panelNorth, panelWest,
71 panelEast, panelSouth, panelCenter, optionPanel, boutonPanel;
72
73 private JLabel pageLabel, pageAcLabel, separateurLabel, separaLabel,
74 expliPageLabel, expliSeparateurLabel, expliPageLabel2,
75 expliSeparateurLabel2, sep, sep2;
76
77 private JTextField pageTextField, separateurTextField;
78
79 private JComboBox choixSep;
80
81 private JButton okBouton, annulerBouton, parcBouton;
82
83
84
85 private boolean combobox;
86
87 private String page = "";
88
89 private String separ = "";
90
91 private Utilisateur user;
92
93 public static String _REP = Configuration.getHandle().getRootNom() + "_"
94 + Configuration.getHandle().getRootNom();
95
96
97
98
99 /**
100 * Creates new form Config
101 *
102 * @param utilisat
103 * the user who will be change
104 */
105 public AdvancedOptionsFrame(Utilisateur utilisat) {
106 this.page = utilisat.getPage();
107 this.separ = utilisat.getSeparateur();
108 this.user = utilisat;
109 initComponents();
110 }
111
112
113
114
115 private void initComponents() {
116
117
118 this.panelAll = new JPanel(new BorderLayout());
119 this.panelNorth = new JPanel();
120 this.panelWest = new JPanel();
121 this.panelEast = new JPanel();
122 this.panelSouth = new JPanel();
123 this.panelCenter = new JPanel(new BorderLayout());
124
125 this.boutonPanel = new JPanel();
126
127 this.optionPanel = new JPanel();
128
129 this.saisieSeparateur = new JPanel();
130
131
132 this.pageLabel = new JLabel();
133 this.pageAcLabel = new JLabel();
134 this.expliPageLabel = new JLabel();
135 this.expliPageLabel2 = new JLabel();
136 this.pageTextField = new JTextField();
137
138
139 this.separateurLabel = new JLabel();
140 this.separaLabel = new JLabel();
141 this.expliSeparateurLabel = new JLabel();
142 this.expliSeparateurLabel2 = new JLabel();
143 this.choixSep = new JComboBox();
144 this.separateurTextField = new JTextField();
145
146
147 Font titre = new Font("Arial", Font.BOLD, 15);
148 this.sep = new JLabel("____________________________________");
149 this.sep2 = new JLabel("____________________________________");
150
151
152
153
154 this.optionPanel.setLayout(new GridLayout(11, 2));
155 this.saisieSeparateur.setLayout(new GridLayout(1, 2));
156 this.boutonPanel.setLayout(new GridLayout(1, 2));
157
158
159 this.pageLabel.setText(Messages
160 .getString("OptionAvance.HOMEPAGE_LABEL"));
161 this.pageLabel.setFont(titre);
162
163 this.optionPanel.add(this.pageLabel);
164 this.optionPanel.add(this.sep);
165
166 this.expliPageLabel.setText(Messages.getString("OptionAvance.ADDRESS"));
167 this.expliPageLabel2.setText(Messages
168 .getString("OptionAvance.HOMEPAGE"));
169
170 this.optionPanel.add(this.expliPageLabel);
171 this.optionPanel.add(new JLabel());
172 this.optionPanel.add(this.expliPageLabel2);
173 this.optionPanel.add(new JLabel());
174
175 this.pageAcLabel
176 .setText(Messages.getString("OptionAvance.FOR_EXEMPLE"));
177 this.optionPanel.add(this.pageAcLabel);
178
179 this.pageTextField.setText(this.page);
180 this.optionPanel.add(this.pageTextField);
181
182 this.parcBouton = new JButton();
183 this.parcBouton.setText(Messages.getString("OptionAvance.BROWSE"));
184
185 this.parcBouton.addMouseListener(new MouseAdapter() {
186 public void mouseReleased(MouseEvent evt) {
187 parcourirFrameBouton(evt);
188
189 }
190 });
191 this.optionPanel.add(new JLabel());
192 this.optionPanel.add(this.parcBouton);
193
194
195 this.separateurLabel.setText(Messages
196 .getString("OptionAvance.SEPARATOR"));
197 this.separateurLabel.setFont(titre);
198
199 this.optionPanel.add(this.separateurLabel);
200
201 this.optionPanel.add(this.sep2);
202
203 this.expliSeparateurLabel.setText(Messages
204 .getString("OptionAvance.TYPE_OF_SEPARATOR"));
205 this.expliSeparateurLabel2.setText(Messages
206 .getString("OptionAvance.IN_OUTFILES"));
207
208 this.optionPanel.add(this.expliSeparateurLabel);
209 this.optionPanel.add(new JLabel());
210 this.optionPanel.add(this.expliSeparateurLabel2);
211
212 this.choixSep.addItem(Messages.getString("OptionAvance.COMMA"));
213 this.choixSep.addItem(Messages.getString("OptionAvance.TAB"));
214 this.choixSep.addItem(Messages.getString("OptionAvance.SPACE"));
215 this.choixSep.addItem(Messages.getString("OptionAvance.SLASH"));
216 this.choixSep.addItem(Messages.getString("OptionAvance.OTHER"));
217 this.choixSep.addActionListener(new ActionListener() {
218 public void actionPerformed(ActionEvent evt) {
219 switchComboBox(evt);
220
221 }
222 });
223
224 this.optionPanel.add(this.choixSep);
225 this.loadSeparator();
226
227 this.optionPanel.add(new JLabel());
228 this.optionPanel.add(new JLabel());
229 this.separaLabel.setText(Messages
230 .getString("OptionAvance.ENTER_SEPARATOR"));
231 this.optionPanel.add(this.separaLabel);
232
233 this.separateurTextField.setColumns(5);
234
235 this.saisieSeparateur.add(this.separateurTextField);
236 this.saisieSeparateur.add(new JLabel());
237 this.optionPanel.add(this.saisieSeparateur);
238 this.optionPanel.add(new JLabel());
239 this.optionPanel.add(new JLabel());
240
241
242
243 this.boutonPanel = new JPanel();
244
245 this.okBouton = new JButton();
246 this.annulerBouton = new JButton();
247
248
249 this.okBouton.setText(Messages.getString("OptionAvance.OK"));
250
251 this.okBouton.addMouseListener(new MouseAdapter() {
252 public void mouseReleased(MouseEvent evt) {
253 okBoutonMouseReleased(evt);
254
255 }
256 });
257
258
259
260 this.annulerBouton.setText(Messages.getString("OptionAvance.CANCEL"));
261
262 this.annulerBouton.addMouseListener(new MouseAdapter() {
263 public void mouseReleased(MouseEvent evt) {
264 annulerBoutonMouseReleased(evt);
265
266 }
267 });
268
269
270 this.boutonPanel.add(this.okBouton);
271 this.boutonPanel.add(this.annulerBouton);
272
273
274
275
276 setTitle(Messages.getString("OptionAvance.ADVANCED_OPTIONS"));
277
278
279 this.panelCenter.add(this.optionPanel, BorderLayout.CENTER);
280 this.panelCenter.add(this.boutonPanel, BorderLayout.SOUTH);
281 this.panelAll.add(this.panelNorth, BorderLayout.NORTH);
282 this.panelAll.add(this.panelWest, BorderLayout.WEST);
283 this.panelAll.add(this.panelEast, BorderLayout.EAST);
284 this.panelAll.add(this.panelSouth, BorderLayout.SOUTH);
285 this.panelAll.add(this.panelCenter, BorderLayout.CENTER);
286 this.getContentPane().add(this.panelAll);
287 this.setLocationRelativeTo(null);
288 pack();
289
290 }
291
292 /**
293 * Allows to put the good separator when the frame opening.
294 */
295 private void loadSeparator() {
296
297 if ((this.separ.equals(";")) || (this.separ.equals("\t")) || (this.separ.equals(" "))
298 || (this.separ.equals("/"))) {
299 if (this.separ.equals(";")) {
300 this.choixSep.setSelectedIndex(0);
301 }
302 if (this.separ.equals("\t")) {
303 this.choixSep.setSelectedIndex(1);
304 }
305 if (this.separ.equals(" ")) {
306 this.choixSep.setSelectedIndex(2);
307 }
308 if (this.separ.equals("/")) {
309 this.choixSep.setSelectedIndex(3);
310 }
311 this.combobox = false;
312 this.separaLabel.setVisible(false);
313 this.separateurTextField.setVisible(false);
314 } else {
315 this.choixSep.setSelectedIndex(4);
316 this.combobox = true;
317 log.debug("Separator : "+this.separ);
318 this.separateurTextField.setText(this.separ);
319 this.separaLabel.setVisible(true);
320 this.separateurTextField.setVisible(true);
321 this.validate();
322 }
323 }
324
325
326
327 /**
328 * Allows to close the frame when the button cancel is pushed
329 *
330 * @param MouseEvent
331 * evt
332 */
333 void annulerBoutonMouseReleased(MouseEvent evt) {
334 this.dispose();
335 }
336
337 /**
338 * Allows to browse your disk to select home page
339 *
340 * @param MouseEvent
341 * evt
342 */
343 void parcourirFrameBouton(MouseEvent evt) {
344 ExplorerFrame exp = new ExplorerFrame(this);
345 exp.setVisible(true);
346 }
347
348 /**
349 * Allows to close the frame and save the modification when the button ok is
350 * pushed
351 *
352 * @param MouseEvent
353 * evt
354 */
355 void okBoutonMouseReleased(MouseEvent evt) {
356
357
358 if (this.combobox == true) {
359 boolean nonnull = !(this.separateurTextField.getText().equals(""));
360 if (nonnull == true) {
361 Configuration.getHandle().setRootSeparator(
362 this.separateurTextField.getText());
363 this.dispose();
364 } else {
365 JOptionPane
366 .showMessageDialog(
367 null,
368 Messages
369 .getString("OptionAvance.WRONG_SEPARATOR"), Messages.getString("OptionAvance.ERROR"),
370 JOptionPane.ERROR_MESSAGE);
371
372 }
373 } else {
374 if (this.choixSep.getSelectedItem().equals(
375 Messages.getString("OptionAvance.COMMA"))) {
376 Configuration.getHandle().setRootSeparator(";");
377 }
378 if (this.choixSep.getSelectedItem().equals(
379 Messages.getString("OptionAvance.TAB"))) {
380 Configuration.getHandle().setRootSeparator("\t");
381 }
382 if (this.choixSep.getSelectedItem().equals(
383 Messages.getString("OptionAvance.SPACE"))) {
384 Configuration.getHandle().setRootSeparator(" ");
385 }
386 if (this.choixSep.getSelectedItem().equals(
387 Messages.getString("OptionAvance.SLASH"))) {
388 Configuration.getHandle().setRootSeparator("/");
389 }
390 }
391
392 try {
393
394 Configuration.getHandle().setRootPage(this.pageTextField.getText());
395
396
397 URL url = new URL(this.pageTextField.getText());
398
399 log.info("URL Valide : " + url);
400
401 ListUtilisateurs.changeSep(this.user, Configuration.getHandle().getRootSeparator());
402 ListUtilisateurs.changePage(this.user, Configuration.getHandle().getRootPage());
403 JOptionPane
404 .showMessageDialog(
405 null,
406 Messages.getString("OptionAvance.MODIF_OK"),
407 Messages.getString("OptionAvance.SUCCESS"), JOptionPane.INFORMATION_MESSAGE);
408 this.dispose();
409 } catch (MalformedURLException ex) {
410 JOptionPane
411 .showMessageDialog(
412 null,
413 Messages.getString("OptionAvance.WRONG_URL"), Messages.getString("OptionAvance.EROOR"),
414 JOptionPane.ERROR_MESSAGE);
415 }
416 }
417
418 public void setAccueilPage(String myPage) {
419 this.pageTextField.setText(myPage);
420 }
421
422 /**
423 * Allows to make visible the Textfield when the icons "autres" is selected.
424 *
425 * @param ActionEvent
426 * evt
427 */
428 void switchComboBox(ActionEvent evt) {
429
430 if (this.combobox == true
431 && !(this.choixSep.getSelectedItem().equals(Messages
432 .getString("OptionAvance.OTHER")))) {
433 this.separaLabel.setVisible(false);
434 this.separateurTextField.setVisible(false);
435 this.validate();
436 }
437 if (this.choixSep.getSelectedItem().equals(
438 Messages.getString("OptionAvance.OTHER"))) {
439 this.combobox = true;
440 this.separaLabel.setVisible(true);
441 this.separateurTextField.setVisible(true);
442 this.validate();
443 }
444
445 }
446
447 }