2 * jSite - ProjectFilesPage.java - Copyright © 2006–2014 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, this);
188 this.wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
189 this.wizard.setNextName(I18n.getMessage("jsite.project-files.insert-now"));
190 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
194 * Creates the panel contains the project file list and options.
196 * @return The created panel
198 private JComponent createProjectFilesPanel() {
199 JPanel projectFilesPanel = new JPanel(new BorderLayout(12, 12));
201 projectFileList = new JList();
202 projectFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
203 projectFileList.setMinimumSize(new Dimension(250, projectFileList.getPreferredSize().height));
204 projectFileList.addListSelectionListener(this);
206 projectFilesPanel.add(new JScrollPane(projectFileList), BorderLayout.CENTER);
208 JPanel fileOptionsAlignmentPanel = new JPanel(new BorderLayout(12, 12));
209 projectFilesPanel.add(fileOptionsAlignmentPanel, BorderLayout.PAGE_END);
210 JPanel fileOptionsPanel = new JPanel(new GridBagLayout());
211 fileOptionsAlignmentPanel.add(fileOptionsPanel, BorderLayout.PAGE_START);
213 alwaysForceInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.always-force-insert"));
214 alwaysForceInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.always-force-insert.tooltip"));
215 alwaysForceInsertCheckBox.setName("always-force-insert");
216 alwaysForceInsertCheckBox.addActionListener(this);
217 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));
219 ignoreHiddenFilesCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.ignore-hidden-files"));
220 ignoreHiddenFilesCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.ignore-hidden-files.tooltip"));
221 ignoreHiddenFilesCheckBox.setName("ignore-hidden-files");
222 ignoreHiddenFilesCheckBox.addActionListener(this);
223 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));
225 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));
227 final JLabel fileOptionsLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
228 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));
230 defaultFileCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.default"));
231 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
232 defaultFileCheckBox.setName("default-file");
233 defaultFileCheckBox.addActionListener(this);
234 defaultFileCheckBox.setEnabled(false);
236 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));
238 fileOptionsInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert"), true);
239 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
240 fileOptionsInsertCheckBox.setName("insert");
241 fileOptionsInsertCheckBox.setMnemonic(KeyEvent.VK_I);
242 fileOptionsInsertCheckBox.addActionListener(this);
243 fileOptionsInsertCheckBox.setEnabled(false);
245 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));
247 fileOptionsForceInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.force-insert"));
248 fileOptionsForceInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.force-insert.tooltip"));
249 fileOptionsForceInsertCheckBox.setName("force-insert");
250 fileOptionsForceInsertCheckBox.setMnemonic(KeyEvent.VK_F);
251 fileOptionsForceInsertCheckBox.addActionListener(this);
252 fileOptionsForceInsertCheckBox.setEnabled(false);
254 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));
256 fileOptionsCustomKeyTextField = new JTextField(45);
257 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
258 fileOptionsCustomKeyTextField.setEnabled(false);
259 fileOptionsCustomKeyTextField.getDocument().addDocumentListener(this);
261 fileOptionsInsertRedirectCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert-redirect"), false);
262 fileOptionsInsertRedirectCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert-redirect.tooltip"));
263 fileOptionsInsertRedirectCheckBox.setName("insert-redirect");
264 fileOptionsInsertRedirectCheckBox.setMnemonic(KeyEvent.VK_R);
265 fileOptionsInsertRedirectCheckBox.addActionListener(this);
266 fileOptionsInsertRedirectCheckBox.setEnabled(false);
268 final TLabel customKeyLabel = new TLabel(I18n.getMessage("jsite.project-files.custom-key") + ":", KeyEvent.VK_K, fileOptionsCustomKeyTextField);
269 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));
270 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));
271 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));
273 fileOptionsRenameCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.rename"), false);
274 fileOptionsRenameCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.rename.tooltip"));
275 fileOptionsRenameCheckBox.setName("rename");
276 fileOptionsRenameCheckBox.setMnemonic(KeyEvent.VK_N);
277 fileOptionsRenameCheckBox.addActionListener(this);
278 fileOptionsRenameCheckBox.setEnabled(false);
280 fileOptionsRenameTextField = new JTextField();
281 fileOptionsRenameTextField.setEnabled(false);
282 fileOptionsRenameTextField.getDocument().addDocumentListener(new DocumentListener() {
284 @SuppressWarnings("synthetic-access")
285 private void storeText(DocumentEvent documentEvent) {
286 FileOption fileOption = getSelectedFile();
287 if (fileOption == null) {
288 /* no file selected. */
291 Document document = documentEvent.getDocument();
292 int documentLength = document.getLength();
294 fileOption.setChangedName(document.getText(0, documentLength).trim());
295 } catch (BadLocationException ble1) {
296 /* ignore, it should never happen. */
301 public void changedUpdate(DocumentEvent documentEvent) {
302 storeText(documentEvent);
306 public void insertUpdate(DocumentEvent documentEvent) {
307 storeText(documentEvent);
311 public void removeUpdate(DocumentEvent documentEvent) {
312 storeText(documentEvent);
317 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));
318 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));
320 fileOptionsMIMETypeComboBox = new JComboBox(MimeTypes.getAllMimeTypes().toArray());
321 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
322 fileOptionsMIMETypeComboBox.setName("project-files.mime-type");
323 fileOptionsMIMETypeComboBox.addActionListener(this);
324 fileOptionsMIMETypeComboBox.setEditable(true);
325 fileOptionsMIMETypeComboBox.setEnabled(false);
327 final TLabel mimeTypeLabel = new TLabel(I18n.getMessage("jsite.project-files.mime-type") + ":", KeyEvent.VK_M, fileOptionsMIMETypeComboBox);
328 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));
329 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));
331 /* create dialog to show while scanning. */
332 scanningFilesDialog = new JDialog(wizard);
333 scanningFilesDialog.setModal(true);
334 scanningFilesDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
336 JPanel progressPanel = new JPanel(new BorderLayout(12, 12));
337 scanningFilesDialog.getContentPane().add(progressPanel, BorderLayout.CENTER);
338 progressPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
340 final TLabel scanningLabel = new TLabel(I18n.getMessage("jsite.project-files.scanning"), SwingConstants.CENTER);
341 progressPanel.add(scanningLabel, BorderLayout.NORTH);
342 progressBar = new JProgressBar(SwingConstants.HORIZONTAL);
343 progressPanel.add(progressBar, BorderLayout.SOUTH);
344 progressBar.setIndeterminate(true);
345 progressBar.setStringPainted(true);
346 progressBar.setPreferredSize(new Dimension(progressBar.getPreferredSize().width * 2, progressBar.getPreferredSize().height));
348 scanningFilesDialog.pack();
349 scanningFilesDialog.addWindowListener(new WindowAdapter() {
355 @SuppressWarnings("synthetic-access")
356 public void windowOpened(WindowEvent e) {
357 SwingUtils.center(scanningFilesDialog, wizard);
361 I18nContainer.getInstance().registerRunnable(new Runnable() {
364 @SuppressWarnings("synthetic-access")
366 alwaysForceInsertCheckBox.setText(I18n.getMessage("jsite.project-files.always-force-insert"));
367 alwaysForceInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.always-force-insert.tooltip"));
368 ignoreHiddenFilesCheckBox.setText(I18n.getMessage("jsite.project-files.ignore-hidden-files"));
369 ignoreHiddenFilesCheckBox.setToolTipText(I18n.getMessage("jsite.projet-files.ignore-hidden-files.tooltip"));
370 fileOptionsLabel.setText("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
371 defaultFileCheckBox.setText(I18n.getMessage("jsite.project-files.default"));
372 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
373 fileOptionsInsertCheckBox.setText(I18n.getMessage("jsite.project-files.insert"));
374 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
375 fileOptionsForceInsertCheckBox.setText(I18n.getMessage("jsite.project-files.force-insert"));
376 fileOptionsForceInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.force-insert.tooltip"));
377 fileOptionsInsertRedirectCheckBox.setText(I18n.getMessage("jsite.project-files.insert-redirect"));
378 fileOptionsInsertRedirectCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert-redirect.tooltip"));
379 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
380 customKeyLabel.setText(I18n.getMessage("jsite.project-files.custom-key") + ":");
381 fileOptionsRenameCheckBox.setText("jsite.project-files.rename");
382 fileOptionsRenameCheckBox.setToolTipText("jsite.project-files.rename.tooltip");
383 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
384 mimeTypeLabel.setText(I18n.getMessage("jsite.project-files.mime-type") + ":");
385 scanningLabel.setText(I18n.getMessage("jsite.project-files.scanning"));
389 return projectFilesPanel;
393 * Sets the project whose files to manage.
396 * The project whose files to manage
398 public void setProject(final Project project) {
399 this.project = project;
400 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
401 setDescription(I18n.getMessage("jsite.project-files.description"));
402 ignoreHiddenFilesCheckBox.setSelected(project.isIgnoreHiddenFiles());
403 alwaysForceInsertCheckBox.setSelected(project.isAlwaysForceInsert());
404 I18nContainer.getInstance().registerRunnable(new Runnable() {
408 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
409 setDescription(I18n.getMessage("jsite.project-files.description"));
419 * Rescans the project’s files.
421 private void actionScan() {
422 projectFileList.clearSelection();
423 projectFileList.setListData(new Object[0]);
425 wizard.setNextEnabled(false);
426 wizard.setPreviousEnabled(false);
427 wizard.setQuitEnabled(false);
429 ignoreHiddenFilesCheckBox.setEnabled(false);
430 scanAction.setEnabled(false);
432 delayedNotification = new StoppableDelay(new Runnable() {
435 @SuppressWarnings("synthetic-access")
437 scanningFilesDialog.setVisible(true);
442 @SuppressWarnings("synthetic-access")
444 scanningFilesDialog.setVisible(false);
447 fileScanner.startInBackground();
448 new Thread(delayedNotification).start();
449 new Thread(new Runnable() {
452 @SuppressWarnings("synthetic-access")
454 while (!delayedNotification.isFinished()) {
457 } catch (InterruptedException ie1) {
460 progressBar.setString(fileScanner.getLastFilename());
469 * Updates the file list.
472 public void fileScannerFinished(FileScanner fileScanner) {
473 delayedNotification.finish();
474 final boolean error = fileScanner.isError();
476 final List<ScannedFile> files = fileScanner.getFiles();
477 SwingUtilities.invokeLater(new Runnable() {
480 @SuppressWarnings("synthetic-access")
482 projectFileList.setListData(files.toArray());
483 projectFileList.clearSelection();
486 Set<String> entriesToRemove = new HashSet<String>();
487 Iterator<String> filenames = new HashSet<String>(project.getFileOptions().keySet()).iterator();
488 while (filenames.hasNext()) {
489 String filename = filenames.next();
490 boolean found = false;
491 for (ScannedFile scannedFile : files) {
492 if (scannedFile.getFilename().equals(filename)) {
498 entriesToRemove.add(filename);
501 for (String filename : entriesToRemove) {
502 project.setFileOption(filename, null);
505 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.scan-error"), null, JOptionPane.ERROR_MESSAGE);
507 SwingUtilities.invokeLater(new Runnable() {
510 @SuppressWarnings("synthetic-access")
512 wizard.setPreviousEnabled(true);
513 wizard.setNextEnabled(!error);
514 wizard.setQuitEnabled(true);
515 ignoreHiddenFilesCheckBox.setEnabled(true);
516 scanAction.setEnabled(true);
522 * Returns the {@link FileOption file options} for the currently selected
525 * @return The {@link FileOption}s for the selected file, or {@code null} if
526 * no file is selected
528 private FileOption getSelectedFile() {
529 ScannedFile scannedFile = (ScannedFile) projectFileList.getSelectedValue();
530 if (scannedFile == null) {
533 return project.getFileOption(scannedFile.getFilename());
537 // INTERFACE ActionListener
544 public void actionPerformed(ActionEvent actionEvent) {
545 Object source = actionEvent.getSource();
546 if (source instanceof JCheckBox) {
547 String checkboxName = ((JCheckBox) source).getName();
548 if ("ignore-hidden-files".equals(checkboxName)) {
549 project.setIgnoreHiddenFiles(((JCheckBox) source).isSelected());
552 } else if ("always-force-insert".equals(checkboxName)) {
553 project.setAlwaysForceInsert(((JCheckBox) source).isSelected());
558 ScannedFile scannedFile = (ScannedFile) projectFileList.getSelectedValue();
559 if (scannedFile == null) {
562 String filename = scannedFile.getFilename();
563 FileOption fileOption = project.getFileOption(filename);
564 if (source instanceof JCheckBox) {
565 JCheckBox checkBox = (JCheckBox) source;
566 if ("default-file".equals(checkBox.getName())) {
567 if (checkBox.isSelected()) {
568 if (filename.indexOf('/') > -1) {
569 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.invalid-default-file"), null, JOptionPane.ERROR_MESSAGE);
570 checkBox.setSelected(false);
572 project.setIndexFile(filename);
575 if (filename.equals(project.getIndexFile())) {
576 project.setIndexFile(null);
579 } else if ("insert".equals(checkBox.getName())) {
580 boolean isInsert = checkBox.isSelected();
581 fileOption.setInsert(isInsert);
582 fileOptionsInsertRedirectCheckBox.setEnabled(!isInsert);
583 } else if ("force-insert".equals(checkBox.getName())) {
584 boolean isForceInsert = checkBox.isSelected();
585 fileOption.setForceInsert(isForceInsert);
586 } else if ("insert-redirect".equals(checkBox.getName())) {
587 boolean isInsertRedirect = checkBox.isSelected();
588 fileOption.setInsertRedirect(isInsertRedirect);
589 fileOptionsCustomKeyTextField.setEnabled(isInsertRedirect);
590 } else if ("rename".equals(checkBox.getName())) {
591 boolean isRenamed = checkBox.isSelected();
592 fileOptionsRenameTextField.setEnabled(isRenamed);
593 fileOption.setChangedName(isRenamed ? fileOptionsRenameTextField.getText() : "");
595 } else if (source instanceof JComboBox) {
596 JComboBox comboBox = (JComboBox) source;
597 if ("project-files.mime-type".equals(comboBox.getName())) {
598 fileOption.setMimeType((String) comboBox.getSelectedItem());
604 // INTERFACE ListSelectionListener
611 @SuppressWarnings("null")
612 public void valueChanged(ListSelectionEvent e) {
613 ScannedFile scannedFile = (ScannedFile) projectFileList.getSelectedValue();
614 boolean enabled = scannedFile != null;
615 String filename = (scannedFile == null) ? null : scannedFile.getFilename();
616 defaultFileCheckBox.setEnabled(enabled);
617 fileOptionsInsertCheckBox.setEnabled(enabled);
618 fileOptionsRenameCheckBox.setEnabled(enabled);
619 fileOptionsMIMETypeComboBox.setEnabled(enabled);
620 if (filename != null) {
621 FileOption fileOption = project.getFileOption(filename);
622 defaultFileCheckBox.setSelected(filename.equals(project.getIndexFile()));
623 fileOptionsInsertCheckBox.setSelected(fileOption.isInsert());
624 fileOptionsForceInsertCheckBox.setEnabled(!project.isAlwaysForceInsert() && scannedFile.getHash().equals(fileOption.getLastInsertHash()));
625 fileOptionsForceInsertCheckBox.setSelected(fileOption.isForceInsert());
626 fileOptionsInsertRedirectCheckBox.setEnabled(!fileOption.isInsert());
627 fileOptionsInsertRedirectCheckBox.setSelected(fileOption.isInsertRedirect());
628 fileOptionsCustomKeyTextField.setEnabled(fileOption.isInsertRedirect());
629 fileOptionsCustomKeyTextField.setText(fileOption.getCustomKey());
630 fileOptionsRenameCheckBox.setSelected(fileOption.getChangedName().isPresent());
631 fileOptionsRenameTextField.setEnabled(fileOption.getChangedName().isPresent());
632 fileOptionsRenameTextField.setText(fileOption.getChangedName().orElse(""));
633 fileOptionsMIMETypeComboBox.getModel().setSelectedItem(fileOption.getMimeType());
635 defaultFileCheckBox.setSelected(false);
636 fileOptionsInsertCheckBox.setSelected(true);
637 fileOptionsForceInsertCheckBox.setEnabled(false);
638 fileOptionsForceInsertCheckBox.setSelected(false);
639 fileOptionsInsertRedirectCheckBox.setEnabled(false);
640 fileOptionsInsertRedirectCheckBox.setSelected(false);
641 fileOptionsCustomKeyTextField.setEnabled(false);
642 fileOptionsCustomKeyTextField.setText("CHK@");
643 fileOptionsRenameCheckBox.setEnabled(false);
644 fileOptionsRenameCheckBox.setSelected(false);
645 fileOptionsRenameTextField.setEnabled(false);
646 fileOptionsRenameTextField.setText("");
647 fileOptionsMIMETypeComboBox.getModel().setSelectedItem(MimeTypes.DEFAULT_CONTENT_TYPE);
652 // INTERFACE DocumentListener
656 * Updates the options of the currently selected file with the changes made
657 * in the “custom key” textfield.
659 * @param documentEvent
660 * The document event to process
662 private void processDocumentUpdate(DocumentEvent documentEvent) {
663 ScannedFile scannedFile = (ScannedFile) projectFileList.getSelectedValue();
664 if (scannedFile == null) {
667 FileOption fileOption = project.getFileOption(scannedFile.getFilename());
668 Document document = documentEvent.getDocument();
670 String text = document.getText(0, document.getLength());
671 fileOption.setCustomKey(text);
672 } catch (BadLocationException ble1) {
681 public void changedUpdate(DocumentEvent documentEvent) {
682 processDocumentUpdate(documentEvent);
689 public void insertUpdate(DocumentEvent documentEvent) {
690 processDocumentUpdate(documentEvent);
697 public void removeUpdate(DocumentEvent documentEvent) {
698 processDocumentUpdate(documentEvent);