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 * Wizard page that lets the user manage the files of a project.
78 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
80 public class ProjectFilesPage extends TWizardPage implements ActionListener, ListSelectionListener, DocumentListener, FileScannerListener, ChangeListener {
83 private Project project;
85 /** The “scan files” action. */
86 private Action scanAction;
88 /** The “edit container” action. */
89 private Action editContainerAction;
91 /** The “add container” action. */
92 private Action addContainerAction;
94 /** The “delete container” action. */
95 protected Action deleteContainerAction;
97 /** The list of project files. */
98 private JList projectFileList;
100 /** The “default file” checkbox. */
101 private JCheckBox defaultFileCheckBox;
103 /** The “insert” checkbox. */
104 private JCheckBox fileOptionsInsertCheckBox;
106 /** The “custom key” textfield. */
107 private JTextField fileOptionsCustomKeyTextField;
109 /** The “mime type” combo box. */
110 private JComboBox fileOptionsMIMETypeComboBox;
112 /** The “mime type” combo box model. */
113 private DefaultComboBoxModel containerComboBoxModel;
115 /** The “container” combo box. */
116 private JComboBox fileOptionsContainerComboBox;
118 /** The “edition replacement range” spinner. */
119 private JSpinner replaceEditionRangeSpinner;
121 /** The “replacement” check box. */
122 private JCheckBox replacementCheckBox;
125 * Creates a new project file page.
128 * The wizard the page belongs to
130 public ProjectFilesPage(final TWizard wizard) {
136 * Initializes the page and all its actions and components.
138 private void pageInit() {
140 setLayout(new BorderLayout(12, 12));
141 add(createProjectFilesPanel(), BorderLayout.CENTER);
145 * Creates all actions.
147 private void createActions() {
148 scanAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.rescan")) {
150 @SuppressWarnings("synthetic-access")
151 public void actionPerformed(ActionEvent actionEvent) {
155 scanAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
156 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
158 addContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.add-container")) {
160 @SuppressWarnings("synthetic-access")
161 public void actionPerformed(ActionEvent actionEvent) {
162 actionAddContainer();
165 addContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.add-container.tooltip"));
166 addContainerAction.setEnabled(false);
168 editContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.edit-container")) {
170 @SuppressWarnings("synthetic-access")
171 public void actionPerformed(ActionEvent actionEvent) {
172 actionEditContainer();
175 editContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.edit-container.tooltip"));
176 editContainerAction.setEnabled(false);
178 deleteContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.delete-container")) {
180 @SuppressWarnings("synthetic-access")
181 public void actionPerformed(ActionEvent actionEvent) {
182 actionDeleteContainer();
185 deleteContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.delete-container.tooltip"));
186 deleteContainerAction.setEnabled(false);
188 I18nContainer.getInstance().registerRunnable(new Runnable() {
190 @SuppressWarnings("synthetic-access")
192 scanAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.rescan"));
193 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
194 addContainerAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.add-container"));
195 addContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.add-container.tooltip"));
196 editContainerAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.edit-container"));
197 editContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.edit-container.tooltip"));
198 deleteContainerAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.delete-container"));
199 deleteContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.delete-container.tooltip"));
208 public void pageAdded(TWizard wizard) {
210 this.wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
211 this.wizard.setNextName(I18n.getMessage("jsite.project-files.insert-now"));
212 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
216 * Creates the panel contains the project file list and options.
218 * @return The created panel
220 private JComponent createProjectFilesPanel() {
221 JPanel projectFilesPanel = new JPanel(new BorderLayout(12, 12));
223 projectFileList = new JList();
224 projectFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
225 projectFileList.setMinimumSize(new Dimension(250, projectFileList.getPreferredSize().height));
226 projectFileList.addListSelectionListener(this);
228 projectFilesPanel.add(new JScrollPane(projectFileList), BorderLayout.CENTER);
230 JPanel fileOptionsAlignmentPanel = new JPanel(new BorderLayout(12, 12));
231 projectFilesPanel.add(fileOptionsAlignmentPanel, BorderLayout.PAGE_END);
232 JPanel fileOptionsPanel = new JPanel(new GridBagLayout());
233 fileOptionsAlignmentPanel.add(fileOptionsPanel, BorderLayout.PAGE_START);
235 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));
237 final JLabel fileOptionsLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
238 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));
240 defaultFileCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.default"));
241 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
242 defaultFileCheckBox.setName("default-file");
243 defaultFileCheckBox.addActionListener(this);
244 defaultFileCheckBox.setEnabled(false);
246 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));
248 fileOptionsInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert"), true);
249 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
250 fileOptionsInsertCheckBox.setName("insert");
251 fileOptionsInsertCheckBox.setMnemonic(KeyEvent.VK_I);
252 fileOptionsInsertCheckBox.addActionListener(this);
253 fileOptionsInsertCheckBox.setEnabled(false);
255 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));
257 fileOptionsCustomKeyTextField = new JTextField(45);
258 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
259 fileOptionsCustomKeyTextField.setEnabled(false);
260 fileOptionsCustomKeyTextField.getDocument().addDocumentListener(this);
262 final TLabel customKeyLabel = new TLabel(I18n.getMessage("jsite.project-files.custom-key") + ":", KeyEvent.VK_K, fileOptionsCustomKeyTextField);
263 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));
264 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));
266 fileOptionsMIMETypeComboBox = new JComboBox(DefaultMIMETypes.getAllMIMETypes());
267 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
268 fileOptionsMIMETypeComboBox.setName("project-files.mime-type");
269 fileOptionsMIMETypeComboBox.addActionListener(this);
270 fileOptionsMIMETypeComboBox.setEditable(true);
271 fileOptionsMIMETypeComboBox.setEnabled(false);
273 final TLabel mimeTypeLabel = new TLabel(I18n.getMessage("jsite.project-files.mime-type") + ":", KeyEvent.VK_M, fileOptionsMIMETypeComboBox);
274 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));
275 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));
277 containerComboBoxModel = new DefaultComboBoxModel();
278 fileOptionsContainerComboBox = new JComboBox(containerComboBoxModel);
279 fileOptionsContainerComboBox.setToolTipText(I18n.getMessage("jsite.project-files.container.tooltip"));
280 fileOptionsContainerComboBox.setName("project-files.container");
281 fileOptionsContainerComboBox.addActionListener(this);
282 fileOptionsContainerComboBox.setEnabled(false);
283 fileOptionsContainerComboBox.setVisible(false);
285 final TLabel containerLabel = new TLabel(I18n.getMessage("jsite.project-files.container") + ":", KeyEvent.VK_C, fileOptionsContainerComboBox);
286 containerLabel.setVisible(false);
287 JButton addContainerButton = new JButton(addContainerAction);
288 addContainerButton.setVisible(false);
289 JButton editContainerButton = new JButton(editContainerAction);
290 editContainerButton.setVisible(false);
291 JButton deleteContainerButton = new JButton(deleteContainerAction);
292 deleteContainerButton.setVisible(false);
293 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));
294 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));
295 fileOptionsPanel.add(addContainerButton, new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
296 fileOptionsPanel.add(editContainerButton, new GridBagConstraints(3, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
297 fileOptionsPanel.add(deleteContainerButton, new GridBagConstraints(4, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
299 JPanel fileOptionsReplacementPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 6, 6));
300 fileOptionsReplacementPanel.setBorder(new EmptyBorder(-6, -6, -6, -6));
302 replacementCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.replacement"));
303 replacementCheckBox.setName("project-files.replace-edition");
304 replacementCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.replacement.tooltip"));
305 replacementCheckBox.addActionListener(this);
306 replacementCheckBox.setEnabled(false);
307 fileOptionsReplacementPanel.add(replacementCheckBox);
309 replaceEditionRangeSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 99, 1));
310 replaceEditionRangeSpinner.setName("project-files.replace-edition-range");
311 replaceEditionRangeSpinner.setToolTipText(I18n.getMessage("jsite.project-files.replacement.edition-range.tooltip"));
312 replaceEditionRangeSpinner.addChangeListener(this);
313 replaceEditionRangeSpinner.setEnabled(false);
314 final JLabel editionRangeLabel = new JLabel(I18n.getMessage("jsite.project-files.replacement.edition-range"));
315 fileOptionsReplacementPanel.add(editionRangeLabel);
316 fileOptionsReplacementPanel.add(replaceEditionRangeSpinner);
318 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));
320 I18nContainer.getInstance().registerRunnable(new Runnable() {
322 @SuppressWarnings("synthetic-access")
324 fileOptionsLabel.setText("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
325 defaultFileCheckBox.setText(I18n.getMessage("jsite.project-files.default"));
326 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
327 fileOptionsInsertCheckBox.setText(I18n.getMessage("jsite.project-files.insert"));
328 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
329 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
330 customKeyLabel.setText(I18n.getMessage("jsite.project-files.custom-key") + ":");
331 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
332 mimeTypeLabel.setText(I18n.getMessage("jsite.project-files.mime-type") + ":");
333 fileOptionsContainerComboBox.setToolTipText(I18n.getMessage("jsite.project-files.container.tooltip"));
334 containerLabel.setText(I18n.getMessage("jsite.project-files.container") + ":");
335 replacementCheckBox.setText(I18n.getMessage("jsite.project-files.replacement"));
336 replacementCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.replacement.tooltip"));
337 replaceEditionRangeSpinner.setToolTipText(I18n.getMessage("jsite.project-files.replacement.edition-range.tooltip"));
338 editionRangeLabel.setText(I18n.getMessage("jsite.project-files.replacement.edition-range"));
342 return projectFilesPanel;
346 * Sets the project whose files to manage.
349 * The project whose files to manage
351 public void setProject(final Project project) {
352 this.project = project;
353 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
354 setDescription(I18n.getMessage("jsite.project-files.description"));
355 I18nContainer.getInstance().registerRunnable(new Runnable() {
358 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
359 setDescription(I18n.getMessage("jsite.project-files.description"));
365 * Returns a list of all project files.
367 * @return All project files
369 private List<String> getProjectFiles() {
370 List<String> files = new ArrayList<String>();
371 for (int index = 0, size = projectFileList.getModel().getSize(); index < size; index++) {
372 files.add((String) projectFileList.getModel().getElementAt(index));
378 * Updates the container combo box model.
380 private void rebuildContainerComboBox() {
381 /* scan files for containers */
382 List<String> files = getProjectFiles();
383 List<String> containers = new ArrayList<String>(); // ComboBoxModel
387 for (String filename : files) {
388 String container = project.getFileOption(filename).getContainer();
389 if (!containers.contains(container)) {
390 containers.add(container);
393 Collections.sort(containers);
394 containerComboBoxModel.removeAllElements();
395 for (String container : containers) {
396 containerComboBoxModel.addElement(container);
405 * Rescans the project’s files.
407 private void actionScan() {
408 projectFileList.clearSelection();
409 projectFileList.setListData(new Object[0]);
411 wizard.setNextEnabled(false);
412 wizard.setPreviousEnabled(false);
413 wizard.setQuitEnabled(false);
415 FileScanner fileScanner = new FileScanner(project);
416 fileScanner.addFileScannerListener(this);
417 new Thread(fileScanner).start();
423 private void actionAddContainer() {
424 String containerName = JOptionPane.showInputDialog(wizard, I18n.getMessage("jsite.project-files.action.add-container.message") + ":", null, JOptionPane.INFORMATION_MESSAGE);
425 if (containerName == null) {
428 containerName = containerName.trim();
429 String filename = (String) projectFileList.getSelectedValue();
430 FileOption fileOption = project.getFileOption(filename);
431 fileOption.setContainer(containerName);
432 rebuildContainerComboBox();
433 fileOptionsContainerComboBox.setSelectedItem(containerName);
437 * Edits the container.
439 private void actionEditContainer() {
440 String selectedFilename = (String) projectFileList.getSelectedValue();
441 FileOption fileOption = project.getFileOption(selectedFilename);
442 String oldContainerName = fileOption.getContainer();
443 String containerName = JOptionPane.showInputDialog(wizard, I18n.getMessage("jsite.project-files.action.edit-container.message") + ":", oldContainerName);
444 if (containerName == null) {
447 if (containerName.equals("")) {
448 fileOption.setContainer("");
449 fileOptionsContainerComboBox.setSelectedItem("");
452 List<String> files = getProjectFiles();
453 for (String filename : files) {
454 fileOption = project.getFileOption(filename);
455 if (fileOption.getContainer().equals(oldContainerName)) {
456 fileOption.setContainer(containerName);
459 rebuildContainerComboBox();
460 fileOptionsContainerComboBox.setSelectedItem(containerName);
464 * Deletes the container.
466 private void actionDeleteContainer() {
467 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.project-files.action.delete-container.message"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
468 String containerName = (String) fileOptionsContainerComboBox.getSelectedItem();
469 List<String> files = getProjectFiles();
470 for (String filename : files) {
471 FileOption fileOption = project.getFileOption(filename);
472 if (fileOption.getContainer().equals(containerName)) {
473 fileOption.setContainer("");
476 fileOptionsContainerComboBox.setSelectedItem("");
483 * Updates the file list.
485 public void fileScannerFinished(FileScanner fileScanner) {
486 final boolean error = fileScanner.isError();
488 final List<String> files = fileScanner.getFiles();
489 SwingUtilities.invokeLater(new Runnable() {
491 @SuppressWarnings("synthetic-access")
493 projectFileList.setListData(files.toArray(new String[files.size()]));
494 projectFileList.clearSelection();
495 rebuildContainerComboBox();
498 Set<String> entriesToRemove = new HashSet<String>();
499 Iterator<String> filenames = project.getFileOptions().keySet().iterator();
500 while (filenames.hasNext()) {
501 String filename = filenames.next();
502 if (!files.contains(filename)) {
503 entriesToRemove.add(filename);
506 for (String filename : entriesToRemove) {
507 project.setFileOption(filename, null);
510 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.scan-error"), null, JOptionPane.ERROR_MESSAGE);
512 SwingUtilities.invokeLater(new Runnable() {
514 @SuppressWarnings("synthetic-access")
516 wizard.setPreviousEnabled(true);
517 wizard.setNextEnabled(!error);
518 wizard.setQuitEnabled(true);
524 // INTERFACE ActionListener
530 public void actionPerformed(ActionEvent actionEvent) {
531 String filename = (String) projectFileList.getSelectedValue();
532 if (filename == null) {
535 FileOption fileOption = project.getFileOption(filename);
536 Object source = actionEvent.getSource();
537 if (source instanceof JCheckBox) {
538 JCheckBox checkBox = (JCheckBox) source;
539 if ("default-file".equals(checkBox.getName())) {
540 if (checkBox.isSelected()) {
541 project.setIndexFile(filename);
543 project.setIndexFile(null);
545 } else if ("insert".equals(checkBox.getName())) {
546 boolean isInsert = checkBox.isSelected();
547 fileOptionsCustomKeyTextField.setEnabled(!isInsert);
548 fileOption.setInsert(isInsert);
550 fileOptionsContainerComboBox.setSelectedItem("");
552 } else if ("project-files.replace-edition".equals(checkBox.getName())) {
553 boolean replaceEdition = checkBox.isSelected();
554 fileOption.setReplaceEdition(replaceEdition);
555 replaceEditionRangeSpinner.setEnabled(replaceEdition);
557 } else if (source instanceof JComboBox) {
558 JComboBox comboBox = (JComboBox) source;
559 if ("project-files.mime-type".equals(comboBox.getName())) {
560 fileOption.setMimeType((String) comboBox.getSelectedItem());
561 } else if ("project-files.container".equals(comboBox.getName())) {
562 String containerName = (String) comboBox.getSelectedItem();
563 fileOption.setContainer(containerName);
564 boolean enabled = !"".equals(containerName);
565 editContainerAction.setEnabled(enabled);
566 deleteContainerAction.setEnabled(enabled);
568 fileOptionsInsertCheckBox.setSelected(true);
575 // INTERFACE ListSelectionListener
581 public void valueChanged(ListSelectionEvent e) {
582 String filename = (String) projectFileList.getSelectedValue();
583 boolean enabled = filename != null;
584 boolean insert = fileOptionsInsertCheckBox.isSelected();
585 defaultFileCheckBox.setEnabled(enabled);
586 fileOptionsInsertCheckBox.setEnabled(enabled);
587 fileOptionsCustomKeyTextField.setEnabled(enabled && !insert);
588 fileOptionsMIMETypeComboBox.setEnabled(enabled);
589 fileOptionsContainerComboBox.setEnabled(enabled);
590 addContainerAction.setEnabled(enabled);
591 editContainerAction.setEnabled(enabled);
592 deleteContainerAction.setEnabled(enabled);
593 replacementCheckBox.setEnabled(enabled && insert);
594 if (filename != null) {
595 FileOption fileOption = project.getFileOption(filename);
596 defaultFileCheckBox.setSelected(filename.equals(project.getIndexFile()));
597 fileOptionsInsertCheckBox.setSelected(fileOption.isInsert());
598 fileOptionsCustomKeyTextField.setText(fileOption.getCustomKey());
599 fileOptionsMIMETypeComboBox.getModel().setSelectedItem(fileOption.getMimeType());
600 fileOptionsContainerComboBox.setSelectedItem(fileOption.getContainer());
601 replacementCheckBox.setSelected(fileOption.getReplaceEdition());
602 replaceEditionRangeSpinner.setValue(fileOption.getEditionRange());
603 replaceEditionRangeSpinner.setEnabled(fileOption.getReplaceEdition());
605 defaultFileCheckBox.setSelected(false);
606 fileOptionsInsertCheckBox.setSelected(true);
607 fileOptionsCustomKeyTextField.setText("CHK@");
608 fileOptionsMIMETypeComboBox.getModel().setSelectedItem(DefaultMIMETypes.DEFAULT_MIME_TYPE);
609 fileOptionsContainerComboBox.setSelectedItem("");
610 replacementCheckBox.setSelected(false);
611 replaceEditionRangeSpinner.setValue(0);
616 // INTERFACE DocumentListener
620 * Updates the options of the currently selected file with the changes made
621 * in the “custom key” textfield.
623 * @param documentEvent
624 * The document event to process
626 private void processDocumentUpdate(DocumentEvent documentEvent) {
627 String filename = (String) projectFileList.getSelectedValue();
628 if (filename == null) {
631 FileOption fileOption = project.getFileOption(filename);
632 Document document = documentEvent.getDocument();
634 String text = document.getText(0, document.getLength());
635 fileOption.setCustomKey(text);
636 } catch (BadLocationException ble1) {
644 public void changedUpdate(DocumentEvent documentEvent) {
645 processDocumentUpdate(documentEvent);
651 public void insertUpdate(DocumentEvent documentEvent) {
652 processDocumentUpdate(documentEvent);
658 public void removeUpdate(DocumentEvent documentEvent) {
659 processDocumentUpdate(documentEvent);
663 // INTERFACE ChangeListener
669 public void stateChanged(ChangeEvent changeEvent) {
670 String filename = (String) projectFileList.getSelectedValue();
671 if (filename == null) {
674 FileOption fileOption = project.getFileOption(filename);
675 Object source = changeEvent.getSource();
676 if (source instanceof JSpinner) {
677 JSpinner spinner = (JSpinner) source;
678 fileOption.setEditionRange((Integer) spinner.getValue());