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.Collection;
33 import java.util.HashSet;
34 import java.util.Iterator;
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.i18n.I18n;
69 import de.todesbaum.jsite.i18n.I18nContainer;
70 import de.todesbaum.util.swing.TLabel;
71 import de.todesbaum.util.swing.TWizard;
72 import de.todesbaum.util.swing.TWizardPage;
75 * Wizard page that lets the user manage the files of a project.
77 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
79 public class ProjectFilesPage extends TWizardPage implements ActionListener, ListSelectionListener, DocumentListener, FileScannerListener {
82 private Project project;
84 /** The “scan files” action. */
85 private Action scanAction;
87 /** The “always force insert” checkbox. */
88 private JCheckBox alwaysForceInsertCheckBox;
90 /** The “ignore hidden files” checkbox. */
91 private JCheckBox ignoreHiddenFilesCheckBox;
93 /** The list of project files. */
94 private JList projectFileList;
96 /** The “default file” checkbox. */
97 private JCheckBox defaultFileCheckBox;
99 /** The “insert” checkbox. */
100 private JCheckBox fileOptionsInsertCheckBox;
102 /** The “force insert” checkbox. */
103 private JCheckBox fileOptionsForceInsertCheckBox;
105 /** The “insert redirect” checkbox. */
106 private JCheckBox fileOptionsInsertRedirectCheckBox;
108 /** The “custom key” textfield. */
109 private JTextField fileOptionsCustomKeyTextField;
111 /** The “rename” check box. */
112 private JCheckBox fileOptionsRenameCheckBox;
114 /** The “new name” text field. */
115 private JTextField fileOptionsRenameTextField;
117 /** The “mime type” combo box. */
118 private JComboBox fileOptionsMIMETypeComboBox;
120 /** Delayed notification for file scanning. */
121 private StoppableDelay delayedNotification;
123 /** Dialog to display while scanning. */
124 private JDialog scanningFilesDialog;
126 /** The file scanner. */
127 private FileScanner fileScanner;
129 /** The progress bar. */
130 private JProgressBar progressBar;
133 * Creates a new project file page.
136 * The wizard the page belongs to
138 public ProjectFilesPage(final TWizard wizard) {
144 * Initializes the page and all its actions and components.
146 private void pageInit() {
148 setLayout(new BorderLayout(12, 12));
149 add(createProjectFilesPanel(), BorderLayout.CENTER);
153 * Creates all actions.
155 private void createActions() {
156 scanAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.rescan")) {
159 @SuppressWarnings("synthetic-access")
160 public void actionPerformed(ActionEvent actionEvent) {
164 scanAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
165 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
167 I18nContainer.getInstance().registerRunnable(new Runnable() {
170 @SuppressWarnings("synthetic-access")
172 scanAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.rescan"));
173 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
182 public void pageAdded(TWizard wizard) {
183 /* create file scanner. */
184 fileScanner = new FileScanner(project, this);
187 this.wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
188 this.wizard.setNextName(I18n.getMessage("jsite.project-files.insert-now"));
189 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
193 * Creates the panel contains the project file list and options.
195 * @return The created panel
197 private JComponent createProjectFilesPanel() {
198 JPanel projectFilesPanel = new JPanel(new BorderLayout(12, 12));
200 projectFileList = new JList();
201 projectFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
202 projectFileList.setMinimumSize(new Dimension(250, projectFileList.getPreferredSize().height));
203 projectFileList.addListSelectionListener(this);
205 projectFilesPanel.add(new JScrollPane(projectFileList), BorderLayout.CENTER);
207 JPanel fileOptionsAlignmentPanel = new JPanel(new BorderLayout(12, 12));
208 projectFilesPanel.add(fileOptionsAlignmentPanel, BorderLayout.PAGE_END);
209 JPanel fileOptionsPanel = new JPanel(new GridBagLayout());
210 fileOptionsAlignmentPanel.add(fileOptionsPanel, BorderLayout.PAGE_START);
212 alwaysForceInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.always-force-insert"));
213 alwaysForceInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.always-force-insert.tooltip"));
214 alwaysForceInsertCheckBox.setName("always-force-insert");
215 alwaysForceInsertCheckBox.addActionListener(this);
216 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));
218 ignoreHiddenFilesCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.ignore-hidden-files"));
219 ignoreHiddenFilesCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.ignore-hidden-files.tooltip"));
220 ignoreHiddenFilesCheckBox.setName("ignore-hidden-files");
221 ignoreHiddenFilesCheckBox.addActionListener(this);
222 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));
224 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));
226 final JLabel fileOptionsLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
227 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));
229 defaultFileCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.default"));
230 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
231 defaultFileCheckBox.setName("default-file");
232 defaultFileCheckBox.addActionListener(this);
233 defaultFileCheckBox.setEnabled(false);
235 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));
237 fileOptionsInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert"), true);
238 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
239 fileOptionsInsertCheckBox.setName("insert");
240 fileOptionsInsertCheckBox.setMnemonic(KeyEvent.VK_I);
241 fileOptionsInsertCheckBox.addActionListener(this);
242 fileOptionsInsertCheckBox.setEnabled(false);
244 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));
246 fileOptionsForceInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.force-insert"));
247 fileOptionsForceInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.force-insert.tooltip"));
248 fileOptionsForceInsertCheckBox.setName("force-insert");
249 fileOptionsForceInsertCheckBox.setMnemonic(KeyEvent.VK_F);
250 fileOptionsForceInsertCheckBox.addActionListener(this);
251 fileOptionsForceInsertCheckBox.setEnabled(false);
253 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));
255 fileOptionsCustomKeyTextField = new JTextField(45);
256 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
257 fileOptionsCustomKeyTextField.setEnabled(false);
258 fileOptionsCustomKeyTextField.getDocument().addDocumentListener(this);
260 fileOptionsInsertRedirectCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert-redirect"), false);
261 fileOptionsInsertRedirectCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert-redirect.tooltip"));
262 fileOptionsInsertRedirectCheckBox.setName("insert-redirect");
263 fileOptionsInsertRedirectCheckBox.setMnemonic(KeyEvent.VK_R);
264 fileOptionsInsertRedirectCheckBox.addActionListener(this);
265 fileOptionsInsertRedirectCheckBox.setEnabled(false);
267 final TLabel customKeyLabel = new TLabel(I18n.getMessage("jsite.project-files.custom-key") + ":", KeyEvent.VK_K, fileOptionsCustomKeyTextField);
268 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));
269 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));
270 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));
272 fileOptionsRenameCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.rename"), false);
273 fileOptionsRenameCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.rename.tooltip"));
274 fileOptionsRenameCheckBox.setName("rename");
275 fileOptionsRenameCheckBox.setMnemonic(KeyEvent.VK_N);
276 fileOptionsRenameCheckBox.addActionListener(this);
277 fileOptionsRenameCheckBox.setEnabled(false);
279 fileOptionsRenameTextField = new JTextField();
280 fileOptionsRenameTextField.setEnabled(false);
281 fileOptionsRenameTextField.getDocument().addDocumentListener(new DocumentListener() {
283 @SuppressWarnings("synthetic-access")
284 private void storeText(DocumentEvent documentEvent) {
285 FileOption fileOption = getSelectedFile();
286 if (fileOption == null) {
287 /* no file selected. */
290 Document document = documentEvent.getDocument();
291 int documentLength = document.getLength();
293 fileOption.setChangedName(document.getText(0, documentLength).trim());
294 } catch (BadLocationException ble1) {
295 /* ignore, it should never happen. */
300 public void changedUpdate(DocumentEvent documentEvent) {
301 storeText(documentEvent);
305 public void insertUpdate(DocumentEvent documentEvent) {
306 storeText(documentEvent);
310 public void removeUpdate(DocumentEvent documentEvent) {
311 storeText(documentEvent);
316 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));
317 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));
319 fileOptionsMIMETypeComboBox = new JComboBox(MimeTypes.getAllMimeTypes().toArray());
320 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
321 fileOptionsMIMETypeComboBox.setName("project-files.mime-type");
322 fileOptionsMIMETypeComboBox.addActionListener(this);
323 fileOptionsMIMETypeComboBox.setEditable(true);
324 fileOptionsMIMETypeComboBox.setEnabled(false);
326 final TLabel mimeTypeLabel = new TLabel(I18n.getMessage("jsite.project-files.mime-type") + ":", KeyEvent.VK_M, fileOptionsMIMETypeComboBox);
327 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));
328 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));
330 /* create dialog to show while scanning. */
331 scanningFilesDialog = new JDialog(wizard);
332 scanningFilesDialog.setModal(true);
333 scanningFilesDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
335 JPanel progressPanel = new JPanel(new BorderLayout(12, 12));
336 scanningFilesDialog.getContentPane().add(progressPanel, BorderLayout.CENTER);
337 progressPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
339 final TLabel scanningLabel = new TLabel(I18n.getMessage("jsite.project-files.scanning"), SwingConstants.CENTER);
340 progressPanel.add(scanningLabel, BorderLayout.NORTH);
341 progressBar = new JProgressBar(SwingConstants.HORIZONTAL);
342 progressPanel.add(progressBar, BorderLayout.SOUTH);
343 progressBar.setIndeterminate(true);
344 progressBar.setStringPainted(true);
345 progressBar.setPreferredSize(new Dimension(progressBar.getPreferredSize().width * 2, progressBar.getPreferredSize().height));
347 scanningFilesDialog.pack();
348 scanningFilesDialog.addWindowListener(new WindowAdapter() {
354 @SuppressWarnings("synthetic-access")
355 public void windowOpened(WindowEvent e) {
356 SwingUtils.center(scanningFilesDialog, wizard);
360 I18nContainer.getInstance().registerRunnable(new Runnable() {
363 @SuppressWarnings("synthetic-access")
365 alwaysForceInsertCheckBox.setText(I18n.getMessage("jsite.project-files.always-force-insert"));
366 alwaysForceInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.always-force-insert.tooltip"));
367 ignoreHiddenFilesCheckBox.setText(I18n.getMessage("jsite.project-files.ignore-hidden-files"));
368 ignoreHiddenFilesCheckBox.setToolTipText(I18n.getMessage("jsite.projet-files.ignore-hidden-files.tooltip"));
369 fileOptionsLabel.setText("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
370 defaultFileCheckBox.setText(I18n.getMessage("jsite.project-files.default"));
371 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
372 fileOptionsInsertCheckBox.setText(I18n.getMessage("jsite.project-files.insert"));
373 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
374 fileOptionsForceInsertCheckBox.setText(I18n.getMessage("jsite.project-files.force-insert"));
375 fileOptionsForceInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.force-insert.tooltip"));
376 fileOptionsInsertRedirectCheckBox.setText(I18n.getMessage("jsite.project-files.insert-redirect"));
377 fileOptionsInsertRedirectCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert-redirect.tooltip"));
378 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
379 customKeyLabel.setText(I18n.getMessage("jsite.project-files.custom-key") + ":");
380 fileOptionsRenameCheckBox.setText("jsite.project-files.rename");
381 fileOptionsRenameCheckBox.setToolTipText("jsite.project-files.rename.tooltip");
382 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
383 mimeTypeLabel.setText(I18n.getMessage("jsite.project-files.mime-type") + ":");
384 scanningLabel.setText(I18n.getMessage("jsite.project-files.scanning"));
388 return projectFilesPanel;
392 * Sets the project whose files to manage.
395 * The project whose files to manage
397 public void setProject(final Project project) {
398 this.project = project;
399 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
400 setDescription(I18n.getMessage("jsite.project-files.description"));
401 ignoreHiddenFilesCheckBox.setSelected(project.isIgnoreHiddenFiles());
402 alwaysForceInsertCheckBox.setSelected(project.isAlwaysForceInsert());
403 I18nContainer.getInstance().registerRunnable(new Runnable() {
407 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
408 setDescription(I18n.getMessage("jsite.project-files.description"));
418 * Rescans the project’s files.
420 private void actionScan() {
421 projectFileList.clearSelection();
422 projectFileList.setListData(new Object[0]);
424 wizard.setNextEnabled(false);
425 wizard.setPreviousEnabled(false);
426 wizard.setQuitEnabled(false);
428 ignoreHiddenFilesCheckBox.setEnabled(false);
429 scanAction.setEnabled(false);
431 delayedNotification = new StoppableDelay(new Runnable() {
434 @SuppressWarnings("synthetic-access")
436 scanningFilesDialog.setVisible(true);
441 @SuppressWarnings("synthetic-access")
443 scanningFilesDialog.setVisible(false);
446 fileScanner.startInBackground();
447 new Thread(delayedNotification).start();
448 new Thread(new Runnable() {
451 @SuppressWarnings("synthetic-access")
453 while (!delayedNotification.isFinished()) {
456 } catch (InterruptedException ie1) {
459 progressBar.setString(fileScanner.getLastFilename());
468 * Updates the file list.
471 public void fileScannerFinished(boolean error, Collection<ScannedFile> files) {
472 delayedNotification.finish();
474 SwingUtilities.invokeLater(new Runnable() {
477 @SuppressWarnings("synthetic-access")
479 projectFileList.setListData(files.toArray());
480 projectFileList.clearSelection();
483 Set<String> entriesToRemove = new HashSet<String>();
484 Iterator<String> filenames = new HashSet<String>(project.getFileOptions().keySet()).iterator();
485 while (filenames.hasNext()) {
486 String filename = filenames.next();
487 boolean found = false;
488 for (ScannedFile scannedFile : files) {
489 if (scannedFile.getFilename().equals(filename)) {
495 entriesToRemove.add(filename);
498 for (String filename : entriesToRemove) {
499 project.setFileOption(filename, null);
502 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.scan-error"), null, JOptionPane.ERROR_MESSAGE);
504 SwingUtilities.invokeLater(new Runnable() {
507 @SuppressWarnings("synthetic-access")
509 wizard.setPreviousEnabled(true);
510 wizard.setNextEnabled(!error);
511 wizard.setQuitEnabled(true);
512 ignoreHiddenFilesCheckBox.setEnabled(true);
513 scanAction.setEnabled(true);
519 * Returns the {@link FileOption file options} for the currently selected
522 * @return The {@link FileOption}s for the selected file, or {@code null} if
523 * no file is selected
525 private FileOption getSelectedFile() {
526 ScannedFile scannedFile = (ScannedFile) projectFileList.getSelectedValue();
527 if (scannedFile == null) {
530 return project.getFileOption(scannedFile.getFilename());
534 // INTERFACE ActionListener
541 public void actionPerformed(ActionEvent actionEvent) {
542 Object source = actionEvent.getSource();
543 if (source instanceof JCheckBox) {
544 String checkboxName = ((JCheckBox) source).getName();
545 if ("ignore-hidden-files".equals(checkboxName)) {
546 project.setIgnoreHiddenFiles(((JCheckBox) source).isSelected());
549 } else if ("always-force-insert".equals(checkboxName)) {
550 project.setAlwaysForceInsert(((JCheckBox) source).isSelected());
555 ScannedFile scannedFile = (ScannedFile) projectFileList.getSelectedValue();
556 if (scannedFile == null) {
559 String filename = scannedFile.getFilename();
560 FileOption fileOption = project.getFileOption(filename);
561 if (source instanceof JCheckBox) {
562 JCheckBox checkBox = (JCheckBox) source;
563 if ("default-file".equals(checkBox.getName())) {
564 if (checkBox.isSelected()) {
565 if (filename.indexOf('/') > -1) {
566 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.invalid-default-file"), null, JOptionPane.ERROR_MESSAGE);
567 checkBox.setSelected(false);
569 project.setIndexFile(filename);
572 if (filename.equals(project.getIndexFile())) {
573 project.setIndexFile(null);
576 } else if ("insert".equals(checkBox.getName())) {
577 boolean isInsert = checkBox.isSelected();
578 fileOption.setInsert(isInsert);
579 fileOptionsInsertRedirectCheckBox.setEnabled(!isInsert);
580 } else if ("force-insert".equals(checkBox.getName())) {
581 boolean isForceInsert = checkBox.isSelected();
582 fileOption.setForceInsert(isForceInsert);
583 } else if ("insert-redirect".equals(checkBox.getName())) {
584 boolean isInsertRedirect = checkBox.isSelected();
585 fileOption.setInsertRedirect(isInsertRedirect);
586 fileOptionsCustomKeyTextField.setEnabled(isInsertRedirect);
587 } else if ("rename".equals(checkBox.getName())) {
588 boolean isRenamed = checkBox.isSelected();
589 fileOptionsRenameTextField.setEnabled(isRenamed);
590 fileOption.setChangedName(isRenamed ? fileOptionsRenameTextField.getText() : "");
592 } else if (source instanceof JComboBox) {
593 JComboBox comboBox = (JComboBox) source;
594 if ("project-files.mime-type".equals(comboBox.getName())) {
595 fileOption.setMimeType((String) comboBox.getSelectedItem());
601 // INTERFACE ListSelectionListener
608 @SuppressWarnings("null")
609 public void valueChanged(ListSelectionEvent e) {
610 ScannedFile scannedFile = (ScannedFile) projectFileList.getSelectedValue();
611 boolean enabled = scannedFile != null;
612 String filename = (scannedFile == null) ? null : scannedFile.getFilename();
613 defaultFileCheckBox.setEnabled(enabled);
614 fileOptionsInsertCheckBox.setEnabled(enabled);
615 fileOptionsRenameCheckBox.setEnabled(enabled);
616 fileOptionsMIMETypeComboBox.setEnabled(enabled);
617 if (filename != null) {
618 FileOption fileOption = project.getFileOption(filename);
619 defaultFileCheckBox.setSelected(filename.equals(project.getIndexFile()));
620 fileOptionsInsertCheckBox.setSelected(fileOption.isInsert());
621 fileOptionsForceInsertCheckBox.setEnabled(!project.isAlwaysForceInsert() && scannedFile.getHash().equals(fileOption.getLastInsertHash()));
622 fileOptionsForceInsertCheckBox.setSelected(fileOption.isForceInsert());
623 fileOptionsInsertRedirectCheckBox.setEnabled(!fileOption.isInsert());
624 fileOptionsInsertRedirectCheckBox.setSelected(fileOption.isInsertRedirect());
625 fileOptionsCustomKeyTextField.setEnabled(fileOption.isInsertRedirect());
626 fileOptionsCustomKeyTextField.setText(fileOption.getCustomKey());
627 fileOptionsRenameCheckBox.setSelected(fileOption.getChangedName().isPresent());
628 fileOptionsRenameTextField.setEnabled(fileOption.getChangedName().isPresent());
629 fileOptionsRenameTextField.setText(fileOption.getChangedName().orElse(""));
630 fileOptionsMIMETypeComboBox.getModel().setSelectedItem(fileOption.getMimeType());
632 defaultFileCheckBox.setSelected(false);
633 fileOptionsInsertCheckBox.setSelected(true);
634 fileOptionsForceInsertCheckBox.setEnabled(false);
635 fileOptionsForceInsertCheckBox.setSelected(false);
636 fileOptionsInsertRedirectCheckBox.setEnabled(false);
637 fileOptionsInsertRedirectCheckBox.setSelected(false);
638 fileOptionsCustomKeyTextField.setEnabled(false);
639 fileOptionsCustomKeyTextField.setText("CHK@");
640 fileOptionsRenameCheckBox.setEnabled(false);
641 fileOptionsRenameCheckBox.setSelected(false);
642 fileOptionsRenameTextField.setEnabled(false);
643 fileOptionsRenameTextField.setText("");
644 fileOptionsMIMETypeComboBox.getModel().setSelectedItem(MimeTypes.DEFAULT_CONTENT_TYPE);
649 // INTERFACE DocumentListener
653 * Updates the options of the currently selected file with the changes made
654 * in the “custom key” textfield.
656 * @param documentEvent
657 * The document event to process
659 private void processDocumentUpdate(DocumentEvent documentEvent) {
660 ScannedFile scannedFile = (ScannedFile) projectFileList.getSelectedValue();
661 if (scannedFile == null) {
664 FileOption fileOption = project.getFileOption(scannedFile.getFilename());
665 Document document = documentEvent.getDocument();
667 String text = document.getText(0, document.getLength());
668 fileOption.setCustomKey(text);
669 } catch (BadLocationException ble1) {
678 public void changedUpdate(DocumentEvent documentEvent) {
679 processDocumentUpdate(documentEvent);
686 public void insertUpdate(DocumentEvent documentEvent) {
687 processDocumentUpdate(documentEvent);
694 public void removeUpdate(DocumentEvent documentEvent) {
695 processDocumentUpdate(documentEvent);