work on new project file backend
[jSite2.git] / src / net / pterodactylus / jsite / gui / FileManager.java
index a7d8c7c..c961280 100644 (file)
 package net.pterodactylus.jsite.gui;
 
 import java.awt.BorderLayout;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.Font;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.io.File;
 import java.util.ArrayList;
 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.JDialog;
-import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
+import javax.swing.JTextField;
 import javax.swing.JTree;
-import javax.swing.event.TreeModelListener;
-import javax.swing.tree.TreeModel;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.tree.DefaultTreeCellRenderer;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreeNode;
 import javax.swing.tree.TreePath;
 
 import net.pterodactylus.jsite.i18n.I18n;
 import net.pterodactylus.jsite.i18n.I18nable;
-import net.pterodactylus.jsite.project.Entry;
+import net.pterodactylus.jsite.i18n.gui.I18nAction;
+import net.pterodactylus.jsite.i18n.gui.I18nLabel;
 import net.pterodactylus.jsite.project.Project;
-import net.pterodactylus.util.data.Node;
-import net.pterodactylus.util.data.Tree;
 import net.pterodactylus.util.logging.Logging;
+import net.pterodactylus.util.swing.SortableTreeNode;
 import net.pterodactylus.util.swing.SwingUtils;
 
 /**
  * Manages physical and virtual files in a project.
- * 
+ *
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
  */
