c1a8eaec6851d763ce5f143f0511c9b8fb0fb5a6
[jSite.git] / src / de / todesbaum / jsite / gui / ProjectFilesPage.java
1 /*
2  * jSite - a tool for uploading websites into Freenet
3  * Copyright (C) 2006 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package de.todesbaum.jsite.gui;
21
22 import java.awt.BorderLayout;
23 import java.awt.Dimension;
24 import java.awt.FlowLayout;
25 import java.awt.GridBagConstraints;
26 import java.awt.GridBagLayout;
27 import java.awt.Insets;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import java.awt.event.KeyEvent;
31 import java.text.MessageFormat;
32 import java.util.ArrayList;
33 import java.util.Collections;
34 import java.util.Iterator;
35 import java.util.List;
36
37 import javax.swing.AbstractAction;
38 import javax.swing.Action;
39 import javax.swing.DefaultComboBoxModel;
40 import javax.swing.JButton;
41 import javax.swing.JCheckBox;
42 import javax.swing.JComboBox;
43 import javax.swing.JComponent;
44 import javax.swing.JLabel;
45 import javax.swing.JList;
46 import javax.swing.JOptionPane;
47 import javax.swing.JPanel;
48 import javax.swing.JScrollPane;
49 import javax.swing.JSpinner;
50 import javax.swing.JTextField;
51 import javax.swing.ListSelectionModel;
52 import javax.swing.SpinnerNumberModel;
53 import javax.swing.SwingUtilities;
54 import javax.swing.border.EmptyBorder;
55 import javax.swing.event.ChangeEvent;
56 import javax.swing.event.ChangeListener;
57 import javax.swing.event.DocumentEvent;
58 import javax.swing.event.DocumentListener;
59 import javax.swing.event.ListSelectionEvent;
60 import javax.swing.event.ListSelectionListener;
61 import javax.swing.text.BadLocationException;
62 import javax.swing.text.Document;
63
64 import de.todesbaum.jsite.application.FileOption;
65 import de.todesbaum.jsite.application.Project;
66 import de.todesbaum.jsite.i18n.I18n;
67 import de.todesbaum.util.mime.DefaultMIMETypes;
68 import de.todesbaum.util.swing.TLabel;
69 import de.todesbaum.util.swing.TWizard;
70 import de.todesbaum.util.swing.TWizardPage;
71
72 /**
73  * @author David Roden <droden@gmail.com>
74  * @version $Id$
75  */
76 public class ProjectFilesPage extends TWizardPage implements ActionListener, ListSelectionListener, DocumentListener, FileScannerListener, ChangeListener {
77
78         protected TWizard wizard;
79
80         protected Project project;
81
82         private Action scanAction;
83         private Action editContainerAction;
84         private Action addContainerAction;
85         private Action deleteContainerAction;
86
87         protected JList projectFileList;
88         private JCheckBox defaultFileCheckBox;
89         private JCheckBox fileOptionsInsertCheckBox;
90         private JTextField fileOptionsCustomKeyTextField;
91         private JComboBox fileOptionsMIMETypeComboBox;
92         protected DefaultComboBoxModel containerComboBoxModel;
93         private JComboBox fileOptionsContainerComboBox;
94         private JSpinner replaceEditionRangeSpinner;
95         private JCheckBox replacementCheckBox;
96
97         public ProjectFilesPage() {
98                 super();
99                 pageInit();
100         }
101
102         private void pageInit() {
103                 createActions();
104                 setLayout(new BorderLayout(12, 12));
105                 add(createProjectFilesPanel(), BorderLayout.CENTER);
106         }
107
108         private void createActions() {
109                 scanAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.rescan")) {
110
111                         public void actionPerformed(ActionEvent actionEvent) {
112                                 actionScan();
113                         }
114                 };
115                 scanAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
116                 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
117
118                 addContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.add-container")) {
119
120                         public void actionPerformed(ActionEvent actionEvent) {
121                                 actionAddContainer();
122                         }
123                 };
124                 addContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.add-container.tooltip"));
125                 addContainerAction.setEnabled(false);
126
127                 editContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.edit-container")) {
128
129                         public void actionPerformed(ActionEvent actionEvent) {
130                                 actionEditContainer();
131                         }
132                 };
133                 editContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.edit-container.tooltip"));
134                 editContainerAction.setEnabled(false);
135
136                 deleteContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.delete-container")) {
137
138                         public void actionPerformed(ActionEvent actionEvent) {
139                                 actionDeleteContainer();
140                         }
141                 };
142                 deleteContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.delete-container.tooltip"));
143                 deleteContainerAction.setEnabled(false);
144         }
145
146         @Override
147         public void pageAdded(TWizard wizard) {
148                 this.wizard = wizard;
149                 actionScan();
150         }
151
152         private JComponent createProjectFilesPanel() {
153                 JPanel projectFilesPanel = new JPanel(new BorderLayout(12, 12));
154
155                 projectFileList = new JList();
156                 projectFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
157                 projectFileList.setMinimumSize(new Dimension(250, projectFileList.getPreferredSize().height));
158                 projectFileList.addListSelectionListener(this);
159
160                 projectFilesPanel.add(new JScrollPane(projectFileList), BorderLayout.CENTER);
161
162                 JPanel fileOptionsAlignmentPanel = new JPanel(new BorderLayout(12, 12));
163                 projectFilesPanel.add(fileOptionsAlignmentPanel, BorderLayout.PAGE_END);
164                 JPanel fileOptionsPanel = new JPanel(new GridBagLayout());
165                 fileOptionsAlignmentPanel.add(fileOptionsPanel, BorderLayout.PAGE_START);
166
167                 fileOptionsPanel.add(new JButton(scanAction), new GridBagConstraints(0, 0, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
168
169                 fileOptionsPanel.add(new JLabel("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>"), new GridBagConstraints(0, 1, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
170
171                 defaultFileCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.default"));
172                 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
173                 defaultFileCheckBox.setName("default-file");
174                 defaultFileCheckBox.addActionListener(this);
175                 defaultFileCheckBox.setEnabled(false);
176
177                 fileOptionsPanel.add(defaultFileCheckBox, new GridBagConstraints(0, 2, 5, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 18, 0, 0), 0, 0));
178
179                 fileOptionsInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert"), true);
180                 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
181                 fileOptionsInsertCheckBox.setName("insert");
182                 fileOptionsInsertCheckBox.setMnemonic(KeyEvent.VK_I);
183                 fileOptionsInsertCheckBox.addActionListener(this);
184                 fileOptionsInsertCheckBox.setEnabled(false);
185
186                 fileOptionsPanel.add(fileOptionsInsertCheckBox, new GridBagConstraints(0, 3, 5, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
187
188                 fileOptionsCustomKeyTextField = new JTextField(45);
189                 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
190                 fileOptionsCustomKeyTextField.setEnabled(false);
191                 fileOptionsCustomKeyTextField.getDocument().addDocumentListener(this);
192
193                 fileOptionsPanel.add(new TLabel(I18n.getMessage("jsite.project-files.custom-key"), KeyEvent.VK_K, fileOptionsCustomKeyTextField), new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
194                 fileOptionsPanel.add(fileOptionsCustomKeyTextField, new GridBagConstraints(1, 4, 4, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
195
196                 fileOptionsMIMETypeComboBox = new JComboBox(DefaultMIMETypes.getAllMIMETypes());
197                 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
198                 fileOptionsMIMETypeComboBox.setName("project-files.mime-type");
199                 fileOptionsMIMETypeComboBox.addActionListener(this);
200                 fileOptionsMIMETypeComboBox.setEnabled(false);
201
202                 fileOptionsPanel.add(new TLabel(I18n.getMessage("jsite.project-files.mime-type"), KeyEvent.VK_M, fileOptionsMIMETypeComboBox), new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
203                 fileOptionsPanel.add(fileOptionsMIMETypeComboBox, new GridBagConstraints(1, 5, 4, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
204
205                 containerComboBoxModel = new DefaultComboBoxModel();
206                 fileOptionsContainerComboBox = new JComboBox(containerComboBoxModel);
207                 fileOptionsContainerComboBox.setToolTipText(I18n.getMessage("jsite.project-files.container.tooltip"));
208                 fileOptionsContainerComboBox.setName("project-files.container");
209                 fileOptionsContainerComboBox.addActionListener(this);
210                 fileOptionsContainerComboBox.setEnabled(false);
211
212                 fileOptionsPanel.add(new TLabel(I18n.getMessage("jsite.project-files.container"), KeyEvent.VK_C, fileOptionsContainerComboBox), new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
213                 fileOptionsPanel.add(fileOptionsContainerComboBox, new GridBagConstraints(1, 6, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
214                 fileOptionsPanel.add(new JButton(addContainerAction), new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
215                 fileOptionsPanel.add(new JButton(editContainerAction), new GridBagConstraints(3, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
216                 fileOptionsPanel.add(new JButton(deleteContainerAction), new GridBagConstraints(4, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
217
218                 JPanel fileOptionsReplacementPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 6, 6));
219                 fileOptionsReplacementPanel.setBorder(new EmptyBorder(-6, -6, -6, -6));
220
221                 replacementCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.replacement"));
222                 replacementCheckBox.setName("project-files.replace-edition");
223                 replacementCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.replacement.tooltip"));
224                 replacementCheckBox.addActionListener(this);
225                 replacementCheckBox.setEnabled(false);
226                 fileOptionsReplacementPanel.add(replacementCheckBox);
227
228                 replaceEditionRangeSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 99, 1));
229                 replaceEditionRangeSpinner.setName("project-files.replace-edition-range");
230                 replaceEditionRangeSpinner.setToolTipText(I18n.getMessage("jsite.project-files.replacement.edition-range.tooltip"));
231                 replaceEditionRangeSpinner.addChangeListener(this);
232                 replaceEditionRangeSpinner.setEnabled(false);
233                 fileOptionsReplacementPanel.add(new JLabel(I18n.getMessage("jsite.project-files.replacement.edition-range")));
234                 fileOptionsReplacementPanel.add(replaceEditionRangeSpinner);
235
236                 fileOptionsPanel.add(fileOptionsReplacementPanel, new GridBagConstraints(0, 7, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 18, 0, 0), 0, 0));
237
238                 return projectFilesPanel;
239         }
240
241         public void setProject(Project project) {
242                 this.project = project;
243                 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
244                 setDescription(I18n.getMessage("jsite.project-files.description"));
245         }
246
247         private List<String> getProjectFiles() {
248                 List<String> files = new ArrayList<String>();
249                 for (int index = 0, size = projectFileList.getModel().getSize(); index < size; index++) {
250                         files.add((String) projectFileList.getModel().getElementAt(index));
251                 }
252                 return files;
253         }
254
255         protected void rebuildContainerComboBox() {
256                 /* scan files for containers */
257                 List<String> files = getProjectFiles();
258                 List<String> containers = new ArrayList<String>(); // ComboBoxModel
259                 // sucks. No
260                 // contains()!
261                 containers.add("");
262                 for (String filename: files) {
263                         String container = project.getFileOption(filename).getContainer();
264                         if (!containers.contains(container)) {
265                                 containers.add(container);
266                         }
267                 }
268                 Collections.sort(containers);
269                 containerComboBoxModel.removeAllElements();
270                 for (String container: containers) {
271                         containerComboBoxModel.addElement(container);
272                 }
273         }
274
275         //
276         // ACTIONS
277         //
278
279         protected void actionScan() {
280                 projectFileList.clearSelection();
281                 projectFileList.setListData(new Object[0]);
282
283                 wizard.setNextEnabled(false);
284                 wizard.setPreviousEnabled(false);
285                 wizard.setQuitEnabled(false);
286
287                 FileScanner fileScanner = new FileScanner(project);
288                 fileScanner.addFileScannerListener(this);
289                 new Thread(fileScanner).start();
290         }
291
292         protected void actionAddContainer() {
293                 String containerName = JOptionPane.showInputDialog(wizard, I18n.getMessage("jsite.project-files.action.add-container.message") + ":", null, JOptionPane.INFORMATION_MESSAGE);
294                 if (containerName == null) {
295                         return;
296                 }
297                 containerName = containerName.trim();
298                 String filename = (String) projectFileList.getSelectedValue();
299                 FileOption fileOption = project.getFileOption(filename);
300                 fileOption.setContainer(containerName);
301                 rebuildContainerComboBox();
302                 fileOptionsContainerComboBox.setSelectedItem(containerName);
303         }
304
305         protected void actionEditContainer() {
306                 String selectedFilename = (String) projectFileList.getSelectedValue();
307                 FileOption fileOption = project.getFileOption(selectedFilename);
308                 String oldContainerName = fileOption.getContainer();
309                 String containerName = JOptionPane.showInputDialog(wizard, I18n.getMessage("jsite.project-files.action.edit-container.message") + ":", oldContainerName);
310                 if (containerName == null) {
311                         return;
312                 }
313                 if (containerName.equals("")) {
314                         fileOption.setContainer("");
315                         fileOptionsContainerComboBox.setSelectedItem("");
316                         return;
317                 }
318                 List<String> files = getProjectFiles();
319                 for (String filename: files) {
320                         fileOption = project.getFileOption(filename);
321                         if (fileOption.getContainer().equals(oldContainerName)) {
322                                 fileOption.setContainer(containerName);
323                         }
324                 }
325                 rebuildContainerComboBox();
326                 fileOptionsContainerComboBox.setSelectedItem(containerName);
327         }
328
329         protected void actionDeleteContainer() {
330                 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.project-files.action.delete-container.message"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
331                         String containerName = (String) fileOptionsContainerComboBox.getSelectedItem();
332                         List<String> files = getProjectFiles();
333                         for (String filename: files) {
334                                 FileOption fileOption = project.getFileOption(filename);
335                                 if (fileOption.getContainer().equals(containerName)) {
336                                         fileOption.setContainer("");
337                                 }
338                         }
339                         fileOptionsContainerComboBox.setSelectedItem("");
340                 }
341         }
342
343         public void fileScannerFinished(FileScanner fileScanner) {
344                 final boolean error = fileScanner.isError();
345                 if (!error) {
346                         final List<String> files = fileScanner.getFiles();
347                         SwingUtilities.invokeLater(new Runnable() {
348
349                                 public void run() {
350                                         projectFileList.setListData(files.toArray(new String[files.size()]));
351                                         projectFileList.clearSelection();
352                                         rebuildContainerComboBox();
353                                 }
354                         });
355                         Iterator<String> filenames = project.getFileOptions().keySet().iterator();
356                         while (filenames.hasNext()) {
357                                 String filename = filenames.next();
358                                 if (!files.contains(filename)) {
359                                         project.setFileOption(filename, null);
360                                 }
361                         }
362                 } else {
363                         JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.scan-error"), null, JOptionPane.ERROR_MESSAGE);
364                 }
365                 SwingUtilities.invokeLater(new Runnable() {
366
367                         public void run() {
368                                 wizard.setPreviousEnabled(true);
369                                 wizard.setNextEnabled(!error);
370                                 wizard.setQuitEnabled(true);
371                         }
372                 });
373         }
374
375         //
376         // INTERFACE ActionListener
377         //
378
379         /**
380          * {@inheritDoc}
381          */
382         public void actionPerformed(ActionEvent actionEvent) {
383                 String filename = (String) projectFileList.getSelectedValue();
384                 if (filename == null) {
385                         return;
386                 }
387                 FileOption fileOption = project.getFileOption(filename);
388                 Object source = actionEvent.getSource();
389                 if (source instanceof JCheckBox) {
390                         JCheckBox checkBox = (JCheckBox) source;
391                         if ("default-file".equals(checkBox.getName())) {
392                                 if (checkBox.isSelected()) {
393                                         project.setIndexFile(filename);
394                                 } else {
395                                         project.setIndexFile(null);
396                                 }
397                         } else if ("insert".equals(checkBox.getName())) {
398                                 boolean isInsert = checkBox.isSelected();
399                                 fileOptionsCustomKeyTextField.setEnabled(!isInsert);
400                                 fileOption.setInsert(isInsert);
401                                 if (!isInsert) {
402                                         fileOptionsContainerComboBox.setSelectedItem("");
403                                 }
404                         } else if ("project-files.replace-edition".equals(checkBox.getName())) {
405                                 boolean replaceEdition = checkBox.isSelected();
406                                 fileOption.setReplaceEdition(replaceEdition);
407                                 replaceEditionRangeSpinner.setEnabled(replaceEdition);
408                         }
409                 } else if (source instanceof JComboBox) {
410                         JComboBox comboBox = (JComboBox) source;
411                         if ("project-files.mime-type".equals(comboBox.getName())) {
412                                 fileOption.setMimeType((String) comboBox.getSelectedItem());
413                         } else if ("project-files.container".equals(comboBox.getName())) {
414                                 String containerName = (String) comboBox.getSelectedItem();
415                                 fileOption.setContainer(containerName);
416                                 boolean enabled = !"".equals(containerName);
417                                 editContainerAction.setEnabled(enabled);
418                                 deleteContainerAction.setEnabled(enabled);
419                                 if (enabled) {
420                                         fileOptionsInsertCheckBox.setSelected(true);
421                                 }
422                         }
423                 }
424         }
425
426         //
427         // INTERFACE ListSelectionListener
428         //
429
430         /**
431          * {@inheritDoc}
432          */
433         public void valueChanged(ListSelectionEvent e) {
434                 String filename = (String) projectFileList.getSelectedValue();
435                 boolean enabled = filename != null;
436                 boolean insert = fileOptionsInsertCheckBox.isSelected();
437                 defaultFileCheckBox.setEnabled(enabled);
438                 fileOptionsInsertCheckBox.setEnabled(enabled);
439                 fileOptionsCustomKeyTextField.setEnabled(enabled && !insert);
440                 fileOptionsMIMETypeComboBox.setEnabled(enabled);
441                 fileOptionsContainerComboBox.setEnabled(enabled);
442                 addContainerAction.setEnabled(enabled);
443                 editContainerAction.setEnabled(enabled);
444                 deleteContainerAction.setEnabled(enabled);
445                 replacementCheckBox.setEnabled(enabled && insert);
446                 if (filename != null) {
447                         FileOption fileOption = project.getFileOption(filename);
448                         defaultFileCheckBox.setSelected(filename.equals(project.getIndexFile()));
449                         fileOptionsInsertCheckBox.setSelected(fileOption.isInsert());
450                         fileOptionsCustomKeyTextField.setText(fileOption.getCustomKey());
451                         fileOptionsMIMETypeComboBox.getModel().setSelectedItem(fileOption.getMimeType());
452                         fileOptionsContainerComboBox.setSelectedItem(fileOption.getContainer());
453                         replacementCheckBox.setSelected(fileOption.getReplaceEdition());
454                         replaceEditionRangeSpinner.setValue(fileOption.getEditionRange());
455                         replaceEditionRangeSpinner.setEnabled(fileOption.getReplaceEdition());
456                 } else {
457                         defaultFileCheckBox.setSelected(false);
458                         fileOptionsInsertCheckBox.setSelected(true);
459                         fileOptionsCustomKeyTextField.setText("CHK@");
460                         fileOptionsMIMETypeComboBox.getModel().setSelectedItem(DefaultMIMETypes.DEFAULT_MIME_TYPE);
461                         fileOptionsContainerComboBox.setSelectedItem("");
462                         replacementCheckBox.setSelected(false);
463                         replaceEditionRangeSpinner.setValue(0);
464                 }
465         }
466
467         //
468         // INTERFACE DocumentListener
469         //
470
471         private void processDocumentUpdate(DocumentEvent documentEvent) {
472                 String filename = (String) projectFileList.getSelectedValue();
473                 if (filename == null) {
474                         return;
475                 }
476                 FileOption fileOption = project.getFileOption(filename);
477                 Document document = documentEvent.getDocument();
478                 try {
479                         String text = document.getText(0, document.getLength());
480                         fileOption.setCustomKey(text);
481                 } catch (BadLocationException ble1) {
482                 }
483         }
484
485         /**
486          * {@inheritDoc}
487          */
488         public void changedUpdate(DocumentEvent documentEvent) {
489                 processDocumentUpdate(documentEvent);
490         }
491
492         /**
493          * {@inheritDoc}
494          */
495         public void insertUpdate(DocumentEvent documentEvent) {
496                 processDocumentUpdate(documentEvent);
497         }
498
499         /**
500          * {@inheritDoc}
501          */
502         public void removeUpdate(DocumentEvent documentEvent) {
503                 processDocumentUpdate(documentEvent);
504         }
505
506         //
507         // INTERFACE ChangeListener
508         //
509
510         /**
511          * {@inheritDoc}
512          */
513         public void stateChanged(ChangeEvent changeEvent) {
514                 String filename = (String) projectFileList.getSelectedValue();
515                 if (filename == null) {
516                         return;
517                 }
518                 FileOption fileOption = project.getFileOption(filename);
519                 Object source = changeEvent.getSource();
520                 if (source instanceof JSpinner) {
521                         JSpinner spinner = (JSpinner) source;
522                         fileOption.setEditionRange((Integer) spinner.getValue());
523                 }
524         }
525
526 }