OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 18 | Rev 28 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 18 Rev 25
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.preferences;
14
 package org.openconcerto.erp.preferences;
15
 
15
 
-
 
16
import org.openconcerto.erp.generationDoc.DocumentLocalStorageManager;
16
import org.openconcerto.erp.generationDoc.SheetXml;
17
import org.openconcerto.erp.generationDoc.SheetXml;
17
import org.openconcerto.erp.utils.FileUtility;
18
import org.openconcerto.erp.utils.FileUtility;
18
import org.openconcerto.ui.DefaultGridBagConstraints;
19
import org.openconcerto.ui.DefaultGridBagConstraints;
19
import org.openconcerto.ui.preferences.DefaultPreferencePanel;
20
import org.openconcerto.ui.preferences.DefaultPreferencePanel;
20
import org.openconcerto.utils.Tuple2;
21
import org.openconcerto.utils.Tuple2;
21
import org.openconcerto.utils.text.SimpleDocumentListener;
22
import org.openconcerto.utils.text.SimpleDocumentListener;
22
 
23
 
23
import java.awt.Color;
24
import java.awt.Color;
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.GridBagLayout;
26
import java.awt.event.ActionEvent;
27
import java.awt.event.ActionEvent;
27
import java.awt.event.ActionListener;
28
import java.awt.event.ActionListener;
28
import java.io.File;
29
import java.io.File;
29
import java.io.IOException;
30
import java.io.IOException;
30
import java.util.ArrayList;
31
import java.util.ArrayList;
31
import java.util.Collections;
32
import java.util.Collections;
32
import java.util.Comparator;
33
import java.util.Comparator;
33
import java.util.HashMap;
34
import java.util.HashMap;
34
import java.util.List;
35
import java.util.List;
35
import java.util.Map;
36
import java.util.Map;
36
import java.util.Map.Entry;
37
import java.util.Map.Entry;
37
 
38
 
38
import javax.swing.BorderFactory;
39
import javax.swing.BorderFactory;
39
import javax.swing.JButton;
40
import javax.swing.JButton;
40
import javax.swing.JFileChooser;
41
import javax.swing.JFileChooser;
41
import javax.swing.JLabel;
42
import javax.swing.JLabel;
42
import javax.swing.JPanel;
43
import javax.swing.JPanel;
43
import javax.swing.JScrollPane;
44
import javax.swing.JScrollPane;
44
import javax.swing.JTextField;
45
import javax.swing.JTextField;
45
import javax.swing.SwingUtilities;
46
import javax.swing.SwingUtilities;
46
import javax.swing.UIManager;
47
import javax.swing.UIManager;
47
import javax.swing.event.DocumentEvent;
48
import javax.swing.event.DocumentEvent;
48
 
49
 
