8022398: javax/swing/JFileChooser/8013442/Test8013442.java fails
Reviewed-by: alexsch
This commit is contained in:
parent
6dd078f94a
commit
e304fd35a0
@ -42,6 +42,7 @@ import javax.swing.filechooser.*;
|
|||||||
import javax.swing.plaf.*;
|
import javax.swing.plaf.*;
|
||||||
import javax.swing.table.*;
|
import javax.swing.table.*;
|
||||||
|
|
||||||
|
import sun.swing.AbstractFilterComboBoxModel;
|
||||||
import sun.swing.SwingUtilities2;
|
import sun.swing.SwingUtilities2;
|
||||||
|
|
||||||
public class AquaFileChooserUI extends FileChooserUI {
|
public class AquaFileChooserUI extends FileChooserUI {
|
||||||
@ -1266,64 +1267,9 @@ public class AquaFileChooserUI extends FileChooserUI {
|
|||||||
/**
|
/**
|
||||||
* Data model for a type-face selection combo-box.
|
* Data model for a type-face selection combo-box.
|
||||||
*/
|
*/
|
||||||
protected class FilterComboBoxModel extends DefaultListModel implements ComboBoxModel, PropertyChangeListener {
|
protected class FilterComboBoxModel extends AbstractFilterComboBoxModel {
|
||||||
int selectedIndex = -1;
|
protected JFileChooser getFileChooser() {
|
||||||
|
return AquaFileChooserUI.this.getFileChooser();
|
||||||
protected FilterComboBoxModel() {
|
|
||||||
super();
|
|
||||||
final FileFilter filters[] = getFileChooser().getChoosableFileFilters();
|
|
||||||
for (int i = 0; i < filters.length; i++) {
|
|
||||||
this.add(i, filters[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void propertyChange(final PropertyChangeEvent e) {
|
|
||||||
final String prop = e.getPropertyName();
|
|
||||||
if (prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
|
|
||||||
this.clear();
|
|
||||||
final FileFilter filters[] = (FileFilter[])e.getNewValue();
|
|
||||||
|
|
||||||
for (int i = 0; i < filters.length; i++) {
|
|
||||||
this.add(i, filters[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
} else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
|
|
||||||
final FileFilter currentFilter = (FileFilter)e.getNewValue();
|
|
||||||
FileFilter filters[] = getFileChooser().getChoosableFileFilters();
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
if (currentFilter != null) {
|
|
||||||
for (final FileFilter element : filters) {
|
|
||||||
if (element == currentFilter) {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found == false) {
|
|
||||||
getFileChooser().addChoosableFileFilter(currentFilter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
filters = getFileChooser().getChoosableFileFilters();
|
|
||||||
setSelectedItem(e.getNewValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelectedItem(final Object filter) {
|
|
||||||
if (filter != null) {
|
|
||||||
selectedIndex = this.indexOf(filter);
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getSelectedItem() {
|
|
||||||
final Object returnValue = null;
|
|
||||||
|
|
||||||
if (this.size() > 0) {
|
|
||||||
if ((selectedIndex != -1) && (selectedIndex < size())) { return this.get(selectedIndex); }
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ import javax.swing.plaf.basic.BasicDirectoryModel;
|
|||||||
import javax.swing.table.*;
|
import javax.swing.table.*;
|
||||||
import javax.accessibility.*;
|
import javax.accessibility.*;
|
||||||
|
|
||||||
|
import sun.swing.AbstractFilterComboBoxModel;
|
||||||
import sun.swing.SwingUtilities2;
|
import sun.swing.SwingUtilities2;
|
||||||
|
|
||||||
import sun.swing.plaf.synth.*;
|
import sun.swing.plaf.synth.*;
|
||||||
@ -1328,71 +1329,9 @@ class GTKFileChooserUI extends SynthFileChooserUI {
|
|||||||
/**
|
/**
|
||||||
* Data model for filter combo-box.
|
* Data model for filter combo-box.
|
||||||
*/
|
*/
|
||||||
protected class FilterComboBoxModel extends AbstractListModel
|
protected class FilterComboBoxModel extends AbstractFilterComboBoxModel {
|
||||||
implements ComboBoxModel, PropertyChangeListener {
|
protected JFileChooser getFileChooser() {
|
||||||
protected FileFilter[] filters;
|
return GTKFileChooserUI.this.getFileChooser();
|
||||||
|
|
||||||
protected FilterComboBoxModel() {
|
|
||||||
super();
|
|
||||||
filters = getFileChooser().getChoosableFileFilters();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void propertyChange(PropertyChangeEvent e) {
|
|
||||||
String prop = e.getPropertyName();
|
|
||||||
if (prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
|
|
||||||
filters = (FileFilter[]) e.getNewValue();
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
} else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelectedItem(Object filter) {
|
|
||||||
if (filter != null) {
|
|
||||||
getFileChooser().setFileFilter((FileFilter) filter);
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getSelectedItem() {
|
|
||||||
// Ensure that the current filter is in the list.
|
|
||||||
// NOTE: we shouldnt' have to do this, since JFileChooser adds
|
|
||||||
// the filter to the choosable filters list when the filter
|
|
||||||
// is set. Lets be paranoid just in case someone overrides
|
|
||||||
// setFileFilter in JFileChooser.
|
|
||||||
FileFilter currentFilter = getFileChooser().getFileFilter();
|
|
||||||
boolean found = false;
|
|
||||||
if (currentFilter != null) {
|
|
||||||
for (FileFilter filter : filters) {
|
|
||||||
if (filter == currentFilter) {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found == false) {
|
|
||||||
getFileChooser().addChoosableFileFilter(currentFilter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getFileChooser().getFileFilter();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize() {
|
|
||||||
if (filters != null) {
|
|
||||||
return filters.length;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getElementAt(int index) {
|
|
||||||
if (index > getSize() - 1) {
|
|
||||||
// This shouldn't happen. Try to recover gracefully.
|
|
||||||
return getFileChooser().getFileFilter();
|
|
||||||
}
|
|
||||||
if (filters != null) {
|
|
||||||
return filters[index];
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import sun.awt.shell.ShellFolder;
|
import sun.awt.shell.ShellFolder;
|
||||||
|
import sun.swing.AbstractFilterComboBoxModel;
|
||||||
import sun.swing.SwingUtilities2;
|
import sun.swing.SwingUtilities2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -777,70 +778,9 @@ public class MotifFileChooserUI extends BasicFileChooserUI {
|
|||||||
/**
|
/**
|
||||||
* Data model for a type-face selection combo-box.
|
* Data model for a type-face selection combo-box.
|
||||||
*/
|
*/
|
||||||
protected class FilterComboBoxModel extends AbstractListModel<FileFilter> implements ComboBoxModel<FileFilter>,
|
protected class FilterComboBoxModel extends AbstractFilterComboBoxModel {
|
||||||
PropertyChangeListener {
|
protected JFileChooser getFileChooser() {
|
||||||
protected FileFilter[] filters;
|
return MotifFileChooserUI.this.getFileChooser();
|
||||||
protected FilterComboBoxModel() {
|
|
||||||
super();
|
|
||||||
filters = getFileChooser().getChoosableFileFilters();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void propertyChange(PropertyChangeEvent e) {
|
|
||||||
String prop = e.getPropertyName();
|
|
||||||
if(prop.equals(JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY)) {
|
|
||||||
filters = (FileFilter[]) e.getNewValue();
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
} else if (prop.equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) {
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelectedItem(Object filter) {
|
|
||||||
if(filter != null) {
|
|
||||||
getFileChooser().setFileFilter((FileFilter) filter);
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getSelectedItem() {
|
|
||||||
// Ensure that the current filter is in the list.
|
|
||||||
// NOTE: we shouldnt' have to do this, since JFileChooser adds
|
|
||||||
// the filter to the choosable filters list when the filter
|
|
||||||
// is set. Lets be paranoid just in case someone overrides
|
|
||||||
// setFileFilter in JFileChooser.
|
|
||||||
FileFilter currentFilter = getFileChooser().getFileFilter();
|
|
||||||
boolean found = false;
|
|
||||||
if(currentFilter != null) {
|
|
||||||
for (FileFilter filter : filters) {
|
|
||||||
if (filter == currentFilter) {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
getFileChooser().addChoosableFileFilter(currentFilter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getFileChooser().getFileFilter();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize() {
|
|
||||||
if(filters != null) {
|
|
||||||
return filters.length;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public FileFilter getElementAt(int index) {
|
|
||||||
if(index > getSize() - 1) {
|
|
||||||
// This shouldn't happen. Try to recover gracefully.
|
|
||||||
return getFileChooser().getFileFilter();
|
|
||||||
}
|
|
||||||
if(filters != null) {
|
|
||||||
return filters[index];
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1193,70 +1193,9 @@ public class WindowsFileChooserUI extends BasicFileChooserUI {
|
|||||||
/**
|
/**
|
||||||
* Data model for a type-face selection combo-box.
|
* Data model for a type-face selection combo-box.
|
||||||
*/
|
*/
|
||||||
protected class FilterComboBoxModel extends AbstractListModel<FileFilter> implements ComboBoxModel<FileFilter>,
|
protected class FilterComboBoxModel extends AbstractFilterComboBoxModel {
|
||||||
PropertyChangeListener {
|
protected JFileChooser getFileChooser() {
|
||||||
protected FileFilter[] filters;
|
return WindowsFileChooserUI.this.getFileChooser();
|
||||||
protected FilterComboBoxModel() {
|
|
||||||
super();
|
|
||||||
filters = getFileChooser().getChoosableFileFilters();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void propertyChange(PropertyChangeEvent e) {
|
|
||||||
String prop = e.getPropertyName();
|
|
||||||
if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
|
|
||||||
filters = (FileFilter[]) e.getNewValue();
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
} else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelectedItem(Object filter) {
|
|
||||||
if(filter != null) {
|
|
||||||
getFileChooser().setFileFilter((FileFilter) filter);
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getSelectedItem() {
|
|
||||||
// Ensure that the current filter is in the list.
|
|
||||||
// NOTE: we shouldnt' have to do this, since JFileChooser adds
|
|
||||||
// the filter to the choosable filters list when the filter
|
|
||||||
// is set. Lets be paranoid just in case someone overrides
|
|
||||||
// setFileFilter in JFileChooser.
|
|
||||||
FileFilter currentFilter = getFileChooser().getFileFilter();
|
|
||||||
boolean found = false;
|
|
||||||
if(currentFilter != null) {
|
|
||||||
for (FileFilter filter : filters) {
|
|
||||||
if (filter == currentFilter) {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(found == false) {
|
|
||||||
getFileChooser().addChoosableFileFilter(currentFilter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getFileChooser().getFileFilter();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize() {
|
|
||||||
if(filters != null) {
|
|
||||||
return filters.length;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public FileFilter getElementAt(int index) {
|
|
||||||
if(index > getSize() - 1) {
|
|
||||||
// This shouldn't happen. Try to recover gracefully.
|
|
||||||
return getFileChooser().getFileFilter();
|
|
||||||
}
|
|
||||||
if(filters != null) {
|
|
||||||
return filters[index];
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1067,69 +1067,9 @@ public class MetalFileChooserUI extends BasicFileChooserUI {
|
|||||||
/**
|
/**
|
||||||
* Data model for a type-face selection combo-box.
|
* Data model for a type-face selection combo-box.
|
||||||
*/
|
*/
|
||||||
protected class FilterComboBoxModel extends AbstractListModel<Object> implements ComboBoxModel<Object>, PropertyChangeListener {
|
protected class FilterComboBoxModel extends AbstractFilterComboBoxModel {
|
||||||
protected FileFilter[] filters;
|
protected JFileChooser getFileChooser() {
|
||||||
protected FilterComboBoxModel() {
|
return MetalFileChooserUI.this.getFileChooser();
|
||||||
super();
|
|
||||||
filters = getFileChooser().getChoosableFileFilters();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void propertyChange(PropertyChangeEvent e) {
|
|
||||||
String prop = e.getPropertyName();
|
|
||||||
if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
|
|
||||||
filters = (FileFilter[]) e.getNewValue();
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
} else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelectedItem(Object filter) {
|
|
||||||
if(filter != null) {
|
|
||||||
getFileChooser().setFileFilter((FileFilter) filter);
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getSelectedItem() {
|
|
||||||
// Ensure that the current filter is in the list.
|
|
||||||
// NOTE: we shouldnt' have to do this, since JFileChooser adds
|
|
||||||
// the filter to the choosable filters list when the filter
|
|
||||||
// is set. Lets be paranoid just in case someone overrides
|
|
||||||
// setFileFilter in JFileChooser.
|
|
||||||
FileFilter currentFilter = getFileChooser().getFileFilter();
|
|
||||||
boolean found = false;
|
|
||||||
if(currentFilter != null) {
|
|
||||||
for (FileFilter filter : filters) {
|
|
||||||
if (filter == currentFilter) {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(found == false) {
|
|
||||||
getFileChooser().addChoosableFileFilter(currentFilter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getFileChooser().getFileFilter();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize() {
|
|
||||||
if(filters != null) {
|
|
||||||
return filters.length;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getElementAt(int index) {
|
|
||||||
if(index > getSize() - 1) {
|
|
||||||
// This shouldn't happen. Try to recover gracefully.
|
|
||||||
return getFileChooser().getFileFilter();
|
|
||||||
}
|
|
||||||
if(filters != null) {
|
|
||||||
return filters[index];
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
104
jdk/src/share/classes/sun/swing/AbstractFilterComboBoxModel.java
Normal file
104
jdk/src/share/classes/sun/swing/AbstractFilterComboBoxModel.java
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation. Oracle designates this
|
||||||
|
* particular file as subject to the "Classpath" exception as provided
|
||||||
|
* by Oracle in the LICENSE file that accompanied this code.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
package sun.swing;
|
||||||
|
|
||||||
|
import javax.swing.AbstractListModel;
|
||||||
|
import javax.swing.ComboBoxModel;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.filechooser.FileFilter;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data model for a type-face selection combo-box.
|
||||||
|
*/
|
||||||
|
public abstract class AbstractFilterComboBoxModel
|
||||||
|
extends AbstractListModel<FileFilter>
|
||||||
|
implements ComboBoxModel<FileFilter>, PropertyChangeListener {
|
||||||
|
|
||||||
|
protected FileFilter[] filters;
|
||||||
|
|
||||||
|
protected AbstractFilterComboBoxModel() {
|
||||||
|
this.filters = getFileChooser().getChoosableFileFilters();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract JFileChooser getFileChooser();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void propertyChange(PropertyChangeEvent event) {
|
||||||
|
String property = event.getPropertyName();
|
||||||
|
if (property == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
|
||||||
|
this.filters = (FileFilter[]) event.getNewValue();
|
||||||
|
fireContentsChanged(this, -1, -1);
|
||||||
|
} else if (property == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
|
||||||
|
fireContentsChanged(this, -1, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelectedItem(Object filter) {
|
||||||
|
if (filter != null) {
|
||||||
|
getFileChooser().setFileFilter((FileFilter) filter);
|
||||||
|
fireContentsChanged(this, -1, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getSelectedItem() {
|
||||||
|
// Ensure that the current filter is in the list.
|
||||||
|
// NOTE: we should not have to do this, since JFileChooser adds
|
||||||
|
// the filter to the choosable filters list when the filter
|
||||||
|
// is set. Lets be paranoid just in case someone overrides
|
||||||
|
// setFileFilter in JFileChooser.
|
||||||
|
FileFilter currentFilter = getFileChooser().getFileFilter();
|
||||||
|
if (currentFilter != null) {
|
||||||
|
for (FileFilter filter : this.filters) {
|
||||||
|
if (filter == currentFilter) {
|
||||||
|
return currentFilter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getFileChooser().addChoosableFileFilter(currentFilter);
|
||||||
|
}
|
||||||
|
return currentFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize() {
|
||||||
|
return (this.filters != null)
|
||||||
|
? filters.length
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileFilter getElementAt(int index) {
|
||||||
|
if (index >= getSize()) {
|
||||||
|
// This shouldn't happen. Try to recover gracefully.
|
||||||
|
return getFileChooser().getFileFilter();
|
||||||
|
}
|
||||||
|
return (this.filters != null)
|
||||||
|
? filters[index]
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
}
|
@ -923,70 +923,9 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI {
|
|||||||
/**
|
/**
|
||||||
* Data model for a type-face selection combo-box.
|
* Data model for a type-face selection combo-box.
|
||||||
*/
|
*/
|
||||||
protected class FilterComboBoxModel extends AbstractListModel<FileFilter> implements ComboBoxModel<FileFilter>,
|
protected class FilterComboBoxModel extends AbstractFilterComboBoxModel {
|
||||||
PropertyChangeListener {
|
protected JFileChooser getFileChooser() {
|
||||||
protected FileFilter[] filters;
|
return SynthFileChooserUIImpl.this.getFileChooser();
|
||||||
protected FilterComboBoxModel() {
|
|
||||||
super();
|
|
||||||
filters = getFileChooser().getChoosableFileFilters();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void propertyChange(PropertyChangeEvent e) {
|
|
||||||
String prop = e.getPropertyName();
|
|
||||||
if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
|
|
||||||
filters = (FileFilter[]) e.getNewValue();
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
} else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) {
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelectedItem(Object filter) {
|
|
||||||
if(filter != null) {
|
|
||||||
getFileChooser().setFileFilter((FileFilter) filter);
|
|
||||||
fireContentsChanged(this, -1, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getSelectedItem() {
|
|
||||||
// Ensure that the current filter is in the list.
|
|
||||||
// NOTE: we shouldnt' have to do this, since JFileChooser adds
|
|
||||||
// the filter to the choosable filters list when the filter
|
|
||||||
// is set. Lets be paranoid just in case someone overrides
|
|
||||||
// setFileFilter in JFileChooser.
|
|
||||||
FileFilter currentFilter = getFileChooser().getFileFilter();
|
|
||||||
boolean found = false;
|
|
||||||
if(currentFilter != null) {
|
|
||||||
for (FileFilter filter : filters) {
|
|
||||||
if (filter == currentFilter) {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(found == false) {
|
|
||||||
getFileChooser().addChoosableFileFilter(currentFilter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getFileChooser().getFileFilter();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize() {
|
|
||||||
if(filters != null) {
|
|
||||||
return filters.length;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public FileFilter getElementAt(int index) {
|
|
||||||
if(index > getSize() - 1) {
|
|
||||||
// This shouldn't happen. Try to recover gracefully.
|
|
||||||
return getFileChooser().getFileFilter();
|
|
||||||
}
|
|
||||||
if(filters != null) {
|
|
||||||
return filters[index];
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user