< prev index next >
src/share/classes/javax/swing/JFileChooser.java
Print this page
rev 1527 : 6727662: Code improvement and warnings removing from swing packages
Summary: Removed unnecessary castings and other warnings
Reviewed-by: malenkov
@@ -246,11 +246,11 @@
private String dialogTitle = null;
private String approveButtonText = null;
private String approveButtonToolTipText = null;
private int approveButtonMnemonic = 0;
- private Vector filters = new Vector(5);
+ private Vector<FileFilter> filters = new Vector<FileFilter>(5);
private JDialog dialog = null;
private int dialogType = OPEN_DIALOG;
private int returnValue = ERROR_OPTION;
private JComponent accessory = null;
@@ -501,11 +501,11 @@
*/
public File[] getSelectedFiles() {
if(selectedFiles == null) {
return new File[0];
} else {
- return (File[]) selectedFiles.clone();
+ return selectedFiles.clone();
}
}
/**
* Sets the list of selected files if the file chooser is
@@ -1411,21 +1411,21 @@
public void setFileFilter(FileFilter filter) {
FileFilter oldValue = fileFilter;
fileFilter = filter;
if (filter != null) {
if (isMultiSelectionEnabled() && selectedFiles != null && selectedFiles.length > 0) {
- Vector fList = new Vector();
+ Vector<File> fList = new Vector<File>();
boolean failed = false;
- for (int i = 0; i < selectedFiles.length; i++) {
- if (filter.accept(selectedFiles[i])) {
- fList.add(selectedFiles[i]);
+ for (File file : selectedFiles) {
+ if (filter.accept(file)) {
+ fList.add(file);
} else {
failed = true;
}
}
if (failed) {
- setSelectedFiles((fList.size() == 0) ? null : (File[])fList.toArray(new File[fList.size()]));
+ setSelectedFiles((fList.size() == 0) ? null : fList.toArray(new File[fList.size()]));
}
} else if (selectedFile != null && !filter.accept(selectedFile)) {
setSelectedFile(null);
}
}
@@ -1698,12 +1698,11 @@
* @see #removeActionListener
*
* @since 1.4
*/
public ActionListener[] getActionListeners() {
- return (ActionListener[])listenerList.getListeners(
- ActionListener.class);
+ return listenerList.getListeners(ActionListener.class);
}
/**
* Notifies all listeners that have registered interest for
* notification on this event type. The event instance
@@ -1740,11 +1739,11 @@
private static class WeakPCL implements PropertyChangeListener {
WeakReference<JFileChooser> jfcRef;
public WeakPCL(JFileChooser jfc) {
- jfcRef = new WeakReference(jfc);
+ jfcRef = new WeakReference<JFileChooser>(jfc);
}
public void propertyChange(PropertyChangeEvent ev) {
assert ev.getPropertyName().equals(SHOW_HIDDEN_PROP);
JFileChooser jfc = jfcRef.get();
if (jfc == null) {
< prev index next >