From: David ‘Bombe’ Roden Date: Thu, 29 May 2008 06:54:05 +0000 (+0200) Subject: fix scroll pane size X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=617d32cb14acf089bfa1afd2a301592a009e3c19;p=jSite2.git fix scroll pane size implement rescan --- diff --git a/src/net/pterodactylus/jsite/gui/FileManager.java b/src/net/pterodactylus/jsite/gui/FileManager.java index 038eda8..20d98a3 100644 --- a/src/net/pterodactylus/jsite/gui/FileManager.java +++ b/src/net/pterodactylus/jsite/gui/FileManager.java @@ -21,6 +21,7 @@ package net.pterodactylus.jsite.gui; import java.awt.BorderLayout; import java.awt.Component; +import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; @@ -44,7 +45,6 @@ import javax.swing.JTree; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreeModel; import net.pterodactylus.jsite.i18n.I18n; import net.pterodactylus.jsite.i18n.I18nable; @@ -76,7 +76,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr private final SortableTreeNode fileTreeRoot; /** The tree model for the project files. */ - private final TreeModel fileTreeModel; + private final DefaultTreeModel fileTreeModel; /** The “rescan” action. */ private I18nAction rescanAction; @@ -90,6 +90,9 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** The tree that shows the files. */ private JTree fileTree; + /** The scroll pane that holds the file tree. */ + private JScrollPane fileScrollPane; + /** The “insert” action. */ private I18nAction insertAction; @@ -166,6 +169,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { initiateFileScan(); + setEnabled(false); } }; insertAction = new I18nAction("fileManager.checkbox.insertFile") { @@ -220,16 +224,21 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr fileTree = new JTree(fileTreeModel); fileTree.setShowsRootHandles(false); fileTree.addTreeSelectionListener(this); - fileTreePanel.add(new JScrollPane(fileTree), BorderLayout.CENTER); + 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()); - fileManagerPanel.add(propertiesPanel, BorderLayout.CENTER); + rightPanel.add(propertiesPanel, BorderLayout.CENTER); propertiesPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(12, 12, 12, 12))); insertCheckBox = new JCheckBox(insertAction); @@ -247,8 +256,12 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /* 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))); - + rightPanel.add(actionButtonPanel, BorderLayout.PAGE_END); + actionButtonPanel.setBorder(BorderFactory.createEtchedBorder()); + + JButton rescanButton = new JButton(rescanAction); + actionButtonPanel.add(rescanButton); + return fileManagerPanel; } @@ -268,6 +281,9 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr return buttonPanel; } + /** + * Initiates a file scan. + */ private void initiateFileScan() { swingInterface.getThreadPool().execute(new Runnable() { @@ -284,13 +300,15 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr return; } synchronized (fileTreeRoot) { + fileTreeRoot.removeAll(); scanDirectory(fileTreeRoot, basePathDirectory); } - fileTree.repaint(); + fileTreeModel.reload(); + fileScrollPane.revalidate(); + rescanAction.setEnabled(true); } 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); @@ -323,6 +341,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr * {@inheritDoc} */ public void valueChanged(TreeSelectionEvent treeSelectionEvent) { + /* TODO */ } // @@ -333,6 +352,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr * {@inheritDoc} */ public void actionPerformed(ActionEvent actionEvent) { + /* TODO */ } }