summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/BindingPanel.java
diff options
context:
space:
mode:
authorBenjamin Culkin <scorpress@gmail.com>2024-05-19 17:56:33 -0400
committerBenjamin Culkin <scorpress@gmail.com>2024-05-19 17:56:33 -0400
commitaedc34d55462a75e329bbf342251ff6504cd117e (patch)
treebcc8f1f2352582717b484df302aeea6696b8f000 /projects/net.wotonomy.test/src/main/java/net/wotonomy/test/BindingPanel.java
Initial import from SVN
Diffstat (limited to 'projects/net.wotonomy.test/src/main/java/net/wotonomy/test/BindingPanel.java')
-rw-r--r--projects/net.wotonomy.test/src/main/java/net/wotonomy/test/BindingPanel.java172
1 files changed, 172 insertions, 0 deletions
diff --git a/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/BindingPanel.java b/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/BindingPanel.java
new file mode 100644
index 0000000..624dc37
--- /dev/null
+++ b/projects/net.wotonomy.test/src/main/java/net/wotonomy/test/BindingPanel.java
@@ -0,0 +1,172 @@
+package net.wotonomy.test;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.JPanel;
+import javax.swing.UIManager;
+import javax.swing.border.EmptyBorder;
+
+import net.wotonomy.ui.swing.components.ButtonPanel;
+import net.wotonomy.ui.swing.components.TreeChooser;
+
+/**
+* BindingPanel is a FileChooser-like panel that
+* uses a TreeModel as a data source. It basically
+* provides an alternative to JTree for rendering
+* and manipulating tree-like data.
+*/
+public class BindingPanel extends JPanel
+{
+ protected TreeChooser treeChooser;
+ protected ButtonPanel okPanel;
+
+ public BindingPanel()
+ {
+ init();
+ }
+
+ protected void init()
+ {
+ this.setBorder( new EmptyBorder( 10, 10, 10, 10 ) );
+ this.setLayout( new BorderLayout( 10, 10 ) );
+
+ this.add( treeChooser = new TreeChooser(), BorderLayout.CENTER );
+
+ okPanel = new ButtonPanel( new String[] { "OK", "Cancel" } );
+ this.add( okPanel, BorderLayout.SOUTH );
+ }
+
+ /**
+ * Creates a new folder.
+ */
+ protected class NewFolderAction extends AbstractAction
+ {
+ protected NewFolderAction()
+ {
+ super("New Folder", UIManager.getIcon("FileChooser.newFolderIcon") );
+ }
+ public void actionPerformed(ActionEvent e)
+ {
+ }
+ }
+
+ /**
+ * Acts on the "home" key event or equivalent event.
+ */
+ protected class GoHomeAction extends AbstractAction
+ {
+ protected GoHomeAction()
+ {
+ super("Go Home", UIManager.getIcon("FileChooser.homeFolderIcon") );
+ }
+ public void actionPerformed(ActionEvent e)
+ {
+ }
+ }
+
+ protected class ChangeToParentDirectoryAction extends AbstractAction
+ {
+ protected ChangeToParentDirectoryAction()
+ {
+ super("Go Up", UIManager.getIcon("FileChooser.upFolderIcon") );
+ }
+ public void actionPerformed(ActionEvent e)
+ {
+ }
+ }
+
+ /**
+ * Responds to an Open or Save request
+ */
+ protected class ApproveSelectionAction extends AbstractAction {
+ public void actionPerformed(ActionEvent e)
+ {
+ }
+ }
+
+
+ /**
+ * Responds to a cancel request.
+ */
+ protected class CancelSelectionAction extends AbstractAction {
+ public void actionPerformed(ActionEvent e)
+ {
+ }
+ }
+
+ /**
+ * Rescans the files in the current directory
+ */
+ protected class UpdateAction extends AbstractAction {
+ public void actionPerformed(ActionEvent e)
+ {
+ }
+ }
+
+ //
+ // Renderer for DirectoryComboBox
+ //
+/*
+ class DirectoryComboBoxRenderer extends DefaultListCellRenderer {
+ IndentIcon ii = new IndentIcon();
+ public Component getListCellRendererComponent(JList list, Object value,
+ int index, boolean isSelected,
+ boolean cellHasFocus) {
+
+ super.getListCellRendererComponent(list, value, index,
+ isSelected, cellHasFocus);
+ File directory = (File) value;
+ if(directory == null) {
+ setText("");
+ return this;
+ }
+
+ String fileName = getFileChooser().getName(directory);
+ setText(fileName);
+
+ // Find the depth of the directory
+ int depth = 0;
+ if(index != -1) {
+ File f = directory;
+ while(f.getParent() != null) {
+ depth++;
+ f = getFileChooser().getFileSystemView().createFileObject(
+ f.getParent()
+ );
+ }
+ }
+
+ Icon icon = getFileChooser().getIcon(directory);
+
+ ii.icon = icon;
+ ii.depth = depth;
+
+ setIcon(ii);
+
+ return this;
+ }
+ }
+
+ final static int space = 10;
+ class IndentIcon implements Icon {
+
+ Icon icon = null;
+ int depth = 0;
+
+ public void paintIcon(Component c, Graphics g, int x, int y) {
+ icon.paintIcon(c, g, x+depth*space, y);
+ }
+
+ public int getIconWidth() {
+ return icon.getIconWidth() + depth*space;
+ }
+
+ public int getIconHeight() {
+ return icon.getIconHeight();
+ }
+
+ }
+*/
+}