2 * jSite - ProjectFilesPage.java - Copyright © 2006–2012 David Roden
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 package de.todesbaum.jsite.gui;
21 import java.awt.BorderLayout;
22 import java.awt.Dimension;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
25 import java.awt.Insets;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.awt.event.KeyEvent;
29 import java.awt.event.WindowAdapter;
30 import java.awt.event.WindowEvent;
31 import java.text.MessageFormat;
32 import java.util.HashSet;
33 import java.util.Iterator;
34 import java.util.List;
37 import javax.swing.AbstractAction;
38 import javax.swing.Action;
39 import javax.swing.BorderFactory;
40 import javax.swing.JButton;
41 import javax.swing.JCheckBox;
42 import javax.swing.JComboBox;
43 import javax.swing.JComponent;
44 import javax.swing.JDialog;
45 import javax.swing.JLabel;
46 import javax.swing.JList;
47 import javax.swing.JOptionPane;
48 import javax.swing.JPanel;
49 import javax.swing.JProgressBar;
50 import javax.swing.JScrollPane;
51 import javax.swing.JTextField;
52 import javax.swing.ListSelectionModel;
53 import javax.swing.SwingConstants;
54 import javax.swing.SwingUtilities;
55 import javax.swing.WindowConstants;
56 import javax.swing.event.DocumentEvent;
57 import javax.swing.event.DocumentListener;
58 import javax.swing.event.ListSelectionEvent;
59 import javax.swing.event.ListSelectionListener;
60 import javax.swing.text.BadLocationException;
61 import javax.swing.text.Document;
63 import net.pterodactylus.util.io.MimeTypes;
64 import net.pterodactylus.util.swing.SwingUtils;
65 import net.pterodactylus.util.thread.StoppableDelay;
66 import de.todesbaum.jsite.application.FileOption;
67 import de.todesbaum.jsite.application.Project;
68 import de.todesbaum.jsite.gui.FileScanner.ScannedFile;
69 import de.todesbaum.jsite.i18n.I18n;
70 import de.todesbaum.jsite.i18n.I18nContainer;
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 {
83 private Project project;
85 /** The “scan files” action. */
86 private Action scanAction;
88 /** The “ignore hidden files” checkbox. */
89 private JCheckBox ignoreHiddenFilesCheckBox;
91 /** The list of project files. */
92 private JList projectFileList;
94 /** The “default file” checkbox. */
95 private JCheckBox defaultFileCheckBox;
97 /** The “insert” checkbox. */
98 private JCheckBox fileOptionsInsertCheckBox;
100 /** The “force insert” checkbox. */
101 private JCheckBox fileOptionsForceInsertCheckBox;
103 /** The “insert redirect” checkbox. */
104 private JCheckBox fileOptionsInsertRedirectCheckBox;
106 /** The “custom key” textfield. */
107 private JTextField fileOptionsCustomKeyTextField;
109 /** The “rename” check box. */
110 private JCheckBox fileOptionsRenameCheckBox;
112 /** The “new name” text field. */
113 private JTextField fileOptionsRenameTextField;
115 /** The “mime type” combo box. */
116 private JComboBox fileOptionsMIMETypeComboBox;
118 /** Delayed notification for file scanning. */
119 private StoppableDelay delayedNotification;
121 /** Dialog to display while scanning. */
122 private JDialog scanningFilesDialog;
124 /** The file scanner. */
125 private FileScanner fileScanner;
127 /** The progress bar. */
128 private JProgressBar progressBar;
131 * Creates a new project file page.
134 * The wizard the page belongs to
136 public ProjectFilesPage(final TWizard wizard) {
142 * Initializes the page and all its actions and components.
144 private void pageInit() {
146 setLayout(new BorderLayout(12, 12));
147 add(createProjectFilesPanel(), BorderLayout.CENTER);
151 * Creates all actions.
153 private void createActions() {
154 scanAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.rescan")) {
157 @SuppressWarnings("synthetic-access")
158 public void actionPerformed(ActionEvent actionEvent) {
162 scanAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
163 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
165 I18nContainer.getInstance().registerRunnable(new Runnable() {
168 @SuppressWarnings("synthetic-access")
170 scanAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.rescan"));
171 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
180 public void pageAdded(TWizard wizard) {
181 /* create file scanner. */
182 fileScanner = new FileScanner(project);
183 fileScanner.addFileScannerListener(this);
186 this.wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
187 this.wizard.setNextName(I18n.getMessage("jsite.project-files.insert-now"));
188 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
192 * Creates the panel contains the project file list and options.
194 * @return The created panel
196 private JComponent createProjectFilesPanel() {
197 JPanel projectFilesPanel = new JPanel(new BorderLayout(12, 12));
199 projectFileList = new JList();
200 projectFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
201 projectFileList.setMinimumSize(new Dimension(250, projectFileList.getPreferredSize().height));
202 projectFileList.addListSelectionListener(this);
204 projectFilesPanel.add(new JScrollPane(projectFileList), BorderLayout.CENTER);
206 JPanel fileOptionsAlignmentPanel = new JPanel(new BorderLayout(12, 12));
207 projectFilesPanel.add(fileOptionsAlignmentPanel, BorderLayout.PAGE_END);
208 JPanel fileOptionsPanel = new JPanel(new GridBagLayout());
209 fileOptionsAlignmentPanel.add(fileOptionsPanel, BorderLayout.PAGE_START);
211 ignoreHiddenFilesCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.ignore-hidden-files"));
212 ignoreHiddenFilesCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.ignore-hidden-files.tooltip"));
213 ignoreHiddenFilesCheckBox.setName("ignore-hidden-files");
214 ignoreHiddenFilesCheckBox.addActionListener(this);
215 fileOptionsPanel.add(ignoreHiddenFilesCheckBox, new GridBagConstraints(0, 0, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
217 fileOptionsPanel.add(new JButton(scanAction), new GridBagConstraints(0, 1, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
219 final JLabel fileOptionsLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
220 fileOptionsPanel.add(fileOptionsLabel, new GridBagConstraints(0, 2, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
222 defaultFileCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.default"));
223 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
224 defaultFileCheckBox.setName("default-file");
225 defaultFileCheckBox.addActionListener(this);
226 defaultFileCheckBox.setEnabled(false);
228 fileOptionsPanel.add(defaultFileCheckBox, new GridBagConstraints(0, 3, 5, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 18, 0, 0), 0, 0));
230 fileOptionsInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert"), true);
231 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
232 fileOptionsInsertCheckBox.setName("insert");
233 fileOptionsInsertCheckBox.setMnemonic(KeyEvent.VK_I);
234 fileOptionsInsertCheckBox.addActionListener(this);
235 fileOptionsInsertCheckBox.setEnabled(false);
237 fileOptionsPanel.add(fileOptionsInsertCheckBox, new GridBagConstraints(0, 4, 5, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
239 fileOptionsForceInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.force-insert"));
240 fileOptionsForceInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.force-insert.tooltip"));
241 fileOptionsForceInsertCheckBox.setName("force-insert");
242 fileOptionsForceInsertCheckBox.setMnemonic(KeyEvent.VK_F);
243 fileOptionsForceInsertCheckBox.addActionListener(this);
244 fileOptionsForceInsertCheckBox.setEnabled(false);
246 fileOptionsPanel.add(fileOptionsForceInsertCheckBox, new GridBagConstraints(0, 5, 5, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
248 fileOptionsCustomKeyTextField = new JTextField(45);
249 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
250 fileOptionsCustomKeyTextField.setEnabled(false);
251 fileOptionsCustomKeyTextField.getDocument().addDocumentListener(this);
253 fileOptionsInsertRedirectCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert-redirect"), false);
254 fileOptionsInsertRedirectCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert-redirect.tooltip"));
255 fileOptionsInsertRedirectCheckBox.setName("insert-redirect");
256 fileOptionsInsertRedirectCheckBox.setMnemonic(KeyEvent.VK_R);
257 fileOptionsInsertRedirectCheckBox.addActionListener(this);
258 fileOptionsInsertRedirectCheckBox.setEnabled(false);
260 final TLabel customKeyLabel = new TLabel(I18n.getMessage("jsite.project-files.custom-key") + ":", KeyEvent.VK_K, fileOptionsCustomKeyTextField);
261 fileOptionsPanel.add(fileOptionsInsertRedirectCheckBox, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
262 fileOptionsPanel.add(customKeyLabel, new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 6, 0, 0), 0, 0));
263 fileOptionsPanel.add(fileOptionsCustomKeyTextField, new GridBagConstraints(2, 6, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
265 fileOptionsRenameCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.rename"), false);
266 fileOptionsRenameCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.rename.tooltip"));
267 fileOptionsRenameCheckBox.setName("rename");
268 fileOptionsRenameCheckBox.setMnemonic(KeyEvent.VK_N);
269 fileOptionsRenameCheckBox.addActionListener(this);
270 fileOptionsRenameCheckBox.setEnabled(false);
272 fileOptionsRenameTextField = new JTextField();
273 fileOptionsRenameTextField.setEnabled(false);
274 fileOptionsRenameTextField.getDocument().addDocumentListener(new DocumentListener() {
276 @SuppressWarnings("synthetic-access")
277 private void storeText(DocumentEvent documentEvent) {
278 FileOption fileOption = getSelectedFile();
279 if (fileOption == null) {
280 /* no file selected. */
283 Document document = documentEvent.getDocument();
284 int documentLength = document.getLength();
286 fileOption.setChangedName(document.getText(0, documentLength).trim());
287 } catch (BadLocationException ble1) {
288 /* ignore, it should never happen. */
293 public void changedUpdate(DocumentEvent documentEvent) {
294 storeText(documentEvent);
298 public void insertUpdate(DocumentEvent documentEvent) {
299 storeText(documentEvent);
303 public void removeUpdate(DocumentEvent documentEvent) {
304 storeText(documentEvent);
309 fileOptionsPanel.add(fileOptionsRenameCheckBox, new GridBagConstraints(0, 7, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
310 fileOptionsPanel.add(fileOptionsRenameTextField, new GridBagConstraints(2, 7, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
312 fileOptionsMIMETypeComboBox = new JComboBox(MimeTypes.getAllMimeTypes().toArray());
313 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
314 fileOptionsMIMETypeComboBox.setName("project-files.mime-type");
315 fileOptionsMIMETypeComboBox.addActionListener(this);
316 fileOptionsMIMETypeComboBox.setEditable(true);
317 fileOptionsMIMETypeComboBox.setEnabled(false);
319 final TLabel mimeTypeLabel = new TLabel(I18n.getMessage("jsite.project-files.mime-type") + ":", KeyEvent.VK_M, fileOptionsMIMETypeComboBox);
320 fileOptionsPanel.add(mimeTypeLabel, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
321 fileOptionsPanel.add(fileOptionsMIMETypeComboBox, new GridBagConstraints(1, 8, 4, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
323 /* create dialog to show while scanning. */
324 scanningFilesDialog = new JDialog(wizard);
325 scanningFilesDialog.setModal(true);
326 scanningFilesDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
328 JPanel progressPanel = new JPanel(new BorderLayout(12, 12));
329 scanningFilesDialog.getContentPane().add(progressPanel, BorderLayout.CENTER);
330 progressPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
332 final TLabel scanningLabel = new TLabel(I18n.getMessage("jsite.project-files.scanning"), SwingConstants.CENTER);
333 progressPanel.add(scanningLabel, BorderLayout.NORTH);
334 progressBar = new JProgressBar(SwingConstants.HORIZONTAL);
335 progressPanel.add(progressBar, BorderLayout.SOUTH);
336 progressBar.setIndeterminate(true);
337 progressBar.setStringPainted(true);
338 progressBar.setPreferredSize(new Dimension(progressBar.getPreferredSize().width * 2, progressBar.getPreferredSize().height));
340 scanningFilesDialog.pack();
341 scanningFilesDialog.addWindowListener(new WindowAdapter() {
347 @SuppressWarnings("synthetic-access")
348 public void windowOpened(WindowEvent e) {
349 SwingUtils.center(scanningFilesDialog, wizard);
353 I18nContainer.getInstance().registerRunnable(new Runnable() {
356 @SuppressWarnings("synthetic-access")
358 ignoreHiddenFilesCheckBox.setText(I18n.getMessage("jsite.project-files.ignore-hidden-files"));
359 ignoreHiddenFilesCheckBox.setToolTipText(I18n.getMessage("jsite.projet-files.ignore-hidden-files.tooltip"));
360 fileOptionsLabel.setText("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
361 defaultFileCheckBox.setText(I18n.getMessage("jsite.project-files.default"));
362 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
363 fileOptionsInsertCheckBox.setText(I18n.getMessage("jsite.project-files.insert"));
364 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
365 fileOptionsForceInsertCheckBox.setText(I18n.getMessage("jsite.project-files.force-insert"));
366 fileOptionsForceInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.force-insert.tooltip"));
367 fileOptionsInsertRedirectCheckBox.setText(I18n.getMessage("jsite.project-files.insert-redirect"));
368 fileOptionsInsertRedirectCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert-redirect.tooltip"));
369 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
370 customKeyLabel.setText(I18n.getMessage("jsite.project-files.custom-key") + ":");
371 fileOptionsRenameCheckBox.setText("jsite.project-files.rename");
372 fileOptionsRenameCheckBox.setToolTipText("jsite.project-files.rename.tooltip");
373 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
374 mimeTypeLabel.setText(I18n.getMessage("jsite.project-files.mime-type") + ":");
375 scanningLabel.setText(I18n.getMessage("jsite.project-files.scanning"));
379 return projectFilesPanel;
383 * Sets the project whose files to manage.
386 * The project whose files to manage
388 public void setProject(final Project project) {
389 this.project = project;
390 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
391 setDescription(I18n.getMessage("jsite.project-files.description"));
392 ignoreHiddenFilesCheckBox.setSelected(project.isIgnoreHiddenFiles());
393 I18nContainer.getInstance().registerRunnable(new Runnable() {
397 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
398 setDescription(I18n.getMessage("jsite.project-files.description"));
408 * Rescans the project’s files.
410 private void actionScan() {
411 projectFileList.clearSelection();
412 projectFileList.setListData(new Object[0]);
414 wizard.setNextEnabled(false);
415 wizard.setPreviousEnabled(false);
416 wizard.setQuitEnabled(false);
418 ignoreHiddenFilesCheckBox.setEnabled(false);
419 scanAction.setEnabled(false);
421 delayedNotification = new StoppableDelay(new Runnable() {
424 @SuppressWarnings("synthetic-access")
426 scanningFilesDialog.setVisible(true);
431 @SuppressWarnings("synthetic-access")
433 scanningFilesDialog.setVisible(false);
436 new Thread(fileScanner).start();
437 new Thread(delayedNotification).start();
438 new Thread(new Runnable() {
441 @SuppressWarnings("synthetic-access")
443 while (!delayedNotification.isFinished()) {
446 } catch (InterruptedException ie1) {
449 progressBar.setString(fileScanner.getLastFilename());
458 * Updates the file list.
461 public void fileScannerFinished(FileScanner fileScanner) {
462 delayedNotification.finish();
463 final boolean error = fileScanner.isError();
465 final List<ScannedFile> files = fileScanner.getFiles();
466 SwingUtilities.invokeLater(new Runnable() {
469 @SuppressWarnings("synthetic-access")
471 projectFileList.setListData(files.toArray());
472 projectFileList.clearSelection();
475 Set<String> entriesToRemove = new HashSet<String>();
476 Iterator<String> filenames = new HashSet<String>(project.getFileOptions().keySet()).iterator();
477 while (filenames.hasNext()) {
478 String filename = filenames.next();
479 boolean found = false;
480 for (ScannedFile scannedFile : files) {
481 if (scannedFile.getFilename().equals(filename)) {
487 entriesToRemove.add(filename);
490 for (String filename : entriesToRemove) {
491 project.setFileOption(filename, null);
494 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.scan-error"), null, JOptionPane.ERROR_MESSAGE);
496 SwingUtilities.invokeLater(new Runnable() {
499 @SuppressWarnings("synthetic-access")
501 wizard.setPreviousEnabled(true);
502 wizard.setNextEnabled(!error);
503 wizard.setQuitEnabled(true);
504 ignoreHiddenFilesCheckBox.setEnabled(true);
505 scanAction.setEnabled(true);
511 * Returns the {@link FileOption file options} for the currently selected
514 * @return The {@link FileOption}s for the selected file, or {@code null} if
515 * no file is selected
517 private FileOption getSelectedFile() {
518 ScannedFile scannedFile = (ScannedFile) projectFileList.getSelectedValue();
519 if (scannedFile == null) {
522 return project.getFileOption(scannedFile.getFilename());
526 // INTERFACE ActionListener
533 public void actionPerformed(ActionEvent actionEvent) {
534 Object source = actionEvent.getSource();
535 if ((source instanceof JCheckBox) && ("ignore-hidden-files".equals(((JCheckBox) source).getName()))) {
536 project.setIgnoreHiddenFiles(((JCheckBox) source).isSelected());
540 ScannedFile scannedFile = (ScannedFile) projectFileList.getSelectedValue();
541 if (scannedFile == null) {
544 String filename = scannedFile.getFilename();
545 FileOption fileOption = project.getFileOption(filename);
546 if (source instanceof JCheckBox) {
547 JCheckBox checkBox = (JCheckBox) source;
548 if ("default-file".equals(checkBox.getName())) {
549 if (checkBox.isSelected()) {
550 if (filename.indexOf('/') > -1) {
551 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.invalid-default-file"), null, JOptionPane.ERROR_MESSAGE);
552 checkBox.setSelected(false);
554 project.setIndexFile(filename);
557 if (filename.equals(project.getIndexFile())) {
558 project.setIndexFile(null);
561 } else if ("insert".equals(checkBox.getName())) {
562 boolean isInsert = checkBox.isSelected();
563 fileOption.setInsert(isInsert);
564 fileOptionsInsertRedirectCheckBox.setEnabled(!isInsert);
565 } else if ("force-insert".equals(checkBox.getName())) {
566 boolean isForceInsert = checkBox.isSelected();
567 fileOption.setForceInsert(isForceInsert);
568 } else if ("insert-redirect".equals(checkBox.getName())) {
569 boolean isInsertRedirect = checkBox.isSelected();
570 fileOption.setInsertRedirect(isInsertRedirect);
571 fileOptionsCustomKeyTextField.setEnabled(isInsertRedirect);
572 } else if ("rename".equals(checkBox.getName())) {
573 boolean isRenamed = checkBox.isSelected();
574 fileOptionsRenameTextField.setEnabled(isRenamed);
575 fileOption.setChangedName(isRenamed ? fileOptionsRenameTextField.getText() : "");
577 } else if (source instanceof JComboBox) {
578 JComboBox comboBox = (JComboBox) source;
579 if ("project-files.mime-type".equals(comboBox.getName())) {
580 fileOption.setMimeType((String) comboBox.getSelectedItem());
586 // INTERFACE ListSelectionListener
593 @SuppressWarnings("null")
594 public void valueChanged(ListSelectionEvent e) {
595 ScannedFile scannedFile = (ScannedFile) projectFileList.getSelectedValue();
596 boolean enabled = scannedFile != null;
597 String filename = (scannedFile == null) ? null : scannedFile.getFilename();
598 defaultFileCheckBox.setEnabled(enabled);
599 fileOptionsInsertCheckBox.setEnabled(enabled);
600 fileOptionsRenameCheckBox.setEnabled(enabled);
601 fileOptionsMIMETypeComboBox.setEnabled(enabled);
602 if (filename != null) {
603 FileOption fileOption = project.getFileOption(filename);
604 defaultFileCheckBox.setSelected(filename.equals(project.getIndexFile()));
605 fileOptionsInsertCheckBox.setSelected(fileOption.isInsert());
606 fileOptionsForceInsertCheckBox.setEnabled(scannedFile.getHash().equals(fileOption.getLastInsertHash()));
607 fileOptionsForceInsertCheckBox.setSelected(fileOption.isForceInsert());
608 fileOptionsInsertRedirectCheckBox.setEnabled(!fileOption.isInsert());
609 fileOptionsInsertRedirectCheckBox.setSelected(fileOption.isInsertRedirect());
610 fileOptionsCustomKeyTextField.setEnabled(fileOption.isInsertRedirect());
611 fileOptionsCustomKeyTextField.setText(fileOption.getCustomKey());
612 fileOptionsRenameCheckBox.setSelected(fileOption.hasChangedName());
613 fileOptionsRenameTextField.setEnabled(fileOption.hasChangedName());
614 fileOptionsRenameTextField.setText(fileOption.getChangedName());
615 fileOptionsMIMETypeComboBox.getModel().setSelectedItem(fileOption.getMimeType());
617 defaultFileCheckBox.setSelected(false);
618 fileOptionsInsertCheckBox.setSelected(true);
619 fileOptionsForceInsertCheckBox.setEnabled(false);
620 fileOptionsForceInsertCheckBox.setSelected(false);
621 fileOptionsInsertRedirectCheckBox.setEnabled(false);
622 fileOptionsInsertRedirectCheckBox.setSelected(false);
623 fileOptionsCustomKeyTextField.setEnabled(false);
624 fileOptionsCustomKeyTextField.setText("CHK@");
625 fileOptionsRenameCheckBox.setEnabled(false);
626 fileOptionsRenameCheckBox.setSelected(false);
627 fileOptionsRenameTextField.setEnabled(false);
628 fileOptionsRenameTextField.setText("");
629 fileOptionsMIMETypeComboBox.getModel().setSelectedItem(MimeTypes.DEFAULT_CONTENT_TYPE);
634 // INTERFACE DocumentListener
638 * Updates the options of the currently selected file with the changes made
639 * in the “custom key” textfield.
641 * @param documentEvent
642 * The document event to process
644 private void processDocumentUpdate(DocumentEvent documentEvent) {
645 ScannedFile scannedFile = (ScannedFile) projectFileList.getSelectedValue();
646 if (scannedFile == null) {
649 FileOption fileOption = project.getFileOption(scannedFile.getFilename());
650 Document document = documentEvent.getDocument();
652 String text = document.getText(0, document.getLength());
653 fileOption.setCustomKey(text);
654 } catch (BadLocationException ble1) {
663 public void changedUpdate(DocumentEvent documentEvent) {
664 processDocumentUpdate(documentEvent);
671 public void insertUpdate(DocumentEvent documentEvent) {
672 processDocumentUpdate(documentEvent);
679 public void removeUpdate(DocumentEvent documentEvent) {
680 processDocumentUpdate(documentEvent);