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