2 * jSite - a tool for uploading websites into Freenet
3 * Copyright (C) 2006 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package de.todesbaum.jsite.gui;
22 import java.awt.BorderLayout;
23 import java.awt.Dimension;
24 import java.awt.FlowLayout;
25 import java.awt.GridBagConstraints;
26 import java.awt.GridBagLayout;
27 import java.awt.Insets;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import java.awt.event.KeyEvent;
31 import java.text.MessageFormat;
32 import java.util.ArrayList;
33 import java.util.Collections;
34 import java.util.HashSet;
35 import java.util.Iterator;
36 import java.util.List;
39 import javax.swing.AbstractAction;
40 import javax.swing.Action;
41 import javax.swing.DefaultComboBoxModel;
42 import javax.swing.JButton;
43 import javax.swing.JCheckBox;
44 import javax.swing.JComboBox;
45 import javax.swing.JComponent;
46 import javax.swing.JLabel;
47 import javax.swing.JList;
48 import javax.swing.JOptionPane;
49 import javax.swing.JPanel;
50 import javax.swing.JScrollPane;
51 import javax.swing.JSpinner;
52 import javax.swing.JTextField;
53 import javax.swing.ListSelectionModel;
54 import javax.swing.SpinnerNumberModel;
55 import javax.swing.SwingUtilities;
56 import javax.swing.border.EmptyBorder;
57 import javax.swing.event.ChangeEvent;
58 import javax.swing.event.ChangeListener;
59 import javax.swing.event.DocumentEvent;
60 import javax.swing.event.DocumentListener;
61 import javax.swing.event.ListSelectionEvent;
62 import javax.swing.event.ListSelectionListener;
63 import javax.swing.text.BadLocationException;
64 import javax.swing.text.Document;
66 import de.todesbaum.jsite.application.FileOption;
67 import de.todesbaum.jsite.application.Project;
68 import de.todesbaum.jsite.i18n.I18n;
69 import de.todesbaum.jsite.i18n.I18nContainer;
70 import de.todesbaum.util.mime.DefaultMIMETypes;
71 import de.todesbaum.util.swing.TLabel;
72 import de.todesbaum.util.swing.TWizard;
73 import de.todesbaum.util.swing.TWizardPage;
76 * Wizard page that lets the user manage the files of a project.
78 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
80 public class ProjectFilesPage extends TWizardPage implements ActionListener, ListSelectionListener, DocumentListener, FileScannerListener, ChangeListener {
83 private Project project;
85 /** The “scan files” action. */
86 private Action scanAction;
88 /** The “edit container” action. */
89 private Action editContainerAction;
91 /** The “add container” action. */
92 private Action addContainerAction;
94 /** The “delete container” action. */
95 protected Action deleteContainerAction;
97 /** The “ignore hidden files” checkbox. */
98 private JCheckBox ignoreHiddenFilesCheckBox;
100 /** The list of project files. */
101 private JList projectFileList;
103 /** The “default file” checkbox. */
104 private JCheckBox defaultFileCheckBox;
106 /** The “insert” checkbox. */
107 private JCheckBox fileOptionsInsertCheckBox;
109 /** The “insert redirect” checkbox. */
110 private JCheckBox fileOptionsInsertRedirectCheckBox;
112 /** The “custom key” textfield. */
113 private JTextField fileOptionsCustomKeyTextField;
115 /** The “rename” check box. */
116 private JCheckBox fileOptionsRenameCheckBox;
118 /** The “new name” text field. */
119 private JTextField fileOptionsRenameTextField;
121 /** The “mime type” combo box. */
122 private JComboBox fileOptionsMIMETypeComboBox;
124 /** The “mime type” combo box model. */
125 private DefaultComboBoxModel containerComboBoxModel;
127 /** The “container” combo box. */
128 private JComboBox fileOptionsContainerComboBox;
130 /** The “edition replacement range” spinner. */
131 private JSpinner replaceEditionRangeSpinner;
133 /** The “replacement” check box. */
134 private JCheckBox replacementCheckBox;
137 * Creates a new project file page.
140 * The wizard the page belongs to
142 public ProjectFilesPage(final TWizard wizard) {
148 * Initializes the page and all its actions and components.
150 private void pageInit() {
152 setLayout(new BorderLayout(12, 12));
153 add(createProjectFilesPanel(), BorderLayout.CENTER);
157 * Creates all actions.
159 private void createActions() {
160 scanAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.rescan")) {
162 @SuppressWarnings("synthetic-access")
163 public void actionPerformed(ActionEvent actionEvent) {
167 scanAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
168 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
170 addContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.add-container")) {
172 @SuppressWarnings("synthetic-access")
173 public void actionPerformed(ActionEvent actionEvent) {
174 actionAddContainer();
177 addContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.add-container.tooltip"));
178 addContainerAction.setEnabled(false);
180 editContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.edit-container")) {
182 @SuppressWarnings("synthetic-access")
183 public void actionPerformed(ActionEvent actionEvent) {
184 actionEditContainer();
187 editContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.edit-container.tooltip"));
188 editContainerAction.setEnabled(false);
190 deleteContainerAction = new AbstractAction(I18n.getMessage("jsite.project-files.action.delete-container")) {
192 @SuppressWarnings("synthetic-access")
193 public void actionPerformed(ActionEvent actionEvent) {
194 actionDeleteContainer();
197 deleteContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.delete-container.tooltip"));
198 deleteContainerAction.setEnabled(false);
200 I18nContainer.getInstance().registerRunnable(new Runnable() {
202 @SuppressWarnings("synthetic-access")
204 scanAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.rescan"));
205 scanAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.rescan.tooltip"));
206 addContainerAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.add-container"));
207 addContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.add-container.tooltip"));
208 editContainerAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.edit-container"));
209 editContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.edit-container.tooltip"));
210 deleteContainerAction.putValue(Action.NAME, I18n.getMessage("jsite.project-files.action.delete-container"));
211 deleteContainerAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project-files.action.delete-container.tooltip"));
220 public void pageAdded(TWizard wizard) {
222 this.wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
223 this.wizard.setNextName(I18n.getMessage("jsite.project-files.insert-now"));
224 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
228 * Creates the panel contains the project file list and options.
230 * @return The created panel
232 private JComponent createProjectFilesPanel() {
233 JPanel projectFilesPanel = new JPanel(new BorderLayout(12, 12));
235 projectFileList = new JList();
236 projectFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
237 projectFileList.setMinimumSize(new Dimension(250, projectFileList.getPreferredSize().height));
238 projectFileList.addListSelectionListener(this);
240 projectFilesPanel.add(new JScrollPane(projectFileList), BorderLayout.CENTER);
242 JPanel fileOptionsAlignmentPanel = new JPanel(new BorderLayout(12, 12));
243 projectFilesPanel.add(fileOptionsAlignmentPanel, BorderLayout.PAGE_END);
244 JPanel fileOptionsPanel = new JPanel(new GridBagLayout());
245 fileOptionsAlignmentPanel.add(fileOptionsPanel, BorderLayout.PAGE_START);
247 ignoreHiddenFilesCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.ignore-hidden-files"));
248 ignoreHiddenFilesCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.ignore-hidden-files.tooltip"));
249 ignoreHiddenFilesCheckBox.setName("ignore-hidden-files");
250 ignoreHiddenFilesCheckBox.addActionListener(this);
251 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));
253 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));
255 final JLabel fileOptionsLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
256 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));
258 defaultFileCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.default"));
259 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
260 defaultFileCheckBox.setName("default-file");
261 defaultFileCheckBox.addActionListener(this);
262 defaultFileCheckBox.setEnabled(false);
264 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));
266 fileOptionsInsertCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert"), true);
267 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
268 fileOptionsInsertCheckBox.setName("insert");
269 fileOptionsInsertCheckBox.setMnemonic(KeyEvent.VK_I);
270 fileOptionsInsertCheckBox.addActionListener(this);
271 fileOptionsInsertCheckBox.setEnabled(false);
273 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));
275 fileOptionsCustomKeyTextField = new JTextField(45);
276 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
277 fileOptionsCustomKeyTextField.setEnabled(false);
278 fileOptionsCustomKeyTextField.getDocument().addDocumentListener(this);
280 fileOptionsInsertRedirectCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.insert-redirect"), false);
281 fileOptionsInsertRedirectCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert-redirect.tooltip"));
282 fileOptionsInsertRedirectCheckBox.setName("insert-redirect");
283 fileOptionsInsertRedirectCheckBox.setMnemonic(KeyEvent.VK_R);
284 fileOptionsInsertRedirectCheckBox.addActionListener(this);
285 fileOptionsInsertRedirectCheckBox.setEnabled(false);
287 final TLabel customKeyLabel = new TLabel(I18n.getMessage("jsite.project-files.custom-key") + ":", KeyEvent.VK_K, fileOptionsCustomKeyTextField);
288 fileOptionsPanel.add(fileOptionsInsertRedirectCheckBox, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
289 fileOptionsPanel.add(customKeyLabel, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 6, 0, 0), 0, 0));
290 fileOptionsPanel.add(fileOptionsCustomKeyTextField, new GridBagConstraints(2, 5, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
292 fileOptionsRenameCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.rename"), false);
293 fileOptionsRenameCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.rename.tooltip"));
294 fileOptionsRenameCheckBox.setName("rename");
295 fileOptionsRenameCheckBox.setMnemonic(KeyEvent.VK_N);
296 fileOptionsRenameCheckBox.addActionListener(this);
297 fileOptionsRenameCheckBox.setEnabled(false);
299 fileOptionsRenameTextField = new JTextField();
300 fileOptionsRenameTextField.setEnabled(false);
301 fileOptionsRenameTextField.getDocument().addDocumentListener(new DocumentListener() {
303 @SuppressWarnings("synthetic-access")
304 private void storeText(DocumentEvent documentEvent) {
305 FileOption fileOption = getSelectedFile();
306 Document document = documentEvent.getDocument();
307 int documentLength = document.getLength();
309 fileOption.setChangedName(document.getText(0, documentLength).trim());
310 } catch (BadLocationException ble1) {
311 /* ignore, it should never happen. */
315 public void changedUpdate(DocumentEvent documentEvent) {
316 storeText(documentEvent);
319 public void insertUpdate(DocumentEvent documentEvent) {
320 storeText(documentEvent);
323 public void removeUpdate(DocumentEvent documentEvent) {
324 storeText(documentEvent);
329 fileOptionsPanel.add(fileOptionsRenameCheckBox, new GridBagConstraints(0, 6, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
330 fileOptionsPanel.add(fileOptionsRenameTextField, new GridBagConstraints(2, 6, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
332 fileOptionsMIMETypeComboBox = new JComboBox(DefaultMIMETypes.getAllMIMETypes());
333 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
334 fileOptionsMIMETypeComboBox.setName("project-files.mime-type");
335 fileOptionsMIMETypeComboBox.addActionListener(this);
336 fileOptionsMIMETypeComboBox.setEditable(true);
337 fileOptionsMIMETypeComboBox.setEnabled(false);
339 final TLabel mimeTypeLabel = new TLabel(I18n.getMessage("jsite.project-files.mime-type") + ":", KeyEvent.VK_M, fileOptionsMIMETypeComboBox);
340 fileOptionsPanel.add(mimeTypeLabel, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
341 fileOptionsPanel.add(fileOptionsMIMETypeComboBox, new GridBagConstraints(1, 7, 4, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
343 containerComboBoxModel = new DefaultComboBoxModel();
344 fileOptionsContainerComboBox = new JComboBox(containerComboBoxModel);
345 fileOptionsContainerComboBox.setToolTipText(I18n.getMessage("jsite.project-files.container.tooltip"));
346 fileOptionsContainerComboBox.setName("project-files.container");
347 fileOptionsContainerComboBox.addActionListener(this);
348 fileOptionsContainerComboBox.setEnabled(false);
349 fileOptionsContainerComboBox.setVisible(false);
351 final TLabel containerLabel = new TLabel(I18n.getMessage("jsite.project-files.container") + ":", KeyEvent.VK_C, fileOptionsContainerComboBox);
352 containerLabel.setVisible(false);
353 JButton addContainerButton = new JButton(addContainerAction);
354 addContainerButton.setVisible(false);
355 JButton editContainerButton = new JButton(editContainerAction);
356 editContainerButton.setVisible(false);
357 JButton deleteContainerButton = new JButton(deleteContainerAction);
358 deleteContainerButton.setVisible(false);
359 fileOptionsPanel.add(containerLabel, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
360 fileOptionsPanel.add(fileOptionsContainerComboBox, new GridBagConstraints(1, 8, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
361 fileOptionsPanel.add(addContainerButton, new GridBagConstraints(2, 8, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
362 fileOptionsPanel.add(editContainerButton, new GridBagConstraints(3, 8, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
363 fileOptionsPanel.add(deleteContainerButton, new GridBagConstraints(4, 8, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
365 JPanel fileOptionsReplacementPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 6, 6));
366 fileOptionsReplacementPanel.setBorder(new EmptyBorder(-6, -6, -6, -6));
368 replacementCheckBox = new JCheckBox(I18n.getMessage("jsite.project-files.replacement"));
369 replacementCheckBox.setName("project-files.replace-edition");
370 replacementCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.replacement.tooltip"));
371 replacementCheckBox.addActionListener(this);
372 replacementCheckBox.setEnabled(false);
373 replacementCheckBox.setVisible(false);
374 fileOptionsReplacementPanel.add(replacementCheckBox);
376 replaceEditionRangeSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 99, 1));
377 replaceEditionRangeSpinner.setName("project-files.replace-edition-range");
378 replaceEditionRangeSpinner.setToolTipText(I18n.getMessage("jsite.project-files.replacement.edition-range.tooltip"));
379 replaceEditionRangeSpinner.addChangeListener(this);
380 replaceEditionRangeSpinner.setEnabled(false);
381 replaceEditionRangeSpinner.setVisible(false);
382 final JLabel editionRangeLabel = new JLabel(I18n.getMessage("jsite.project-files.replacement.edition-range"));
383 editionRangeLabel.setVisible(false);
384 fileOptionsReplacementPanel.add(editionRangeLabel);
385 fileOptionsReplacementPanel.add(replaceEditionRangeSpinner);
387 fileOptionsPanel.add(fileOptionsReplacementPanel, new GridBagConstraints(0, 9, 5, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 18, 0, 0), 0, 0));
389 I18nContainer.getInstance().registerRunnable(new Runnable() {
391 @SuppressWarnings("synthetic-access")
393 ignoreHiddenFilesCheckBox.setText(I18n.getMessage("jsite.project-files.ignore-hidden-files"));
394 ignoreHiddenFilesCheckBox.setToolTipText(I18n.getMessage("jsite.projet-files.ignore-hidden-files.tooltip"));
395 fileOptionsLabel.setText("<html><b>" + I18n.getMessage("jsite.project-files.file-options") + "</b></html>");
396 defaultFileCheckBox.setText(I18n.getMessage("jsite.project-files.default"));
397 defaultFileCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.default.tooltip"));
398 fileOptionsInsertCheckBox.setText(I18n.getMessage("jsite.project-files.insert"));
399 fileOptionsInsertCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert.tooltip"));
400 fileOptionsInsertRedirectCheckBox.setText(I18n.getMessage("jsite.project-files.insert-redirect"));
401 fileOptionsInsertRedirectCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.insert-redirect.tooltip"));
402 fileOptionsCustomKeyTextField.setToolTipText(I18n.getMessage("jsite.project-files.custom-key.tooltip"));
403 customKeyLabel.setText(I18n.getMessage("jsite.project-files.custom-key") + ":");
404 fileOptionsRenameCheckBox.setText("jsite.project-files.rename");
405 fileOptionsRenameCheckBox.setToolTipText("jsite.project-files.rename.tooltip");
406 fileOptionsMIMETypeComboBox.setToolTipText(I18n.getMessage("jsite.project-files.mime-type.tooltip"));
407 mimeTypeLabel.setText(I18n.getMessage("jsite.project-files.mime-type") + ":");
408 fileOptionsContainerComboBox.setToolTipText(I18n.getMessage("jsite.project-files.container.tooltip"));
409 containerLabel.setText(I18n.getMessage("jsite.project-files.container") + ":");
410 replacementCheckBox.setText(I18n.getMessage("jsite.project-files.replacement"));
411 replacementCheckBox.setToolTipText(I18n.getMessage("jsite.project-files.replacement.tooltip"));
412 replaceEditionRangeSpinner.setToolTipText(I18n.getMessage("jsite.project-files.replacement.edition-range.tooltip"));
413 editionRangeLabel.setText(I18n.getMessage("jsite.project-files.replacement.edition-range"));
417 return projectFilesPanel;
421 * Sets the project whose files to manage.
424 * The project whose files to manage
426 public void setProject(final Project project) {
427 this.project = project;
428 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
429 setDescription(I18n.getMessage("jsite.project-files.description"));
430 ignoreHiddenFilesCheckBox.setSelected(project.isIgnoreHiddenFiles());
431 I18nContainer.getInstance().registerRunnable(new Runnable() {
434 setHeading(MessageFormat.format(I18n.getMessage("jsite.project-files.heading"), project.getName()));
435 setDescription(I18n.getMessage("jsite.project-files.description"));
441 * Returns a list of all project files.
443 * @return All project files
445 private List<String> getProjectFiles() {
446 List<String> files = new ArrayList<String>();
447 for (int index = 0, size = projectFileList.getModel().getSize(); index < size; index++) {
448 files.add((String) projectFileList.getModel().getElementAt(index));
454 * Updates the container combo box model.
456 private void rebuildContainerComboBox() {
457 /* scan files for containers */
458 List<String> files = getProjectFiles();
459 List<String> containers = new ArrayList<String>(); // ComboBoxModel
463 for (String filename : files) {
464 String container = project.getFileOption(filename).getContainer();
465 if (!containers.contains(container)) {
466 containers.add(container);
469 Collections.sort(containers);
470 containerComboBoxModel.removeAllElements();
471 for (String container : containers) {
472 containerComboBoxModel.addElement(container);
481 * Rescans the project’s files.
483 private void actionScan() {
484 projectFileList.clearSelection();
485 projectFileList.setListData(new Object[0]);
487 wizard.setNextEnabled(false);
488 wizard.setPreviousEnabled(false);
489 wizard.setQuitEnabled(false);
491 FileScanner fileScanner = new FileScanner(project);
492 fileScanner.addFileScannerListener(this);
493 new Thread(fileScanner).start();
499 private void actionAddContainer() {
500 String containerName = JOptionPane.showInputDialog(wizard, I18n.getMessage("jsite.project-files.action.add-container.message") + ":", null, JOptionPane.INFORMATION_MESSAGE);
501 if (containerName == null) {
504 containerName = containerName.trim();
505 String filename = (String) projectFileList.getSelectedValue();
506 FileOption fileOption = project.getFileOption(filename);
507 fileOption.setContainer(containerName);
508 rebuildContainerComboBox();
509 fileOptionsContainerComboBox.setSelectedItem(containerName);
513 * Edits the container.
515 private void actionEditContainer() {
516 String selectedFilename = (String) projectFileList.getSelectedValue();
517 FileOption fileOption = project.getFileOption(selectedFilename);
518 String oldContainerName = fileOption.getContainer();
519 String containerName = JOptionPane.showInputDialog(wizard, I18n.getMessage("jsite.project-files.action.edit-container.message") + ":", oldContainerName);
520 if (containerName == null) {
523 if (containerName.equals("")) {
524 fileOption.setContainer("");
525 fileOptionsContainerComboBox.setSelectedItem("");
528 List<String> files = getProjectFiles();
529 for (String filename : files) {
530 fileOption = project.getFileOption(filename);
531 if (fileOption.getContainer().equals(oldContainerName)) {
532 fileOption.setContainer(containerName);
535 rebuildContainerComboBox();
536 fileOptionsContainerComboBox.setSelectedItem(containerName);
540 * Deletes the container.
542 private void actionDeleteContainer() {
543 if (JOptionPane.showConfirmDialog(wizard, I18n.getMessage("jsite.project-files.action.delete-container.message"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
544 String containerName = (String) fileOptionsContainerComboBox.getSelectedItem();
545 List<String> files = getProjectFiles();
546 for (String filename : files) {
547 FileOption fileOption = project.getFileOption(filename);
548 if (fileOption.getContainer().equals(containerName)) {
549 fileOption.setContainer("");
552 fileOptionsContainerComboBox.setSelectedItem("");
559 * Updates the file list.
561 public void fileScannerFinished(FileScanner fileScanner) {
562 final boolean error = fileScanner.isError();
564 final List<String> files = fileScanner.getFiles();
565 SwingUtilities.invokeLater(new Runnable() {
567 @SuppressWarnings("synthetic-access")
569 projectFileList.setListData(files.toArray(new String[files.size()]));
570 projectFileList.clearSelection();
571 rebuildContainerComboBox();
574 Set<String> entriesToRemove = new HashSet<String>();
575 Iterator<String> filenames = new HashSet<String>(project.getFileOptions().keySet()).iterator();
576 while (filenames.hasNext()) {
577 String filename = filenames.next();
578 if (!files.contains(filename)) {
579 entriesToRemove.add(filename);
582 for (String filename : entriesToRemove) {
583 project.setFileOption(filename, null);
586 JOptionPane.showMessageDialog(wizard, I18n.getMessage("jsite.project-files.scan-error"), null, JOptionPane.ERROR_MESSAGE);
588 SwingUtilities.invokeLater(new Runnable() {
590 @SuppressWarnings("synthetic-access")
592 wizard.setPreviousEnabled(true);
593 wizard.setNextEnabled(!error);
594 wizard.setQuitEnabled(true);
600 * Returns the {@link FileOption file options} for the currently selected
603 * @return The {@link FileOption}s for the selected file, or {@code null} if
604 * no file is selected
606 private FileOption getSelectedFile() {
607 String filename = (String) projectFileList.getSelectedValue();
608 if (filename == null) {
611 return project.getFileOption(filename);
615 // INTERFACE ActionListener
621 public void actionPerformed(ActionEvent actionEvent) {
622 Object source = actionEvent.getSource();
623 if ((source instanceof JCheckBox) && ("ignore-hidden-files".equals(((JCheckBox) source).getName()))) {
624 project.setIgnoreHiddenFiles(((JCheckBox) source).isSelected());
628 String filename = (String) projectFileList.getSelectedValue();
629 if (filename == null) {
632 FileOption fileOption = project.getFileOption(filename);
633 if (source instanceof JCheckBox) {
634 JCheckBox checkBox = (JCheckBox) source;
635 if ("default-file".equals(checkBox.getName())) {
636 if (checkBox.isSelected()) {
637 project.setIndexFile(filename);
639 project.setIndexFile(null);
641 } else if ("insert".equals(checkBox.getName())) {
642 boolean isInsert = checkBox.isSelected();
643 fileOption.setInsert(isInsert);
645 fileOptionsContainerComboBox.setSelectedItem("");
647 fileOptionsInsertRedirectCheckBox.setEnabled(!isInsert);
648 } else if ("insert-redirect".equals(checkBox.getName())) {
649 boolean isInsertRedirect = checkBox.isSelected();
650 fileOption.setInsertRedirect(isInsertRedirect);
651 fileOptionsCustomKeyTextField.setEnabled(isInsertRedirect);
652 } else if ("rename".equals(checkBox.getName())) {
653 boolean isRenamed = checkBox.isSelected();
654 fileOptionsRenameTextField.setEnabled(isRenamed);
655 fileOption.setChangedName(isRenamed ? fileOptionsRenameTextField.getText() : "");
656 } else if ("project-files.replace-edition".equals(checkBox.getName())) {
657 boolean replaceEdition = checkBox.isSelected();
658 fileOption.setReplaceEdition(replaceEdition);
659 replaceEditionRangeSpinner.setEnabled(replaceEdition);
661 } else if (source instanceof JComboBox) {
662 JComboBox comboBox = (JComboBox) source;
663 if ("project-files.mime-type".equals(comboBox.getName())) {
664 fileOption.setMimeType((String) comboBox.getSelectedItem());
665 } else if ("project-files.container".equals(comboBox.getName())) {
666 String containerName = (String) comboBox.getSelectedItem();
667 fileOption.setContainer(containerName);
668 boolean enabled = !"".equals(containerName);
669 editContainerAction.setEnabled(enabled);
670 deleteContainerAction.setEnabled(enabled);
672 fileOptionsInsertCheckBox.setSelected(true);
679 // INTERFACE ListSelectionListener
685 public void valueChanged(ListSelectionEvent e) {
686 String filename = (String) projectFileList.getSelectedValue();
687 boolean enabled = filename != null;
688 boolean insert = fileOptionsInsertCheckBox.isSelected();
689 defaultFileCheckBox.setEnabled(enabled);
690 fileOptionsInsertCheckBox.setEnabled(enabled);
691 fileOptionsRenameCheckBox.setEnabled(enabled);
692 fileOptionsMIMETypeComboBox.setEnabled(enabled);
693 fileOptionsContainerComboBox.setEnabled(enabled);
694 addContainerAction.setEnabled(enabled);
695 editContainerAction.setEnabled(enabled);
696 deleteContainerAction.setEnabled(enabled);
697 replacementCheckBox.setEnabled(enabled && insert);
698 if (filename != null) {
699 FileOption fileOption = project.getFileOption(filename);
700 defaultFileCheckBox.setSelected(filename.equals(project.getIndexFile()));
701 fileOptionsInsertCheckBox.setSelected(fileOption.isInsert());
702 fileOptionsInsertRedirectCheckBox.setEnabled(!fileOption.isInsert());
703 fileOptionsInsertRedirectCheckBox.setSelected(fileOption.isInsertRedirect());
704 fileOptionsCustomKeyTextField.setEnabled(fileOption.isInsertRedirect());
705 fileOptionsCustomKeyTextField.setText(fileOption.getCustomKey());
706 fileOptionsRenameCheckBox.setSelected(fileOption.hasChangedName());
707 fileOptionsRenameTextField.setEnabled(fileOption.hasChangedName());
708 fileOptionsRenameTextField.setText(fileOption.getChangedName());
709 fileOptionsMIMETypeComboBox.getModel().setSelectedItem(fileOption.getMimeType());
710 fileOptionsContainerComboBox.setSelectedItem(fileOption.getContainer());
711 replacementCheckBox.setSelected(fileOption.getReplaceEdition());
712 replaceEditionRangeSpinner.setValue(fileOption.getEditionRange());
713 replaceEditionRangeSpinner.setEnabled(fileOption.getReplaceEdition());
715 defaultFileCheckBox.setSelected(false);
716 fileOptionsInsertCheckBox.setSelected(true);
717 fileOptionsInsertRedirectCheckBox.setEnabled(false);
718 fileOptionsInsertRedirectCheckBox.setSelected(false);
719 fileOptionsCustomKeyTextField.setEnabled(false);
720 fileOptionsCustomKeyTextField.setText("CHK@");
721 fileOptionsRenameCheckBox.setEnabled(false);
722 fileOptionsRenameCheckBox.setSelected(false);
723 fileOptionsRenameTextField.setEnabled(false);
724 fileOptionsRenameTextField.setText("");
725 fileOptionsMIMETypeComboBox.getModel().setSelectedItem(DefaultMIMETypes.DEFAULT_MIME_TYPE);
726 fileOptionsContainerComboBox.setSelectedItem("");
727 replacementCheckBox.setSelected(false);
728 replaceEditionRangeSpinner.setValue(0);
733 // INTERFACE DocumentListener
737 * Updates the options of the currently selected file with the changes made
738 * in the “custom key” textfield.
740 * @param documentEvent
741 * The document event to process
743 private void processDocumentUpdate(DocumentEvent documentEvent) {
744 String filename = (String) projectFileList.getSelectedValue();
745 if (filename == null) {
748 FileOption fileOption = project.getFileOption(filename);
749 Document document = documentEvent.getDocument();
751 String text = document.getText(0, document.getLength());
752 fileOption.setCustomKey(text);
753 } catch (BadLocationException ble1) {
761 public void changedUpdate(DocumentEvent documentEvent) {
762 processDocumentUpdate(documentEvent);
768 public void insertUpdate(DocumentEvent documentEvent) {
769 processDocumentUpdate(documentEvent);
775 public void removeUpdate(DocumentEvent documentEvent) {
776 processDocumentUpdate(documentEvent);
780 // INTERFACE ChangeListener
786 public void stateChanged(ChangeEvent changeEvent) {
787 String filename = (String) projectFileList.getSelectedValue();
788 if (filename == null) {
791 FileOption fileOption = project.getFileOption(filename);
792 Object source = changeEvent.getSource();
793 if (source instanceof JSpinner) {
794 JSpinner spinner = (JSpinner) source;
795 fileOption.setEditionRange((Integer) spinner.getValue());