add label above project files
[jSite2.git] / src / net / pterodactylus / jsite / gui / FileManager.java
index faec4ae..d84b6d2 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,21 +34,30 @@ 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.JCheckBox;
+import javax.swing.JComboBox;
 import javax.swing.JDialog;
 import javax.swing.JFrame;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTree;
 import javax.swing.event.TreeModelListener;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
 import javax.swing.tree.TreeModel;
 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;
 
@@ -51,7 +66,7 @@ import net.pterodactylus.util.swing.SwingUtils;
  * 
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
  */
-public class FileManager extends JDialog implements I18nable {
+public class FileManager extends JDialog implements I18nable, TreeSelectionListener {
 
        /** Logger. */
        private static final Logger logger = Logging.getLogger(FileManager.class.getName());
@@ -62,9 +77,27 @@ 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 “project files” label. */
+       private I18nLabel projectFilesLabel;
+       
        /** The tree that shows the files. */
        private JTree fileTree;
 
+       /** The “insert” action. */
+       private I18nAction insertAction;
+       
+       /** The “insert” checkbox. */
+       private JCheckBox insertCheckBox;
+       
+       /** The “mime type” label. */
+       private I18nLabel mimeTypeLabel;
+
+       /** The “mime type” combo box. */
+       private JComboBox mimeTypeComboBox;
+
        /**
         * Creates a new file manager.
         * 
@@ -78,25 +111,105 @@ 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);
+                       }
+               };
+               insertAction = new I18nAction("fileManager.checkbox.insertFile") {
+                       /**
+                        * {@inheritDoc}
+                        */
+                       public void actionPerformed(ActionEvent actionEvent) {
+                               /* TODO - implements. */
+                       }
+               };
+       }
+
+       /**
         * 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));
+
+               JPanel fileTreePanel = new JPanel(new BorderLayout(12, 12));
+               fileManagerPanel.add(fileTreePanel, BorderLayout.LINE_START);
+               
                fileTree = new JTree(fileTreeModel);
                fileTree.setShowsRootHandles(false);
-               contentPanel.add(new JScrollPane(fileTree), BorderLayout.CENTER);
+               fileTreePanel.add(new JScrollPane(fileTree), BorderLayout.CENTER);
+               
+               projectFilesLabel = new I18nLabel("fileManager.label.projectFiles", fileTree);
+               JPanel projectFilesLabelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
+               fileTreePanel.add(projectFilesLabelPanel, BorderLayout.NORTH);
+               projectFilesLabelPanel.add(projectFilesLabel);
 
-               setContentPane(contentPanel);
+               JPanel propertiesPanel = new JPanel(new GridBagLayout());
+               fileManagerPanel.add(propertiesPanel, BorderLayout.CENTER);
+               propertiesPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(12, 12, 12, 12)));
+
+               insertCheckBox = new JCheckBox(insertAction);
+               propertiesPanel.add(insertCheckBox, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
+
+               List<String> allMimeTypes = MimeTypes.getAllMimeTypes();
+               allMimeTypes.add(0, "auto-detect");
+               mimeTypeComboBox = new JComboBox(allMimeTypes.toArray(new String[0]));
+               mimeTypeLabel = new I18nLabel("fileManager.label.mimeType", mimeTypeComboBox);
+               propertiesPanel.add(mimeTypeLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 0, 0, 0), 0, 0));
+               propertiesPanel.add(mimeTypeComboBox, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0));
+
+               propertiesPanel.add(new JPanel(), new GridBagConstraints(0, 2, 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;
        }
 
        //
@@ -110,6 +223,17 @@ public class FileManager extends JDialog implements I18nable {
                setTitle(I18n.get("fileManager.title", project.getName()));
        }
 
+       //
+       // INTERFACE TreeSelectionListener
+       //
+       
+       /**
+        * {@inheritDoc}
+        */
+       public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
+               /* TODO - implement */
+       }
+
        /**
         * Model for the tree of files.
         * 
@@ -259,7 +383,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 +446,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 +568,7 @@ public class FileManager extends JDialog implements I18nable {
                //
                // INTERFACE Comparable
                //
-               
+
                /**
                 * {@inheritDoc}
                 */