diff options
author | Mark Wielaard <mark@gcc.gnu.org> | 2006-01-17 18:09:40 +0000 |
---|---|---|
committer | Mark Wielaard <mark@gcc.gnu.org> | 2006-01-17 18:09:40 +0000 |
commit | 2127637945ea6b763966398130e0770fa993c860 (patch) | |
tree | c976ca91e3ef0bda3b34b37c0195145638d8d08e /libjava/classpath/javax/swing/JFileChooser.java | |
parent | bcb36c3e02e3bd2843aad1b9888513dfb5d6e337 (diff) | |
download | gcc-2127637945ea6b763966398130e0770fa993c860.zip gcc-2127637945ea6b763966398130e0770fa993c860.tar.gz gcc-2127637945ea6b763966398130e0770fa993c860.tar.bz2 |
Imported GNU Classpath 0.20
Imported GNU Classpath 0.20
* Makefile.am (AM_CPPFLAGS): Add classpath/include.
* java/nio/charset/spi/CharsetProvider.java: New override file.
* java/security/Security.java: Likewise.
* sources.am: Regenerated.
* Makefile.in: Likewise.
From-SVN: r109831
Diffstat (limited to 'libjava/classpath/javax/swing/JFileChooser.java')
-rw-r--r-- | libjava/classpath/javax/swing/JFileChooser.java | 78 |
1 files changed, 52 insertions, 26 deletions
diff --git a/libjava/classpath/javax/swing/JFileChooser.java b/libjava/classpath/javax/swing/JFileChooser.java index 1598641..3a9d6a0 100644 --- a/libjava/classpath/javax/swing/JFileChooser.java +++ b/libjava/classpath/javax/swing/JFileChooser.java @@ -40,6 +40,7 @@ package javax.swing; import java.awt.Component; import java.awt.Frame; import java.awt.HeadlessException; +import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; @@ -407,8 +408,7 @@ public class JFileChooser extends JComponent implements Accessible */ public JFileChooser(String currentDirectoryPath) { - setup(null); - setCurrentDirectory(fsv.createFileObject(currentDirectoryPath)); + this(currentDirectoryPath, null); } /** @@ -424,7 +424,10 @@ public class JFileChooser extends JComponent implements Accessible public JFileChooser(String currentDirectoryPath, FileSystemView fsv) { setup(fsv); - setCurrentDirectory(fsv.createFileObject(currentDirectoryPath)); + File dir = null; + if (currentDirectoryPath != null) + dir = getFileSystemView().createFileObject(currentDirectoryPath); + setCurrentDirectory(dir); } /** @@ -525,7 +528,7 @@ public class JFileChooser extends JComponent implements Accessible */ public void setSelectedFile(File file) { - if (selectedFile != file) + if (selectedFile == null || !selectedFile.equals(file)) { File old = selectedFile; selectedFile = file; @@ -534,10 +537,10 @@ public class JFileChooser extends JComponent implements Accessible } /** - * Returns the selected file or files. + * Returns the selected file or files in an array. If no files are selected, + * an empty array is returned. * - * @return An array of the selected files, or <code>null</code> if there are - * no selected files. + * @return An array of the selected files (possibly empty). */ public File[] getSelectedFiles() { @@ -545,7 +548,7 @@ public class JFileChooser extends JComponent implements Accessible return selectedFiles; if (selectedFile != null) return new File[] { selectedFile }; - return null; + return new File[0]; } /** @@ -557,6 +560,12 @@ public class JFileChooser extends JComponent implements Accessible */ public void setSelectedFiles(File[] selectedFiles) { + if (selectedFiles == null) + selectedFiles = new File[0]; + if (selectedFiles.length > 0) + setSelectedFile(selectedFiles[0]); + else + setSelectedFile(null); if (this.selectedFiles != selectedFiles) { File[] old = this.selectedFiles; @@ -564,8 +573,6 @@ public class JFileChooser extends JComponent implements Accessible firePropertyChange(SELECTED_FILES_CHANGED_PROPERTY, old, selectedFiles); } - if (selectedFiles != null) - setSelectedFile(selectedFiles[0]); } /** @@ -607,8 +614,7 @@ public class JFileChooser extends JComponent implements Accessible */ public void changeToParentDirectory() { - if (fsv.getParentDirectory(currentDir) != null) - setCurrentDirectory(fsv.getParentDirectory(currentDir)); + setCurrentDirectory(fsv.getParentDirectory(currentDir)); } /** @@ -652,7 +658,8 @@ public class JFileChooser extends JComponent implements Accessible retval = ERROR_OPTION; - d.pack(); + Insets i = d.getInsets(); + d.setSize(500 + i.top + i.bottom, d.getPreferredSize().height); d.show(); return retval; } @@ -676,7 +683,8 @@ public class JFileChooser extends JComponent implements Accessible retval = ERROR_OPTION; - d.pack(); + Insets i = d.getInsets(); + d.setSize(500 + i.top + i.bottom, d.getPreferredSize().height); d.show(); return retval; } @@ -702,7 +710,8 @@ public class JFileChooser extends JComponent implements Accessible retval = ERROR_OPTION; - d.pack(); + Insets i = d.getInsets(); + d.setSize(500 + i.top + i.bottom, d.getPreferredSize().height); d.show(); return retval; } @@ -958,14 +967,19 @@ public class JFileChooser extends JComponent implements Accessible * {@link #CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY}) to all registered * listeners. * - * @param filter the filter. + * @param filter the filter (<code>null</code> permitted). */ public void addChoosableFileFilter(FileFilter filter) { - FileFilter[] old = getChoosableFileFilters(); - choosableFilters.add(filter); - FileFilter[] newFilters = getChoosableFileFilters(); - firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, old, newFilters); + if (filter != null) + { + FileFilter[] old = getChoosableFileFilters(); + choosableFilters.add(filter); + FileFilter[] newFilters = getChoosableFileFilters(); + firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, old, + newFilters); + } + setFileFilter(filter); } /** @@ -981,6 +995,8 @@ public class JFileChooser extends JComponent implements Accessible */ public boolean removeChoosableFileFilter(FileFilter f) { + if (f == currentFilter) + setFileFilter(null); FileFilter[] old = getChoosableFileFilters(); if (! choosableFilters.remove(f)) return false; @@ -1037,6 +1053,10 @@ public class JFileChooser extends JComponent implements Accessible if (isAcceptAll != b) { isAcceptAll = b; + if (b) + addChoosableFileFilter(getAcceptAllFileFilter()); + else + removeChoosableFileFilter(getAcceptAllFileFilter()); firePropertyChange(ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY, ! isAcceptAll, isAcceptAll); } @@ -1208,15 +1228,17 @@ public class JFileChooser extends JComponent implements Accessible * property name {@link #FILE_FILTER_CHANGED_PROPERTY}) to all registered * listeners. * - * @param filter the filter. + * @param filter the filter (<code>null</code> permitted). */ public void setFileFilter(FileFilter filter) { if (currentFilter != filter) { - FileFilter old = currentFilter; - currentFilter = filter; - firePropertyChange(FILE_FILTER_CHANGED_PROPERTY, old, currentFilter); + if (filter != null && !choosableFilters.contains(filter)) + addChoosableFileFilter(filter); + FileFilter old = currentFilter; + currentFilter = filter; + firePropertyChange(FILE_FILTER_CHANGED_PROPERTY, old, currentFilter); } } @@ -1356,8 +1378,12 @@ public class JFileChooser extends JComponent implements Accessible public boolean accept(File f) { if (f == null) - return false; - return getFileFilter().accept(f); + return true; + FileFilter ff = getFileFilter(); + if (ff != null) + return ff.accept(f); + else + return true; } /** |