From b2b988f8db27bedf00c1c87895b20032d282215e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 2 Jun 2008 18:17:21 +0200 Subject: [PATCH] continue work on file manager --- src/net/pterodactylus/jsite/gui/FileManager.java | 160 +++++++++++++++++++-- src/net/pterodactylus/jsite/i18n/jSite.properties | 16 ++- .../pterodactylus/jsite/i18n/jSite_de.properties | 18 ++- 3 files changed, 179 insertions(+), 15 deletions(-) diff --git a/src/net/pterodactylus/jsite/gui/FileManager.java b/src/net/pterodactylus/jsite/gui/FileManager.java index e513d23..6771487 100644 --- a/src/net/pterodactylus/jsite/gui/FileManager.java +++ b/src/net/pterodactylus/jsite/gui/FileManager.java @@ -46,6 +46,7 @@ import javax.swing.AbstractAction; import javax.swing.AbstractButton; import javax.swing.Action; import javax.swing.BorderFactory; +import javax.swing.ComboBoxModel; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; @@ -57,6 +58,7 @@ import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.JTree; +import javax.swing.event.ListDataListener; import javax.swing.event.TreeModelEvent; import javax.swing.event.TreeModelListener; import javax.swing.event.TreeSelectionEvent; @@ -138,8 +140,8 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** The “file size” text field. */ private JTextField fileSizeTextField; - /** The “override” label. */ - private I18nLabel fileSettingsLabel; + /** The “insert settings” label. */ + private I18nLabel insertSettingsLabel; /** The “insert default” label. */ private I18nLabel insertDefaultLabel; @@ -159,6 +161,27 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe /** The “override insert” checkbox. */ private JCheckBox insertOverrideCheckBox; + /** The “content type settings” label. */ + private I18nLabel contentTypeSettingsLabel; + + /** The “content type default” label. */ + private I18nLabel contentTypeDefaultLabel; + + /** The “content type default” text field. */ + private JTextField contentTypeDefaultTextField; + + /** The “override content type default” action. */ + private I18nAction overrideContentTypeDefaultAction; + + /** The “override content type default” checkbox. */ + private JCheckBox overrideContentTypeDefaultCheckBox; + + /** The “content type override” action. */ + private Action contentTypeOverrideAction; + + /** The “content type override” combo box. */ + private JComboBox contentTypeOverrideComboBox; + /** The context menu for the tree. */ private JPopupMenu treeContextMenu; @@ -354,6 +377,26 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe } }; insertOverrideAction.setEnabled(false); + overrideContentTypeDefaultAction = new I18nAction("fileManager.checkbox.overrideContentTypeDefault") { + + /** + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent actionEvent) { + /* TODO */ + } + }; + overrideContentTypeDefaultAction.setEnabled(false); + contentTypeOverrideAction = new AbstractAction() { + + /** + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent actionEvent) { + /* TODO */ + } + }; + contentTypeOverrideAction.setEnabled(false); } /** @@ -413,11 +456,11 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe JPanel propertiesPanel = new JPanel(new GridBagLayout()); rightPanel.add(propertiesPanel, BorderLayout.CENTER); propertiesPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(12, 12, 12, 12))); - propertiesPanel.setPreferredSize(new Dimension(400, 350)); + propertiesPanel.setPreferredSize(new Dimension(500, 350)); filePropertiesLabel = new I18nLabel("fileManager.label.fileProperties"); filePropertiesLabel.setFont(filePropertiesLabel.getFont().deriveFont(Font.BOLD)); - propertiesPanel.add(filePropertiesLabel, new GridBagConstraints(0, 0, 4, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + propertiesPanel.add(filePropertiesLabel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); filePathLabel = new I18nLabel("fileManager.label.filePath"); filePathTextField = new JTextField(); @@ -438,9 +481,9 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe propertiesPanel.add(fileSizeTextField, new GridBagConstraints(1, 3, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); /* file settings. */ - fileSettingsLabel = new I18nLabel("fileManager.label.fileSettings"); - fileSettingsLabel.setFont(fileSettingsLabel.getFont().deriveFont(Font.BOLD)); - propertiesPanel.add(fileSettingsLabel, new GridBagConstraints(0, 4, 4, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(24, 0, 0, 0), 0, 0)); + insertSettingsLabel = new I18nLabel("fileManager.label.insertSetting"); + insertSettingsLabel.setFont(insertSettingsLabel.getFont().deriveFont(Font.BOLD)); + propertiesPanel.add(insertSettingsLabel, new GridBagConstraints(0, 4, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(24, 0, 0, 0), 0, 0)); insertDefaultLabel = new I18nLabel("fileManager.label.insertDefault"); propertiesPanel.add(insertDefaultLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0)); @@ -448,12 +491,28 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe insertDefaultCheckBox.setEnabled(false); propertiesPanel.add(insertDefaultCheckBox, new GridBagConstraints(1, 5, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); overrideInsertDefaultCheckBox = new JCheckBox(overrideInsertDefaultAction); - propertiesPanel.add(overrideInsertDefaultCheckBox, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); + propertiesPanel.add(overrideInsertDefaultCheckBox, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0)); insertOverrideCheckBox = new JCheckBox(insertOverrideAction); - propertiesPanel.add(insertOverrideCheckBox, new GridBagConstraints(3, 5, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); + propertiesPanel.add(insertOverrideCheckBox, new GridBagConstraints(1, 6, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); + + /* content type settings. */ + contentTypeSettingsLabel = new I18nLabel("fileManager.label.contentTypeSetting"); + contentTypeSettingsLabel.setFont(contentTypeSettingsLabel.getFont().deriveFont(Font.BOLD)); + propertiesPanel.add(contentTypeSettingsLabel, new GridBagConstraints(0, 7, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(24, 0, 0, 0), 0, 0)); + + contentTypeDefaultLabel = new I18nLabel("fileManager.label.contentTypeDefault"); + propertiesPanel.add(contentTypeDefaultLabel, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0)); + contentTypeDefaultTextField = new JTextField(); + contentTypeDefaultTextField.setEditable(false); + propertiesPanel.add(contentTypeDefaultTextField, new GridBagConstraints(1, 8, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); + overrideContentTypeDefaultCheckBox = new JCheckBox(overrideContentTypeDefaultAction); + propertiesPanel.add(overrideContentTypeDefaultCheckBox, new GridBagConstraints(0, 9, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0)); + contentTypeOverrideComboBox = new JComboBox(); + contentTypeOverrideComboBox.addActionListener(contentTypeOverrideAction); + propertiesPanel.add(contentTypeOverrideComboBox, new GridBagConstraints(1, 9, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); /* glue panel. */ - propertiesPanel.add(new JPanel(), new GridBagConstraints(0, 6, 4, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + propertiesPanel.add(new JPanel(), new GridBagConstraints(0, 10, 2, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); /* action button panel */ JPanel actionButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12)); @@ -677,6 +736,33 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe } } + /** + * Returns the extension of the given filename. If the file name does not + * have an extension, the name of the file (without any path components) is + * returned. + * + * @param fileName + * The name of the file + * @return The extension of the file + */ + private String getFileExtension(String fileName) { + String lastComponent = fileName.substring(fileName.lastIndexOf(File.separator) + 1); + return lastComponent.substring(lastComponent.lastIndexOf('.') + 1); + } + + private void fillComboBox(String fileName) { + String fileExtension = getFileExtension(fileName); + List allMimeTypes = MimeTypes.getAllMimeTypes(); + List eligibleMimeTypes = MimeTypes.getMimeTypes(fileExtension); + for (String mimeType: eligibleMimeTypes) { + allMimeTypes.remove(mimeType); + allMimeTypes.add(eligibleMimeTypes.indexOf(mimeType), mimeType); + } + allMimeTypes.add(eligibleMimeTypes.size(), "--"); + allMimeTypes.add(0, null); + contentTypeOverrideComboBox.set + } + // // INTERFACE I18nable // @@ -708,6 +794,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe boolean overrideInsertSelected = false; boolean insertOverrideEnabled = false; boolean insertOverrideSelected = false; + String defaultContentType = MimeTypes.DEFAULT_CONTENT_TYPE; if (selectedProjectFileWrappers.size() == 1) { ProjectFileWrapper projectFileWrapper = selectedProjectFileWrappers.get(0); ProjectFile projectFile = projectFileWrapper.getProjectFile(); @@ -721,6 +808,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe fileSizeText = String.valueOf(projectFile.getSize()); insertDefaultSelected = !projectFile.isHidden(); overrideInsertEnabled = true; + defaultContentType = MimeTypes.getMimeType(getFileExtension(projectFile.getName())); FileOverride fileOverride = project.getFileOverride(projectFile); if (fileOverride != null) { Boolean overrideInsert = fileOverride.isInsert(); @@ -740,6 +828,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe setSelected(overrideInsertDefaultCheckBox, overrideInsertSelected); setEnabled(insertOverrideAction, insertOverrideEnabled); setSelected(insertOverrideCheckBox, insertOverrideSelected); + contentTypeDefaultTextField.setText(defaultContentType); } // @@ -1135,4 +1224,55 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe } + private class MimeTypeListModel implements ComboBoxModel { + + private List listDataListeners = new ArrayList(); + private Object selectedItem; + + /** + * @see javax.swing.ListModel#addListDataListener(javax.swing.event.ListDataListener) + */ + public void addListDataListener(ListDataListener listDataListener) { + listDataListeners.add(listDataListener); + } + + /** + * @see javax.swing.ListModel#removeListDataListener(javax.swing.event.ListDataListener) + */ + public void removeListDataListener(ListDataListener listDataListener) { + listDataListeners.remove(listDataListener); + } + + /** + * @see javax.swing.ComboBoxModel#getSelectedItem() + */ + public Object getSelectedItem() { + return selectedItem; + } + + /** + * @see javax.swing.ComboBoxModel#setSelectedItem(java.lang.Object) + */ + public void setSelectedItem(Object anItem) { + selectedItem = anItem; + } + + /** + * @see javax.swing.ListModel#getElementAt(int) + */ + public Object getElementAt(int index) { + // TODO Auto-generated method stub + return null; + } + + /** + * @see javax.swing.ListModel#getSize() + */ + public int getSize() { + // TODO Auto-generated method stub + return 0; + } + + } + } diff --git a/src/net/pterodactylus/jsite/i18n/jSite.properties b/src/net/pterodactylus/jsite/i18n/jSite.properties index 25599b6..aef5ea9 100644 --- a/src/net/pterodactylus/jsite/i18n/jSite.properties +++ b/src/net/pterodactylus/jsite/i18n/jSite.properties @@ -361,18 +361,30 @@ fileManager.label.fileName.mnemonic: VK_UNDEFINED fileManager.label.fileSize.name: File size fileManager.label.fileSize.mnemonic: VK_UNDEFINED -fileManager.label.fileSettings.name: File Settings -fileManager.label.fileSettings.mnemonic: VK_UNDEFINED +fileManager.label.insertSetting.name: Insert +fileManager.label.insertSetting.mnemonic: VK_UNDEFINED fileManager.label.insertDefault.name: Insert Default fileManager.label.insertDefault.mnemonic: VK_UNDEFINED +fileManager.label.contentTypeSetting.name: Content Type +fileManager.label.contentTypeSetting.mnemonic: VK_UNDEFINED + +fileManager.label.contentTypeDefault.name: Default +fileManager.label.contentTypeDefault.mnemonic: VK_UNDEFINED + fileManager.checkbox.overrideInsertDefault.name: Override fileManager.checkbox.overrideInsertDefault.mnemonic: VK_I fileManager.checkbox.overrideInsertDefault.accelerator: VK_UNDEFINED fileManager.checkbox.overrideInsertDefault.shortDescription: Overrides the default \u201cInsert\u201d setting fileManager.checkbox.overrideInsertDefault.longDescription: Overrides the default \u201cInsert\u201d setting +fileManager.checkbox.overrideContentTypeDefault.name: Override +fileManager.checkbox.overrideContentTypeDefault.mnemonic: VK_C +fileManager.checkbox.overrideContentTypeDefault.accelerator: VK_UNDEFINED +fileManager.checkbox.overrideContentTypeDefault.shortDescription: Overrides the default \u201cContent Type\u201d setting +fileManager.checkbox.overrideContentTypeDefault.longDescription: Overrides the default \u201cContent Type\u201d setting + fileManager.menu.item.setDefaultFile.name: Set as default file fileManager.menu.item.setDefaultFile.mnemonic: VK_D fileManager.menu.item.setDefaultFile.accelerator: VK_UNDEFINED diff --git a/src/net/pterodactylus/jsite/i18n/jSite_de.properties b/src/net/pterodactylus/jsite/i18n/jSite_de.properties index 04a3317..a050603 100644 --- a/src/net/pterodactylus/jsite/i18n/jSite_de.properties +++ b/src/net/pterodactylus/jsite/i18n/jSite_de.properties @@ -361,18 +361,30 @@ fileManager.label.fileName.mnemonic: VK_UNDEFINED fileManager.label.fileSize.name: Dateigr\u00f6\u00dfe fileManager.label.fileSize.mnemonic: VK_UNDEFINED -fileManager.label.fileSettings.name: Dateieinstellungen -fileManager.label.fileSettings.mnemonic: VK_UNDEFINED +fileManager.label.insertSetting.name: Einf\u00fcgen +fileManager.label.insertSetting.mnemonic: VK_UNDEFINED -fileManager.label.insertDefault.name: Einf\u00fcgen +fileManager.label.insertDefault.name: Standard fileManager.label.insertDefault.mnemonic: VK_UNDEFINED +fileManager.label.contentTypeSetting.name: MIME-Typ +fileManager.label.contentTypeSetting.mnemonic: VK_UNDEFINED + +fileManager.label.contentTypeDefault.name: Standard +fileManager.label.contentTypeDefault.mnemonic: VK_UNDEFINED + fileManager.checkbox.overrideInsertDefault.name: \u00dcberschreiben fileManager.checkbox.overrideInsertDefault.mnemonic: VK_E fileManager.checkbox.overrideInsertDefault.accelerator: VK_UNDEFINED fileManager.checkbox.overrideInsertDefault.shortDescription: \u00dcberschreibt die \u201eEinf\u00fcgen\u201c-Einstellung fileManager.checkbox.overrideInsertDefault.longDescription: \u00dcberschreibt die \u201eEinf\u00fcgen\u201c-Einstellung +fileManager.checkbox.overrideContentTypeDefault.name: Überschreiben +fileManager.checkbox.overrideContentTypeDefault.mnemonic: VK_C +fileManager.checkbox.overrideContentTypeDefault.accelerator: VK_UNDEFINED +fileManager.checkbox.overrideContentTypeDefault.shortDescription: \u00dcberschreibt die \u201eMIME-Typ\u201c-Einstellung +fileManager.checkbox.overrideContentTypeDefault.longDescription: \u00dcberschreibt die \u201eMIME-Typ\u201c-Einstellung + fileManager.menu.item.setDefaultFile.name: Als Indexdatei benutzen fileManager.menu.item.setDefaultFile.mnemonic: VK_I fileManager.menu.item.setDefaultFile.accelerator: VK_UNDEFINED -- 2.7.4