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

Print this page


   1 /*
   2  * Copyright (c) 1998, 2013, 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 AbstractListModel<Object> implements ComboBoxModel<Object>, PropertyChangeListener {
1071         protected FileFilter[] filters;
1072         protected FilterComboBoxModel() {
1073             super();
1074             filters = getFileChooser().getChoosableFileFilters();
1075         }
1076 
1077         public void propertyChange(PropertyChangeEvent e) {
1078             String prop = e.getPropertyName();
1079             if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
1080                 filters = (FileFilter[]) e.getNewValue();
1081                 fireContentsChanged(this, -1, -1);
1082             } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
1083                 fireContentsChanged(this, -1, -1);
1084             }
1085         }
1086 
1087         public void setSelectedItem(Object filter) {
1088             if(filter != null) {
1089                 getFileChooser().setFileFilter((FileFilter) filter);


1127             }
1128             if(filters != null) {
1129                 return filters[index];
1130             } else {
1131                 return null;
1132             }
1133         }
1134     }
1135 
1136     public void valueChanged(ListSelectionEvent e) {
1137         JFileChooser fc = getFileChooser();
1138         File f = fc.getSelectedFile();
1139         if (!e.getValueIsAdjusting() && f != null && !getFileChooser().isTraversable(f)) {
1140             setFileName(fileNameString(f));
1141         }
1142     }
1143 
1144     /**
1145      * Acts when DirectoryComboBox has changed the selected item.
1146      */

1147     protected class DirectoryComboBoxAction extends AbstractAction {
1148         protected DirectoryComboBoxAction() {
1149             super("DirectoryComboBoxAction");
1150         }
1151 
1152         public void actionPerformed(ActionEvent e) {
1153             directoryComboBox.hidePopup();
1154             File f = (File)directoryComboBox.getSelectedItem();
1155             if (!getFileChooser().getCurrentDirectory().equals(f)) {
1156                 getFileChooser().setCurrentDirectory(f);
1157             }
1158         }
1159     }
1160 
1161     protected JButton getApproveButton(JFileChooser fc) {
1162         return approveButton;
1163     }
1164 
1165 
1166     /**


1227                                          (numChildren - 1) * hGap,
1228                                          extraHeight + height);
1229                 }
1230             }
1231             return new Dimension(0, 0);
1232         }
1233 
1234         public Dimension preferredLayoutSize(Container c) {
1235             return minimumLayoutSize(c);
1236         }
1237 
1238         public void removeLayoutComponent(Component c) { }
1239     }
1240 
1241     private static void groupLabels(AlignedLabel[] group) {
1242         for (int i = 0; i < group.length; i++) {
1243             group[i].group = group;
1244         }
1245     }
1246 

1247     private class AlignedLabel extends JLabel {
1248         private AlignedLabel[] group;
1249         private int maxWidth = 0;
1250 
1251         AlignedLabel() {
1252             super();
1253             setAlignmentX(JComponent.LEFT_ALIGNMENT);
1254         }
1255 
1256 
1257         AlignedLabel(String text) {
1258             super(text);
1259             setAlignmentX(JComponent.LEFT_ALIGNMENT);
1260         }
1261 
1262         public Dimension getPreferredSize() {
1263             Dimension d = super.getPreferredSize();
1264             // Align the width with all other labels in group.
1265             return new Dimension(getMaxWidth() + 11, d.height);
1266         }
   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") // Same-version serialization only
1079     protected class FilterComboBoxModel extends AbstractListModel<Object> implements ComboBoxModel<Object>, PropertyChangeListener {
1080         protected FileFilter[] filters;
1081         protected FilterComboBoxModel() {
1082             super();
1083             filters = getFileChooser().getChoosableFileFilters();
1084         }
1085 
1086         public void propertyChange(PropertyChangeEvent e) {
1087             String prop = e.getPropertyName();
1088             if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
1089                 filters = (FileFilter[]) e.getNewValue();
1090                 fireContentsChanged(this, -1, -1);
1091             } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
1092                 fireContentsChanged(this, -1, -1);
1093             }
1094         }
1095 
1096         public void setSelectedItem(Object filter) {
1097             if(filter != null) {
1098                 getFileChooser().setFileFilter((FileFilter) filter);


1136             }
1137             if(filters != null) {
1138                 return filters[index];
1139             } else {
1140                 return null;
1141             }
1142         }
1143     }
1144 
1145     public void valueChanged(ListSelectionEvent e) {
1146         JFileChooser fc = getFileChooser();
1147         File f = fc.getSelectedFile();
1148         if (!e.getValueIsAdjusting() && f != null && !getFileChooser().isTraversable(f)) {
1149             setFileName(fileNameString(f));
1150         }
1151     }
1152 
1153     /**
1154      * Acts when DirectoryComboBox has changed the selected item.
1155      */
1156     @SuppressWarnings("serial") // Superclass is not serializable across versions
1157     protected class DirectoryComboBoxAction extends AbstractAction {
1158         protected DirectoryComboBoxAction() {
1159             super("DirectoryComboBoxAction");
1160         }
1161 
1162         public void actionPerformed(ActionEvent e) {
1163             directoryComboBox.hidePopup();
1164             File f = (File)directoryComboBox.getSelectedItem();
1165             if (!getFileChooser().getCurrentDirectory().equals(f)) {
1166                 getFileChooser().setCurrentDirectory(f);
1167             }
1168         }
1169     }
1170 
1171     protected JButton getApproveButton(JFileChooser fc) {
1172         return approveButton;
1173     }
1174 
1175 
1176     /**


1237                                          (numChildren - 1) * hGap,
1238                                          extraHeight + height);
1239                 }
1240             }
1241             return new Dimension(0, 0);
1242         }
1243 
1244         public Dimension preferredLayoutSize(Container c) {
1245             return minimumLayoutSize(c);
1246         }
1247 
1248         public void removeLayoutComponent(Component c) { }
1249     }
1250 
1251     private static void groupLabels(AlignedLabel[] group) {
1252         for (int i = 0; i < group.length; i++) {
1253             group[i].group = group;
1254         }
1255     }
1256 
1257     @SuppressWarnings("serial") // Superclass is not serializable across versions
1258     private class AlignedLabel extends JLabel {
1259         private AlignedLabel[] group;
1260         private int maxWidth = 0;
1261 
1262         AlignedLabel() {
1263             super();
1264             setAlignmentX(JComponent.LEFT_ALIGNMENT);
1265         }
1266 
1267 
1268         AlignedLabel(String text) {
1269             super(text);
1270             setAlignmentX(JComponent.LEFT_ALIGNMENT);
1271         }
1272 
1273         public Dimension getPreferredSize() {
1274             Dimension d = super.getPreferredSize();
1275             // Align the width with all other labels in group.
1276             return new Dimension(getMaxWidth() + 11, d.height);
1277         }