From ee76b8ccdc96c88a6d24094cfe06306de3f66381 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 31 May 2008 23:22:45 +0200 Subject: [PATCH] add override removal add mime type override --- src/net/pterodactylus/jsite/gui/FileManager.java | 94 +++++++++++++++++++--- src/net/pterodactylus/jsite/i18n/jSite.properties | 18 +++++ .../pterodactylus/jsite/i18n/jSite_de.properties | 18 +++++ 3 files changed, 118 insertions(+), 12 deletions(-) diff --git a/src/net/pterodactylus/jsite/gui/FileManager.java b/src/net/pterodactylus/jsite/gui/FileManager.java index b0713a3..9a3a758 100644 --- a/src/net/pterodactylus/jsite/gui/FileManager.java +++ b/src/net/pterodactylus/jsite/gui/FileManager.java @@ -47,6 +47,7 @@ import java.util.logging.Logger; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JCheckBox; +import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; @@ -71,6 +72,7 @@ import net.pterodactylus.jsite.i18n.gui.I18nMenu; import net.pterodactylus.jsite.project.FileOverride; import net.pterodactylus.jsite.project.Project; import net.pterodactylus.jsite.project.ProjectFile; +import net.pterodactylus.util.io.MimeTypes; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.swing.SwingUtils; @@ -159,6 +161,9 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** The “apply mime type override” action. */ private I18nAction applyMimeTypeOverrideAction; + /** The “remove override” action. */ + private I18nAction removeOverrideAction; + /** * Creates a new file manager. * @@ -300,6 +305,16 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr applyMimeTypeOverride(); } }; + removeOverrideAction = new I18nAction("fileManager.menu.item.removeOverride") { + + /** + * {@inheritDoc} + */ + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + removeOverride(); + } + }; } /** @@ -314,6 +329,8 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr overrideMenu.add(applyInsertOverrideAction); overrideMenu.add(applyMimeTypeOverrideAction); + overrideMenu.addSeparator(); + overrideMenu.add(removeOverrideAction); JPanel contentPanel = new JPanel(new BorderLayout(12, 12)); contentPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); @@ -508,13 +525,9 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr return; } logger.log(Level.INFO, "selected insert override: " + insertCheckBox.isSelected()); - TreePath[] selectedPaths = fileTree.getSelectionPaths(); - for (TreePath selectedPath: selectedPaths) { - ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) selectedPath.getLastPathComponent(); - ProjectFile projectFile = projectFileWrapper.getProjectFile(); - if (!projectFile.isFile()) { - continue; - } + List selectedProjectFileWrappers = getSelectedProjectFileWrappers(true); + for (ProjectFileWrapper selectedProjectFileWrapper : selectedProjectFileWrappers) { + ProjectFile projectFile = selectedProjectFileWrapper.getProjectFile(); FileOverride fileOverride = project.getFileOverride(projectFile); if (fileOverride == null) { fileOverride = new FileOverride(); @@ -529,7 +542,63 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr * override for the “mime type” setting for multiple files. */ private void applyMimeTypeOverride() { - /* TODO */ + List allMimeTypes = MimeTypes.getAllMimeTypes(); + allMimeTypes.add(0, null); + JComboBox mimeTypeComboBox = new JComboBox(allMimeTypes.toArray()); + String okString = I18n.get("general.button.okay.name"); + String cancelString = I18n.get("general.button.cancel.name"); + int choice = JOptionPane.showOptionDialog(this, new Object[] { I18n.get("fileManager.dialog.mimeTypeOverride.message"), mimeTypeComboBox }, I18n.get("fileManager.dialog.mimeTypeOverride.title"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] { okString, cancelString }, okString); + if ((choice == JOptionPane.CLOSED_OPTION) || (choice == 1)) { + return; + } + logger.log(Level.FINE, "selected mime type: " + mimeTypeComboBox.getSelectedItem()); + List selectedProjectFileWrappers = getSelectedProjectFileWrappers(true); + for (ProjectFileWrapper selectedProjectFileWrapper : selectedProjectFileWrappers) { + ProjectFile projectFile = selectedProjectFileWrapper.getProjectFile(); + FileOverride fileOverride = project.getFileOverride(projectFile); + if (fileOverride == null) { + fileOverride = new FileOverride(); + project.addFileOverride(projectFile, fileOverride); + } + fileOverride.setContentType((String) mimeTypeComboBox.getSelectedItem()); + } + } + + /** + * Removes the overrides of all selected files. + */ + private void removeOverride() { + String continueString = I18n.get("general.button.continue.name"); + String cancelString = I18n.get("general.button.cancel.name"); + List selectedProjectFileWrappers = getSelectedProjectFileWrappers(true); + int choice = JOptionPane.showOptionDialog(this, I18n.get("fileManager.dialog.removeOverride.message", selectedProjectFileWrappers.size()), I18n.get("fileManager.dialog.removeOverride.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, new Object[] { continueString, cancelString }, continueString); + if ((choice == JOptionPane.CLOSED_OPTION) || (choice == 1)) { + return; + } + for (ProjectFileWrapper selectedProjectFileWrapper : selectedProjectFileWrappers) { + project.removeFileOverride(selectedProjectFileWrapper.getProjectFile()); + } + } + + /** + * Returns all currently selected {@link ProjectFileWrapper}s. + * + * @param filesOnly + * true to return only selected files, + * false to include directories + * @return All selected project file wrappers + */ + private List getSelectedProjectFileWrappers(boolean filesOnly) { + List selectedProjectFileWrappers = new ArrayList(); + TreePath[] selectedPaths = fileTree.getSelectionPaths(); + for (TreePath selectedPath : selectedPaths) { + ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) selectedPath.getLastPathComponent(); + if (filesOnly && !projectFileWrapper.getProjectFile().isFile()) { + continue; + } + selectedProjectFileWrappers.add(projectFileWrapper); + } + return selectedProjectFileWrappers; } // @@ -558,6 +627,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr filePathTextField.setText(""); fileNameTextField.setText(""); fileSizeTextField.setText(""); + overrideAction.setEnabled(false); if ((selectedPaths != null) && (selectedPaths.length == 1)) { Object lastPathComponent = selectedPaths[0].getLastPathComponent(); if (!(lastPathComponent instanceof ProjectFileWrapper)) { @@ -577,8 +647,8 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr fileNameTextField.setText(projectFile.getName()); fileSizeTextField.setText(String.valueOf(projectFile.getSize())); } + overrideAction.setEnabled(true); } else if ((selectedPaths != null) && (selectedPaths.length > 1)) { - /* TODO */ } } @@ -755,7 +825,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr currentProjectFileParent = currentProjectFileParent.getParent(); } while (currentProjectFileParent != null); TreeModelEvent treeModelEvent = new TreeModelEvent(this, parentProjectFileWrappers.toArray(), new int[] { getIndexOfChild(projectFileWrappers.get(changedProjectFileParent), changedProjectFileWrapper) }, new Object[] { changedProjectFileWrapper }); - for (TreeModelListener treeModelListener: treeModelListeners) { + for (TreeModelListener treeModelListener : treeModelListeners) { treeModelListener.treeNodesChanged(treeModelEvent); } } @@ -768,7 +838,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr * @param newRootNode */ protected void fireTreeStructureChanged(ProjectFileWrapper newRootNode) { - for (TreeModelListener treeModelListener: treeModelListeners) { + for (TreeModelListener treeModelListener : treeModelListeners) { treeModelListener.treeStructureChanged(new TreeModelEvent(this, new Object[] { newRootNode })); } } @@ -808,7 +878,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr private void createWrappers(ProjectFile projectFile) { projectFileWrappers.put(projectFile, new ProjectFileWrapper(projectFile)); pathProjectFiles.put(projectFile.getCompletePath(), projectFile); - for (ProjectFile projectFileChild: projectFile.getFiles()) { + for (ProjectFile projectFileChild : projectFile.getFiles()) { if (projectFileChild.isDirectory()) { createWrappers(projectFileChild); } diff --git a/src/net/pterodactylus/jsite/i18n/jSite.properties b/src/net/pterodactylus/jsite/i18n/jSite.properties index 3a2061e..faf2c71 100644 --- a/src/net/pterodactylus/jsite/i18n/jSite.properties +++ b/src/net/pterodactylus/jsite/i18n/jSite.properties @@ -14,6 +14,12 @@ general.button.okay.accelerator: Ctrl-VK_O general.button.okay.shortDescription: Confirm general.button.okay.longDescription: Confirm and close dialog +general.button.continue.name: Continue +general.button.continue.mnemonic: VK_C +general.button.continue.accelerator: VK_UNDEFINED +general.button.continue.shortDescription: Continue +general.button.continue.longDescription: Continue with the action + general.button.cancel.name: Cancel general.button.cancel.mnemonic: VK_C general.button.cancel.accelerator: VK_ESCAPE @@ -406,5 +412,17 @@ fileManager.menu.item.applyMimeTypeOverride.accelerator: Ctrl-VK_C fileManager.menu.item.applyMimeTypeOverride.shortDescription: Overrides default \u201cContent Type\u201d setting fileManager.menu.item.applyMimeTypeOverride.longDescription: Overrides default \u201cContent Type\u201d setting +fileManager.menu.item.removeOverride.name: Remove +fileManager.menu.item.removeOverride.mnemonic: VK_R +fileManager.menu.item.removeOverride.accelerator: VK_UNDEFINED +fileManager.menu.item.removeOverride.shortDescription: Removes the override from the selected files +fileManager.menu.item.removeOverride.longDescription: Removes the override from the selected files + fileManager.dialog.insertOverride.title: Apply Insert Override fileManager.dialog.insertOverride.message: Please choose a setting for the \u201cInsert\u201d override. + +fileManager.dialog.mimeTypeOverride.title: Apply MIME Type Override +fileManager.dialog.mimeTypeOverride.message: Please choose an override MIME type. + +fileManager.dialog.removeOverride.title: Remove Override? +fileManager.dialog.removeOverride.message: You are about to remove the override for the {0} selected file{0,choice,0#s|1#|2#s}. diff --git a/src/net/pterodactylus/jsite/i18n/jSite_de.properties b/src/net/pterodactylus/jsite/i18n/jSite_de.properties index 47e5a53..5579c27 100644 --- a/src/net/pterodactylus/jsite/i18n/jSite_de.properties +++ b/src/net/pterodactylus/jsite/i18n/jSite_de.properties @@ -14,6 +14,12 @@ general.button.okay.accelerator: Ctrl-VK_O general.button.okay.shortDescription: \u00c4nderungen akzeptieren general.button.okay.longDescription: Dialog schlie\u00dfen und \u00c4nderungen akzeptieren +general.button.continue.name: Weiter +general.button.continue.mnemonic: VK_W +general.button.continue.accelerator: VK_UNDEFINED +general.button.continue.shortDescription: Weiter +general.button.continue.longDescription: Setzt die Aktion fort + general.button.cancel.name: Abbrechen general.button.cancel.mnemonic: VK_B general.button.cancel.accelerator: VK_ESCAPE @@ -406,5 +412,17 @@ fileManager.menu.item.applyMimeTypeOverride.accelerator: Ctrl-VK_M fileManager.menu.item.applyMimeTypeOverride.shortDescription: \u00dcberschreibt die \u201eMIME-Typ\u201c-Einstellung fileManager.menu.item.applyMimeTypeOverride.longDescription: \u00dcberschreibt die \u201eMIME-Typ\u201c-Einstellung +fileManager.menu.item.removeOverride.name: Entfernen +fileManager.menu.item.removeOverride.mnemonic: VK_N +fileManager.menu.item.removeOverride.accelerator: VK_UNDEFINED +fileManager.menu.item.removeOverride.shortDescription: Entfernt die \u00dcberschreibung der ausgew\u00e4hlten Dateien +fileManager.menu.item.removeOverride.longDescription: Entfernt die \u00dcberschreibung der ausgew\u00e4hlten Dateien + fileManager.dialog.insertOverride.title: \u201eEinf\u00fcgen\u201c-Einstellung \u00fcberschreiben fileManager.dialog.insertOverride.message: Bitte eine Option zum \u00dcberschreiben der \u201eEinf\u00fcgen\u201c-Einstellung ausw\u00e4hlen. + +fileManager.dialog.mimeTypeOverride.title: \u201eMIME-Typ\u201c-Einstellung \u00fcberschreiben +fileManager.dialog.mimeTypeOverride.message: Bitte einen MIME-Typ zum \u00dcberschreiben ausw\u00e4hlen. + +fileManager.dialog.removeOverride.title: \u00dcberschreibungen entfernen? +fileManager.dialog.removeOverride.message: Die \u00dcberschreibungen f\u00fcr {0} Datei{0,choice,0#en|1#|2#en} werden entfernt. -- 2.7.4