Classes in this File | Line Coverage | Branch Coverage | Complexity | |||||||
BindingPanel |
|
| 1.0;1 |
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 | 0 | public BindingPanel() |
26 | 0 | { |
27 | 0 | init(); |
28 | 0 | } |
29 | ||
30 | protected void init() |
|
31 | { |
|
32 | 0 | this.setBorder( new EmptyBorder( 10, 10, 10, 10 ) ); |
33 | 0 | this.setLayout( new BorderLayout( 10, 10 ) ); |
34 | ||
35 | 0 | this.add( treeChooser = new TreeChooser(), BorderLayout.CENTER ); |
36 | ||
37 | 0 | okPanel = new ButtonPanel( new String[] { "OK", "Cancel" } ); |
38 | 0 | this.add( okPanel, BorderLayout.SOUTH ); |
39 | 0 | } |
40 | ||
41 | /** |
|
42 | * Creates a new folder. |
|
43 | */ |
|
44 | protected class NewFolderAction extends AbstractAction |
|
45 | { |
|
46 | protected NewFolderAction() |
|
47 | 0 | { |
48 | 0 | super("New Folder", UIManager.getIcon("FileChooser.newFolderIcon") ); |
49 | 0 | } |
50 | public void actionPerformed(ActionEvent e) |
|
51 | { |
|
52 | 0 | } |
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 | 0 | { |
62 | 0 | super("Go Home", UIManager.getIcon("FileChooser.homeFolderIcon") ); |
63 | 0 | } |
64 | public void actionPerformed(ActionEvent e) |
|
65 | { |
|
66 | 0 | } |
67 | } |
|
68 | ||
69 | protected class ChangeToParentDirectoryAction extends AbstractAction |
|
70 | { |
|
71 | protected ChangeToParentDirectoryAction() |
|
72 | 0 | { |
73 | 0 | super("Go Up", UIManager.getIcon("FileChooser.upFolderIcon") ); |
74 | 0 | } |
75 | public void actionPerformed(ActionEvent e) |
|
76 | { |
|
77 | 0 | } |
78 | } |
|
79 | ||
80 | /** |
|
81 | * Responds to an Open or Save request |
|
82 | */ |
|
83 | 0 | protected class ApproveSelectionAction extends AbstractAction { |
84 | public void actionPerformed(ActionEvent e) |
|
85 | { |
|
86 | 0 | } |
87 | } |
|
88 | ||
89 | ||
90 | /** |
|
91 | * Responds to a cancel request. |
|
92 | */ |
|
93 | 0 | protected class CancelSelectionAction extends AbstractAction { |
94 | public void actionPerformed(ActionEvent e) |
|
95 | { |
|
96 | 0 | } |
97 | } |
|
98 | ||
99 | /** |
|
100 | * Rescans the files in the current directory |
|
101 | */ |
|
102 | 0 | protected class UpdateAction extends AbstractAction { |
103 | public void actionPerformed(ActionEvent e) |
|
104 | { |
|
105 | 0 | } |
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 | } |