From dc77498d76f44c218603e026b825b389865bba73 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 28 May 2008 23:04:43 +0200 Subject: [PATCH] next stab at file manager --- src/net/pterodactylus/jsite/gui/FileManager.java | 67 ++++++++++++++++++---- src/net/pterodactylus/jsite/i18n/jSite.properties | 6 ++ .../pterodactylus/jsite/i18n/jSite_de.properties | 6 ++ 3 files changed, 69 insertions(+), 10 deletions(-) diff --git a/src/net/pterodactylus/jsite/gui/FileManager.java b/src/net/pterodactylus/jsite/gui/FileManager.java index 8f10ebb..038eda8 100644 --- a/src/net/pterodactylus/jsite/gui/FileManager.java +++ b/src/net/pterodactylus/jsite/gui/FileManager.java @@ -37,13 +37,12 @@ import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JDialog; -import javax.swing.JFrame; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTree; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; -import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeModel; @@ -54,11 +53,12 @@ import net.pterodactylus.jsite.i18n.gui.I18nLabel; import net.pterodactylus.jsite.project.Project; import net.pterodactylus.util.io.MimeTypes; 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, ActionListener, TreeSelectionListener { @@ -72,9 +72,15 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** 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 TreeModel fileTreeModel; + /** The “rescan” action. */ + private I18nAction rescanAction; + /** The “close” action. */ private I18nAction closeAction; @@ -101,7 +107,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * Creates a new file manager. - * + * * @param swingInterface * The Swing interface * @param project @@ -112,7 +118,8 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr logger.log(Level.FINEST, "project: " + project); this.swingInterface = swingInterface; this.project = project; - fileTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode(File.separator)); + fileTreeRoot = new SortableTreeNode(project.getName()); + fileTreeModel = new DefaultTreeModel(fileTreeRoot); initActions(); initComponents(); pack(); @@ -131,7 +138,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr if (visible) { initiateFileScan(); } - super.setVisible(visible); + super.setVisible(visible); } // @@ -151,6 +158,16 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr setVisible(false); } }; + rescanAction = new I18nAction("fileManager.button.rescan") { + + /** + * {@inheritDoc} + */ + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + initiateFileScan(); + } + }; insertAction = new I18nAction("fileManager.checkbox.insertFile") { /** @@ -190,12 +207,13 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** * 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)); + /* file tree panel */ JPanel fileTreePanel = new JPanel(new BorderLayout(12, 12)); fileManagerPanel.add(fileTreePanel, BorderLayout.LINE_START); @@ -209,6 +227,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr fileTreePanel.add(projectFilesLabelPanel, BorderLayout.NORTH); projectFilesLabelPanel.add(projectFilesLabel); + /* properties panel */ JPanel propertiesPanel = new JPanel(new GridBagLayout()); fileManagerPanel.add(propertiesPanel, BorderLayout.CENTER); propertiesPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(12, 12, 12, 12))); @@ -226,12 +245,16 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr 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)); + /* action button panel */ + JPanel actionButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12)); + actionButtonPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(-12, -12, -12, -12))); + return fileManagerPanel; } /** * Creates the button panel. - * + * * @return The button panel */ private Component createButtonPanel() { @@ -247,13 +270,37 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr private void initiateFileScan() { swingInterface.getThreadPool().execute(new Runnable() { + /** * @see java.lang.Runnable#run() */ + @SuppressWarnings("synthetic-access") public void run() { - String basePath = project.getBasePath(); - File basePathDirectory = new File(basePath); + String basePath = project.getBasePath(); + File basePathDirectory = new File(basePath); + if (!basePathDirectory.exists() || !basePathDirectory.isDirectory()) { + /* TODO - i18n */ + JOptionPane.showMessageDialog(FileManager.this, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE); + return; + } + synchronized (fileTreeRoot) { + scanDirectory(fileTreeRoot, basePathDirectory); + } + fileTree.repaint(); + } + + private void scanDirectory(SortableTreeNode rootNode, File directory) { + System.out.println("scanning " + directory.getAbsolutePath()); + for (File file: directory.listFiles()) { + SortableTreeNode fileNode = new SortableTreeNode(file.getName()); + rootNode.add(fileNode); + if (file.isDirectory()) { + scanDirectory(fileNode, file); + } + } + rootNode.sort(); } + }); } diff --git a/src/net/pterodactylus/jsite/i18n/jSite.properties b/src/net/pterodactylus/jsite/i18n/jSite.properties index 5c02c6f..9f12cce 100644 --- a/src/net/pterodactylus/jsite/i18n/jSite.properties +++ b/src/net/pterodactylus/jsite/i18n/jSite.properties @@ -331,6 +331,12 @@ fileManager.button.close.accelerator: VK_ESC fileManager.button.close.shortDescription: Close the file manager fileManager.button.close.longDescription: Close the file manager +fileManager.button.rescan.name: Rescan Files +fileManager.button.rescan.mnemonic: VK_R +fileManager.button.rescan.accelerator: Ctrl-VK_R +fileManager.button.rescan.shortDescription: Rescans the project\u2019s directory +fileManager.button.rescan.longDescription: Rescans the project\u2019s directory + fileManager.label.projectFiles.name: Project Files fileManager.label.projectFiles.mnemonic: VK_F diff --git a/src/net/pterodactylus/jsite/i18n/jSite_de.properties b/src/net/pterodactylus/jsite/i18n/jSite_de.properties index ce447ac..343f8aa 100644 --- a/src/net/pterodactylus/jsite/i18n/jSite_de.properties +++ b/src/net/pterodactylus/jsite/i18n/jSite_de.properties @@ -331,6 +331,12 @@ fileManager.button.close.accelerator: VK_ESC fileManager.button.close.shortDescription: Beendet die Dateiverwaltung fileManager.button.close.longDescription: Beendet die Dateiverwaltung +fileManager.button.rescan.name: Dateien neu einlesen +fileManager.button.rescan.mnemonic: VK_L +fileManager.button.rescan.accelerator: Ctrl-VK_L +fileManager.button.rescan.shortDescription: Liest die Projektdateien neu ein +fileManager.button.rescan.longDescription: Liest die Projektdateien neu ein + fileManager.label.projectFiles.name: Projektdateien fileManager.label.projectFiles.mnemonic: VK_D -- 2.7.4