import java.awt.BorderLayout;
import java.awt.Component;
+import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
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;
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;
/** 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;
@SuppressWarnings("synthetic-access")
public void actionPerformed(ActionEvent actionEvent) {
initiateFileScan();
+ setEnabled(false);
}
};
insertAction = new I18nAction("fileManager.checkbox.insertFile") {
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);
/* 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;
}
return buttonPanel;
}
+ /**
+ * Initiates a file scan.
+ */
private void initiateFileScan() {
swingInterface.getThreadPool().execute(new Runnable() {
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);
* {@inheritDoc}
*/
public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
+ /* TODO */
}
//
* {@inheritDoc}
*/
public void actionPerformed(ActionEvent actionEvent) {
+ /* TODO */
}
}