-public class FileManager extends JDialog implements I18nable {
+public class FileManager extends JDialog implements I18nable, ActionListener, TreeSelectionListener {
 
        /** Logger. */
        private static final Logger logger = Logging.getLogger(FileManager.class.getName());
 
+       /** The Swing interface. */
+       private final SwingInterface swingInterface;
+
        /** The project whose files to manage. */
        private final Project project;
 
+       /** The root of the file tree. */
+       private final SortableTreeNode fileTreeRoot;
+
        /** The tree model for the project files. */
-       private final FileTreeModel fileTreeModel;
+       private final DefaultTreeModel fileTreeModel;
+
+       /** Files that are hidden as per {@link File#isHidden()}. */
+       private final List<String> hiddenFiles = new ArrayList<String>();
+
+       /** The tree cell renderer. */
+       private final FileCellRenderer fileCellRenderer;
+
+       /** The “rescan” action. */
+       private I18nAction rescanAction;
+
+       /** The “close” action. */
+       private I18nAction closeAction;
+
+       /** The “project files” label. */
+       private I18nLabel projectFilesLabel;
 
        /** The tree that shows the files. */
        private JTree fileTree;
 
+       /** The scroll pane that holds the file tree. */
+       private JScrollPane fileScrollPane;
+
+       /** The “file properties” label. */
+       private I18nLabel filePropertiesLabel;
+
+       /** The “file path” label. */
+       private I18nLabel filePathLabel;
+
+       /** The “file path” textfield. */
+       private JTextField filePathTextField;
+
+       /** The “file name” label. */
+       private I18nLabel fileNameLabel;
+
+       /** The “file name” textfield. */
+       private JTextField fileNameTextField;
+
+       /** The “file size” label. */
+       private I18nLabel fileSizeLabel;
+
+       /** The “file size” text field. */
+       private JTextField fileSizeTextField;
+
        /**
         * Creates a new file manager.
-        * 
-        * @param parent
-        *            The parent frame
+        *
+        * @param swingInterface
+        *            The Swing interface
         * @param project
         *            The project whose files to manage
         */
-       public FileManager(JFrame parent, Project project) {
-               super(parent, I18n.get("fileManager.title", project.getName()), true);
+       public FileManager(SwingInterface swingInterface, Project project) {
+               super(swingInterface.getMainWindow(), I18n.get("fileManager.title", project.getName()), true);
                logger.log(Level.FINEST, "project: " + project);
+               this.swingInterface = swingInterface;
                this.project = project;
-               fileTreeModel = new FileTreeModel();
+               fileTreeRoot = new SortableTreeNode(project.getName());
+               fileTreeModel = new DefaultTreeModel(fileTreeRoot);
+               fileCellRenderer = new FileCellRenderer();
+               initActions();
                initComponents();
-               SwingUtils.repackCentered(this);
+               pack();
+               SwingUtils.center(this);
        }
 
        //
-       // PRIVATE ACTIONS
+       // ACTIONS
        //
 
        /**
-        * Initializes all components.
+        * @see java.awt.Component#setVisible(boolean)
         */
-       private void initComponents() {
-               JPanel contentPanel = new JPanel(new BorderLayout(12, 12));
-
-               fileTree = new JTree(fileTreeModel);
-               fileTree.setShowsRootHandles(false);
-               contentPanel.add(new JScrollPane(fileTree), BorderLayout.CENTER);
-
-               setContentPane(contentPanel);
+       @Override
+       public void setVisible(boolean visible) {
+               if (visible) {
+                       initiateFileScan();
+               }
+               super.setVisible(visible);
        }
 
        //
-       // INTERFACE I18nable
+       // PRIVATE METHODS
        //
 
        /**
-        * {@inheritDoc}
+        * Initializes all actions.
         */
-       public void updateI18n() {
-               setTitle(I18n.get("fileManager.title", project.getName()));
+       private void initActions() {
+               closeAction = new I18nAction("fileManager.button.close") {
+
+                       /**
+                        * {@inheritDoc}
+                        */
+                       public void actionPerformed(ActionEvent e) {
+                               setVisible(false);
+                       }
+               };
+               rescanAction = new I18nAction("fileManager.button.rescan") {
+
+                       /**
+                        * {@inheritDoc}
+                        */
+                       @SuppressWarnings("synthetic-access")
+                       public void actionPerformed(ActionEvent actionEvent) {
+                               initiateFileScan();
+                       }
+               };
        }
 
        /**
-        * Model for the tree of files.
-        * 
-        * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
+        * Initializes all components.
         */
-       private class FileTreeModel implements TreeModel, PropertyChangeListener {
+       private void initComponents() {
+               JPanel contentPanel = new JPanel(new BorderLayout(12, 12));
+               contentPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
 
-               /** Tree model listeners. */
-               private final List<TreeModelListener> treeModelListeners = new ArrayList<TreeModelListener>();
+               contentPanel.add(createFileManagerPanel(), BorderLayout.CENTER);
+               contentPanel.add(createButtonPanel(), BorderLayout.PAGE_END);
 
-               /** The tree of files. */
-               private final Tree<FileTreePath> fileTreePathTree = new Tree<FileTreePath>();
+               setContentPane(contentPanel);
+       }
 
-               /**
-                * Creates a new file tree model.
-                */
-               FileTreeModel() {
-                       buildTree();
-               }
+       /**
+        * 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));
 
-               //
-               // EVENT MANAGEMENT
-               //
+               /* file tree panel */
+               JPanel fileTreePanel = new JPanel(new BorderLayout(12, 12));
+               fileManagerPanel.add(fileTreePanel, BorderLayout.LINE_START);
 
-               /**
-                * {@inheritDoc}
-                */
-               public void addTreeModelListener(TreeModelListener treeModelListener) {
-                       treeModelListeners.add(treeModelListener);
-               }
+               fileTree = new JTree(fileTreeModel);
+               fileTree.setShowsRootHandles(false);
+               fileTree.addTreeSelectionListener(this);
+               fileTree.setCellRenderer(fileCellRenderer);
+               fileTreePanel.add(fileScrollPane = new JScrollPane(fileTree), BorderLayout.CENTER);
+               fileScrollPane.setPreferredSize(new Dimension(250, 400));
+
+               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);
+
+               /* the right panel */
+               JPanel rightPanel = new JPanel(new BorderLayout(12, 12));
+               fileManagerPanel.add(rightPanel, BorderLayout.CENTER);
+
+               /* properties panel */
+               JPanel propertiesPanel = new JPanel(new GridBagLayout());
+               rightPanel.add(propertiesPanel, BorderLayout.CENTER);
+               propertiesPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(12, 12, 12, 12)));
+
+               filePropertiesLabel = new I18nLabel("fileManager.label.fileProperties");
+               filePropertiesLabel.setFont(filePropertiesLabel.getFont().deriveFont(Font.BOLD));
+               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();
+               filePathTextField.setEditable(false);
+               propertiesPanel.add(filePathLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0));
+               propertiesPanel.add(filePathTextField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0));
+
+               fileNameLabel = new I18nLabel("fileManager.label.fileName");
+               fileNameTextField = new JTextField();
+               fileNameTextField.setEditable(false);
+               propertiesPanel.add(fileNameLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0));
+               propertiesPanel.add(fileNameTextField, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0));
+
+               fileSizeLabel = new I18nLabel("fileManager.label.fileSize");
+               fileSizeTextField = new JTextField();
+               fileSizeTextField.setEditable(false);
+               propertiesPanel.add(fileSizeLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0));
+               propertiesPanel.add(fileSizeTextField, new GridBagConstraints(1, 3, 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, 3, 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));
+               rightPanel.add(actionButtonPanel, BorderLayout.PAGE_END);
+               actionButtonPanel.setBorder(BorderFactory.createEtchedBorder());
+
+               JButton rescanButton = new JButton(rescanAction);
+               actionButtonPanel.add(rescanButton);
+
+               return fileManagerPanel;
+       }
 
