src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java

Print this page


   1 /*
   2  * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 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         directoryComboBox = new JComboBox() {

 238             public Dimension getPreferredSize() {
 239                 Dimension d = super.getPreferredSize();
 240                 // Must be small enough to not affect total width.
 241                 d.width = 150;
 242                 return d;
 243             }
 244         };

 245         directoryComboBox.putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY,
 246                                             lookInLabelText);
 247         directoryComboBox.putClientProperty( "JComboBox.isTableCellEditor", Boolean.TRUE );
 248         lookInLabel.setLabelFor(directoryComboBox);
 249         directoryComboBoxModel = createDirectoryComboBoxModel(fc);
 250         directoryComboBox.setModel(directoryComboBoxModel);
 251         directoryComboBox.addActionListener(directoryComboBoxAction);
 252         directoryComboBox.setRenderer(createDirectoryComboBoxRenderer(fc));
 253         directoryComboBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
 254         directoryComboBox.setAlignmentY(JComponent.TOP_ALIGNMENT);
 255         directoryComboBox.setMaximumRowCount(8);
 256 
 257         topPanel.add(directoryComboBox, BorderLayout.CENTER);
 258 
 259         // Up Button
 260         JButton upFolderButton = new JButton(getChangeToParentDirectoryAction());
 261         upFolderButton.setText(null);
 262         upFolderButton.setIcon(upFolderIcon);
 263         upFolderButton.setToolTipText(upFolderToolTipText);
 264         upFolderButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY,


 363         filePane.setPreferredSize(LIST_PREF_SIZE);
 364         fc.add(filePane, BorderLayout.CENTER);
 365 
 366         // ********************************** //
 367         // **** Construct the bottom panel ** //
 368         // ********************************** //
 369         JPanel bottomPanel = getBottomPanel();
 370         bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.Y_AXIS));
 371         fc.add(bottomPanel, BorderLayout.SOUTH);
 372 
 373         // FileName label and textfield
 374         JPanel fileNamePanel = new JPanel();
 375         fileNamePanel.setLayout(new BoxLayout(fileNamePanel, BoxLayout.LINE_AXIS));
 376         bottomPanel.add(fileNamePanel);
 377         bottomPanel.add(Box.createRigidArea(vstrut5));
 378 
 379         fileNameLabel = new AlignedLabel();
 380         populateFileNameLabel();
 381         fileNamePanel.add(fileNameLabel);
 382 
 383         fileNameTextField = new JTextField(35) {

 384             public Dimension getMaximumSize() {
 385                 return new Dimension(Short.MAX_VALUE, super.getPreferredSize().height);
 386             }
 387         };

 388         fileNamePanel.add(fileNameTextField);
 389         fileNameLabel.setLabelFor(fileNameTextField);
 390         fileNameTextField.addFocusListener(
 391             new FocusAdapter() {
 392                 public void focusGained(FocusEvent e) {
 393                     if (!getFileChooser().isMultiSelectionEnabled()) {
 394                         filePane.clearSelection();
 395                     }
 396                 }
 397             }
 398         );
 399         if (fc.isMultiSelectionEnabled()) {
 400             setFileName(fileNameString(fc.getSelectedFiles()));
 401         } else {
 402             setFileName(fileNameString(fc.getSelectedFile()));
 403         }
 404 
 405 
 406         // Filetype label and combobox
 407         JPanel filesOfTypePanel = new JPanel();


 517         return filePane.createDetailsView();
 518     }
 519 
 520     /**
 521      * Creates a selection listener for the list of files and directories.
 522      *
 523      * @param fc a <code>JFileChooser</code>
 524      * @return a <code>ListSelectionListener</code>
 525      */
 526     public ListSelectionListener createListSelectionListener(JFileChooser fc) {
 527         return super.createListSelectionListener(fc);
 528     }
 529 
 530     // Obsolete class, not used in this version.
 531     protected class SingleClickListener extends MouseAdapter {
 532         public  SingleClickListener(JList list) {
 533         }
 534     }
 535 
 536     // Obsolete class, not used in this version.

 537     protected class FileRenderer extends DefaultListCellRenderer  {
 538     }
 539 
 540     public void uninstallUI(JComponent c) {
 541         // Remove listeners
 542         c.removePropertyChangeListener(filterComboBoxModel);
 543         c.removePropertyChangeListener(filePane);
 544         cancelButton.removeActionListener(getCancelSelectionAction());
 545         approveButton.removeActionListener(getApproveSelectionAction());
 546         fileNameTextField.removeActionListener(getApproveSelectionAction());
 547 
 548         if (filePane != null) {
 549             filePane.uninstallUI();
 550             filePane = null;
 551         }
 552 
 553         super.uninstallUI(c);
 554     }
 555 
 556     /**


 836             }
 837         }
 838     }
 839 
 840     public String getDirectoryName() {
 841         // PENDING(jeff) - get the name from the directory combobox
 842         return null;
 843     }
 844 
 845     public void setDirectoryName(String dirname) {
 846         // PENDING(jeff) - set the name in the directory combobox
 847     }
 848 
 849     protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer(JFileChooser fc) {
 850         return new DirectoryComboBoxRenderer();
 851     }
 852 
 853     //
 854     // Renderer for DirectoryComboBox
 855     //

 856     class DirectoryComboBoxRenderer extends DefaultListCellRenderer  {
 857         IndentIcon ii = new IndentIcon();
 858         public Component getListCellRendererComponent(JList list, Object value,
 859                                                       int index, boolean isSelected,
 860                                                       boolean cellHasFocus) {
 861 
 862             super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
 863 
 864             if (value == null) {
 865                 setText("");
 866                 return this;
 867             }
 868             File directory = (File)value;
 869             setText(getFileChooser().getName(directory));
 870             Icon icon = getFileChooser().getIcon(directory);
 871             ii.icon = icon;
 872             ii.depth = directoryComboBoxModel.getDepth(index);
 873             setIcon(ii);
 874 
 875             return this;


 893         public int getIconWidth() {
 894             return icon.getIconWidth() + depth*space;
 895         }
 896 
 897         public int getIconHeight() {
 898             return icon.getIconHeight();
 899         }
 900 
 901     }
 902 
 903     //
 904     // DataModel for DirectoryComboxbox
 905     //
 906     protected DirectoryComboBoxModel createDirectoryComboBoxModel(JFileChooser fc) {
 907         return new DirectoryComboBoxModel();
 908     }
 909 
 910     /**
 911      * Data model for a type-face selection combo-box.
 912      */

 913     protected class DirectoryComboBoxModel extends AbstractListModel<Object> implements ComboBoxModel<Object> {
 914         Vector<File> directories = new Vector<File>();
 915         int[] depths = null;
 916         File selectedDirectory = null;
 917         JFileChooser chooser = getFileChooser();
 918         FileSystemView fsv = chooser.getFileSystemView();
 919 
 920         public DirectoryComboBoxModel() {
 921             // Add the current directory to the model, and make it the
 922             // selectedDirectory
 923             File dir = getFileChooser().getCurrentDirectory();
 924             if(dir != null) {
 925                 addItem(dir);
 926             }
 927         }
 928 
 929         /**
 930          * Adds the directory to the model and sets it to be selected,
 931          * additionally clears out the previous selected directory and
 932          * the paths leading up to it, if any.


1025 
1026         public int getSize() {
1027             return directories.size();
1028         }
1029 
1030         public Object getElementAt(int index) {
1031             return directories.elementAt(index);
1032         }
1033     }
1034 
1035     //
1036     // Renderer for Types ComboBox
1037     //
1038     protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
1039         return new FilterComboBoxRenderer();
1040     }
1041 
1042     /**
1043      * Render different type sizes and styles.
1044      */

1045     public class FilterComboBoxRenderer extends DefaultListCellRenderer {
1046         public Component getListCellRendererComponent(JList list,
1047             Object value, int index, boolean isSelected,
1048             boolean cellHasFocus) {
1049 
1050             super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
1051 
1052             if (value != null && value instanceof FileFilter) {
1053                 setText(((FileFilter)value).getDescription());
1054             }
1055 
1056             return this;
1057         }
1058     }
1059 
1060     //
1061     // DataModel for Types Comboxbox
1062     //
1063     protected FilterComboBoxModel createFilterComboBoxModel() {
1064         return new FilterComboBoxModel();
1065     }
1066 
1067     /**
1068      * Data model for a type-face selection combo-box.
1069      */

1070     protected class FilterComboBoxModel extends AbstractFilterComboBoxModel {
1071         protected JFileChooser getFileChooser() {
1072             return MetalFileChooserUI.this.getFileChooser();
1073         }
1074     }
1075 
1076     public void valueChanged(ListSelectionEvent e) {
1077         JFileChooser fc = getFileChooser();
1078         File f = fc.getSelectedFile();
1079         if (!e.getValueIsAdjusting() && f != null && !getFileChooser().isTraversable(f)) {
1080             setFileName(fileNameString(f));
1081         }
1082     }
1083 
1084     /**
1085      * Acts when DirectoryComboBox has changed the selected item.
1086      */

1087     protected class DirectoryComboBoxAction extends AbstractAction {
1088         protected DirectoryComboBoxAction() {
1089             super("DirectoryComboBoxAction");
1090         }
1091 
1092         public void actionPerformed(ActionEvent e) {
1093             directoryComboBox.hidePopup();
1094             File f = (File)directoryComboBox.getSelectedItem();
1095             if (!getFileChooser().getCurrentDirectory().equals(f)) {
1096                 getFileChooser().setCurrentDirectory(f);
1097             }
1098         }
1099     }
1100 
1101     protected JButton getApproveButton(JFileChooser fc) {
1102         return approveButton;
1103     }
1104 
1105 
1106     /**


1167                                          (numChildren - 1) * hGap,
1168                                          extraHeight + height);
1169                 }
1170             }
1171             return new Dimension(0, 0);
1172         }
1173 
1174         public Dimension preferredLayoutSize(Container c) {
1175             return minimumLayoutSize(c);
1176         }
1177 
1178         public void removeLayoutComponent(Component c) { }
1179     }
1180 
1181     private static void groupLabels(AlignedLabel[] group) {
1182         for (int i = 0; i < group.length; i++) {
1183             group[i].group = group;
1184         }
1185     }
1186 

1187     private class AlignedLabel extends JLabel {
1188         private AlignedLabel[] group;
1189         private int maxWidth = 0;
1190 
1191         AlignedLabel() {
1192             super();
1193             setAlignmentX(JComponent.LEFT_ALIGNMENT);
1194         }
1195 
1196 
1197         AlignedLabel(String text) {
1198             super(text);
1199             setAlignmentX(JComponent.LEFT_ALIGNMENT);
1200         }
1201 
1202         public Dimension getPreferredSize() {
1203             Dimension d = super.getPreferredSize();
1204             // Align the width with all other labels in group.
1205             return new Dimension(getMaxWidth() + 11, d.height);
1206         }
   1 /*
   2  * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 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 
 259         topPanel.add(directoryComboBox, BorderLayout.CENTER);
 260 
 261         // Up Button
 262         JButton upFolderButton = new JButton(getChangeToParentDirectoryAction());
 263         upFolderButton.setText(null);
 264         upFolderButton.setIcon(upFolderIcon);
 265         upFolderButton.setToolTipText(upFolderToolTipText);
 266         upFolderButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY,


 365         filePane.setPreferredSize(LIST_PREF_SIZE);
 366         fc.add(filePane, BorderLayout.CENTER);
 367 
 368         // ********************************** //
 369         // **** Construct the bottom panel ** //
 370         // ********************************** //
 371         JPanel bottomPanel = getBottomPanel();
 372         bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.Y_AXIS));
 373         fc.add(bottomPanel, BorderLayout.SOUTH);
 374 
 375         // FileName label and textfield
 376         JPanel fileNamePanel = new JPanel();
 377         fileNamePanel.setLayout(new BoxLayout(fileNamePanel, BoxLayout.LINE_AXIS));
 378         bottomPanel.add(fileNamePanel);
 379         bottomPanel.add(Box.createRigidArea(vstrut5));
 380 
 381         fileNameLabel = new AlignedLabel();
 382         populateFileNameLabel();
 383         fileNamePanel.add(fileNameLabel);
 384 
 385         @SuppressWarnings("serial") // anonymous class
 386         JTextField tmp2 = new JTextField(35) {
 387             public Dimension getMaximumSize() {
 388                 return new Dimension(Short.MAX_VALUE, super.getPreferredSize().height);
 389             }
 390         };
 391         fileNameTextField = tmp2;
 392         fileNamePanel.add(fileNameTextField);
 393         fileNameLabel.setLabelFor(fileNameTextField);
 394         fileNameTextField.addFocusListener(
 395             new FocusAdapter() {
 396                 public void focusGained(FocusEvent e) {
 397                     if (!getFileChooser().isMultiSelectionEnabled()) {
 398                         filePane.clearSelection();
 399                     }
 400                 }
 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();


 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         }
 557 
 558         super.uninstallUI(c);
 559     }
 560 
 561     /**


 841             }
 842         }
 843     }
 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;


 899         public int getIconWidth() {
 900             return icon.getIconWidth() + depth*space;
 901         }
 902 
 903         public int getIconHeight() {
 904             return icon.getIconHeight();
 905         }
 906 
 907     }
 908 
 909     //
 910     // DataModel for DirectoryComboxbox
 911     //
 912     protected DirectoryComboBoxModel createDirectoryComboBoxModel(JFileChooser fc) {
 913         return new DirectoryComboBoxModel();
 914     }
 915 
 916     /**
 917      * Data model for a type-face selection combo-box.
 918      */
 919     @SuppressWarnings("serial") // Superclass is not serializable across versions
 920     protected class DirectoryComboBoxModel extends AbstractListModel<Object> implements ComboBoxModel<Object> {
 921         Vector<File> directories = new Vector<File>();
 922         int[] depths = null;
 923         File selectedDirectory = null;
 924         JFileChooser chooser = getFileChooser();
 925         FileSystemView fsv = chooser.getFileSystemView();
 926 
 927         public DirectoryComboBoxModel() {
 928             // Add the current directory to the model, and make it the
 929             // selectedDirectory
 930             File dir = getFileChooser().getCurrentDirectory();
 931             if(dir != null) {
 932                 addItem(dir);
 933             }
 934         }
 935 
 936         /**
 937          * Adds the directory to the model and sets it to be selected,
 938          * additionally clears out the previous selected directory and
 939          * the paths leading up to it, if any.


1032 
1033         public int getSize() {
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 
1075     /**
1076      * Data model for a type-face selection combo-box.
1077      */
1078     @SuppressWarnings("serial") // anonymous class
1079     protected class FilterComboBoxModel extends AbstractFilterComboBoxModel {
1080         protected JFileChooser getFileChooser() {
1081             return MetalFileChooserUI.this.getFileChooser();
1082         }
1083     }
1084 
1085     public void valueChanged(ListSelectionEvent e) {
1086         JFileChooser fc = getFileChooser();
1087         File f = fc.getSelectedFile();
1088         if (!e.getValueIsAdjusting() && f != null && !getFileChooser().isTraversable(f)) {
1089             setFileName(fileNameString(f));
1090         }
1091     }
1092 
1093     /**
1094      * Acts when DirectoryComboBox has changed the selected item.
1095      */
1096     @SuppressWarnings("serial") // Superclass is not serializable across versions
1097     protected class DirectoryComboBoxAction extends AbstractAction {
1098         protected DirectoryComboBoxAction() {
1099             super("DirectoryComboBoxAction");
1100         }
1101 
1102         public void actionPerformed(ActionEvent e) {
1103             directoryComboBox.hidePopup();
1104             File f = (File)directoryComboBox.getSelectedItem();
1105             if (!getFileChooser().getCurrentDirectory().equals(f)) {
1106                 getFileChooser().setCurrentDirectory(f);
1107             }
1108         }
1109     }
1110 
1111     protected JButton getApproveButton(JFileChooser fc) {
1112         return approveButton;
1113     }
1114 
1115 
1116     /**


1177                                          (numChildren - 1) * hGap,
1178                                          extraHeight + height);
1179                 }
1180             }
1181             return new Dimension(0, 0);
1182         }
1183 
1184         public Dimension preferredLayoutSize(Container c) {
1185             return minimumLayoutSize(c);
1186         }
1187 
1188         public void removeLayoutComponent(Component c) { }
1189     }
1190 
1191     private static void groupLabels(AlignedLabel[] group) {
1192         for (int i = 0; i < group.length; i++) {
1193             group[i].group = group;
1194         }
1195     }
1196 
1197     @SuppressWarnings("serial") // Superclass is not serializable across versions
1198     private class AlignedLabel extends JLabel {
1199         private AlignedLabel[] group;
1200         private int maxWidth = 0;
1201 
1202         AlignedLabel() {
1203             super();
1204             setAlignmentX(JComponent.LEFT_ALIGNMENT);
1205         }
1206 
1207 
1208         AlignedLabel(String text) {
1209             super(text);
1210             setAlignmentX(JComponent.LEFT_ALIGNMENT);
1211         }
1212 
1213         public Dimension getPreferredSize() {
1214             Dimension d = super.getPreferredSize();
1215             // Align the width with all other labels in group.
1216             return new Dimension(getMaxWidth() + 11, d.height);
1217         }