2 * jSite - a tool for uploading websites into Freenet
3 * Copyright (C) 2006 David Roden
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.
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.
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.
20 package de.todesbaum.jsite.gui;
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.HashSet;
35 import java.util.Iterator;
36 import java.util.List;
39 import javax.swing.AbstractAction;
40 import javax.swing.Action;
41 import javax.swing.DefaultComboBoxModel;
42 import javax.swing.JButton;
43 import javax.swing.JCheckBox;
44 import javax.swing.JComboBox;
45 import javax.swing.JComponent;
46 import javax.swing.JLabel;
47 import javax.swing.JList;
48 import javax.swing.JOptionPane;
49 import javax.swing.JPanel;
50 import javax.swing.JScrollPane;
51 import javax.swing.JSpinner;
52 import javax.swing.JTextField;
53 import javax.swing.ListSelectionModel;
54 import javax.swing.SpinnerNumberModel;
55 import javax.swing.SwingUtilities;
56 import javax.swing.border.EmptyBorder;
57 import javax.swing.event.ChangeEvent;
58 import javax.swing.event.ChangeListener;
59 import javax.swing.event.DocumentEvent;
60 import javax.swing.event.DocumentListener;
61 import javax.swing.event.ListSelectionEvent;
62 import javax.swing.event.ListSelectionListener;
63 import javax.swing.text.BadLocationException;
64 import javax.swing.text.Document;
66 import de.todesbaum.jsite.application.FileOption;
67 import de.todesbaum.jsite.application.Project;
68 import de.todesbaum.jsite.i18n.I18n;
69 import de.todesbaum.jsite.i18n.I18nContainer;
70 import de.todesbaum.util.mime.DefaultMIMETypes;
71 import de.todesbaum.util.swing.TLabel;
72 import de.todesbaum.util.swing.TWizard;
73 import de.todesbaum.util.swing.TWizardPage;
76 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
78 public class ProjectFilesPage extends TWizardPage implements ActionListener, ListSelectionListener, DocumentListener, FileScannerListener, ChangeListener {
80 private Project project;
82 private Action scanAction;
83 private Action editContainerAction;
84 private Action addContainerAction;
85 private Action deleteContainerAction;
87 private JList projectFileList;
88 private JCheckBox defaultFileCheckBox;
89 private JCheckBox fileOptionsInsertCheckBox;
90 private JTextField fileOptionsCustomKeyTextField;
91 private JComboBox fileOptionsMIMETypeComboBox;
92 private DefaultComboBoxModel containerComboBoxModel;
93 private JComboBox fileOptionsContainerComboBox;
94 private JSpinner replaceEditionRangeSpinner;
95 private JCheckBox replacementCheckBox;
97 public ProjectFilesPage(final TWizard wizard) {
102 private void pageInit() {
104 setLayout(new BorderLayout(12, 12));
105 add(createProjectFilesPanel(), BorderLayout.CENTER);
108 private void createActions() {
109 scanAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.rescan")) {
111 @SuppressWarnings("synthetic-access")
112 public void actionPerformed(ActionEvent actionEvent) {
116 scanAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
117 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
119 addContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.add-container")) {
121 @SuppressWarnings("synthetic-access")
122 public void actionPerformed(ActionEvent actionEvent) {
123 actionAddContainer();
126 addContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.add-container.tooltip"));
127 addContainerAction.setEnabled(false);
129 editContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.edit-container")) {
131 @SuppressWarnings("synthetic-access")
132 public void actionPerformed(ActionEvent actionEvent) {
133 actionEditContainer();
136 editContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.edit-container.tooltip"));
137 editContainerAction.setEnabled(false);
139 deleteContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.delete-container")) {
141 @SuppressWarnings("synthetic-access")
142 public void actionPerformed(ActionEvent actionEvent) {
143 actionDeleteContainer();
146 deleteContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.delete-container.tooltip"));
147 deleteContainerAction.setEnabled(false);
149 I18nContainer.getInstance().registerRunnable(new Runnable() {
151 @SuppressWarnings("synthetic-access")
153 scanAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.rescan"));
154 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
155 addContainerAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.add-container"));
156 addContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.add-container.tooltip"));
157 editContainerAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.edit-container"));
158 editContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.edit-container.tooltip"));
159 deleteContainerAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.delete-container"));
160 deleteContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.delete-container.tooltip"));
166 public void pageAdded(TWizard wizard) {
168 this.wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
169 this.wizard.setNextName(I18n.getMessage("jsite.project-files.insert-now"));
170 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
173 private JComponent createProjectFilesPanel() {
174 JPanel projectFilesPanel = new JPanel(new BorderLayout(12, 12));
176 projectFileList = new JList();
177 projectFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
178 projectFileList.setMinimumSize(new Dimension(250, projectFileList.getPreferredSize().height));
179 projectFileList.addListSelectionListener(this);
181 projectFilesPanel.add(new JScrollPane(projectFileList), BorderLayout.CENTER);
183 JPanel fileOptionsAlignmentPanel = new JPanel(new BorderLayout(12, 12));
184 projectFilesPanel.add(fileOptionsAlignmentPanel, BorderLayout.PAGE_END);
185 JPanel fileOptionsPanel = new JPanel(new GridBagLayout());
186 fileOptionsAlignmentPanel.add(fileOptionsPanel, BorderLayout.PAGE_START);
188 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));
190 final JLabel fileOptionsLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
191 fileOptionsPanel.add(fileOptionsLabel, new GridBagConstraints(0, 1, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
193 defaultFileCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.default"));
194 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
195 defaultFileCheckBox.setName("default-file");
196 defaultFileCheckBox.addActionListener(this);
197 defaultFileCheckBox.setEnabled(false);
199 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));
201 fileOptionsInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert"), true);
202 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
203 fileOptionsInsertCheckBox.setName("insert");
204 fileOptionsInsertCheckBox.setMnemonic(KeyEvent.VK_I);
205 fileOptionsInsertCheckBox.addActionListener(this);
206 fileOptionsInsertCheckBox.setEnabled(false);
208 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));
210 fileOptionsCustomKeyTextField = new JTextField(45);
211 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
212 fileOptionsCustomKeyTextField.setEnabled(false);
213 fileOptionsCustomKeyTextField.getDocument().addDocumentListener(this);
215 final TLabel customKeyLabel = new TLabel(I18n.getMessage("jsite.project-files.custom-key") + ":", KeyEvent.VK_K, fileOptionsCustomKeyTextField);
216 fileOptionsPanel.add(customKeyLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
217 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));
219 fileOptionsMIMETypeComboBox = new JComboBox(DefaultMIMETypes.getAllMIMETypes());
220 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
221 fileOptionsMIMETypeComboBox.setName("project-files.mime-type");
222 fileOptionsMIMETypeComboBox.addActionListener(this);
223 fileOptionsMIMETypeComboBox.setEnabled(false);
225 final TLabel mimeTypeLabel = new TLabel(I18n.getMessage("jsite.project-files.mime-type") + ":", KeyEvent.VK_M, fileOptionsMIMETypeComboBox);
226 fileOptionsPanel.add(mimeTypeLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
227 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));
229 containerComboBoxModel = new DefaultComboBoxModel();
230 fileOptionsContainerComboBox = new JComboBox(containerComboBoxModel);
231 fileOptionsContainerComboBox.setToolTipText(I18n.getMessage("jsite.project-files.container.tooltip"));
232 fileOptionsContainerComboBox.setName("project-files.container");
233 fileOptionsContainerComboBox.addActionListener(this);
234 fileOptionsContainerComboBox.setEnabled(false);
236 final TLabel containerLabel = new TLabel(I18n.getMessage("jsite.project-files.container") + ":", KeyEvent.VK_C, fileOptionsContainerComboBox);
237 fileOptionsPanel.add(containerLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
238 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));
239 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));
240 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));
241 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));
243 JPanel fileOptionsReplacementPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 6, 6));
244 fileOptionsReplacementPanel.setBorder(new EmptyBorder(-6, -6, -6, -6));
246 replacementCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.replacement"));
247 replacementCheckBox.setName("project-files.replace-edition");
248 replacementCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.replacement.tooltip"));
249 replacementCheckBox.addActionListener(this);
250 replacementCheckBox.setEnabled(false);
251 fileOptionsReplacementPanel.add(replacementCheckBox);
253 replaceEditionRangeSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 99, 1));
254 replaceEditionRangeSpinner.setName("project-files.replace-edition-range");
255 replaceEditionRangeSpinner.setToolTipText(I18n.getMessage("jsite.project-files.replacement.edition-range.tooltip"));
256 replaceEditionRangeSpinner.addChangeListener(this);
257 replaceEditionRangeSpinner.setEnabled(false);
258 final JLabel editionRangeLabel = new JLabel(I18n.getMessage("jsite.project-files.replacement.edition-range"));
259 fileOptionsReplacementPanel.add(editionRangeLabel);
260 fileOptionsReplacementPanel.add(replaceEditionRangeSpinner);
262 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));
264 I18nContainer.getInstance().registerRunnable(new Runnable() {
266 @SuppressWarnings("synthetic-access")
268 fileOptionsLabel.setText("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
269 defaultFileCheckBox.setText(I18n.getMessage("jsite.project-files.default"));
270 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
271 fileOptionsInsertCheckBox.setText(I18n.getMessage("jsite.project-files.insert"));
272 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
273 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
274 customKeyLabel.setText(I18n.getMessage("jsite.project-files.custom-key") + ":");
275 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
276 mimeTypeLabel.setText(I18n.getMessage("jsite.project-files.mime-type") + ":");
277 fileOptionsContainerComboBox.setToolTipText(I18n.getMessage("jsite.project-files.container.tooltip"));
278 containerLabel.setText(I18n.getMessage("jsite.project-files.container") + ":");
279 replacementCheckBox.setText(I18n.getMessage("jsite.project-files.replacement"));
280 replacementCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.replacement.tooltip"));
281 replaceEditionRangeSpinner.setToolTipText(I18n.getMessage("jsite.project-files.replacement.edition-range.tooltip"));
282 editionRangeLabel.setText(I18n.getMessage("jsite.project-files.replacement.edition-range"));
286 return projectFilesPanel;
289 public void setProject(final Project project) {
290 this.project = project;
291 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
292 setDescription(I18n.getMessage("jsite.project-files.description"));
293 I18nContainer.getInstance().registerRunnable(new Runnable() {
296 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
297 setDescription(I18n.getMessage("jsite.project-files.description"));
302 private List<String> getProjectFiles() {
303 List<String> files = new ArrayList<String>();
304 for (int index = 0, size = projectFileList.getModel().getSize(); index < size; index++) {
305 files.add((String) projectFileList.getModel().getElementAt(index));
310 private void rebuildContainerComboBox() {
311 /* scan files for containers */
312 List<String> files = getProjectFiles();
313 List<String> containers = new ArrayList<String>(); // ComboBoxModel
317 for (String filename : files) {
318 String container = project.getFileOption(filename).getContainer();
319 if (!containers.contains(container)) {
320 containers.add(container);
323 Collections.sort(containers);
324 containerComboBoxModel.removeAllElements();
325 for (String container : containers) {
326 containerComboBoxModel.addElement(container);
334 private void actionScan() {
335 projectFileList.clearSelection();
336 projectFileList.setListData(new Object[0]);
338 wizard.setNextEnabled(false);
339 wizard.setPreviousEnabled(false);
340 wizard.setQuitEnabled(false);
342 FileScanner fileScanner = new FileScanner(project);
343 fileScanner.addFileScannerListener(this);
344 new Thread(fileScanner).start();
347 private void actionAddContainer() {
348 String containerName = JOptionPane.showInputDialog(wizard, I18n.getMessage("jsite.project-files.action.add-container.message") + ":", null, JOptionPane.INFORMATION_MESSAGE);
349 if (containerName == null) {
352 containerName = containerName.trim();
353 String filename = (String) projectFileList.getSelectedValue();
354 FileOption fileOption = project.getFileOption(filename);
355 fileOption.setContainer(containerName);
356 rebuildContainerComboBox();
357 fileOptionsContainerComboBox.setSelectedItem(containerName);
360 private void actionEditContainer() {
361 String selectedFilename = (String) projectFileList.getSelectedValue();
362 FileOption fileOption = project.getFileOption(selectedFilename);
363 String oldContainerName = fileOption.getContainer();
364 String containerName = JOptionPane.showInputDialog(wizard, I18n.getMessage("jsite.project-files.action.edit-container.message") + ":", oldContainerName);
365 if (containerName == null) {
368 if (containerName.equals("")) {
369 fileOption.setContainer("");
370 fileOptionsContainerComboBox.setSelectedItem("");
373 List<String> files = getProjectFiles();
374 for (String filename : files) {
375 fileOption = project.getFileOption(filename);
376 if (fileOption.getContainer().equals(oldContainerName)) {
377 fileOption.setContainer(containerName);
380 rebuildContainerComboBox();
381 fileOptionsContainerComboBox.setSelectedItem(containerName);
384 private void actionDeleteContainer() {
385 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.project-files.action.delete-container.message"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
386 String containerName = (String) fileOptionsContainerComboBox.getSelectedItem();
387 List<String> files = getProjectFiles();
388 for (String filename : files) {
389 FileOption fileOption = project.getFileOption(filename);
390 if (fileOption.getContainer().equals(containerName)) {
391 fileOption.setContainer("");
394 fileOptionsContainerComboBox.setSelectedItem("");
398 public void fileScannerFinished(FileScanner fileScanner) {
399 final boolean error = fileScanner.isError();
401 final List<String> files = fileScanner.getFiles();
402 SwingUtilities.invokeLater(new Runnable() {
404 @SuppressWarnings("synthetic-access")
406 projectFileList.setListData(files.toArray(new String[files.size()]));
407 projectFileList.clearSelection();
408 rebuildContainerComboBox();
411 Set<String> entriesToRemove = new HashSet<String>();
412 Iterator<String> filenames = project.getFileOptions().keySet().iterator();
413 while (filenames.hasNext()) {
414 String filename = filenames.next();
415 if (!files.contains(filename)) {
416 entriesToRemove.add(filename);
419 for (String filename : entriesToRemove) {
420 project.setFileOption(filename, null);
423 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.scan-error"), null, JOptionPane.ERROR_MESSAGE);
425 SwingUtilities.invokeLater(new Runnable() {
427 @SuppressWarnings("synthetic-access")
429 wizard.setPreviousEnabled(true);
430 wizard.setNextEnabled(!error);
431 wizard.setQuitEnabled(true);
437 // INTERFACE ActionListener
443 public void actionPerformed(ActionEvent actionEvent) {
444 String filename = (String) projectFileList.getSelectedValue();
445 if (filename == null) {
448 FileOption fileOption = project.getFileOption(filename);
449 Object source = actionEvent.getSource();
450 if (source instanceof JCheckBox) {
451 JCheckBox checkBox = (JCheckBox) source;
452 if ("default-file".equals(checkBox.getName())) {
453 if (checkBox.isSelected()) {
454 project.setIndexFile(filename);
456 project.setIndexFile(null);
458 } else if ("insert".equals(checkBox.getName())) {
459 boolean isInsert = checkBox.isSelected();
460 fileOptionsCustomKeyTextField.setEnabled(!isInsert);
461 fileOption.setInsert(isInsert);
463 fileOptionsContainerComboBox.setSelectedItem("");
465 } else if ("project-files.replace-edition".equals(checkBox.getName())) {
466 boolean replaceEdition = checkBox.isSelected();
467 fileOption.setReplaceEdition(replaceEdition);
468 replaceEditionRangeSpinner.setEnabled(replaceEdition);
470 } else if (source instanceof JComboBox) {
471 JComboBox comboBox = (JComboBox) source;
472 if ("project-files.mime-type".equals(comboBox.getName())) {
473 fileOption.setMimeType((String) comboBox.getSelectedItem());
474 } else if ("project-files.container".equals(comboBox.getName())) {
475 String containerName = (String) comboBox.getSelectedItem();
476 fileOption.setContainer(containerName);
477 boolean enabled = !"".equals(containerName);
478 editContainerAction.setEnabled(enabled);
479 deleteContainerAction.setEnabled(enabled);
481 fileOptionsInsertCheckBox.setSelected(true);
488 // INTERFACE ListSelectionListener
494 public void valueChanged(ListSelectionEvent e) {
495 String filename = (String) projectFileList.getSelectedValue();
496 boolean enabled = filename != null;
497 boolean insert = fileOptionsInsertCheckBox.isSelected();
498 defaultFileCheckBox.setEnabled(enabled);
499 fileOptionsInsertCheckBox.setEnabled(enabled);
500 fileOptionsCustomKeyTextField.setEnabled(enabled && !insert);
501 fileOptionsMIMETypeComboBox.setEnabled(enabled);
502 fileOptionsContainerComboBox.setEnabled(enabled);
503 addContainerAction.setEnabled(enabled);
504 editContainerAction.setEnabled(enabled);
505 deleteContainerAction.setEnabled(enabled);
506 replacementCheckBox.setEnabled(enabled && insert);
507 if (filename != null) {
508 FileOption fileOption = project.getFileOption(filename);
509 defaultFileCheckBox.setSelected(filename.equals(project.getIndexFile()));
510 fileOptionsInsertCheckBox.setSelected(fileOption.isInsert());
511 fileOptionsCustomKeyTextField.setText(fileOption.getCustomKey());
512 fileOptionsMIMETypeComboBox.getModel().setSelectedItem(fileOption.getMimeType());
513 fileOptionsContainerComboBox.setSelectedItem(fileOption.getContainer());
514 replacementCheckBox.setSelected(fileOption.getReplaceEdition());
515 replaceEditionRangeSpinner.setValue(fileOption.getEditionRange());
516 replaceEditionRangeSpinner.setEnabled(fileOption.getReplaceEdition());
518 defaultFileCheckBox.setSelected(false);
519 fileOptionsInsertCheckBox.setSelected(true);
520 fileOptionsCustomKeyTextField.setText("CHK@");
521 fileOptionsMIMETypeComboBox.getModel().setSelectedItem(DefaultMIMETypes.DEFAULT_MIME_TYPE);
522 fileOptionsContainerComboBox.setSelectedItem("");
523 replacementCheckBox.setSelected(false);
524 replaceEditionRangeSpinner.setValue(0);
529 // INTERFACE DocumentListener
532 private void processDocumentUpdate(DocumentEvent documentEvent) {
533 String filename = (String) projectFileList.getSelectedValue();
534 if (filename == null) {
537 FileOption fileOption = project.getFileOption(filename);
538 Document document = documentEvent.getDocument();
540 String text = document.getText(0, document.getLength());
541 fileOption.setCustomKey(text);
542 } catch (BadLocationException ble1) {
549 public void changedUpdate(DocumentEvent documentEvent) {
550 processDocumentUpdate(documentEvent);
556 public void insertUpdate(DocumentEvent documentEvent) {
557 processDocumentUpdate(documentEvent);
563 public void removeUpdate(DocumentEvent documentEvent) {
564 processDocumentUpdate(documentEvent);
568 // INTERFACE ChangeListener
574 public void stateChanged(ChangeEvent changeEvent) {
575 String filename = (String) projectFileList.getSelectedValue();
576 if (filename == null) {
579 FileOption fileOption = project.getFileOption(filename);
580 Object source = changeEvent.getSource();
581 if (source instanceof JSpinner) {
582 JSpinner spinner = (JSpinner) source;
583 fileOption.setEditionRange((Integer) spinner.getValue());