< prev index next >

## src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java

Print this page

    rev 48858 : Work in progress for JDK-6303622
    Use generic in Swing components like JComboBox
    1. Added generic return type and parameter type for JComboBox.
    2. Modified JList related classes as well.
    3. Reverted the changes made to "getSelectedValues" as suggested by Joe.
    4. Modified files that were failing on Linux and Mac as well.

    1132             depths = new int[directories.size()];
    1133             for (int i = 0; i < depths.length; i++) {
    1134                 File dir = directories.get(i);
    1135                 File parent = dir.getParentFile();
    1136                 depths[i] = 0;
    1137                 if (parent != null) {
    1138                     for (int j = i-1; j >= 0; j--) {
    1139                         if (parent.equals(directories.get(j))) {
    1140                             depths[i] = depths[j] + 1;
    1141                             break;
    1142                         }
    1143                     }
    1144                 }
    1145             }
    1146         }
    1147
    1148         public int getDepth(int i) {
    1149             return (depths != null && i >= 0 && i < depths.length) ? depths[i] : 0;
    1150         }
    1151
    1152         public void setSelectedItem(Object selectedDirectory) {
    1153             this.selectedDirectory = (File)selectedDirectory;
    1154             fireContentsChanged(this, -1, -1);
    1155         }
    1156
    1157         public Object getSelectedItem() {
    1158             return selectedDirectory;
    1159         }
    1160
    1161         public int getSize() {
    1162             return directories.size();
    1163         }
    1164
    1165         public File getElementAt(int index) {
    1166             return directories.elementAt(index);
    1167         }
    1168     }
    1169
    1170     //
    1171     // Renderer for Types ComboBox
    1172     //
    1173     protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
    1174         return new FilterComboBoxRenderer();
    1175     }
    1176
    1177     /**
    1205      */
    1206     @SuppressWarnings("serial") // Superclass is not serializable across versions
    1207     protected class FilterComboBoxModel extends AbstractListModel<FileFilter> implements ComboBoxModel<FileFilter>,
    1208             PropertyChangeListener {
    1209         protected FileFilter[] filters;
    1210         protected FilterComboBoxModel() {
    1211             super();
    1212             filters = getFileChooser().getChoosableFileFilters();
    1213         }
    1214
    1215         public void propertyChange(PropertyChangeEvent e) {
    1216             String prop = e.getPropertyName();
    1217             if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
    1218                 filters = (FileFilter[]) e.getNewValue();
    1219                 fireContentsChanged(this, -1, -1);
    1220             } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
    1221                 fireContentsChanged(this, -1, -1);
    1222             }
    1223         }
    1224
    1225         public void setSelectedItem(Object filter) {
    1226             if(filter != null) {
    1227                 getFileChooser().setFileFilter((FileFilter) filter);
    1228                 fireContentsChanged(this, -1, -1);
    1229             }
    1230         }
    1231
    1232         public Object getSelectedItem() {
    1233             // Ensure that the current filter is in the list.
    1234             // NOTE: we shouldnt' have to do this, since JFileChooser adds
    1235             // the filter to the choosable filters list when the filter
    1236             // is set. Lets be paranoid just in case someone overrides
    1237             // setFileFilter in JFileChooser.
    1238             FileFilter currentFilter = getFileChooser().getFileFilter();
    1239             boolean found = false;
    1240             if(currentFilter != null) {
    1241                 for (FileFilter filter : filters) {
    1242                     if (filter == currentFilter) {
    1243                         found = true;
    1244                     }
    1245                 }
    1246                 if(found == false) {
    1247                     getFileChooser().addChoosableFileFilter(currentFilter);
    1248                 }
    1249             }
    1250             return getFileChooser().getFileFilter();
    1251         }
    1252
    1271         }
    1272     }
    1273
    1274     public void valueChanged(ListSelectionEvent e) {
    1275         JFileChooser fc = getFileChooser();
    1276         File f = fc.getSelectedFile();
    1277         if (!e.getValueIsAdjusting() && f != null && !getFileChooser().isTraversable(f)) {
    1278             setFileName(fileNameString(f));
    1279         }
    1280     }
    1281
    1282     /**
    1283      * Acts when DirectoryComboBox has changed the selected item.
    1284      */
    1285     protected class DirectoryComboBoxAction implements ActionListener {
    1286
    1287
    1288
    1289
    1290         public void actionPerformed(ActionEvent e) {
    1291             File f = (File)directoryComboBox.getSelectedItem();
    1292             getFileChooser().setCurrentDirectory(f);
    1293         }
    1294     }
    1295
    1296     protected JButton getApproveButton(JFileChooser fc) {
    1297         return approveButton;
    1298     }
    1299
    1300     public FileView getFileView(JFileChooser fc) {
    1301         return fileView;
    1302     }
    1303
    1304     // ***********************
    1305     // * FileView operations *
    1306     // ***********************
    1307     protected class WindowsFileView extends BasicFileView {
    1308         /* FileView type descriptions */
    1309
    1310         public Icon getIcon(File f) {
    1311             Icon icon = getCachedIcon(f);
    1132             depths = new int[directories.size()];
    1133             for (int i = 0; i < depths.length; i++) {
    1134                 File dir = directories.get(i);
    1135                 File parent = dir.getParentFile();
    1136                 depths[i] = 0;
    1137                 if (parent != null) {
    1138                     for (int j = i-1; j >= 0; j--) {
    1139                         if (parent.equals(directories.get(j))) {
    1140                             depths[i] = depths[j] + 1;
    1141                             break;
    1142                         }
    1143                     }
    1144                 }
    1145             }
    1146         }
    1147
    1148         public int getDepth(int i) {
    1149             return (depths != null && i >= 0 && i < depths.length) ? depths[i] : 0;
    1150         }
    1151
    1152         public void setSelectedItem(File selectedDirectory) {
    1153             this.selectedDirectory = selectedDirectory;
    1154             fireContentsChanged(this, -1, -1);
    1155         }
    1156
    1157         public File getSelectedItem() {
    1158             return selectedDirectory;
    1159         }
    1160
    1161         public int getSize() {
    1162             return directories.size();
    1163         }
    1164
    1165         public File getElementAt(int index) {
    1166             return directories.elementAt(index);
    1167         }
    1168     }
    1169
    1170     //
    1171     // Renderer for Types ComboBox
    1172     //
    1173     protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
    1174         return new FilterComboBoxRenderer();
    1175     }
    1176
    1177     /**
    1205      */
    1206     @SuppressWarnings("serial") // Superclass is not serializable across versions
    1207     protected class FilterComboBoxModel extends AbstractListModel<FileFilter> implements ComboBoxModel<FileFilter>,
    1208             PropertyChangeListener {
    1209         protected FileFilter[] filters;
    1210         protected FilterComboBoxModel() {
    1211             super();
    1212             filters = getFileChooser().getChoosableFileFilters();
    1213         }
    1214
    1215         public void propertyChange(PropertyChangeEvent e) {
    1216             String prop = e.getPropertyName();
    1217             if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
    1218                 filters = (FileFilter[]) e.getNewValue();
    1219                 fireContentsChanged(this, -1, -1);
    1220             } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
    1221                 fireContentsChanged(this, -1, -1);
    1222             }
    1223         }
    1224
    1225         public void setSelectedItem(FileFilter filter) {
    1226             if(filter != null) {
    1227                 getFileChooser().setFileFilter(filter);
    1228                 fireContentsChanged(this, -1, -1);
    1229             }
    1230         }
    1231
    1232         public FileFilter getSelectedItem() {
    1233             // Ensure that the current filter is in the list.
    1234             // NOTE: we shouldnt' have to do this, since JFileChooser adds
    1235             // the filter to the choosable filters list when the filter
    1236             // is set. Lets be paranoid just in case someone overrides
    1237             // setFileFilter in JFileChooser.
    1238             FileFilter currentFilter = getFileChooser().getFileFilter();
    1239             boolean found = false;
    1240             if(currentFilter != null) {
    1241                 for (FileFilter filter : filters) {
    1242                     if (filter == currentFilter) {
    1243                         found = true;
    1244                     }
    1245                 }
    1246                 if(found == false) {
    1247                     getFileChooser().addChoosableFileFilter(currentFilter);
    1248                 }
    1249             }
    1250             return getFileChooser().getFileFilter();
    1251         }
    1252
    1271         }
    1272     }
    1273
    1274     public void valueChanged(ListSelectionEvent e) {
    1275         JFileChooser fc = getFileChooser();
    1276         File f = fc.getSelectedFile();
    1277         if (!e.getValueIsAdjusting() && f != null && !getFileChooser().isTraversable(f)) {
    1278             setFileName(fileNameString(f));
    1279         }
    1280     }
    1281
    1282     /**
    1283      * Acts when DirectoryComboBox has changed the selected item.
    1284      */
    1285     protected class DirectoryComboBoxAction implements ActionListener {
    1286
    1287
    1288
    1289
    1290         public void actionPerformed(ActionEvent e) {
    1291             File f = directoryComboBox.getSelectedItem();
    1292             getFileChooser().setCurrentDirectory(f);
    1293         }
    1294     }
    1295
    1296     protected JButton getApproveButton(JFileChooser fc) {
    1297         return approveButton;
    1298     }
    1299
    1300     public FileView getFileView(JFileChooser fc) {
    1301         return fileView;
    1302     }
    1303
    1304     // ***********************
    1305     // * FileView operations *
    1306     // ***********************
    1307     protected class WindowsFileView extends BasicFileView {
    1308         /* FileView type descriptions */
    1309
    1310         public Icon getIcon(File f) {
    1311             Icon icon = getCachedIcon(f);

< prev index next >