package net.pterodactylus.jsite.gui;
import java.awt.BorderLayout;
+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.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.io.File;
+import java.awt.event.ActionListener;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
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.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
+import javax.swing.JTextField;
import javax.swing.JTree;
+import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
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.jsite.project.ProjectFile;
import net.pterodactylus.util.logging.Logging;
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, 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 tree model for the project files. */
- private final FileTreeModel fileTreeModel;
+ private final ProjectFileTreeModel fileTreeModel;
+
+ /** 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 “mime type” label. */
- private I18nLabel mimeTypeLabel;
+ /** 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 “mime type” combo box. */
- private JComboBox mimeTypeComboBox;
+ /** 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();
+ fileTreeModel = new ProjectFileTreeModel();
+ fileCellRenderer = new FileCellRenderer();
initActions();
initComponents();
pack();
}
//
+ // ACTIONS
+ //
+
+ /**
+ * @see java.awt.Component#setVisible(boolean)
+ */
+ @Override
+ public void setVisible(boolean visible) {
+ if (visible) {
+ initiateFileScan();
+ }
+ super.setVisible(visible);
+ }
+
+ //
// PRIVATE METHODS
//
setVisible(false);
}
};
+ rescanAction = new I18nAction("fileManager.button.rescan") {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void actionPerformed(ActionEvent actionEvent) {
+ initiateFileScan();
+ }
+ };
}
/**
*/
private Component createFileManagerPanel() {
JPanel fileManagerPanel = new JPanel(new BorderLayout(12, 12));
- fileManagerPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(12, 12, 12, 12)));
+
+ /* file tree panel */
+ JPanel fileTreePanel = new JPanel(new BorderLayout(12, 12));
+ fileManagerPanel.add(fileTreePanel, BorderLayout.LINE_START);
fileTree = new JTree(fileTreeModel);
- fileManagerPanel.add(new JScrollPane(fileTree), BorderLayout.LINE_START);
fileTree.setShowsRootHandles(false);
+ fileTree.addTreeSelectionListener(this);
+ fileTree.setCellRenderer(fileCellRenderer);
+ fileTreePanel.add(fileScrollPane = new JScrollPane(fileTree), BorderLayout.CENTER);
+ fileScrollPane.setPreferredSize(new Dimension(250, 400));
- JPanel propertiesPanel = new JPanel(new GridBagLayout());
- fileManagerPanel.add(propertiesPanel, 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);
- 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));
+ /* the right panel */
+ JPanel rightPanel = new JPanel(new BorderLayout(12, 12));
+ fileManagerPanel.add(rightPanel, BorderLayout.CENTER);
- 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));
+ /* 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, 4, 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;
}
return buttonPanel;
}
+ /**
+ * 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);
+ ProjectFile baseProjectFile = project.getBaseFile();
+ if (baseProjectFile != null) {
+ fileTreeModel.setBaseProjectFile(baseProjectFile);
+ }
+ // fileScrollPane.revalidate();
+ rescanAction.setEnabled(true);
+ fileTree.setEnabled(true);
+ }
+
+ });
+ }
+
//
// INTERFACE I18nable
//
*/
public void updateI18n() {
setTitle(I18n.get("fileManager.title", project.getName()));
+ projectFilesLabel.updateI18n();
+ filePropertiesLabel.updateI18n();
+ filePathLabel.updateI18n();
+ }
+
+ //
+ // INTERFACE TreeSelectionListener
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
+ /* TODO */
+ }
+
+ //
+ // INTERFACE ActionListener
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ public void actionPerformed(ActionEvent actionEvent) {
+ /* TODO */
}
/**
- * Model for the tree of files.
+ * Tree cell renderer that takes care of certain display properties for
+ * project-specific stuff.
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
- private class FileTreeModel implements TreeModel, PropertyChangeListener {
+ private class FileCellRenderer extends DefaultTreeCellRenderer {
+
+ /**
+ * Empty constructor.
+ */
+ FileCellRenderer() {
+ /* do nothing. */
+ }
+
+ /**
+ * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree,
+ * java.lang.Object, boolean, boolean, boolean, int, boolean)
+ */
+ @SuppressWarnings("synthetic-access")
+ @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.SEVERE, "superCellRenderer is not a JLabel!");
+ return superCellRenderer;
+ }
+ if (!(value instanceof ProjectFileWrapper)) {
+ logger.log(Level.SEVERE, "value is not a ProjectFileWrapper!");
+ return superCellRenderer;
+ }
+ ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) value;
+ ProjectFile projectFile = projectFileWrapper.getProjectFile();
+ String completePath = projectFile.getCompletePath();
+ if (projectFile.isHidden()) {
+ /* TODO - check override */
+ 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 if (completePath.equals(project.getDefaultFile())) {
+ superCellRenderer.setFont(superCellRenderer.getFont().deriveFont(Font.BOLD));
+ } else {
+ superCellRenderer.setFont(superCellRenderer.getFont().deriveFont(Font.PLAIN));
+ }
+ return superCellRenderer;
+ }
+
+ }
+
+ /**
+ * TreeModel that is based on {@link Project#getBaseFile()}.
+ *
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ */
+ private class ProjectFileTreeModel implements TreeModel {
/** Tree model listeners. */
- private final List<TreeModelListener> treeModelListeners = new ArrayList<TreeModelListener>();
+ private final List<TreeModelListener> treeModelListeners = Collections.synchronizedList(new ArrayList<TreeModelListener>());
- /** The tree of files. */
- private final Tree<FileTreePath> fileTreePathTree = new Tree<FileTreePath>();
+ /** The base project file. */
+ private ProjectFile baseProjectFile;
+
+ /** Maps project files to wrappers. */
+ private final Map<ProjectFile, ProjectFileWrapper> projectFileWrappers = Collections.synchronizedMap(new HashMap<ProjectFile, ProjectFileWrapper>());
/**
- * Creates a new file tree model.
+ * Empty constructor.
*/
- FileTreeModel() {
- buildTree();
+ ProjectFileTreeModel() {
+ /* do nothing. */
}
//
treeModelListeners.remove(treeModelListener);
}
- //
- // ACCESSORS
- //
-
/**
- * {@inheritDoc}
+ * Notifies all listeners that the tree structure has changed
+ * significantly.
+ *
+ * @see TreeModelListener#treeStructureChanged(TreeModelEvent)
+ * @param newRootNode
*/
- @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();
+ protected void fireTreeStructureChanged(ProjectFileWrapper newRootNode) {
+ for (TreeModelListener treeModelListener: treeModelListeners) {
+ treeModelListener.treeStructureChanged(new TreeModelEvent(this, new Object[] { newRootNode }));
}
- return null;
}
- /**
- * {@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();
- }
- return -1;
- }
+ //
+ // ACCESSORS
+ //
/**
- * {@inheritDoc}
+ * Sets the new base project file. This causes the model to reload.
+ *
+ * @param baseProjectFile
+ * The new base project file
*/
- @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);
- }
- return -1;
+ public synchronized void setBaseProjectFile(ProjectFile baseProjectFile) {
+ this.baseProjectFile = baseProjectFile;
+ projectFileWrappers.clear();
+ createWrappers(baseProjectFile);
+ fireTreeStructureChanged(projectFileWrappers.get(baseProjectFile));
}
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("synthetic-access")
- public Object getRoot() {
- logger.log(Level.FINEST, "getRoot()");
- return fileTreePathTree.getRootNode().getChild(0).getElement();
- }
+ //
+ // PRIVATE METHODS
+ //
/**
- * {@inheritDoc}
+ * Creates {@link ProjectFileWrapper}s for all files below the given
+ * project file.
+ *
+ * @param projectFile
+ * The base project file for all project files to create
+ * wrappers for
*/
- @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;
+ private void createWrappers(ProjectFile projectFile) {
+ projectFileWrappers.put(projectFile, new ProjectFileWrapper(projectFile));
+ for (ProjectFile projectFileChild: projectFile.getFiles()) {
+ if (projectFileChild.isDirectory()) {
+ createWrappers(projectFileChild);
+ }
+ projectFileWrappers.put(projectFileChild, new ProjectFileWrapper(projectFileChild));
}
- return true;
}
//
- // ACTIONS
+ // INTERFACE TreeModel
//
/**
* {@inheritDoc}
*/
- public void valueForPathChanged(TreePath path, Object newValue) {
- /* TODO - implement */
+ public Object getRoot() {
+ return projectFileWrappers.get(baseProjectFile);
}
- //
- // PRIVATE METHODS
- //
-
/**
- * 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
+ * {@inheritDoc}
*/
- private Node<FileTreePath> findNode(Object node) {
- if (node == null) {
- return fileTreePathTree.getRootNode().getChild(0);
+ @SuppressWarnings("synthetic-access")
+ public Object getChild(Object parent, int index) {
+ if (!(parent instanceof ProjectFileWrapper)) {
+ logger.log(Level.SEVERE, "parent is not a ProjectFileWrapper!");
+ return null;
}
- return fileTreePathTree.getRootNode().getChild(0).findChild((FileTreePath) node);
+ ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) parent;
+ ProjectFile projectFile = projectFileWrapper.getProjectFile();
+ return projectFileWrappers.get(projectFile.getFiles().get(index));
}
/**
- * Builds the tree from the project’s file entries.
+ * {@inheritDoc}
*/
@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. */
+ public int getChildCount(Object parent) {
+ if (!(parent instanceof ProjectFileWrapper)) {
+ logger.log(Level.SEVERE, "parent is not a ProjectFileWrapper!");
+ return -1;
+ }
+ ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) parent;
+ ProjectFile projectFile = projectFileWrapper.getProjectFile();
+ return projectFile.getFiles().size();
}
/**
- * 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.
+ * {@inheritDoc}
*/
- 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);
+ @SuppressWarnings("synthetic-access")
+ public int getIndexOfChild(Object parent, Object child) {
+ if (!(parent instanceof ProjectFileWrapper)) {
+ logger.log(Level.SEVERE, "parent is not a ProjectFileWrapper!");
+ return -1;
+ }
+ if (!(child instanceof ProjectFileWrapper)) {
+ logger.log(Level.SEVERE, "child is not a ProjectFileWrapper!");
+ return -1;
}
- fileTreePathRootNode.sortChildren();
+ ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) parent;
+ ProjectFile projectFile = projectFileWrapper.getProjectFile();
+ return projectFile.getFiles().indexOf(((ProjectFileWrapper) child).getProjectFile());
}
/**
- * Builds a tree matching the directory structure of the given entries.
- *
- * @param pathRootNode
- * The root node of the tree
- * @param entries
- * The entries
+ * {@inheritDoc}
*/
- 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);
- }
- }
+ @SuppressWarnings("synthetic-access")
+ public boolean isLeaf(Object node) {
+ if (!(node instanceof ProjectFileWrapper)) {
+ logger.log(Level.SEVERE, "node is not a ProjectFileWrapper!");
+ return true;
}
+ ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) node;
+ ProjectFile projectFile = projectFileWrapper.getProjectFile();
+ return projectFile.getFiles().isEmpty();
}
- //
- // INTERFACE PropertyChangeListener
- //
-
/**
* {@inheritDoc}
*/
- public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
- if (propertyChangeEvent.getSource() instanceof Project) {
- if (propertyChangeEvent.getPropertyName().equals(Project.PROPERTY_BASE_PATH_ENTRIES)) {
- buildTree();
- }
- }
+ public void valueForPathChanged(TreePath path, Object newValue) {
+ /* ignore, items will not be modified in tree. */
}
}
/**
- * 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.
+ * Wrapper around a {@link ProjectFile} that overwrites
+ * {@link Object#toString()} to return the project file’s name.
*
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
*/
- private static class FileTreePath implements Comparable<FileTreePath> {
+ private static class ProjectFileWrapper {
- /** 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) {
- if (filePath.indexOf(File.separatorChar) != -1) {
- this.fileName = filePath.substring(filePath.lastIndexOf(File.separatorChar) + 1);
- } else {
- this.fileName = filePath;
- }
- } 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;
- }
+ /** The wrapped project file. */
+ private final ProjectFile projectFile;
/**
- * Returns the file entry associated with this path, if any.
+ * Creates a new wrapper around a project file.
*
- * @return The file entry associated with this path, or
- * <code>null</code> if this path denotes a directory
+ * @param projectFile
+ * The project file to wrap
*/
- public Entry getFileEntry() {
- return fileEntry;
+ public ProjectFileWrapper(ProjectFile projectFile) {
+ this.projectFile = projectFile;
}
/**
- * Sets the entry associated with this path.
+ * Returns the wrapped project file.
*
- * @param fileEntry
- * The entry
- */
- public void setFileEntry(Entry fileEntry) {
- this.fileEntry = fileEntry;
- }
-
- /**
- * {@inheritDoc}
+ * @return The wrapped project file
*/
- @Override
- public boolean equals(Object object) {
- if ((object == null) || !(object instanceof FileTreePath)) {
- return false;
- }
- FileTreePath fileTreePath = (FileTreePath) object;
- return fileTreePath.filePath.equals(filePath);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return filePath.hashCode();
+ public ProjectFile getProjectFile() {
+ return projectFile;
}
/**
*/
@Override
public String toString() {
- return fileName;
- }
-
- //
- // INTERFACE Comparable
- //
-
- /**
- * {@inheritDoc}
- */
- public int compareTo(FileTreePath otherFileTreePath) {
- return filePath.compareTo(otherFileTreePath.filePath);
+ return projectFile.getName();
}
}