49
public abstract class AbstractGenerationDocumentPreferencePanel extends DefaultPreferencePanel {
50
public abstract class AbstractGenerationDocumentPreferencePanel extends DefaultPreferencePanel {
50
 
51
 
51
    protected Map<String, String> mapKeyLabel = new HashMap<String, String>();
52
    protected Map<String, String> mapKeyLabel = new HashMap<String, String>();
52
    private final Map<String, JTextField> mapKeyTextOO = new HashMap<String, JTextField>();
53
    private final Map<String, JTextField> mapKeyTextOO = new HashMap<String, JTextField>();
53
    private final Map<String, JTextField> mapKeyTextPDF = new HashMap<String, JTextField>();
54
    private final Map<String, JTextField> mapKeyTextPDF = new HashMap<String, JTextField>();
54
 
55
 
55
    private JFileChooser fileChooser;
56
    private JFileChooser fileChooser;
56
 
57
 
57
    private static final String formatOO = "Format Open Office : ";
58
    private static final String formatOO = "Format Open Office : ";
58
    private static final String formatPDF = "Format PDF : ";
59
    private static final String formatPDF = "Format PDF : ";
59
    private static final String parcourir = "...";
60
    private static final String parcourir = "...";
60
    private static final String defaut = "Définir l'emplacement suivant pour tous";
61
    private static final String defaut = "Définir l'emplacement suivant pour tous";
61
 
62
 
62
    public AbstractGenerationDocumentPreferencePanel() {
63
    public AbstractGenerationDocumentPreferencePanel() {
63
        super();
64
        super();
64
    }
65
    }
65
 
66
 
66
    public void uiInit() {
67
    public void uiInit() {
67
        setLayout(new GridBagLayout());
68
        setLayout(new GridBagLayout());
68
        final GridBagConstraints c = new DefaultGridBagConstraints();
69
        final GridBagConstraints c = new DefaultGridBagConstraints();
69
 
70
 
70
        // Emplacement par défaut
71
        // Emplacement par défaut
71
        final GridBagConstraints cDefault = new DefaultGridBagConstraints();
72
        final GridBagConstraints cDefault = new DefaultGridBagConstraints();
72
        final JLabel labelDefaut = new JLabel(defaut);
73
        final JLabel labelDefaut = new JLabel(defaut);
73
        final JTextField textDefault = new JTextField();
74
        final JTextField textDefault = new JTextField();
74
        textDefault.setEditable(false);
75
        textDefault.setEditable(false);
75
        final JButton buttonDefault = new JButton(parcourir);
76
        final JButton buttonDefault = new JButton(parcourir);
76
        buttonDefault.addActionListener(new ActionListener() {
77
        buttonDefault.addActionListener(new ActionListener() {
77
            @Override
78
            @Override
78
            public void actionPerformed(final ActionEvent e) {
79
            public void actionPerformed(final ActionEvent e) {
79
                directoryChoose(textDefault);
80
                directoryChoose(textDefault);
80
            }
81
            }
81
        });
82
        });
82
 
83
 
83
        final JButton buttonSetDefaut = new JButton("Appliquer");
84
        final JButton buttonSetDefaut = new JButton("Appliquer");
84
        buttonSetDefaut.addActionListener(new ActionListener() {
85
        buttonSetDefaut.addActionListener(new ActionListener() {
85
            @Override
86
            @Override
86
            public void actionPerformed(final ActionEvent e) {
87
            public void actionPerformed(final ActionEvent e) {
87
 
88
 
88
                final String folder = textDefault.getText();
89
                final String folder = textDefault.getText();
89
 
90
 
90
                for (final Entry<String, JTextField> entry : AbstractGenerationDocumentPreferencePanel.this.mapKeyTextOO.entrySet()) {
91
                for (final Entry<String, JTextField> entry : AbstractGenerationDocumentPreferencePanel.this.mapKeyTextOO.entrySet()) {
91
                    entry.getValue().setText(folder + File.separator + AbstractGenerationDocumentPreferencePanel.this.mapKeyLabel.get(entry.getKey()));
92
                    entry.getValue().setText(folder + File.separator + AbstractGenerationDocumentPreferencePanel.this.mapKeyLabel.get(entry.getKey()));
92
                }
93
                }
93
 
94
 
94
                for (final Entry<String, JTextField> entry : AbstractGenerationDocumentPreferencePanel.this.mapKeyTextPDF.entrySet()) {
95
                for (final Entry<String, JTextField> entry : AbstractGenerationDocumentPreferencePanel.this.mapKeyTextPDF.entrySet()) {
95
                    entry.getValue().setText(folder + File.separator + AbstractGenerationDocumentPreferencePanel.this.mapKeyLabel.get(entry.getKey()));
96
                    entry.getValue().setText(folder + File.separator + AbstractGenerationDocumentPreferencePanel.this.mapKeyLabel.get(entry.getKey()));
96
                }
97
                }
97
            }
98
            }
98
        });
99
        });
99
 
100
 
100
        textDefault.getDocument().addDocumentListener(new SimpleDocumentListener() {
101
        textDefault.getDocument().addDocumentListener(new SimpleDocumentListener() {
101
            @Override
102
            @Override
102
            public void update(final DocumentEvent e) {
103
            public void update(final DocumentEvent e) {
103
                buttonSetDefaut.setEnabled(textDefault.getText().trim().length() > 0);
104
                buttonSetDefaut.setEnabled(textDefault.getText().trim().length() > 0);
104
            }
105
            }
105
        });
106
        });
106
        buttonSetDefaut.setEnabled(false);
107
        buttonSetDefaut.setEnabled(false);
107
        cDefault.gridx = GridBagConstraints.RELATIVE;
108
        cDefault.gridx = GridBagConstraints.RELATIVE;
108
        final JPanel panelDefaut = new JPanel(new GridBagLayout());
109
        final JPanel panelDefaut = new JPanel(new GridBagLayout());
109
        panelDefaut.add(labelDefaut, cDefault);
110
        panelDefaut.add(labelDefaut, cDefault);
110
        cDefault.weightx = 1;
111
        cDefault.weightx = 1;
111
        panelDefaut.add(textDefault, cDefault);
112
        panelDefaut.add(textDefault, cDefault);
112
        cDefault.weightx = 0;
113
        cDefault.weightx = 0;
113
        panelDefaut.add(buttonDefault, cDefault);
114
        panelDefaut.add(buttonDefault, cDefault);
114
        panelDefaut.add(buttonSetDefaut, cDefault);
115
        panelDefaut.add(buttonSetDefaut, cDefault);
115
        c.gridwidth = GridBagConstraints.REMAINDER;
116
        c.gridwidth = GridBagConstraints.REMAINDER;
116
        c.weightx = 1;
117
        c.weightx = 1;
117
 
118
 
118
        this.add(panelDefaut, c);
119
        this.add(panelDefaut, c);
119
 
120
 
120
        final List<String> list = new ArrayList<String>(this.mapKeyLabel.keySet());
121
        final List<String> list = new ArrayList<String>(this.mapKeyLabel.keySet());
121
        Collections.sort(list, new Comparator<String>() {
122
        Collections.sort(list, new Comparator<String>() {
122
            @Override
123
            @Override
123
            public int compare(final String o1, final String o2) {
124
            public int compare(final String o1, final String o2) {
124
                return o1.compareTo(o2);
125
                return o1.compareTo(o2);
125
            }
126
            }
126
        });
127
        });
127
 
128
 
128
        final JPanel panelGlobal = new JPanel(new GridBagLayout());
129
        final JPanel panelGlobal = new JPanel(new GridBagLayout());
129
        final GridBagConstraints cGlobal = new DefaultGridBagConstraints();
130
        final GridBagConstraints cGlobal = new DefaultGridBagConstraints();
130
 
131
 
131
        final int size = list.size();
132
        final int size = list.size();
132
        for (int i = 0; i < size; i++) {
133
        for (int i = 0; i < size; i++) {
133
            final String key = list.get(i);
134
            final String key = list.get(i);
134
            cGlobal.gridwidth = 1;
135
            cGlobal.gridwidth = 1;
135
            cGlobal.weightx = 1;
136
            cGlobal.weightx = 1;
136
            cGlobal.gridy++;
137
            cGlobal.gridy++;
137
            cGlobal.gridx = 0;
138
            cGlobal.gridx = 0;
138
            cGlobal.anchor = GridBagConstraints.NORTHWEST;
139
            cGlobal.anchor = GridBagConstraints.NORTHWEST;
139
 
140
 
140
            if (i == size - 1) {
141
            if (i == size - 1) {
141
                cGlobal.weighty = 1;
142
                cGlobal.weighty = 1;
142
            }
143
            }
143
 
144
 
144
            final JPanel panel = new JPanel();
145
            final JPanel panel = new JPanel();
145
            panel.setOpaque(false);
146
            panel.setOpaque(false);
146
            panel.setBorder(BorderFactory.createTitledBorder(this.mapKeyLabel.get(key)));
147
            panel.setBorder(BorderFactory.createTitledBorder(this.mapKeyLabel.get(key)));
147
            panel.setLayout(new GridBagLayout());
148
            panel.setLayout(new GridBagLayout());
148
            final GridBagConstraints cPanel = new DefaultGridBagConstraints();
149
            final GridBagConstraints cPanel = new DefaultGridBagConstraints();
149
 
150
 
150
            // Emplacement SXC
151
            // Emplacement SXC
151
 
152
 
152
            panel.add(new JLabel(formatOO), cPanel);
153
            panel.add(new JLabel(formatOO), cPanel);
153
            cPanel.gridx++;
154
            cPanel.gridx++;
154
            cPanel.weightx = 1;
155
            cPanel.weightx = 1;
155
            final JTextField text = new JTextField();
156
            final JTextField text = new JTextField();
156
            text.setEditable(false);
157
            text.setEditable(false);
157
            this.mapKeyTextOO.put(key, text);
158
            this.mapKeyTextOO.put(key, text);
158
            panel.add(text, cPanel);
159
            panel.add(text, cPanel);
159
 
160
 
160
            final JButton button = new JButton(parcourir);
161
            final JButton button = new JButton(parcourir);
161
            cPanel.gridx++;
162
            cPanel.gridx++;
162
            cPanel.weightx = 0;
163
            cPanel.weightx = 0;
163
            cPanel.fill = GridBagConstraints.NONE;
164
            cPanel.fill = GridBagConstraints.NONE;
164
            panel.add(button, cPanel);
165
            panel.add(button, cPanel);
165
 
166
 
166
            // Emplacement PDF
167
            // Emplacement PDF
167
            cPanel.fill = GridBagConstraints.HORIZONTAL;
168
            cPanel.fill = GridBagConstraints.HORIZONTAL;
168
            cPanel.weightx = 0;
169
            cPanel.weightx = 0;
169
            cPanel.gridy++;
170
            cPanel.gridy++;
170
            cPanel.gridx = 0;
171
            cPanel.gridx = 0;
171
            cPanel.gridwidth = 1;
172
            cPanel.gridwidth = 1;
172
            panel.add(new JLabel(formatPDF), cPanel);
173
            panel.add(new JLabel(formatPDF), cPanel);
173
            cPanel.gridx++;
174
            cPanel.gridx++;
174
            cPanel.weightx = 1;
175
            cPanel.weightx = 1;
175
            final JTextField textPDF = new JTextField();
176
            final JTextField textPDF = new JTextField();
176
            textPDF.setEditable(false);
177
            textPDF.setEditable(false);
177
            this.mapKeyTextPDF.put(key, textPDF);
178
            this.mapKeyTextPDF.put(key, textPDF);
178
            panel.add(textPDF, cPanel);
179
            panel.add(textPDF, cPanel);
179
 
180
 
180
            final JButton buttonPDF = new JButton(parcourir);
181
            final JButton buttonPDF = new JButton(parcourir);
181
            cPanel.gridx++;
182
            cPanel.gridx++;
182
            cPanel.weightx = 0;
183
            cPanel.weightx = 0;
183
            cPanel.fill = GridBagConstraints.NONE;
184
            cPanel.fill = GridBagConstraints.NONE;
184
            panel.add(buttonPDF, cPanel);
185
            panel.add(buttonPDF, cPanel);
185
 
186
 
186
            panelGlobal.add(panel, cGlobal);
187
            panelGlobal.add(panel, cGlobal);
187
 
188
 
188
            button.addActionListener(new ActionListener() {
189
            button.addActionListener(new ActionListener() {
189
                @Override
190
                @Override
190
                public void actionPerformed(final ActionEvent e) {
191
                public void actionPerformed(final ActionEvent e) {
191
                    directoryChoose(AbstractGenerationDocumentPreferencePanel.this.mapKeyTextOO.get(key));
192
                    directoryChoose(AbstractGenerationDocumentPreferencePanel.this.mapKeyTextOO.get(key));
192
                }
193
                }
193
            });
194
            });
194
            buttonPDF.addActionListener(new ActionListener() {
195
            buttonPDF.addActionListener(new ActionListener() {
195
                @Override
196
                @Override
196
                public void actionPerformed(final ActionEvent e) {
197
                public void actionPerformed(final ActionEvent e) {
197
                    directoryChoose(AbstractGenerationDocumentPreferencePanel.this.mapKeyTextPDF.get(key));
198
                    directoryChoose(AbstractGenerationDocumentPreferencePanel.this.mapKeyTextPDF.get(key));
198
                }
199
                }
199
            });
200
            });
200
 
201
 
201
        }
202
        }
202
 
203
 
203
        c.gridwidth = GridBagConstraints.REMAINDER;
204
        c.gridwidth = GridBagConstraints.REMAINDER;
204
        c.weightx = 1;
205
        c.weightx = 1;
205
        c.weighty = 1;
206
        c.weighty = 1;
206
        c.gridy++;
207
        c.gridy++;
207
        c.gridx = 0;
208
        c.gridx = 0;
208
        c.fill = GridBagConstraints.BOTH;
209
        c.fill = GridBagConstraints.BOTH;
209
        this.add(new JScrollPane(panelGlobal), c);
210
        this.add(new JScrollPane(panelGlobal), c);
210
 
211
 
211
        setValues();
212
        setValues();
212
    }
213
    }
213
 
214
 
214
    @Override
215
    @Override
215
    public void storeValues() {
216
    public void storeValues() {
216
 
217
 
217
        try {
218
        try {
218
            final File z = new File(".");
219
            final File z = new File(".");
219
            for (final Entry<String, JTextField> entry : this.mapKeyTextOO.entrySet()) {
220
            for (final Entry<String, JTextField> entry : this.mapKeyTextOO.entrySet()) {
220
                final File f = new File(entry.getValue().getText());
221
                final File f = new File(entry.getValue().getText());
221
                TemplateNXProps.getInstance().setProperty(entry.getKey() + "OO", FileUtility.getPrimaryPath(z.getCanonicalFile(), f));
222
                TemplateNXProps.getInstance().setProperty(entry.getKey() + "OO", FileUtility.getPrimaryPath(z.getCanonicalFile(), f));
222
            }
223
            }
223
 
224
 
224
            for (final Entry<String, JTextField> entry : this.mapKeyTextPDF.entrySet()) {
225
            for (final Entry<String, JTextField> entry : this.mapKeyTextPDF.entrySet()) {
225
                final File f = new File(entry.getValue().getText());
226
                final File f = new File(entry.getValue().getText());
226
                TemplateNXProps.getInstance().setProperty(entry.getKey() + "PDF", FileUtility.getPrimaryPath(z.getCanonicalFile(), f));
227
                TemplateNXProps.getInstance().setProperty(entry.getKey() + "PDF", FileUtility.getPrimaryPath(z.getCanonicalFile(), f));
227
            }
228
            }
228
 
229
 
229
        } catch (final IOException e) {
230
        } catch (final IOException e) {
230
            e.printStackTrace();
231
            e.printStackTrace();
231
        }
232
        }
232
 
233
 
233
        TemplateNXProps.getInstance().store();
234
        TemplateNXProps.getInstance().store();
234
    }
235
    }
235
 
236
 
236
    @Override
237
    @Override
237
    public void restoreToDefaults() {
238
    public void restoreToDefaults() {
238
        final Color foregroundColor = UIManager.getColor("TextField.foreground");
239
        final Color foregroundColor = UIManager.getColor("TextField.foreground");
239
 
240
 
240
        for (final Entry<String, JTextField> entry : this.mapKeyTextOO.entrySet()) {
241
        for (final Entry<String, JTextField> entry : this.mapKeyTextOO.entrySet()) {
241
            final File f = new File(SheetXml.getLocationForTuple(Tuple2.create("GetDefault", this.mapKeyLabel.get(entry.getKey())), false));
242
            final File f = DocumentLocalStorageManager.getInstance().getDocumentOutputDirectory("Default");
242
            final JTextField textField = entry.getValue();
243
            final JTextField textField = entry.getValue();
243
            if (f.exists()) {
244
            if (f.exists()) {
244
                textField.setForeground(foregroundColor);
245
                textField.setForeground(foregroundColor);
245
            } else {
246
            } else {
246
                textField.setForeground(Color.RED);
247
                textField.setForeground(Color.RED);
247
            }
248
            }
248
            try {
249
            try {
249
                textField.setText(f.getCanonicalPath());
250
                textField.setText(f.getCanonicalPath());
250
            } catch (IOException e) {
251
            } catch (IOException e) {
251
                // TODO Auto-generated catch block
252
                // TODO Auto-generated catch block
252
                e.printStackTrace();
253
                e.printStackTrace();
253
            }
254
            }
254
        }
255
        }
255
 
256
 
256
        for (final Entry<String, JTextField> entry : this.mapKeyTextPDF.entrySet()) {
257
        for (final Entry<String, JTextField> entry : this.mapKeyTextPDF.entrySet()) {
257
            final File f = new File(SheetXml.getLocationForTuple(Tuple2.create("GetDefault", this.mapKeyLabel.get(entry.getKey())), true));
258
            final File f = DocumentLocalStorageManager.getInstance().getDocumentOutputDirectory("Default");
258
            final JTextField textField = entry.getValue();
259
            final JTextField textField = entry.getValue();
259
            if (f.exists()) {
260
            if (f.exists()) {
260
                textField.setForeground(foregroundColor);
261
                textField.setForeground(foregroundColor);
261
            } else {
262
            } else {
262
                textField.setForeground(Color.RED);
263
                textField.setForeground(Color.RED);
263
            }
264
            }
264
            try {
265
            try {
265
                textField.setText(f.getCanonicalPath());
266
                textField.setText(f.getCanonicalPath());
266
            } catch (IOException e) {
267
            } catch (IOException e) {
267
                // TODO Auto-generated catch block
-
 
268
                e.printStackTrace();
268
                e.printStackTrace();
269
            }
269
            }
270
        }
270
        }
271
    }
271
    }
272
 
272
 
273
    private void setValues() {
273
    private void setValues() {
274
        try {
274
        try {
275
            updateTextFields(this.mapKeyTextOO, "OO");
275
            updateTextFields(this.mapKeyTextOO, "OO");
276
            updateTextFields(this.mapKeyTextPDF, "PDF");
276
            updateTextFields(this.mapKeyTextPDF, "PDF");
277
        } catch (final IOException e) {
277
        } catch (final IOException e) {
278
            e.printStackTrace();
278
            e.printStackTrace();
279
        }
279
        }
280
    }
280
    }
281
 
281
 
282
    private void updateTextFields(final Map<String, JTextField> map, final String format) throws IOException {
282
    private void updateTextFields(final Map<String, JTextField> map, final String format) throws IOException {
283
        final Color foregroundColor = UIManager.getColor("TextField.foreground");
283
        final Color foregroundColor = UIManager.getColor("TextField.foreground");
-
 
284
        final DocumentLocalStorageManager storage = DocumentLocalStorageManager.getInstance();
284
        for (final Entry<String, JTextField> entry : map.entrySet()) {
285
        for (final Entry<String, JTextField> entry : map.entrySet()) {
-
 
286
            final File f;
-
 
287
            if (format.equalsIgnoreCase("PDF")) {
-
 
288
                f = storage.getPDFOutputDirectory(entry.getKey());
-
 
289
            } else {
285
            final File f = new File(SheetXml.getLocationForTuple(Tuple2.create(entry.getKey(), this.mapKeyLabel.get(entry.getKey())), format.equalsIgnoreCase("PDF")));
290
                f = storage.getDocumentOutputDirectory(entry.getKey());
-
 
291
            }
286
            final JTextField textField = entry.getValue();
292
            final JTextField textField = entry.getValue();
287
            if (f.exists()) {
293
            if (f.exists()) {
288
                textField.setForeground(foregroundColor);
294
                textField.setForeground(foregroundColor);
289
            } else {
295
            } else {
290
                textField.setForeground(Color.RED);
296
                textField.setForeground(Color.RED);
291
            }
297
            }
292
            textField.setText(f.getCanonicalPath());
298
            textField.setText(f.getCanonicalPath());
293
        }
299
        }
294
    }
300
    }
295
 
301
 
296
    private void directoryChoose(final JTextField field) {
302
    private void directoryChoose(final JTextField field) {
297
 
303
 
298
        if (this.fileChooser == null) {
304
        if (this.fileChooser == null) {
299
            this.fileChooser = new JFileChooser();
305
            this.fileChooser = new JFileChooser();
300
            this.fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
306
            this.fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
301
        }
307
        }
302
        this.fileChooser.setCurrentDirectory(new File(field.getText()));
308
        this.fileChooser.setCurrentDirectory(new File(field.getText()));
303
        SwingUtilities.invokeLater(new Runnable() {
309
        SwingUtilities.invokeLater(new Runnable() {
304
            public void run() {
310
            public void run() {
305
 
311
 
306
                if (AbstractGenerationDocumentPreferencePanel.this.fileChooser.showDialog(AbstractGenerationDocumentPreferencePanel.this, "Sélectionner") == JFileChooser.APPROVE_OPTION) {
312
                if (AbstractGenerationDocumentPreferencePanel.this.fileChooser.showDialog(AbstractGenerationDocumentPreferencePanel.this, "Sélectionner") == JFileChooser.APPROVE_OPTION) {
307
                    final File selectedFile = AbstractGenerationDocumentPreferencePanel.this.fileChooser.getSelectedFile();
313
                    final File selectedFile = AbstractGenerationDocumentPreferencePanel.this.fileChooser.getSelectedFile();
308
                    if (selectedFile.exists()) {
314
                    if (selectedFile.exists()) {
309
                        field.setForeground(UIManager.getColor("TextField.foreground"));
315
                        field.setForeground(UIManager.getColor("TextField.foreground"));
310
                    } else {
316
                    } else {
311
                        field.setForeground(Color.RED);
317
                        field.setForeground(Color.RED);
312
                    }
318
                    }
313
 
319
 
314
                    field.setText(selectedFile.getAbsolutePath());
320
                    field.setText(selectedFile.getAbsolutePath());
315
                }
321
                }
316
            }
322
            }
317
        });
323
        });
318
    }
324
    }
319
}
325
}