39 |
package javax.swing.plaf.metal; |
package javax.swing.plaf.metal; |
40 |
|
|
41 |
import java.awt.Component; |
import java.awt.Component; |
42 |
|
import java.awt.event.ActionEvent; |
43 |
import java.beans.PropertyChangeEvent; |
import java.beans.PropertyChangeEvent; |
44 |
import java.beans.PropertyChangeListener; |
import java.beans.PropertyChangeListener; |
45 |
import java.io.File; |
import java.io.File; |
46 |
import java.util.List; |
import java.util.List; |
47 |
|
|
48 |
|
import javax.swing.AbstractAction; |
49 |
import javax.swing.AbstractListModel; |
import javax.swing.AbstractListModel; |
50 |
import javax.swing.ComboBoxModel; |
import javax.swing.ComboBoxModel; |
51 |
import javax.swing.DefaultListCellRenderer; |
import javax.swing.DefaultListCellRenderer; |
52 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
53 |
import javax.swing.JFileChooser; |
import javax.swing.JFileChooser; |
54 |
import javax.swing.JList; |
import javax.swing.JList; |
55 |
|
import javax.swing.UIManager; |
56 |
import javax.swing.filechooser.FileFilter; |
import javax.swing.filechooser.FileFilter; |
57 |
import javax.swing.filechooser.FileSystemView; |
import javax.swing.filechooser.FileSystemView; |
58 |
|
import javax.swing.filechooser.FileView; |
59 |
import javax.swing.plaf.ComponentUI; |
import javax.swing.plaf.ComponentUI; |
60 |
import javax.swing.plaf.basic.BasicFileChooserUI; |
import javax.swing.plaf.basic.BasicFileChooserUI; |
61 |
|
|
161 |
} |
} |
162 |
|
|
163 |
/** |
/** |
164 |
|
* Handles changes to the selection in the directory combo box. |
165 |
|
*/ |
166 |
|
protected class DirectoryComboBoxAction |
167 |
|
extends AbstractAction |
168 |
|
{ |
169 |
|
/** |
170 |
|
* Creates a new action. |
171 |
|
*/ |
172 |
|
protected DirectoryComboBoxAction() |
173 |
|
{ |
174 |
|
} |
175 |
|
|
176 |
|
/** |
177 |
|
* Handles the action event. |
178 |
|
* |
179 |
|
* @param e the event. |
180 |
|
*/ |
181 |
|
public void actionPerformed(ActionEvent e) |
182 |
|
{ |
183 |
|
JFileChooser fc = getFileChooser(); |
184 |
|
fc.setCurrentDirectory((File) directoryModel.getSelectedItem()); |
185 |
|
} |
186 |
|
} |
187 |
|
|
188 |
|
/** |
189 |
|
* A renderer for the files and directories in the file chooser. |
190 |
|
*/ |
191 |
|
protected class FileRenderer |
192 |
|
extends DefaultListCellRenderer |
193 |
|
{ |
194 |
|
|
195 |
|
/** |
196 |
|
* Creates a new renderer. |
197 |
|
*/ |
198 |
|
protected FileRenderer() |
199 |
|
{ |
200 |
|
} |
201 |
|
|
202 |
|
/** |
203 |
|
* Returns a component that can render the specified value. |
204 |
|
* |
205 |
|
* @param list the list. |
206 |
|
* @param value the value (a {@link File}). |
207 |
|
* @param index the index. |
208 |
|
* @param isSelected is the item selected? |
209 |
|
* @param cellHasFocus does the item have the focus? |
210 |
|
* |
211 |
|
* @return The renderer. |
212 |
|
*/ |
213 |
|
public Component getListCellRendererComponent(JList list, Object value, |
214 |
|
int index, boolean isSelected, boolean cellHasFocus) |
215 |
|
{ |
216 |
|
FileView v = getFileView(getFileChooser()); |
217 |
|
File f = (File) value; |
218 |
|
setText(v.getName(f)); |
219 |
|
setIcon(v.getIcon(f)); |
220 |
|
if (isSelected) |
221 |
|
{ |
222 |
|
setBackground(list.getSelectionBackground()); |
223 |
|
setForeground(list.getSelectionForeground()); |
224 |
|
} |
225 |
|
else |
226 |
|
{ |
227 |
|
setBackground(list.getBackground()); |
228 |
|
setForeground(list.getForeground()); |
229 |
|
} |
230 |
|
|
231 |
|
setEnabled(list.isEnabled()); |
232 |
|
setFont(list.getFont()); |
233 |
|
|
234 |
|
if (cellHasFocus) |
235 |
|
setBorder(UIManager.getBorder("List.focusCellHighlightBorder")); |
236 |
|
else |
237 |
|
setBorder(noFocusBorder); |
238 |
|
return this; |
239 |
|
} |
240 |
|
} |
241 |
|
|
242 |
|
/** |
243 |
* A combo box model for the file selection filters. |
* A combo box model for the file selection filters. |
244 |
*/ |
*/ |
245 |
protected class FilterComboBoxModel |
protected class FilterComboBoxModel |
372 |
} |
} |
373 |
} |
} |
374 |
|
|
375 |
|
/** The model for the directory combo box. */ |
376 |
|
private DirectoryComboBoxModel directoryModel; |
377 |
|
|
378 |
/** |
/** |
379 |
* A factory method that returns a UI delegate for the specified |
* A factory method that returns a UI delegate for the specified |
380 |
* component. |
* component. |