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(); } * * } */ }