-               /**
-                * {@inheritDoc}
-                */
-               public void removeTreeModelListener(TreeModelListener treeModelListener) {
-                       treeModelListeners.remove(treeModelListener);
-               }
+       /**
+        * Creates the button panel.
+        *
+        * @return The button panel
+        */
+       private Component createButtonPanel() {
+               JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 12, 12));
 
-               //
-               // ACCESSORS
-               //
+               buttonPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12));
+               JButton closeButton = new JButton(closeAction);
+               buttonPanel.add(closeButton);
 
-               /**
-                * {@inheritDoc}
-                */
-               @SuppressWarnings("synthetic-access")
-               public Object getChild(Object parent, int index) {
-                       logger.log(Level.FINEST, "getChild(" + parent + ", " + index + ")");
-                       Node<FileTreePath> parentNode = findNode(parent);
-                       if (parentNode != null) {
-                               return parentNode.getChild(index).getElement();
-                       }
-                       return null;
-               }
+               getRootPane().setDefaultButton(closeButton);
+               return buttonPanel;
+       }
 
-               /**
-                * {@inheritDoc}
-                */
-               @SuppressWarnings("synthetic-access")
-               public int getChildCount(Object parent) {
-                       logger.log(Level.FINEST, "getChildCount(" + parent + ")");
-                       Node<FileTreePath> parentNode = findNode(parent);
-                       if (parentNode != null) {
-                               logger.log(Level.FINEST, "getChildCount(" + parent + "): " + parentNode.size());
-                               return parentNode.size();
+       /**
+        * Initiates a file scan.
+        */
+       private void initiateFileScan() {
+               swingInterface.getThreadPool().execute(new Runnable() {
+
+                       /**
+                        * @see java.lang.Runnable#run()
+                        */
+                       @SuppressWarnings("synthetic-access")
+                       public void run() {
+                               fileTree.setEnabled(false);
+                               rescanAction.setEnabled(false);
+                               String basePath = project.getBasePath();
+                               File basePathDirectory = new File(basePath);
+                               fileTreeRoot.removeAll();
+                               hiddenFiles.clear();
+                               if (!basePathDirectory.exists() || !basePathDirectory.isDirectory()) {
+                                       /* TODO - i18n */
+                                       JOptionPane.showMessageDialog(FileManager.this, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE);
+                               } else {
+                                       scanDirectory(fileTreeRoot, basePathDirectory, "", hiddenFiles);
+                               }
+                               fileTreeModel.reload();
+                               // fileScrollPane.revalidate();
+                               rescanAction.setEnabled(true);
+                               fileTree.setEnabled(true);
                        }
-                       return -1;
-               }
 
-               /**
-                * {@inheritDoc}
-                */
-               @SuppressWarnings("synthetic-access")
-               public int getIndexOfChild(Object parent, Object child) {
-                       logger.log(Level.FINEST, "getIndexOfChild(" + parent + ", " + child + ")");
-                       Node<FileTreePath> parentNode = findNode(parent);
-                       if (parentNode != null) {
-                               return parentNode.getIndexOfChild((FileTreePath) child);
+                       private void scanDirectory(SortableTreeNode rootNode, File directory, String currentDirectory, List<String> hiddenFiles) {
+                               for (File file : directory.listFiles()) {
+                                       String fileName = file.getName();
+                                       SortableTreeNode fileNode = new SortableTreeNode(fileName);
+                                       rootNode.add(fileNode);
+                                       if (file.isFile() && file.isHidden()) {
+                                               hiddenFiles.add((currentDirectory + File.separator + fileName).substring(1));
+                                       }
+                                       if (file.isDirectory()) {
+                                               scanDirectory(fileNode, file, currentDirectory + File.separator + fileName, hiddenFiles);
+                                       }
+                               }
+                               rootNode.sort();
                        }
-                       return -1;
-               }
 
-               /**
-                * {@inheritDoc}
-                */
-               @SuppressWarnings("synthetic-access")
-               public Object getRoot() {
-                       logger.log(Level.FINEST, "getRoot()");
-                       return fileTreePathTree.getRootNode().getChild(0).getElement();
-               }
+               });
+       }
 
-               /**
-                * {@inheritDoc}
-                */
-               @SuppressWarnings("synthetic-access")
-               public boolean isLeaf(Object node) {
-                       logger.log(Level.FINEST, "isLeaf(" + node + ")");
-                       Node<FileTreePath> parentNode = findNode(node);
-                       if (parentNode != null) {
-                               return parentNode.size() == 0;
+       /**
+        * Returns the complete path for the given node.
+        *
+        * @param treeNode
+        *            The node
+        * @return The complete path for the node, or the empty string (“”) for the
+        *         root node
+        */
+       private String getPathForNode(TreeNode treeNode) {
+               TreeNode[] pathToNode = fileTreeModel.getPathToRoot(treeNode);
+               StringBuilder completePathBuilder = new StringBuilder();
+               boolean first = true;
+               for (TreeNode nodePathNode : pathToNode) {
+                       if (first) {
+                               first = false;
+                               continue;
                        }
-                       return true;
-               }
-
-               //
-               // ACTIONS
-               //
-
-               /**
-                * {@inheritDoc}
-                */
-               public void valueForPathChanged(TreePath path, Object newValue) {
-                       /* TODO - implement */
+                       if (!(nodePathNode instanceof SortableTreeNode)) {
+                               logger.log(Level.WARNING, "nodePathNode is not a SortableTreeNode!");
+                               continue;
+                       }
+                       completePathBuilder.append(File.separatorChar).append(((SortableTreeNode) nodePathNode).getUserObject());
                }
+               String completePath = (completePathBuilder.length() == 0) ? "" : completePathBuilder.substring(1);
+               return completePath;
+       }
 
-               //
-               // PRIVATE METHODS
-               //
+       //
+       // INTERFACE I18nable
+       //
 
-               /**
-                * Finds the node for the given object. This method is quite necessary
-                * because the element for the root node of the JTree is
-                * <code>null</code>
-                * 
-                * @param node
-                *            The element whose node to return
-                * @return The node, or <code>null</code> if no node could be found
-                */
-               private Node<FileTreePath> findNode(Object node) {
-                       if (node == null) {
-                               return fileTreePathTree.getRootNode().getChild(0);
-                       }
-                       return fileTreePathTree.getRootNode().getChild(0).findChild((FileTreePath) node);
-               }
+       /**
+        * {@inheritDoc}
+        */
+       public void updateI18n() {
+               setTitle(I18n.get("fileManager.title", project.getName()));
+               projectFilesLabel.updateI18n();
+               filePropertiesLabel.updateI18n();
+               filePathLabel.updateI18n();
+       }
 
-               /**
-                * Builds the tree from the project’s file entries.
-                */
-               @SuppressWarnings("synthetic-access")
-               private void buildTree() {
-                       Tree<String> pathTree = new Tree<String>();
-                       Node<String> pathRootNode = pathTree.getRootNode().addChild(File.separator);
-                       logger.log(Level.FINEST, "project: " + project);
-                       buildTree(pathRootNode, project.getBasePathEntries());
-                       buildTree(pathRootNode, project.getVirtualEntries());
-                       /* now convert to a tree suitable for the JTree. */
-                       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. */
-               }
+       //
+       // INTERFACE TreeSelectionListener
+       //
 
-               /**
-                * Traverses the tree of path nodes and converts all paths to
-                * {@link FileTreePath} objects, suitable for the JTree.
-                * 
-                * @param completePath
-                *            The base path of the current root node
-                * @param pathRootNode
-                *            The root node of the path tree
-                * @param fileTreePathRootNode
-                *            The root node of the file tree path tree.
-                */
-               private void convertTree(String completePath, Node<String> pathRootNode, Node<FileTreePath> fileTreePathRootNode) {
-                       for (Node<String> pathChild: pathRootNode) {
-                               String currentFilePath = completePath + pathChild.getElement();
-                               Node<FileTreePath> newNode = fileTreePathRootNode.addChild(new FileTreePath(currentFilePath));
-                               convertTree(currentFilePath, pathChild, newNode);
+       /**
+        * {@inheritDoc}
+        */
+       public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
+               TreePath[] selectedPaths = fileTree.getSelectionPaths();
+               if ((selectedPaths != null) && (selectedPaths.length == 1)) {
+                       Object lastPathComponent = selectedPaths[0].getLastPathComponent();
+                       if (!(lastPathComponent instanceof SortableTreeNode)) {
+                               logger.log(Level.WARNING, "lastPathComponent is not a SortableTreeNode!");
+                               return;
                        }
-                       fileTreePathRootNode.sortChildren();
-               }
-
-               /**
-                * Builds a tree matching the directory structure of the given entries.
-                * 
-                * @param pathRootNode
-                *            The root node of the tree
-                * @param entries
-                *            The entries
-                */
-               private void buildTree(Node<String> pathRootNode, List<Entry> entries) {
-                       for (Entry basePathEntry: entries) {
-                               String entryName = basePathEntry.getName();
-                               String[] directories = entryName.split("\\" + File.separator);
-                               Node<String> currentPathNode = pathRootNode;
-                               for (String directory: directories) {
-                                       if (!currentPathNode.hasChild(directory)) {
-                                               currentPathNode = currentPathNode.addChild(directory);
-                                       } else {
-                                               currentPathNode = currentPathNode.getChild(directory);
-                                       }
-                               }
+                       SortableTreeNode node = (SortableTreeNode) lastPathComponent;
+                       String completePath = getPathForNode(node);
+                       int lastSeparator = completePath.lastIndexOf(File.separatorChar);
+                       String filePath = "";
+                       String fileName;
+                       if (lastSeparator == -1) {
+                               fileName = completePath;
+                       } else {
+                               filePath = completePath.substring(0, lastSeparator);
+                               fileName = completePath.substring(lastSeparator + 1);
                        }
+                       filePathTextField.setText(filePath);
+                       fileNameTextField.setText(fileName);
+                       return;
                }
+               filePathTextField.setText("");
+               fileNameTextField.setText("");
+       }
 
-               //
-               // INTERFACE PropertyChangeListener
-               //
-
-               /**
-                * {@inheritDoc}
-                */
-               public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
-                       if (propertyChangeEvent.getSource() instanceof Project) {
-                               if (propertyChangeEvent.getPropertyName().equals(Project.PROPERTY_BASE_PATH_ENTRIES)) {
-                                       buildTree();
-                               }
-                       }
-               }
+       //
+       // INTERFACE ActionListener
+       //
 
+       /**
+        * {@inheritDoc}
+        */
+       public void actionPerformed(ActionEvent actionEvent) {
+               /* TODO */
        }
 
        /**
-        * 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.
-        * 
+        * Tree cell renderer that takes care of certain display properties for
+        * project-specific stuff.
+        *
         * @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;
+       private class FileCellRenderer extends DefaultTreeCellRenderer {
 
                /**
-                * 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
+                * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree,
+                *      java.lang.Object, boolean, boolean, boolean, int, boolean)
                 */
-               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) {
-                               if (filePath.indexOf(File.separatorChar) != -1) {
-                                       this.fileName = filePath.substring(filePath.lastIndexOf(File.separatorChar) + 1);
+               @Override
+               public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
+                       Component superCellRenderer = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
+                       if (!(superCellRenderer instanceof JLabel)) {
+                               logger.log(Level.WARNING, "superCellRenderer is not a JLabel!");
+                               return superCellRenderer;
+                       }
+                       if (!(value instanceof SortableTreeNode)) {
+                               logger.log(Level.WARNING, "value is not a SortableTreeNode!");
+                               return superCellRenderer;
+                       }
+                       SortableTreeNode node = (SortableTreeNode) value;
+                       TreeNode[] pathToRoot = fileTreeModel.getPathToRoot(node);
+                       if (pathToRoot.length > 1) {
+                               String completePath = getPathForNode(node);
+                               if (project.getDefaultFile().equals(completePath)) {
+                                       superCellRenderer.setFont(superCellRenderer.getFont().deriveFont(Font.BOLD));
                                } else {
-                                       this.fileName = filePath;
+                                       if (hiddenFiles.contains(completePath)) {
+                                               /* fade hidden files’ font */
+                                               Color foreground = superCellRenderer.getForeground();
+                                               Color background = selected ? getBackgroundSelectionColor() : getBackgroundNonSelectionColor();
+                                               Color averageColor = new Color((foreground.getRed() + background.getRed()) / 2, (foreground.getGreen() + background.getGreen()) / 2, (foreground.getBlue() + background.getBlue()) / 2);
+                                               superCellRenderer.setForeground(averageColor);
+                                       } else {
+                                               superCellRenderer.setFont(superCellRenderer.getFont().deriveFont(Font.PLAIN));
+                                       }
                                }
                        } else {
-                               this.fileName = fileName;
-                       }
-               }
-
-               /**
-                * Returns the complete file path.
-                * 
-                * @return The file path
-                */
-               public String getFilePath() {
-                       return filePath;
-               }
-
-               /**
-                * Returns the file name, i.e. everything after the last
-                * {@link File#separatorChar}.
-                * 
-                * @return The file name
-                */
-               public String getFileName() {
-                       return fileName;
-               }
-
-               /**
-                * Returns the file entry associated with this path, if any.
-                * 
-                * @return The file entry associated with this path, or
-                *         <code>null</code> if this path denotes a directory
-                */
-               public Entry getFileEntry() {
-                       return fileEntry;
-               }
-
-               /**
-                * Sets the entry associated with this path.
-                * 
-                * @param fileEntry
-                *            The entry
-                */
-               public void setFileEntry(Entry fileEntry) {
-                       this.fileEntry = fileEntry;
-               }
-
-               /**
-                * {@inheritDoc}
-                */
-               @Override
-               public boolean equals(Object object) {
-                       if ((object == null) || !(object instanceof FileTreePath)) {
-                               return false;
+                               superCellRenderer.setFont(superCellRenderer.getFont().deriveFont(Font.BOLD));
                        }
-                       FileTreePath fileTreePath = (FileTreePath) object;
-                       return fileTreePath.filePath.equals(filePath);
-               }
-
-               /**
-                * {@inheritDoc}
-                */
-               @Override
-               public int hashCode() {
-                       return filePath.hashCode();
-               }
-
-               /**
-                * {@inheritDoc}
-                */
-               @Override
-               public String toString() {
-                       return fileName;
-               }
-
-               //
-               // INTERFACE Comparable
-               //
-
-               /**
-                * {@inheritDoc}
-                */
-               public int compareTo(FileTreePath otherFileTreePath) {
-                       return filePath.compareTo(otherFileTreePath.filePath);
+                       return superCellRenderer;
                }
 
        }