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 “always force insert” checkbox. */
89 private JCheckBox alwaysForceInsertCheckBox;
91 /** The “ignore hidden files” checkbox. */
92 private JCheckBox ignoreHiddenFilesCheckBox;
94 /** The list of project files. */
95 private JList projectFileList;
97 /** The “default file” checkbox. */
98 private JCheckBox defaultFileCheckBox;
100 /** The “insert” checkbox. */
101 private JCheckBox fileOptionsInsertCheckBox;
103 /** The “force insert” checkbox. */
104 private JCheckBox fileOptionsForceInsertCheckBox;
106 /** The “insert redirect” checkbox. */
107 private JCheckBox fileOptionsInsertRedirectCheckBox;
109 /** The “custom key” textfield. */
110 private JTextField fileOptionsCustomKeyTextField;
112 /** The “rename” check box. */
113 private JCheckBox fileOptionsRenameCheckBox;
115 /** The “new name” text field. */
116 private JTextField fileOptionsRenameTextField;
118 /** The “mime type” combo box. */
119 private JComboBox fileOptionsMIMETypeComboBox;
121 /** Delayed notification for file scanning. */
122 private StoppableDelay delayedNotification;
124 /** Dialog to display while scanning. */
125 private JDialog scanningFilesDialog;
127 /** The file scanner. */
128 private FileScanner fileScanner;
130 /** The progress bar. */
131 private JProgressBar progressBar;
134 * Creates a new project file page.
137 * The wizard the page belongs to
139 public ProjectFilesPage(final TWizard wizard) {
145 * Initializes the page and all its actions and components.
147 private void pageInit() {
149 setLayout(new BorderLayout(12, 12));
150 add(createProjectFilesPanel(), BorderLayout.CENTER);
154 * Creates all actions.
156 private void createActions() {
157 scanAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.rescan")) {
160 @SuppressWarnings("synthetic-access")
161 public void actionPerformed(ActionEvent actionEvent) {
165 scanAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
166 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
168 I18nContainer.getInstance().registerRunnable(new Runnable() {
171 @SuppressWarnings("synthetic-access")
173 scanAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.rescan"));
174 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
183 public void pageAdded(TWizard wizard) {
184 /* create file scanner. */
185 fileScanner = new FileScanner(project);
186 fileScanner.addFileScannerListener(this);
189 this.wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
190 this.wizard.setNextName(I18n.getMessage("jsite.project-files.insert-now"));
191 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
195 * Creates the panel contains the project file list and options.
197 * @return The created panel
199 private JComponent createProjectFilesPanel() {
200 JPanel projectFilesPanel = new JPanel(new BorderLayout(12, 12));
202 projectFileList = new JList();
203 projectFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
204 projectFileList.setMinimumSize(new Dimension(250, projectFileList.getPreferredSize().height));
205 projectFileList.addListSelectionListener(this);
207 projectFilesPanel.add(new JScrollPane(projectFileList), BorderLayout.CENTER);
209 JPanel fileOptionsAlignmentPanel = new JPanel(new BorderLayout(12, 12));
210 projectFilesPanel.add(fileOptionsAlignmentPanel, BorderLayout.PAGE_END);
211 JPanel fileOptionsPanel = new JPanel(new GridBagLayout());
212 fileOptionsAlignmentPanel.add(fileOptionsPanel, BorderLayout.PAGE_START);
214 alwaysForceInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.always-force-insert"));
215 alwaysForceInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.always-force-insert.tooltip"));
216 alwaysForceInsertCheckBox.setName("always-force-insert");
217 alwaysForceInsertCheckBox.addActionListener(this);
218 fileOptionsPanel.add(alwaysForceInsertCheckBox, new GridBagConstraints(0, 0, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
220 ignoreHiddenFilesCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.ignore-hidden-files"));
221 ignoreHiddenFilesCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.ignore-hidden-files.tooltip"));
222 ignoreHiddenFilesCheckBox.setName("ignore-hidden-files");
223 ignoreHiddenFilesCheckBox.addActionListener(this);
224 fileOptionsPanel.add(ignoreHiddenFilesCheckBox, new GridBagConstraints(0, 1, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
226 fileOptionsPanel.add(new JButton(scanAction), new GridBagConstraints(0, 2, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
228 final JLabel fileOptionsLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
229 fileOptionsPanel.add(fileOptionsLabel, new GridBagConstraints(0, 3, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
231 defaultFileCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.default"));
232 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
233 defaultFileCheckBox.setName("default-file");
234 defaultFileCheckBox.addActionListener(this);
235 defaultFileCheckBox.setEnabled(false);
237 fileOptionsPanel.add(defaultFileCheckBox, new GridBagConstraints(0, 4, 5, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 18, 0, 0), 0, 0));
239 fileOptionsInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert"), true);
240 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
241 fileOptionsInsertCheckBox.setName("insert");
242 fileOptionsInsertCheckBox.setMnemonic(KeyEvent.VK_I);
243 fileOptionsInsertCheckBox.addActionListener(this);
244 fileOptionsInsertCheckBox.setEnabled(false);
246 fileOptionsPanel.add(fileOptionsInsertCheckBox, new GridBagConstraints(0, 5, 5, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
248 fileOptionsForceInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.force-insert"));
249 fileOptionsForceInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.force-insert.tooltip"));
250 fileOptionsForceInsertCheckBox.setName("force-insert");
251 fileOptionsForceInsertCheckBox.setMnemonic(KeyEvent.VK_F);
252 fileOptionsForceInsertCheckBox.addActionListener(this);
253 fileOptionsForceInsertCheckBox.setEnabled(false);
255 fileOptionsPanel.add(fileOptionsForceInsertCheckBox, new GridBagConstraints(0, 6, 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 fileOptionsInsertRedirectCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert-redirect"), false);
263 fileOptionsInsertRedirectCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert-redirect.tooltip"));
264 fileOptionsInsertRedirectCheckBox.setName("insert-redirect");
265 fileOptionsInsertRedirectCheckBox.setMnemonic(KeyEvent.VK_R);
266 fileOptionsInsertRedirectCheckBox.addActionListener(this);
267 fileOptionsInsertRedirectCheckBox.setEnabled(false);
269 final TLabel customKeyLabel = new TLabel(I18n.getMessage("jsite.project-files.custom-key") + ":", KeyEvent.VK_K, fileOptionsCustomKeyTextField);
270 fileOptionsPanel.add(fileOptionsInsertRedirectCheckBox, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
271 fileOptionsPanel.add(customKeyLabel, new GridBagConstraints(1, 7, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 6, 0, 0), 0, 0));
272 fileOptionsPanel.add(fileOptionsCustomKeyTextField, new GridBagConstraints(2, 7, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
274 fileOptionsRenameCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.rename"), false);
275 fileOptionsRenameCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.rename.tooltip"));
276 fileOptionsRenameCheckBox.setName("rename");
277 fileOptionsRenameCheckBox.setMnemonic(KeyEvent.VK_N);
278 fileOptionsRenameCheckBox.addActionListener(this);
279 fileOptionsRenameCheckBox.setEnabled(false);
281 fileOptionsRenameTextField = new JTextField();
282 fileOptionsRenameTextField.setEnabled(false);
283 fileOptionsRenameTextField.getDocument().addDocumentListener(new DocumentListener() {
285 @SuppressWarnings("synthetic-access")
286 private void storeText(DocumentEvent documentEvent) {
287 FileOption fileOption = getSelectedFile();
288 if (fileOption == null) {
289 /* no file selected. */
292 Document document = documentEvent.getDocument();
293 int documentLength = document.getLength();
295 fileOption.setChangedName(document.getText(0, documentLength).trim());
296 } catch (BadLocationException ble1) {
297 /* ignore, it should never happen. */
302 public void changedUpdate(DocumentEvent documentEvent) {
303 storeText(documentEvent);
307 public void insertUpdate(DocumentEvent documentEvent) {
308 storeText(documentEvent);
312 public void removeUpdate(DocumentEvent documentEvent) {
313 storeText(documentEvent);
318 fileOptionsPanel.add(fileOptionsRenameCheckBox, new GridBagConstraints(0, 8, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
319 fileOptionsPanel.add(fileOptionsRenameTextField, new GridBagConstraints(2, 8, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
321 fileOptionsMIMETypeComboBox = new JComboBox(MimeTypes.getAllMimeTypes().toArray());
322 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
323 fileOptionsMIMETypeComboBox.setName("project-files.mime-type");
324 fileOptionsMIMETypeComboBox.addActionListener(this);
325 fileOptionsMIMETypeComboBox.setEditable(true);
326 fileOptionsMIMETypeComboBox.setEnabled(false);
328 final TLabel mimeTypeLabel = new TLabel(I18n.getMessage("jsite.project-files.mime-type") + ":", KeyEvent.VK_M, fileOptionsMIMETypeComboBox);
329 fileOptionsPanel.add(mimeTypeLabel, new GridBagConstraints(0, 9, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
330 fileOptionsPanel.add(fileOptionsMIMETypeComboBox, new GridBagConstraints(1, 9, 4, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
332 /* create dialog to show while scanning. */
333 scanningFilesDialog = new JDialog(wizard);
334 scanningFilesDialog.setModal(true);
335 scanningFilesDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
337 JPanel progressPanel = new JPanel(new BorderLayout(12, 12));
338 scanningFilesDialog.getContentPane().add(progressPanel, BorderLayout.CENTER);
339 progressPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
341 final TLabel scanningLabel = new TLabel(I18n.getMessage("jsite.project-files.scanning"), SwingConstants.CENTER);
342 progressPanel.add(scanningLabel, BorderLayout.NORTH);
343 progressBar = new JProgressBar(SwingConstants.HORIZONTAL);
344 progressPanel.add(progressBar, BorderLayout.SOUTH);
345 progressBar.setIndeterminate(true);
346 progressBar.setStringPainted(true);
347 progressBar.setPreferredSize(new Dimension(progressBar.getPreferredSize().width * 2, progressBar.getPreferredSize().height));
349 scanningFilesDialog.pack();
350 scanningFilesDialog.addWindowListener(new WindowAdapter() {
356 @SuppressWarnings("synthetic-access")
357 public void windowOpened(WindowEvent e) {
358 SwingUtils.center(scanningFilesDialog, wizard);
362 I18nContainer.getInstance().registerRunnable(new Runnable() {
365 @SuppressWarnings("synthetic-access")
367 alwaysForceInsertCheckBox.setText(I18n.getMessage("jsite.project-files.always-force-insert"));
368 alwaysForceInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.always-force-insert.tooltip"));
369 ignoreHiddenFilesCheckBox.setText(I18n.getMessage("jsite.project-files.ignore-hidden-files"));
370 ignoreHiddenFilesCheckBox.setToolTipText(I18n.getMessage("jsite.projet-files.ignore-hidden-files.tooltip"));
371 fileOptionsLabel.setText("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
372 defaultFileCheckBox.setText(I18n.getMessage("jsite.project-files.default"));
373 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
374 fileOptionsInsertCheckBox.setText(I18n.getMessage("jsite.project-files.insert"));
375 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
376 fileOptionsForceInsertCheckBox.setText(I18n.getMessage("jsite.project-files.force-insert"));
377 fileOptionsForceInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.force-insert.tooltip"));
378 fileOptionsInsertRedirectCheckBox.setText(I18n.getMessage("jsite.project-files.insert-redirect"));
379 fileOptionsInsertRedirectCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert-redirect.tooltip"));
380 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
381 customKeyLabel.setText(I18n.getMessage("jsite.project-files.custom-key") + ":");
382 fileOptionsRenameCheckBox.setText("jsite.project-files.rename");
383 fileOptionsRenameCheckBox.setToolTipText("jsite.project-files.rename.tooltip");
384 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
385 mimeTypeLabel.setText(I18n.getMessage("jsite.project-files.mime-type") + ":");
386 scanningLabel.setText(I18n.getMessage("jsite.project-files.scanning"));
390 return projectFilesPanel;
394 * Sets the project whose files to manage.
397 * The project whose files to manage
399 public void setProject(final Project project) {
400 this.project = project;
401 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
402 setDescription(I18n.getMessage("jsite.project-files.description"));
403 ignoreHiddenFilesCheckBox.setSelected(project.isIgnoreHiddenFiles());
404 alwaysForceInsertCheckBox.setSelected(project.isAlwaysForceInsert());
405 I18nContainer.getInstance().registerRunnable(new Runnable() {
409 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
410 setDescription(I18n.getMessage("jsite.project-files.description"));
420 * Rescans the project’s files.
422 private void actionScan() {
423 projectFileList.clearSelection();
424 projectFileList.setListData(new Object[0]);
426 wizard.setNextEnabled(false);
427 wizard.setPreviousEnabled(false);
428 wizard.setQuitEnabled(false);
430 ignoreHiddenFilesCheckBox.setEnabled(false);
431 scanAction.setEnabled(false);
433 delayedNotification = new StoppableDelay(new Runnable() {
436 @SuppressWarnings("synthetic-access")
438 scanningFilesDialog.setVisible(true);
443 @SuppressWarnings("synthetic-access")
445 scanningFilesDialog.setVisible(false);
448 new Thread(fileScanner).start();
449 new Thread(delayedNotification).start();
450 new Thread(new Runnable() {
453 @SuppressWarnings("synthetic-access")
455 while (!delayedNotification.isFinished()) {
458 } catch (InterruptedException ie1) {
461 progressBar.setString(fileScanner.getLastFilename());
470 * Updates the file list.
473 public void fileScannerFinished(FileScanner fileScanner) {
474 delayedNotification.finish();
475 final boolean error = fileScanner.isError();
477 final List<ScannedFile> files = fileScanner.getFiles();
478 SwingUtilities.invokeLater(new Runnable() {
481 @SuppressWarnings("synthetic-access")
483 projectFileList.setListData(files.toArray());
484 projectFileList.clearSelection();
487 Set<String> entriesToRemove = new HashSet<String>();
488 Iterator<String> filenames = new HashSet<String>(project.getFileOptions().keySet()).iterator();
489 while (filenames.hasNext()) {
490 String filename = filenames.next();
491 boolean found = false;
492 for (ScannedFile scannedFile : files) {
493 if (scannedFile.getFilename().equals(filename)) {
499 entriesToRemove.add(filename);
502 for (String filename : entriesToRemove) {
503 project.setFileOption(filename, null);
506 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.scan-error"), null, JOptionPane.ERROR_MESSAGE);
508 SwingUtilities.invokeLater(new Runnable() {
511 @SuppressWarnings("synthetic-access")
513 wizard.setPreviousEnabled(true);
514 wizard.setNextEnabled(!error);
515 wizard.setQuitEnabled(true);
516 ignoreHiddenFilesCheckBox.setEnabled(true);
517 scanAction.setEnabled(true);
523 * Returns the {@link FileOption file options} for the currently selected
526 * @return The {@link FileOption}s for the selected file, or {@code null} if
527 * no file is selected
529 private FileOption getSelectedFile() {
530 ScannedFile scannedFile = (ScannedFile) projectFileList.getSelectedValue();
531 if (scannedFile == null) {
534 return project.getFileOption(scannedFile.getFilename());
538 // INTERFACE ActionListener
545 public void actionPerformed(ActionEvent actionEvent) {
546 Object source = actionEvent.getSource();
547 if (source instanceof JCheckBox) {
548 String checkboxName = ((JCheckBox) source).getName();
549 if ("ignore-hidden-files".equals(checkboxName)) {
550 project.setIgnoreHiddenFiles(((JCheckBox) source).isSelected());
553 } else if ("always-force-insert".equals(checkboxName)) {
554 project.setAlwaysForceInsert(((JCheckBox) source).isSelected());
559 ScannedFile scannedFile = (ScannedFile) projectFileList.getSelectedValue();
560 if (scannedFile == null) {
563 String filename = scannedFile.getFilename();
564 FileOption fileOption = project.getFileOption(filename);
565 if (source instanceof JCheckBox) {
566 JCheckBox checkBox = (JCheckBox) source;
567 if ("default-file".equals(checkBox.getName())) {
568 if (checkBox.isSelected()) {
569 if (filename.indexOf('/') > -1) {
570 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.invalid-default-file"), null, JOptionPane.ERROR_MESSAGE);
571 checkBox.setSelected(false);
573 project.setIndexFile(filename);
576 if (filename.equals(project.getIndexFile())) {
577 project.setIndexFile(null);
580 } else if ("insert".equals(checkBox.getName())) {
581 boolean isInsert = checkBox.isSelected();
582 fileOption.setInsert(isInsert);
583 fileOptionsInsertRedirectCheckBox.setEnabled(!isInsert);
584 } else if ("force-insert".equals(checkBox.getName())) {
585 boolean isForceInsert = checkBox.isSelected();
586 fileOption.setForceInsert(isForceInsert);
587 } else if ("insert-redirect".equals(checkBox.getName())) {
588 boolean isInsertRedirect = checkBox.isSelected();
589 fileOption.setInsertRedirect(isInsertRedirect);
590 fileOptionsCustomKeyTextField.setEnabled(isInsertRedirect);
591 } else if ("rename".equals(checkBox.getName())) {
592 boolean isRenamed = checkBox.isSelected();
593 fileOptionsRenameTextField.setEnabled(isRenamed);
594 fileOption.setChangedName(isRenamed ? fileOptionsRenameTextField.getText() : "");
596 } else if (source instanceof JComboBox) {
597 JComboBox comboBox = (JComboBox) source;
598 if ("project-files.mime-type".equals(comboBox.getName())) {
599 fileOption.setMimeType((String) comboBox.getSelectedItem());
605 // INTERFACE ListSelectionListener
612 @SuppressWarnings("null")
613 public void valueChanged(ListSelectionEvent e) {
614 ScannedFile scannedFile = (ScannedFile) projectFileList.getSelectedValue();
615 boolean enabled = scannedFile != null;
616 String filename = (scannedFile == null) ? null : scannedFile.getFilename();
617 defaultFileCheckBox.setEnabled(enabled);
618 fileOptionsInsertCheckBox.setEnabled(enabled);
619 fileOptionsRenameCheckBox.setEnabled(enabled);
620 fileOptionsMIMETypeComboBox.setEnabled(enabled);
621 if (filename != null) {
622 FileOption fileOption = project.getFileOption(filename);
623 defaultFileCheckBox.setSelected(filename.equals(project.getIndexFile()));
624 fileOptionsInsertCheckBox.setSelected(fileOption.isInsert());
625 fileOptionsForceInsertCheckBox.setEnabled(!project.isAlwaysForceInsert() && scannedFile.getHash().equals(fileOption.getLastInsertHash()));
626 fileOptionsForceInsertCheckBox.setSelected(fileOption.isForceInsert());
627 fileOptionsInsertRedirectCheckBox.setEnabled(!fileOption.isInsert());
628 fileOptionsInsertRedirectCheckBox.setSelected(fileOption.isInsertRedirect());
629 fileOptionsCustomKeyTextField.setEnabled(fileOption.isInsertRedirect());
630 fileOptionsCustomKeyTextField.setText(fileOption.getCustomKey());
631 fileOptionsRenameCheckBox.setSelected(fileOption.getChangedName().isPresent());
632 fileOptionsRenameTextField.setEnabled(fileOption.getChangedName().isPresent());
633 fileOptionsRenameTextField.setText(fileOption.getChangedName().or(""));
634 fileOptionsMIMETypeComboBox.getModel().setSelectedItem(fileOption.getMimeType());
636 defaultFileCheckBox.setSelected(false);
637 fileOptionsInsertCheckBox.setSelected(true);
638 fileOptionsForceInsertCheckBox.setEnabled(false);
639 fileOptionsForceInsertCheckBox.setSelected(false);
640 fileOptionsInsertRedirectCheckBox.setEnabled(false);
641 fileOptionsInsertRedirectCheckBox.setSelected(false);
642 fileOptionsCustomKeyTextField.setEnabled(false);
643 fileOptionsCustomKeyTextField.setText("CHK@");
644 fileOptionsRenameCheckBox.setEnabled(false);
645 fileOptionsRenameCheckBox.setSelected(false);
646 fileOptionsRenameTextField.setEnabled(false);
647 fileOptionsRenameTextField.setText("");
648 fileOptionsMIMETypeComboBox.getModel().setSelectedItem(MimeTypes.DEFAULT_CONTENT_TYPE);
653 // INTERFACE DocumentListener
657 * Updates the options of the currently selected file with the changes made
658 * in the “custom key” textfield.
660 * @param documentEvent
661 * The document event to process
663 private void processDocumentUpdate(DocumentEvent documentEvent) {
664 ScannedFile scannedFile = (ScannedFile) projectFileList.getSelectedValue();
665 if (scannedFile == null) {
668 FileOption fileOption = project.getFileOption(scannedFile.getFilename());
669 Document document = documentEvent.getDocument();
671 String text = document.getText(0, document.getLength());
672 fileOption.setCustomKey(text);
673 } catch (BadLocationException ble1) {
682 public void changedUpdate(DocumentEvent documentEvent) {
683 processDocumentUpdate(documentEvent);
690 public void insertUpdate(DocumentEvent documentEvent) {
691 processDocumentUpdate(documentEvent);
698 public void removeUpdate(DocumentEvent documentEvent) {
699 processDocumentUpdate(documentEvent);