< prev index next >

## src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.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.

    1141             File canonical;
    1142             try {
    1143                 canonical = fsv.createFileObject(ShellFolder.getNormalizedFile(directory).getPath());
    1144             } catch (IOException e) {
    1145                 // Maybe drive is not ready. Can't abort here.
    1146                 canonical = directory;
    1147             }
    1148
    1149             // create File instances of each directory leading up to the top
    1150             File f = canonical;
    1151             do {
    1152                 directories.add(f);
    1153             } while ((f = f.getParentFile()) != null);
    1154             int newSize = directories.size();
    1155             if (newSize > 0) {
    1156                 fireIntervalAdded(this, 0, newSize);
    1157             }
    1158             setSelectedItem(canonical);
    1159         }
    1160
    1161         public void setSelectedItem(Object selectedDirectory) {
    1162             this.selectedDirectory = (File)selectedDirectory;
    1163             fireContentsChanged(this, -1, -1);
    1164         }
    1165
    1166         public Object getSelectedItem() {
    1167             return selectedDirectory;
    1168         }
    1169
    1170         public int getSize() {
    1171             return directories.size();
    1172         }
    1173
    1174         @Override
    1175         public File getElementAt(int index) {
    1176             return directories.elementAt(index);
    1177         }
    1178     }
    1179
    1180     /**
    1181      * Acts when DirectoryComboBox has changed the selected item.
    1182      */
    1183     @SuppressWarnings("serial") // Superclass is not serializable across versions
    1184     protected class DirectoryComboBoxAction extends AbstractAction {
    1185         protected DirectoryComboBoxAction() {
    1186             super("DirectoryComboBoxAction");
    1187         }
    1188
    1189         public void actionPerformed(ActionEvent e) {
    1190             File f = (File)directoryComboBox.getSelectedItem();
    1191             getFileChooser().setCurrentDirectory(f);
    1192         }
    1193     }
    1194
    1195     /**
    1196      * Creates a new folder.
    1197      */
    1198     @SuppressWarnings("serial") // Superclass is not serializable across versions
    1199     private class NewFolderAction extends AbstractAction {
    1200         protected NewFolderAction() {
    1201             super(FilePane.ACTION_NEW_FOLDER);
    1202         }
    1203         public void actionPerformed(ActionEvent e) {
    1204             if (readOnly) {
    1205                 return;
    1206             }
    1207             JFileChooser fc = getFileChooser();
    1208             File currentDirectory = fc.getCurrentDirectory();
    1209             String dirName = JOptionPane.showInputDialog(fc,
    1210                     newFolderDialogText, newFolderButtonText,
    1356     @SuppressWarnings("serial") // JDK implementation class
    1357     protected class FilterComboBoxModel extends AbstractListModel<FileFilter>
    1358             implements ComboBoxModel<FileFilter>, PropertyChangeListener {
    1359         protected FileFilter[] filters;
    1360
    1361         protected FilterComboBoxModel() {
    1362             super();
    1363             filters = getFileChooser().getChoosableFileFilters();
    1364         }
    1365
    1366         public void propertyChange(PropertyChangeEvent e) {
    1367             String prop = e.getPropertyName();
    1368             if (prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
    1369                 filters = (FileFilter[]) e.getNewValue();
    1370                 fireContentsChanged(this, -1, -1);
    1371             } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
    1372                 fireContentsChanged(this, -1, -1);
    1373             }
    1374         }
    1375
    1376         public void setSelectedItem(Object filter) {
    1377             if (filter != null) {
    1378                 getFileChooser().setFileFilter((FileFilter) filter);
    1379                 fireContentsChanged(this, -1, -1);
    1380             }
    1381         }
    1382
    1383         public Object getSelectedItem() {
    1384             // Ensure that the current filter is in the list.
    1385             // NOTE: we shouldnt' have to do this, since JFileChooser adds
    1386             // the filter to the choosable filters list when the filter
    1387             // is set. Lets be paranoid just in case someone overrides
    1388             // setFileFilter in JFileChooser.
    1389             FileFilter currentFilter = getFileChooser().getFileFilter();
    1390             boolean found = false;
    1391             if (currentFilter != null) {
    1392                 for (FileFilter filter : filters) {
    1393                     if (filter == currentFilter) {
    1394                         found = true;
    1395                     }
    1396                 }
    1397                 if (found == false) {
    1398                     getFileChooser().addChoosableFileFilter(currentFilter);
    1399                 }
    1400             }
    1401             return getFileChooser().getFileFilter();
    1402         }
    1403
    1141             File canonical;
    1142             try {
    1143                 canonical = fsv.createFileObject(ShellFolder.getNormalizedFile(directory).getPath());
    1144             } catch (IOException e) {
    1145                 // Maybe drive is not ready. Can't abort here.
    1146                 canonical = directory;
    1147             }
    1148
    1149             // create File instances of each directory leading up to the top
    1150             File f = canonical;
    1151             do {
    1152                 directories.add(f);
    1153             } while ((f = f.getParentFile()) != null);
    1154             int newSize = directories.size();
    1155             if (newSize > 0) {
    1156                 fireIntervalAdded(this, 0, newSize);
    1157             }
    1158             setSelectedItem(canonical);
    1159         }
    1160
    1161         public void setSelectedItem(File selectedDirectory) {
    1162             this.selectedDirectory = selectedDirectory;
    1163             fireContentsChanged(this, -1, -1);
    1164         }
    1165
    1166         public File getSelectedItem() {
    1167             return selectedDirectory;
    1168         }
    1169
    1170         public int getSize() {
    1171             return directories.size();
    1172         }
    1173
    1174         @Override
    1175         public File getElementAt(int index) {
    1176             return directories.elementAt(index);
    1177         }
    1178     }
    1179
    1180     /**
    1181      * Acts when DirectoryComboBox has changed the selected item.
    1182      */
    1183     @SuppressWarnings("serial") // Superclass is not serializable across versions
    1184     protected class DirectoryComboBoxAction extends AbstractAction {
    1185         protected DirectoryComboBoxAction() {
    1186             super("DirectoryComboBoxAction");
    1187         }
    1188
    1189         public void actionPerformed(ActionEvent e) {
    1190             File f = directoryComboBox.getSelectedItem();
    1191             getFileChooser().setCurrentDirectory(f);
    1192         }
    1193     }
    1194
    1195     /**
    1196      * Creates a new folder.
    1197      */
    1198     @SuppressWarnings("serial") // Superclass is not serializable across versions
    1199     private class NewFolderAction extends AbstractAction {
    1200         protected NewFolderAction() {
    1201             super(FilePane.ACTION_NEW_FOLDER);
    1202         }
    1203         public void actionPerformed(ActionEvent e) {
    1204             if (readOnly) {
    1205                 return;
    1206             }
    1207             JFileChooser fc = getFileChooser();
    1208             File currentDirectory = fc.getCurrentDirectory();
    1209             String dirName = JOptionPane.showInputDialog(fc,
    1210                     newFolderDialogText, newFolderButtonText,
    1356     @SuppressWarnings("serial") // JDK implementation class
    1357     protected class FilterComboBoxModel extends AbstractListModel<FileFilter>
    1358             implements ComboBoxModel<FileFilter>, PropertyChangeListener {
    1359         protected FileFilter[] filters;
    1360
    1361         protected FilterComboBoxModel() {
    1362             super();
    1363             filters = getFileChooser().getChoosableFileFilters();
    1364         }
    1365
    1366         public void propertyChange(PropertyChangeEvent e) {
    1367             String prop = e.getPropertyName();
    1368             if (prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
    1369                 filters = (FileFilter[]) e.getNewValue();
    1370                 fireContentsChanged(this, -1, -1);
    1371             } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
    1372                 fireContentsChanged(this, -1, -1);
    1373             }
    1374         }
    1375
    1376         public void setSelectedItem(FileFilter filter) {
    1377             if (filter != null) {
    1378                 getFileChooser().setFileFilter(filter);
    1379                 fireContentsChanged(this, -1, -1);
    1380             }
    1381         }
    1382
    1383         public FileFilter getSelectedItem() {
    1384             // Ensure that the current filter is in the list.
    1385             // NOTE: we shouldnt' have to do this, since JFileChooser adds
    1386             // the filter to the choosable filters list when the filter
    1387             // is set. Lets be paranoid just in case someone overrides
    1388             // setFileFilter in JFileChooser.
    1389             FileFilter currentFilter = getFileChooser().getFileFilter();
    1390             boolean found = false;
    1391             if (currentFilter != null) {
    1392                 for (FileFilter filter : filters) {
    1393                     if (filter == currentFilter) {
    1394                         found = true;
    1395                     }
    1396                 }
    1397                 if (found == false) {
    1398                     getFileChooser().addChoosableFileFilter(currentFilter);
    1399                 }
    1400             }
    1401             return getFileChooser().getFileFilter();
    1402         }
    1403

< prev index next >