41 import java.security.AccessController;
42 import java.security.PrivilegedAction;
43 import javax.accessibility.*;
44
45 import sun.awt.shell.ShellFolder;
46 import sun.swing.*;
47
48 /**
49 * Metal L&F implementation of a FileChooser.
50 *
51 * @author Jeff Dinkins
52 */
53 public class MetalFileChooserUI extends BasicFileChooserUI {
54
55 // Much of the Metal UI for JFilechooser is just a copy of
56 // the windows implementation, but using Metal themed buttons, lists,
57 // icons, etc. We are planning a complete rewrite, and hence we've
58 // made most things in this class private.
59
60 private JLabel lookInLabel;
61 private JComboBox directoryComboBox;
62 private DirectoryComboBoxModel directoryComboBoxModel;
63 private Action directoryComboBoxAction = new DirectoryComboBoxAction();
64
65 private FilterComboBoxModel filterComboBoxModel;
66
67 private JTextField fileNameTextField;
68
69 private FilePane filePane;
70 private JToggleButton listViewButton;
71 private JToggleButton detailsViewButton;
72
73 private JButton approveButton;
74 private JButton cancelButton;
75
76 private JPanel buttonPanel;
77 private JPanel bottomPanel;
78
79 private JComboBox filterComboBox;
80
81 private static final Dimension hstrut5 = new Dimension(5, 1);
82 private static final Dimension hstrut11 = new Dimension(11, 1);
83
84 private static final Dimension vstrut5 = new Dimension(1, 5);
85
86 private static final Insets shrinkwrap = new Insets(0,0,0,0);
87
88 // Preferred and Minimum sizes for the dialog box
89 private static int PREF_WIDTH = 500;
90 private static int PREF_HEIGHT = 326;
91 private static Dimension PREF_SIZE = new Dimension(PREF_WIDTH, PREF_HEIGHT);
92
93 private static int MIN_WIDTH = 500;
94 private static int MIN_HEIGHT = 326;
95 private static Dimension MIN_SIZE = new Dimension(MIN_WIDTH, MIN_HEIGHT);
96
97 private static int LIST_PREF_WIDTH = 405;
98 private static int LIST_PREF_HEIGHT = 135;
99 private static Dimension LIST_PREF_SIZE = new Dimension(LIST_PREF_WIDTH, LIST_PREF_HEIGHT);
179 public boolean isDirectorySelected() {
180 return MetalFileChooserUI.this.isDirectorySelected();
181 }
182
183 public File getDirectory() {
184 return MetalFileChooserUI.this.getDirectory();
185 }
186
187 public Action getChangeToParentDirectoryAction() {
188 return MetalFileChooserUI.this.getChangeToParentDirectoryAction();
189 }
190
191 public Action getApproveSelectionAction() {
192 return MetalFileChooserUI.this.getApproveSelectionAction();
193 }
194
195 public Action getNewFolderAction() {
196 return MetalFileChooserUI.this.getNewFolderAction();
197 }
198
199 public MouseListener createDoubleClickListener(JList list) {
200 return MetalFileChooserUI.this.createDoubleClickListener(getFileChooser(),
201 list);
202 }
203
204 public ListSelectionListener createListSelectionListener() {
205 return MetalFileChooserUI.this.createListSelectionListener(getFileChooser());
206 }
207 }
208
209 public void installComponents(JFileChooser fc) {
210 FileSystemView fsv = fc.getFileSystemView();
211
212 fc.setBorder(new EmptyBorder(12, 12, 11, 11));
213 fc.setLayout(new BorderLayout(0, 11));
214
215 filePane = new FilePane(new MetalFileChooserUIAccessor());
216 fc.addPropertyChangeListener(filePane);
217
218 // ********************************* //
219 // **** Construct the top panel **** //
220 // ********************************* //
221
222 // Directory manipulation buttons
223 JPanel topPanel = new JPanel(new BorderLayout(11, 0));
224 JPanel topButtonPanel = new JPanel();
225 topButtonPanel.setLayout(new BoxLayout(topButtonPanel, BoxLayout.LINE_AXIS));
226 topPanel.add(topButtonPanel, BorderLayout.AFTER_LINE_ENDS);
227
228 // Add the top panel to the fileChooser
229 fc.add(topPanel, BorderLayout.NORTH);
230
231 // ComboBox Label
232 lookInLabel = new JLabel(lookInLabelText);
233 lookInLabel.setDisplayedMnemonic(lookInLabelMnemonic);
234 topPanel.add(lookInLabel, BorderLayout.BEFORE_LINE_BEGINS);
235
236 // CurrentDir ComboBox
237 @SuppressWarnings("serial") // anonymous class
238 JComboBox tmp1 = new JComboBox() {
239 public Dimension getPreferredSize() {
240 Dimension d = super.getPreferredSize();
241 // Must be small enough to not affect total width.
242 d.width = 150;
243 return d;
244 }
245 };
246 directoryComboBox = tmp1;
247 directoryComboBox.putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY,
248 lookInLabelText);
249 directoryComboBox.putClientProperty( "JComboBox.isTableCellEditor", Boolean.TRUE );
250 lookInLabel.setLabelFor(directoryComboBox);
251 directoryComboBoxModel = createDirectoryComboBoxModel(fc);
252 directoryComboBox.setModel(directoryComboBoxModel);
253 directoryComboBox.addActionListener(directoryComboBoxAction);
254 directoryComboBox.setRenderer(createDirectoryComboBoxRenderer(fc));
255 directoryComboBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
256 directoryComboBox.setAlignmentY(JComponent.TOP_ALIGNMENT);
257 directoryComboBox.setMaximumRowCount(8);
258
401 }
402 );
403 if (fc.isMultiSelectionEnabled()) {
404 setFileName(fileNameString(fc.getSelectedFiles()));
405 } else {
406 setFileName(fileNameString(fc.getSelectedFile()));
407 }
408
409
410 // Filetype label and combobox
411 JPanel filesOfTypePanel = new JPanel();
412 filesOfTypePanel.setLayout(new BoxLayout(filesOfTypePanel, BoxLayout.LINE_AXIS));
413 bottomPanel.add(filesOfTypePanel);
414
415 AlignedLabel filesOfTypeLabel = new AlignedLabel(filesOfTypeLabelText);
416 filesOfTypeLabel.setDisplayedMnemonic(filesOfTypeLabelMnemonic);
417 filesOfTypePanel.add(filesOfTypeLabel);
418
419 filterComboBoxModel = createFilterComboBoxModel();
420 fc.addPropertyChangeListener(filterComboBoxModel);
421 filterComboBox = new JComboBox(filterComboBoxModel);
422 filterComboBox.putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY,
423 filesOfTypeLabelText);
424 filesOfTypeLabel.setLabelFor(filterComboBox);
425 filterComboBox.setRenderer(createFilterComboBoxRenderer());
426 filesOfTypePanel.add(filterComboBox);
427
428 // buttons
429 getButtonPanel().setLayout(new ButtonAreaLayout());
430
431 approveButton = new JButton(getApproveButtonText(fc));
432 // Note: Metal does not use mnemonics for approve and cancel
433 approveButton.addActionListener(getApproveSelectionAction());
434 approveButton.setToolTipText(getApproveButtonToolTipText(fc));
435 getButtonPanel().add(approveButton);
436
437 cancelButton = new JButton(cancelButtonText);
438 cancelButton.setToolTipText(cancelButtonToolTipText);
439 cancelButton.addActionListener(getCancelSelectionAction());
440 getButtonPanel().add(cancelButton);
441
516 protected JPanel createList(JFileChooser fc) {
517 return filePane.createList();
518 }
519
520 protected JPanel createDetailsView(JFileChooser fc) {
521 return filePane.createDetailsView();
522 }
523
524 /**
525 * Creates a selection listener for the list of files and directories.
526 *
527 * @param fc a <code>JFileChooser</code>
528 * @return a <code>ListSelectionListener</code>
529 */
530 public ListSelectionListener createListSelectionListener(JFileChooser fc) {
531 return super.createListSelectionListener(fc);
532 }
533
534 // Obsolete class, not used in this version.
535 protected class SingleClickListener extends MouseAdapter {
536 public SingleClickListener(JList list) {
537 }
538 }
539
540 // Obsolete class, not used in this version.
541 @SuppressWarnings("serial") // Superclass is not serializable across versions
542 protected class FileRenderer extends DefaultListCellRenderer {
543 }
544
545 public void uninstallUI(JComponent c) {
546 // Remove listeners
547 c.removePropertyChangeListener(filterComboBoxModel);
548 c.removePropertyChangeListener(filePane);
549 cancelButton.removeActionListener(getCancelSelectionAction());
550 approveButton.removeActionListener(getApproveSelectionAction());
551 fileNameTextField.removeActionListener(getApproveSelectionAction());
552
553 if (filePane != null) {
554 filePane.uninstallUI();
555 filePane = null;
556 }
844
845 public String getDirectoryName() {
846 // PENDING(jeff) - get the name from the directory combobox
847 return null;
848 }
849
850 public void setDirectoryName(String dirname) {
851 // PENDING(jeff) - set the name in the directory combobox
852 }
853
854 protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer(JFileChooser fc) {
855 return new DirectoryComboBoxRenderer();
856 }
857
858 //
859 // Renderer for DirectoryComboBox
860 //
861 @SuppressWarnings("serial") // Superclass is not serializable across versions
862 class DirectoryComboBoxRenderer extends DefaultListCellRenderer {
863 IndentIcon ii = new IndentIcon();
864 public Component getListCellRendererComponent(JList list, Object value,
865 int index, boolean isSelected,
866 boolean cellHasFocus) {
867
868 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
869
870 if (value == null) {
871 setText("");
872 return this;
873 }
874 File directory = (File)value;
875 setText(getFileChooser().getName(directory));
876 Icon icon = getFileChooser().getIcon(directory);
877 ii.icon = icon;
878 ii.depth = directoryComboBoxModel.getDepth(index);
879 setIcon(ii);
880
881 return this;
882 }
883 }
884
1034 return directories.size();
1035 }
1036
1037 public Object getElementAt(int index) {
1038 return directories.elementAt(index);
1039 }
1040 }
1041
1042 //
1043 // Renderer for Types ComboBox
1044 //
1045 protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
1046 return new FilterComboBoxRenderer();
1047 }
1048
1049 /**
1050 * Render different type sizes and styles.
1051 */
1052 @SuppressWarnings("serial") // Superclass is not serializable across versions
1053 public class FilterComboBoxRenderer extends DefaultListCellRenderer {
1054 public Component getListCellRendererComponent(JList list,
1055 Object value, int index, boolean isSelected,
1056 boolean cellHasFocus) {
1057
1058 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
1059
1060 if (value != null && value instanceof FileFilter) {
1061 setText(((FileFilter)value).getDescription());
1062 }
1063
1064 return this;
1065 }
1066 }
1067
1068 //
1069 // DataModel for Types Comboxbox
1070 //
1071 protected FilterComboBoxModel createFilterComboBoxModel() {
1072 return new FilterComboBoxModel();
1073 }
1074
|
41 import java.security.AccessController;
42 import java.security.PrivilegedAction;
43 import javax.accessibility.*;
44
45 import sun.awt.shell.ShellFolder;
46 import sun.swing.*;
47
48 /**
49 * Metal L&F implementation of a FileChooser.
50 *
51 * @author Jeff Dinkins
52 */
53 public class MetalFileChooserUI extends BasicFileChooserUI {
54
55 // Much of the Metal UI for JFilechooser is just a copy of
56 // the windows implementation, but using Metal themed buttons, lists,
57 // icons, etc. We are planning a complete rewrite, and hence we've
58 // made most things in this class private.
59
60 private JLabel lookInLabel;
61 private JComboBox<Object> directoryComboBox;
62 private DirectoryComboBoxModel directoryComboBoxModel;
63 private Action directoryComboBoxAction = new DirectoryComboBoxAction();
64
65 private FilterComboBoxModel filterComboBoxModel;
66
67 private JTextField fileNameTextField;
68
69 private FilePane filePane;
70 private JToggleButton listViewButton;
71 private JToggleButton detailsViewButton;
72
73 private JButton approveButton;
74 private JButton cancelButton;
75
76 private JPanel buttonPanel;
77 private JPanel bottomPanel;
78
79 private JComboBox<?> filterComboBox;
80
81 private static final Dimension hstrut5 = new Dimension(5, 1);
82 private static final Dimension hstrut11 = new Dimension(11, 1);
83
84 private static final Dimension vstrut5 = new Dimension(1, 5);
85
86 private static final Insets shrinkwrap = new Insets(0,0,0,0);
87
88 // Preferred and Minimum sizes for the dialog box
89 private static int PREF_WIDTH = 500;
90 private static int PREF_HEIGHT = 326;
91 private static Dimension PREF_SIZE = new Dimension(PREF_WIDTH, PREF_HEIGHT);
92
93 private static int MIN_WIDTH = 500;
94 private static int MIN_HEIGHT = 326;
95 private static Dimension MIN_SIZE = new Dimension(MIN_WIDTH, MIN_HEIGHT);
96
97 private static int LIST_PREF_WIDTH = 405;
98 private static int LIST_PREF_HEIGHT = 135;
99 private static Dimension LIST_PREF_SIZE = new Dimension(LIST_PREF_WIDTH, LIST_PREF_HEIGHT);
179 public boolean isDirectorySelected() {
180 return MetalFileChooserUI.this.isDirectorySelected();
181 }
182
183 public File getDirectory() {
184 return MetalFileChooserUI.this.getDirectory();
185 }
186
187 public Action getChangeToParentDirectoryAction() {
188 return MetalFileChooserUI.this.getChangeToParentDirectoryAction();
189 }
190
191 public Action getApproveSelectionAction() {
192 return MetalFileChooserUI.this.getApproveSelectionAction();
193 }
194
195 public Action getNewFolderAction() {
196 return MetalFileChooserUI.this.getNewFolderAction();
197 }
198
199 public MouseListener createDoubleClickListener(JList<?> list) {
200 return MetalFileChooserUI.this.createDoubleClickListener(getFileChooser(),
201 list);
202 }
203
204 public ListSelectionListener createListSelectionListener() {
205 return MetalFileChooserUI.this.createListSelectionListener(getFileChooser());
206 }
207 }
208
209 public void installComponents(JFileChooser fc) {
210 FileSystemView fsv = fc.getFileSystemView();
211
212 fc.setBorder(new EmptyBorder(12, 12, 11, 11));
213 fc.setLayout(new BorderLayout(0, 11));
214
215 filePane = new FilePane(new MetalFileChooserUIAccessor());
216 fc.addPropertyChangeListener(filePane);
217
218 // ********************************* //
219 // **** Construct the top panel **** //
220 // ********************************* //
221
222 // Directory manipulation buttons
223 JPanel topPanel = new JPanel(new BorderLayout(11, 0));
224 JPanel topButtonPanel = new JPanel();
225 topButtonPanel.setLayout(new BoxLayout(topButtonPanel, BoxLayout.LINE_AXIS));
226 topPanel.add(topButtonPanel, BorderLayout.AFTER_LINE_ENDS);
227
228 // Add the top panel to the fileChooser
229 fc.add(topPanel, BorderLayout.NORTH);
230
231 // ComboBox Label
232 lookInLabel = new JLabel(lookInLabelText);
233 lookInLabel.setDisplayedMnemonic(lookInLabelMnemonic);
234 topPanel.add(lookInLabel, BorderLayout.BEFORE_LINE_BEGINS);
235
236 // CurrentDir ComboBox
237 @SuppressWarnings("serial") // anonymous class
238 JComboBox<Object> tmp1 = new JComboBox<Object>() {
239 public Dimension getPreferredSize() {
240 Dimension d = super.getPreferredSize();
241 // Must be small enough to not affect total width.
242 d.width = 150;
243 return d;
244 }
245 };
246 directoryComboBox = tmp1;
247 directoryComboBox.putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY,
248 lookInLabelText);
249 directoryComboBox.putClientProperty( "JComboBox.isTableCellEditor", Boolean.TRUE );
250 lookInLabel.setLabelFor(directoryComboBox);
251 directoryComboBoxModel = createDirectoryComboBoxModel(fc);
252 directoryComboBox.setModel(directoryComboBoxModel);
253 directoryComboBox.addActionListener(directoryComboBoxAction);
254 directoryComboBox.setRenderer(createDirectoryComboBoxRenderer(fc));
255 directoryComboBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
256 directoryComboBox.setAlignmentY(JComponent.TOP_ALIGNMENT);
257 directoryComboBox.setMaximumRowCount(8);
258
401 }
402 );
403 if (fc.isMultiSelectionEnabled()) {
404 setFileName(fileNameString(fc.getSelectedFiles()));
405 } else {
406 setFileName(fileNameString(fc.getSelectedFile()));
407 }
408
409
410 // Filetype label and combobox
411 JPanel filesOfTypePanel = new JPanel();
412 filesOfTypePanel.setLayout(new BoxLayout(filesOfTypePanel, BoxLayout.LINE_AXIS));
413 bottomPanel.add(filesOfTypePanel);
414
415 AlignedLabel filesOfTypeLabel = new AlignedLabel(filesOfTypeLabelText);
416 filesOfTypeLabel.setDisplayedMnemonic(filesOfTypeLabelMnemonic);
417 filesOfTypePanel.add(filesOfTypeLabel);
418
419 filterComboBoxModel = createFilterComboBoxModel();
420 fc.addPropertyChangeListener(filterComboBoxModel);
421 filterComboBox = new JComboBox<>(filterComboBoxModel);
422 filterComboBox.putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY,
423 filesOfTypeLabelText);
424 filesOfTypeLabel.setLabelFor(filterComboBox);
425 filterComboBox.setRenderer(createFilterComboBoxRenderer());
426 filesOfTypePanel.add(filterComboBox);
427
428 // buttons
429 getButtonPanel().setLayout(new ButtonAreaLayout());
430
431 approveButton = new JButton(getApproveButtonText(fc));
432 // Note: Metal does not use mnemonics for approve and cancel
433 approveButton.addActionListener(getApproveSelectionAction());
434 approveButton.setToolTipText(getApproveButtonToolTipText(fc));
435 getButtonPanel().add(approveButton);
436
437 cancelButton = new JButton(cancelButtonText);
438 cancelButton.setToolTipText(cancelButtonToolTipText);
439 cancelButton.addActionListener(getCancelSelectionAction());
440 getButtonPanel().add(cancelButton);
441
516 protected JPanel createList(JFileChooser fc) {
517 return filePane.createList();
518 }
519
520 protected JPanel createDetailsView(JFileChooser fc) {
521 return filePane.createDetailsView();
522 }
523
524 /**
525 * Creates a selection listener for the list of files and directories.
526 *
527 * @param fc a <code>JFileChooser</code>
528 * @return a <code>ListSelectionListener</code>
529 */
530 public ListSelectionListener createListSelectionListener(JFileChooser fc) {
531 return super.createListSelectionListener(fc);
532 }
533
534 // Obsolete class, not used in this version.
535 protected class SingleClickListener extends MouseAdapter {
536 public SingleClickListener(JList<?> list) {
537 }
538 }
539
540 // Obsolete class, not used in this version.
541 @SuppressWarnings("serial") // Superclass is not serializable across versions
542 protected class FileRenderer extends DefaultListCellRenderer {
543 }
544
545 public void uninstallUI(JComponent c) {
546 // Remove listeners
547 c.removePropertyChangeListener(filterComboBoxModel);
548 c.removePropertyChangeListener(filePane);
549 cancelButton.removeActionListener(getCancelSelectionAction());
550 approveButton.removeActionListener(getApproveSelectionAction());
551 fileNameTextField.removeActionListener(getApproveSelectionAction());
552
553 if (filePane != null) {
554 filePane.uninstallUI();
555 filePane = null;
556 }
844
845 public String getDirectoryName() {
846 // PENDING(jeff) - get the name from the directory combobox
847 return null;
848 }
849
850 public void setDirectoryName(String dirname) {
851 // PENDING(jeff) - set the name in the directory combobox
852 }
853
854 protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer(JFileChooser fc) {
855 return new DirectoryComboBoxRenderer();
856 }
857
858 //
859 // Renderer for DirectoryComboBox
860 //
861 @SuppressWarnings("serial") // Superclass is not serializable across versions
862 class DirectoryComboBoxRenderer extends DefaultListCellRenderer {
863 IndentIcon ii = new IndentIcon();
864 public Component getListCellRendererComponent(JList<?> list, Object value,
865 int index, boolean isSelected,
866 boolean cellHasFocus) {
867
868 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
869
870 if (value == null) {
871 setText("");
872 return this;
873 }
874 File directory = (File)value;
875 setText(getFileChooser().getName(directory));
876 Icon icon = getFileChooser().getIcon(directory);
877 ii.icon = icon;
878 ii.depth = directoryComboBoxModel.getDepth(index);
879 setIcon(ii);
880
881 return this;
882 }
883 }
884
1034 return directories.size();
1035 }
1036
1037 public Object getElementAt(int index) {
1038 return directories.elementAt(index);
1039 }
1040 }
1041
1042 //
1043 // Renderer for Types ComboBox
1044 //
1045 protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
1046 return new FilterComboBoxRenderer();
1047 }
1048
1049 /**
1050 * Render different type sizes and styles.
1051 */
1052 @SuppressWarnings("serial") // Superclass is not serializable across versions
1053 public class FilterComboBoxRenderer extends DefaultListCellRenderer {
1054 public Component getListCellRendererComponent(JList<?> list,
1055 Object value, int index, boolean isSelected,
1056 boolean cellHasFocus) {
1057
1058 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
1059
1060 if (value != null && value instanceof FileFilter) {
1061 setText(((FileFilter)value).getDescription());
1062 }
1063
1064 return this;
1065 }
1066 }
1067
1068 //
1069 // DataModel for Types Comboxbox
1070 //
1071 protected FilterComboBoxModel createFilterComboBoxModel() {
1072 return new FilterComboBoxModel();
1073 }
1074
|