add mime type combo box
[jSite2.git] / src / net / pterodactylus / jsite / gui / FileManager.java
index faec4ae..580aedd 100644 (file)
 package net.pterodactylus.jsite.gui;
 
 import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.FlowLayout;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.io.File;
@@ -28,6 +34,9 @@ import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
 import javax.swing.JDialog;
 import javax.swing.JFrame;
 import javax.swing.JPanel;
@@ -39,10 +48,13 @@ import javax.swing.tree.TreePath;
 
 import net.pterodactylus.jsite.i18n.I18n;
 import net.pterodactylus.jsite.i18n.I18nable;
+import net.pterodactylus.jsite.i18n.gui.I18nAction;
+import net.pterodactylus.jsite.i18n.gui.I18nLabel;
 import net.pterodactylus.jsite.project.Entry;
 import net.pterodactylus.jsite.project.Project;
 import net.pterodactylus.util.data.Node;
 import net.pterodactylus.util.data.Tree;
+import net.pterodactylus.util.io.MimeTypes;
 import net.pterodactylus.util.logging.Logging;
 import net.pterodactylus.util.swing.SwingUtils;
 
@@ -62,9 +74,18 @@ public class FileManager extends JDialog implements I18nable {
        /** The tree model for the project files. */
        private final FileTreeModel fileTreeModel;
 
+       /** The “close” action. */
+       private I18nAction closeAction;
+
        /** The tree that shows the files. */
        private JTree fileTree;
 
+       /** The “mime type” label. */
+       private I18nLabel mimeTypeLabel;
+
+       /** The “mime type” combo box. */
+       private JComboBox mimeTypeComboBox;
+
        /**
         * Creates a new file manager.
         * 
@@ -78,25 +99,84 @@ public class FileManager extends JDialog implements I18nable {
                logger.log(Level.FINEST, "project: " + project);
                this.project = project;
                fileTreeModel = new FileTreeModel();
+               initActions();
                initComponents();
-               SwingUtils.repackCentered(this);
+               pack();
+               SwingUtils.center(this);
        }
 
        //
-       // PRIVATE ACTIONS
+       // PRIVATE METHODS
        //
 
        /**
+        * Initializes all actions.
+        */
+       private void initActions() {
+               closeAction = new I18nAction("fileManager.button.close") {
+
+                       /**
+                        * {@inheritDoc}
+                        */
+                       public void actionPerformed(ActionEvent e) {
+                               setVisible(false);
+                       }
+               };
+       }
+
+       /**
         * Initializes all components.
         */
        private void initComponents() {
                JPanel contentPanel = new JPanel(new BorderLayout(12, 12));
+               contentPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
+
+               contentPanel.add(createFileManagerPanel(), BorderLayout.CENTER);
+               contentPanel.add(createButtonPanel(), BorderLayout.PAGE_END);
+
+               setContentPane(contentPanel);
+       }
+
+       /**
+        * Creates the main panel with the file tree and the file properties.
+        * 
+        * @return The mail panel
+        */
+       private Component createFileManagerPanel() {
+               JPanel fileManagerPanel = new JPanel(new BorderLayout(12, 12));
+               fileManagerPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(12, 12, 12, 12)));
 
                fileTree = new JTree(fileTreeModel);
+               fileManagerPanel.add(new JScrollPane(fileTree), BorderLayout.LINE_START);
                fileTree.setShowsRootHandles(false);
-               contentPanel.add(new JScrollPane(fileTree), BorderLayout.CENTER);
 
-               setContentPane(contentPanel);
+               JPanel propertiesPanel = new JPanel(new GridBagLayout());
+               fileManagerPanel.add(propertiesPanel, BorderLayout.CENTER);
+
+               mimeTypeComboBox = new JComboBox(MimeTypes.getAllMimeTypes().toArray(new String[0]));
+               mimeTypeLabel = new I18nLabel("projectPanel.label.mimeType", mimeTypeComboBox);
+               propertiesPanel.add(mimeTypeLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
+               propertiesPanel.add(mimeTypeComboBox, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 6, 0, 0), 0, 0));
+
+               propertiesPanel.add(new JPanel(), new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
+
+               return fileManagerPanel;
+       }
+
+       /**
+        * Creates the button panel.
+        * 
+        * @return The button panel
+        */
+       private Component createButtonPanel() {
+               JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 12, 12));
+
+               buttonPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12));
+               JButton closeButton = new JButton(closeAction);
+               buttonPanel.add(closeButton);
+
+               getRootPane().setDefaultButton(closeButton);
+               return buttonPanel;
        }
 
        //
@@ -259,7 +339,7 @@ public class FileManager extends JDialog implements I18nable {
                        Node<FileTreePath> fileTreePathRootNode = fileTreePathTree.getRootNode();
                        fileTreePathRootNode.removeAllChildren();
                        convertTree(File.separator, pathRootNode, fileTreePathRootNode.addChild(new FileTreePath(File.separator, project.getName())));
-                       /* TODO  - now add entries to all file tree path tree nodes. */
+                       /* TODO - now add entries to all file tree path tree nodes. */
                }
 
                /**
@@ -322,16 +402,45 @@ public class FileManager extends JDialog implements I18nable {
 
        }
 
+       /**
+        * Container that is used to back the {@link FileTreeModel}. Each
+        * FileTreePath contains a complete path name, a filename, and the
+        * associated {@link Entry}, if any.
+        * 
+        * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
+        */
        private static class FileTreePath implements Comparable<FileTreePath> {
 
+               /** The complete file path. */
                private final String filePath;
+
+               /** The file name. */
                private final String fileName;
+
+               /** The file entry, if any. */
                private Entry fileEntry;
 
+               /**
+                * Creates a new file tree path with an auto-detected file name. The
+                * file name is everything after the last separator in the complete
+                * path, or the complete path itself if it does not contain any
+                * separators.
+                * 
+                * @param filePath
+                *            The complete file path
+                */
                public FileTreePath(String filePath) {
                        this(filePath, null);
                }
 
+               /**
+                * Creates a new file tree path with the given file path and file name.
+                * 
+                * @param filePath
+                *            The complete file path
+                * @param fileName
+                *            The file name
+                */
                public FileTreePath(String filePath, String fileName) {
                        this.filePath = filePath;
                        if (fileName == null) {
@@ -415,7 +524,7 @@ public class FileManager extends JDialog implements I18nable {
                //
                // INTERFACE Comparable
                //
-               
+
                /**
                 * {@inheritDoc}
                 */