View Javadoc

1   package net.wotonomy.test;
2   
3   import java.awt.BorderLayout;
4   import java.awt.event.ActionEvent;
5   
6   import javax.swing.AbstractAction;
7   import javax.swing.JPanel;
8   import javax.swing.UIManager;
9   import javax.swing.border.EmptyBorder;
10  
11  import net.wotonomy.ui.swing.components.ButtonPanel;
12  import net.wotonomy.ui.swing.components.TreeChooser;
13  
14  /***
15  * BindingPanel is a FileChooser-like panel that
16  * uses a TreeModel as a data source.  It basically
17  * provides an alternative to JTree for rendering 
18  * and manipulating tree-like data.
19  */
20  public class BindingPanel extends JPanel 
21  {    
22  	protected TreeChooser treeChooser;
23  	protected ButtonPanel okPanel;
24  	
25      public BindingPanel()
26      {
27  		init();
28  	}
29  	
30  	protected void init()
31  	{
32  		this.setBorder( new EmptyBorder( 10, 10, 10, 10 ) );
33  		this.setLayout( new BorderLayout( 10, 10 ) );	
34          
35          this.add( treeChooser = new TreeChooser(), BorderLayout.CENTER );
36  		
37  		okPanel = new ButtonPanel( new String[] { "OK", "Cancel" } );
38  		this.add( okPanel, BorderLayout.SOUTH );
39  	}
40  	
41      /***
42       * Creates a new folder.
43       */
44      protected class NewFolderAction extends AbstractAction 
45  	{
46  		protected NewFolderAction() 
47  		{
48  			super("New Folder", UIManager.getIcon("FileChooser.newFolderIcon") );
49  		}
50  		public void actionPerformed(ActionEvent e) 
51  		{
52  		}
53      }
54  
55      /***
56       * Acts on the "home" key event or equivalent event.
57       */
58      protected class GoHomeAction extends AbstractAction 
59  	{
60  		protected GoHomeAction() 
61  		{
62  			super("Go Home", UIManager.getIcon("FileChooser.homeFolderIcon") );
63  		}
64  		public void actionPerformed(ActionEvent e) 
65  		{
66  		}
67      }
68  
69      protected class ChangeToParentDirectoryAction extends AbstractAction 
70  	{
71  		protected ChangeToParentDirectoryAction() 
72  		{
73  			super("Go Up", UIManager.getIcon("FileChooser.upFolderIcon") );
74  		}
75  		public void actionPerformed(ActionEvent e) 
76  		{
77  		}
78  	}
79  
80      /***
81       * Responds to an Open or Save request
82       */
83      protected class ApproveSelectionAction extends AbstractAction {
84  		public void actionPerformed(ActionEvent e) 
85  		{
86  		}
87      }
88  
89  
90      /***
91       * Responds to a cancel request.
92       */
93      protected class CancelSelectionAction extends AbstractAction {
94  		public void actionPerformed(ActionEvent e) 
95  		{
96  		}
97      }
98  
99      /***
100      * Rescans the files in the current directory
101      */
102     protected class UpdateAction extends AbstractAction {
103 		public void actionPerformed(ActionEvent e) 
104 		{
105 		}
106     }
107     
108     //
109     // Renderer for DirectoryComboBox
110     //
111 /*	
112     class DirectoryComboBoxRenderer extends DefaultListCellRenderer  {
113 		IndentIcon ii = new IndentIcon();
114 		public Component getListCellRendererComponent(JList list, Object value,
115 								  int index, boolean isSelected,
116 								  boolean cellHasFocus) {
117 	
118 			super.getListCellRendererComponent(list, value, index,
119 							   isSelected, cellHasFocus);
120 			File directory = (File) value;
121 			if(directory == null) {
122 			setText("");
123 			return this;
124 			}
125 	
126 			String fileName = getFileChooser().getName(directory);
127 				setText(fileName);
128 	
129 			// Find the depth of the directory
130 			int depth = 0;
131 			if(index != -1) {
132 			File f = directory;
133 			while(f.getParent() != null) {
134 				depth++;
135 						f = getFileChooser().getFileSystemView().createFileObject(
136 							f.getParent()
137 						);
138 			}
139 			}
140 			
141 			Icon icon = getFileChooser().getIcon(directory);
142 	
143 			ii.icon = icon;
144 			ii.depth = depth;
145 			
146 			setIcon(ii);
147 	
148 			return this;
149 		}
150     }
151 
152     final static int space = 10;
153     class IndentIcon implements Icon {
154 	
155 		Icon icon = null;
156 		int depth = 0;
157 	
158 		public void paintIcon(Component c, Graphics g, int x, int y) {
159 			icon.paintIcon(c, g, x+depth*space, y);
160 		}
161 	
162 		public int getIconWidth() {
163 			return icon.getIconWidth() + depth*space;
164 		}
165 	
166 		public int getIconHeight() {
167 			return icon.getIconHeight();
168 		}
169 	
170     }
171 */
172 }