< prev index next >

## src/java.desktop/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.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.

     817             depths = new int[directories.size()];
     818             for (int i = 0; i < depths.length; i++) {
     819                 File dir = directories.get(i);
     820                 File parent = dir.getParentFile();
     821                 depths[i] = 0;
     822                 if (parent != null) {
     823                     for (int j = i-1; j >= 0; j--) {
     824                         if (parent.equals(directories.get(j))) {
     825                             depths[i] = depths[j] + 1;
     826                             break;
     827                         }
     828                     }
     829                 }
     830             }
     831         }
     832
     833         public int getDepth(int i) {
     834             return (depths != null && i >= 0 && i < depths.length) ? depths[i] : 0;
     835         }
     836
     837         public void setSelectedItem(Object selectedDirectory) {
     838             this.selectedDirectory = (File)selectedDirectory;

     839             fireContentsChanged(this, -1, -1);
     840         }
     841
     842         public Object getSelectedItem() {

     843             return selectedDirectory;
     844         }
     845
     846         public int getSize() {
     847             return directories.size();
     848         }
     849
     850         public File getElementAt(int index) {
     851             return directories.elementAt(index);
     852         }
     853     }
     854
     855     /**
     856      * Acts when DirectoryComboBox has changed the selected item.
     857      */
     858     @SuppressWarnings("serial") // JDK-implementation class
     859     protected class DirectoryComboBoxAction extends AbstractAction {
     860         protected DirectoryComboBoxAction() {
     861             super("DirectoryComboBoxAction");
     862         }
     918      */
     919     @SuppressWarnings("serial") // JDK-implementation class
     920     protected class FilterComboBoxModel extends AbstractListModel<FileFilter> implements ComboBoxModel<FileFilter>,
     921             PropertyChangeListener {
     922         protected FileFilter[] filters;
     923         protected FilterComboBoxModel() {
     924             super();
     925             filters = getFileChooser().getChoosableFileFilters();
     926         }
     927
     928         public void propertyChange(PropertyChangeEvent e) {
     929             String prop = e.getPropertyName();
     930             if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
     931                 filters = (FileFilter[]) e.getNewValue();
     932                 fireContentsChanged(this, -1, -1);
     933             } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
     934                 fireContentsChanged(this, -1, -1);
     935             }
     936         }
     937
     938         public void setSelectedItem(Object filter) {
     939             if(filter != null) {
     940                 getFileChooser().setFileFilter((FileFilter) filter);
     941                 fireContentsChanged(this, -1, -1);
     942             }
     943         }
     944
     945         public Object getSelectedItem() {
     946             // Ensure that the current filter is in the list.
     947             // NOTE: we shouldnt' have to do this, since JFileChooser adds
     948             // the filter to the choosable filters list when the filter
     949             // is set. Lets be paranoid just in case someone overrides
     950             // setFileFilter in JFileChooser.
     951             FileFilter currentFilter = getFileChooser().getFileFilter();
     952             boolean found = false;
     953             if(currentFilter != null) {
     954                 for (FileFilter filter : filters) {
     955                     if (filter == currentFilter) {
     956                         found = true;
     957                     }
     958                 }
     959                 if(found == false) {
     960                     getFileChooser().addChoosableFileFilter(currentFilter);
     961                 }
     962             }
     963             return getFileChooser().getFileFilter();
     964         }
     965
     817             depths = new int[directories.size()];
     818             for (int i = 0; i < depths.length; i++) {
     819                 File dir = directories.get(i);
     820                 File parent = dir.getParentFile();
     821                 depths[i] = 0;
     822                 if (parent != null) {
     823                     for (int j = i-1; j >= 0; j--) {
     824                         if (parent.equals(directories.get(j))) {
     825                             depths[i] = depths[j] + 1;
     826                             break;
     827                         }
     828                     }
     829                 }
     830             }
     831         }
     832
     833         public int getDepth(int i) {
     834             return (depths != null && i >= 0 && i < depths.length) ? depths[i] : 0;
     835         }
     836
     837         @Override
     838         public void setSelectedItem(File selectedDirectory) {
     839             this.selectedDirectory = selectedDirectory;
     840             fireContentsChanged(this, -1, -1);
     841         }
     842
     843         @Override
     844         public File getSelectedItem() {
     845             return selectedDirectory;
     846         }
     847
     848         public int getSize() {
     849             return directories.size();
     850         }
     851
     852         public File getElementAt(int index) {
     853             return directories.elementAt(index);
     854         }
     855     }
     856
     857     /**
     858      * Acts when DirectoryComboBox has changed the selected item.
     859      */
     860     @SuppressWarnings("serial") // JDK-implementation class
     861     protected class DirectoryComboBoxAction extends AbstractAction {
     862         protected DirectoryComboBoxAction() {
     863             super("DirectoryComboBoxAction");
     864         }
     920      */
     921     @SuppressWarnings("serial") // JDK-implementation class
     922     protected class FilterComboBoxModel extends AbstractListModel<FileFilter> implements ComboBoxModel<FileFilter>,
     923             PropertyChangeListener {
     924         protected FileFilter[] filters;
     925         protected FilterComboBoxModel() {
     926             super();
     927             filters = getFileChooser().getChoosableFileFilters();
     928         }
     929
     930         public void propertyChange(PropertyChangeEvent e) {
     931             String prop = e.getPropertyName();
     932             if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
     933                 filters = (FileFilter[]) e.getNewValue();
     934                 fireContentsChanged(this, -1, -1);
     935             } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
     936                 fireContentsChanged(this, -1, -1);
     937             }
     938         }
     939
     940         public void setSelectedItem(FileFilter filter) {
     941             if(filter != null) {
     942                 getFileChooser().setFileFilter(filter);
     943                 fireContentsChanged(this, -1, -1);
     944             }
     945         }
     946
     947         public FileFilter getSelectedItem() {
     948             // Ensure that the current filter is in the list.
     949             // NOTE: we shouldnt' have to do this, since JFileChooser adds
     950             // the filter to the choosable filters list when the filter
     951             // is set. Lets be paranoid just in case someone overrides
     952             // setFileFilter in JFileChooser.
     953             FileFilter currentFilter = getFileChooser().getFileFilter();
     954             boolean found = false;
     955             if(currentFilter != null) {
     956                 for (FileFilter filter : filters) {
     957                     if (filter == currentFilter) {
     958                         found = true;
     959                     }
     960                 }
     961                 if(found == false) {
     962                     getFileChooser().addChoosableFileFilter(currentFilter);
     963                 }
     964             }
     965             return getFileChooser().getFileFilter();
     966         }
     967

< prev index next >