< prev index next >

## src/java.desktop/macosx/classes/com/apple/laf/AquaFileChooserUI.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.

    1238             };
    1239
    1240             // Add root file (the desktop) to the model
    1241             final File[] roots = getFileChooser().getFileSystemView().getRoots();
    1242             for (final File element : roots) {
    1243                 path.addElement(element);
    1244             }
    1245             fPathCount = path.size();
    1246
    1247             // insert all the path fDirectories leading up to the
    1248             // selected directory in reverse order (current directory at top)
    1249             for (int i = 0; i < path.size(); i++) {
    1250                 fDirectories.addElement(path.elementAt(i));
    1251             }
    1252
    1253             setSelectedItem(fDirectories.elementAt(0));
    1254
    1255             // dump();
    1256         }
    1257
    1258         public void setSelectedItem(final Object selectedDirectory) {
    1259             this.fSelectedDirectory = (File)selectedDirectory;
    1260             fireContentsChanged(this, -1, -1);
    1261         }
    1262
    1263         public Object getSelectedItem() {
    1264             return fSelectedDirectory;
    1265         }
    1266
    1267         public int getSize() {
    1268             return fDirectories.size();
    1269         }
    1270
    1271         public File getElementAt(final int index) {
    1272             return fDirectories.elementAt(index);
    1273         }
    1274     }
    1275
    1276     //
    1277     // Renderer for Types ComboBox
    1278     //
    1279     @SuppressWarnings("serial") // anonymous class
    1280     protected ListCellRenderer<FileFilter> createFilterComboBoxRenderer() {
    1281         return new AquaComboBoxRendererInternal<FileFilter>(filterComboBox) {
    1282             public Component getListCellRendererComponent(final JList<? extends FileFilter> list,
    1283                                                           final FileFilter filter,
    1301     /**
    1302      * Data model for a type-face selection combo-box.
    1303      */
    1304     @SuppressWarnings("serial") // Superclass is not serializable across versions
    1305     protected class FilterComboBoxModel extends AbstractListModel<FileFilter> implements ComboBoxModel<FileFilter>,
    1306             PropertyChangeListener {
    1307         protected FileFilter[] filters;
    1308         Object oldFileFilter = getFileChooser().getFileFilter();
    1309
    1310         protected FilterComboBoxModel() {
    1311             super();
    1312             filters = getFileChooser().getChoosableFileFilters();
    1313         }
    1314
    1315         public void propertyChange(PropertyChangeEvent e) {
    1316             String prop = e.getPropertyName();
    1317             if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
    1318                 filters = (FileFilter[]) e.getNewValue();
    1319                 fireContentsChanged(this, -1, -1);
    1320             } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
    1321                 setSelectedItem(e.getNewValue());
    1322             }
    1323         }
    1324
    1325         public void setSelectedItem(Object filter) {
    1326             if (filter != null && !isSelectedFileFilterInModel(filter)) {
    1327                 oldFileFilter = filter;
    1328                 getFileChooser().setFileFilter((FileFilter) filter);
    1329                 fireContentsChanged(this, -1, -1);
    1330             }
    1331         }
    1332
    1333         private boolean isSelectedFileFilterInModel(Object filter) {
    1334             return Objects.equals(filter, oldFileFilter);
    1335         }
    1336
    1337         public Object getSelectedItem() {
    1338             // Ensure that the current filter is in the list.
    1339             // NOTE: we shouldnt' have to do this, since JFileChooser adds
    1340             // the filter to the choosable filters list when the filter
    1341             // is set. Lets be paranoid just in case someone overrides
    1342             // setFileFilter in JFileChooser.
    1343             FileFilter currentFilter = getFileChooser().getFileFilter();
    1344             boolean found = false;
    1345             if(currentFilter != null) {
    1346                 for (FileFilter filter : filters) {
    1347                     if (filter == currentFilter) {
    1348                         found = true;
    1349                     }
    1350                 }
    1351                 if(found == false) {
    1352                     getFileChooser().addChoosableFileFilter(currentFilter);
    1353                 }
    1354             }
    1355             return getFileChooser().getFileFilter();
    1356         }
    1357
    1390         }
    1391
    1392         public void actionPerformed(final ActionEvent e) {
    1393             Object selectedFilter = filterComboBox.getSelectedItem();
    1394             if (!containsFileFilter(selectedFilter)) {
    1395                 getFileChooser().setFileFilter((FileFilter) selectedFilter);
    1396             }
    1397         }
    1398     }
    1399
    1400     /**
    1401      * Acts when DirectoryComboBox has changed the selected item.
    1402      */
    1403     @SuppressWarnings("serial") // Superclass is not serializable across versions
    1404     protected class DirectoryComboBoxAction extends AbstractAction {
    1405         protected DirectoryComboBoxAction() {
    1406             super("DirectoryComboBoxAction");
    1407         }
    1408
    1409         public void actionPerformed(final ActionEvent e) {
    1410             getFileChooser().setCurrentDirectory((File)directoryComboBox.getSelectedItem());
    1411         }
    1412     }
    1413
    1414     // Sorting Table operations
    1415     @SuppressWarnings("serial") // Superclass is not serializable across versions
    1416     class JSortingTableHeader extends JTableHeader {
    1417         public JSortingTableHeader(final TableColumnModel cm) {
    1418             super(cm);
    1419             setReorderingAllowed(true); // This causes mousePress to call setDraggedColumn
    1420         }
    1421
    1422         // One sort state for each column.  Both are ascending by default
    1423         final boolean fSortAscending[] = {true, true};
    1424
    1425         // Instead of dragging, it selects which one to sort by
    1426         public void setDraggedColumn(final TableColumn aColumn) {
    1427             if (aColumn != null) {
    1428                 final int colIndex = aColumn.getModelIndex();
    1429                 if (colIndex != fSortColumn) {
    1430                     filechooser.firePropertyChange(AquaFileSystemModel.SORT_BY_CHANGED, fSortColumn, colIndex);
    1238             };
    1239
    1240             // Add root file (the desktop) to the model
    1241             final File[] roots = getFileChooser().getFileSystemView().getRoots();
    1242             for (final File element : roots) {
    1243                 path.addElement(element);
    1244             }
    1245             fPathCount = path.size();
    1246
    1247             // insert all the path fDirectories leading up to the
    1248             // selected directory in reverse order (current directory at top)
    1249             for (int i = 0; i < path.size(); i++) {
    1250                 fDirectories.addElement(path.elementAt(i));
    1251             }
    1252
    1253             setSelectedItem(fDirectories.elementAt(0));
    1254
    1255             // dump();
    1256         }
    1257
    1258         public void setSelectedItem(final File selectedDirectory) {
    1259             this.fSelectedDirectory = selectedDirectory;
    1260             fireContentsChanged(this, -1, -1);
    1261         }
    1262
    1263         public File getSelectedItem() {
    1264             return fSelectedDirectory;
    1265         }
    1266
    1267         public int getSize() {
    1268             return fDirectories.size();
    1269         }
    1270
    1271         public File getElementAt(final int index) {
    1272             return fDirectories.elementAt(index);
    1273         }
    1274     }
    1275
    1276     //
    1277     // Renderer for Types ComboBox
    1278     //
    1279     @SuppressWarnings("serial") // anonymous class
    1280     protected ListCellRenderer<FileFilter> createFilterComboBoxRenderer() {
    1281         return new AquaComboBoxRendererInternal<FileFilter>(filterComboBox) {
    1282             public Component getListCellRendererComponent(final JList<? extends FileFilter> list,
    1283                                                           final FileFilter filter,
    1301     /**
    1302      * Data model for a type-face selection combo-box.
    1303      */
    1304     @SuppressWarnings("serial") // Superclass is not serializable across versions
    1305     protected class FilterComboBoxModel extends AbstractListModel<FileFilter> implements ComboBoxModel<FileFilter>,
    1306             PropertyChangeListener {
    1307         protected FileFilter[] filters;
    1308         Object oldFileFilter = getFileChooser().getFileFilter();
    1309
    1310         protected FilterComboBoxModel() {
    1311             super();
    1312             filters = getFileChooser().getChoosableFileFilters();
    1313         }
    1314
    1315         public void propertyChange(PropertyChangeEvent e) {
    1316             String prop = e.getPropertyName();
    1317             if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
    1318                 filters = (FileFilter[]) e.getNewValue();
    1319                 fireContentsChanged(this, -1, -1);
    1320             } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
    1321                 setSelectedItem((FileFilter)e.getNewValue());
    1322             }
    1323         }
    1324
    1325         public void setSelectedItem(FileFilter filter) {
    1326             if (filter != null && !isSelectedFileFilterInModel(filter)) {
    1327                 oldFileFilter = filter;
    1328                 getFileChooser().setFileFilter(filter);
    1329                 fireContentsChanged(this, -1, -1);
    1330             }
    1331         }
    1332
    1333         private boolean isSelectedFileFilterInModel(FileFilter filter) {
    1334             return Objects.equals(filter, oldFileFilter);
    1335         }
    1336
    1337         public FileFilter getSelectedItem() {
    1338             // Ensure that the current filter is in the list.
    1339             // NOTE: we shouldnt' have to do this, since JFileChooser adds
    1340             // the filter to the choosable filters list when the filter
    1341             // is set. Lets be paranoid just in case someone overrides
    1342             // setFileFilter in JFileChooser.
    1343             FileFilter currentFilter = getFileChooser().getFileFilter();
    1344             boolean found = false;
    1345             if(currentFilter != null) {
    1346                 for (FileFilter filter : filters) {
    1347                     if (filter == currentFilter) {
    1348                         found = true;
    1349                     }
    1350                 }
    1351                 if(found == false) {
    1352                     getFileChooser().addChoosableFileFilter(currentFilter);
    1353                 }
    1354             }
    1355             return getFileChooser().getFileFilter();
    1356         }
    1357
    1390         }
    1391
    1392         public void actionPerformed(final ActionEvent e) {
    1393             Object selectedFilter = filterComboBox.getSelectedItem();
    1394             if (!containsFileFilter(selectedFilter)) {
    1395                 getFileChooser().setFileFilter((FileFilter) selectedFilter);
    1396             }
    1397         }
    1398     }
    1399
    1400     /**
    1401      * Acts when DirectoryComboBox has changed the selected item.
    1402      */
    1403     @SuppressWarnings("serial") // Superclass is not serializable across versions
    1404     protected class DirectoryComboBoxAction extends AbstractAction {
    1405         protected DirectoryComboBoxAction() {
    1406             super("DirectoryComboBoxAction");
    1407         }
    1408
    1409         public void actionPerformed(final ActionEvent e) {
    1410             getFileChooser().setCurrentDirectory(directoryComboBox.getSelectedItem());
    1411         }
    1412     }
    1413
    1414     // Sorting Table operations
    1415     @SuppressWarnings("serial") // Superclass is not serializable across versions
    1416     class JSortingTableHeader extends JTableHeader {
    1417         public JSortingTableHeader(final TableColumnModel cm) {
    1418             super(cm);
    1419             setReorderingAllowed(true); // This causes mousePress to call setDraggedColumn
    1420         }
    1421
    1422         // One sort state for each column.  Both are ascending by default
    1423         final boolean fSortAscending[] = {true, true};
    1424
    1425         // Instead of dragging, it selects which one to sort by
    1426         public void setDraggedColumn(final TableColumn aColumn) {
    1427             if (aColumn != null) {
    1428                 final int colIndex = aColumn.getModelIndex();
    1429                 if (colIndex != fSortColumn) {
    1430                     filechooser.firePropertyChange(AquaFileSystemModel.SORT_BY_CHANGED, fSortColumn, colIndex);

< prev index next >