提交 65a27f3e 编写于 作者: R rupashka

7031941: Use generificated JComboBox and JList in core libraries

Reviewed-by: alexp
上级 95fbd452
...@@ -49,11 +49,11 @@ public class MotifFileChooserUI extends BasicFileChooserUI { ...@@ -49,11 +49,11 @@ public class MotifFileChooserUI extends BasicFileChooserUI {
private FilterComboBoxModel filterComboBoxModel; private FilterComboBoxModel filterComboBoxModel;
protected JList directoryList = null; protected JList<File> directoryList = null;
protected JList fileList = null; protected JList<File> fileList = null;
protected JTextField pathField = null; protected JTextField pathField = null;
protected JComboBox filterComboBox = null; protected JComboBox<FileFilter> filterComboBox = null;
protected JTextField filenameTextField = null; protected JTextField filenameTextField = null;
private static final Dimension hstrut10 = new Dimension(10, 1); private static final Dimension hstrut10 = new Dimension(10, 1);
...@@ -337,7 +337,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI { ...@@ -337,7 +337,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI {
align(l); align(l);
leftPanel.add(l); leftPanel.add(l);
filterComboBox = new JComboBox() { filterComboBox = new JComboBox<FileFilter>() {
public Dimension getMaximumSize() { public Dimension getMaximumSize() {
Dimension d = super.getMaximumSize(); Dimension d = super.getMaximumSize();
d.height = getPreferredSize().height; d.height = getPreferredSize().height;
...@@ -557,7 +557,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI { ...@@ -557,7 +557,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI {
} }
protected JScrollPane createFilesList() { protected JScrollPane createFilesList() {
fileList = new JList(); fileList = new JList<File>();
if(getFileChooser().isMultiSelectionEnabled()) { if(getFileChooser().isMultiSelectionEnabled()) {
fileList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); fileList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
...@@ -576,7 +576,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI { ...@@ -576,7 +576,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI {
if (SwingUtilities.isLeftMouseButton(e) && !chooser.isMultiSelectionEnabled()) { if (SwingUtilities.isLeftMouseButton(e) && !chooser.isMultiSelectionEnabled()) {
int index = SwingUtilities2.loc2IndexFileList(fileList, e.getPoint()); int index = SwingUtilities2.loc2IndexFileList(fileList, e.getPoint());
if (index >= 0) { if (index >= 0) {
File file = (File) fileList.getModel().getElementAt(index); File file = fileList.getModel().getElementAt(index);
setFileName(chooser.getName(file)); setFileName(chooser.getName(file));
} }
} }
...@@ -593,7 +593,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI { ...@@ -593,7 +593,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI {
} }
protected JScrollPane createDirectoryList() { protected JScrollPane createDirectoryList() {
directoryList = new JList(); directoryList = new JList<File>();
align(directoryList); align(directoryList);
directoryList.setCellRenderer(new DirectoryCellRenderer()); directoryList.setCellRenderer(new DirectoryCellRenderer());
...@@ -658,7 +658,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI { ...@@ -658,7 +658,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI {
} }
} }
protected class MotifDirectoryListModel extends AbstractListModel implements ListDataListener { protected class MotifDirectoryListModel extends AbstractListModel<File> implements ListDataListener {
public MotifDirectoryListModel() { public MotifDirectoryListModel() {
getModel().addListDataListener(this); getModel().addListDataListener(this);
} }
...@@ -667,7 +667,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI { ...@@ -667,7 +667,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI {
return getModel().getDirectories().size(); return getModel().getDirectories().size();
} }
public Object getElementAt(int index) { public File getElementAt(int index) {
return getModel().getDirectories().elementAt(index); return getModel().getDirectories().elementAt(index);
} }
...@@ -694,7 +694,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI { ...@@ -694,7 +694,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI {
} }
protected class MotifFileListModel extends AbstractListModel implements ListDataListener { protected class MotifFileListModel extends AbstractListModel<File> implements ListDataListener {
public MotifFileListModel() { public MotifFileListModel() {
getModel().addListDataListener(this); getModel().addListDataListener(this);
} }
...@@ -711,7 +711,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI { ...@@ -711,7 +711,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI {
return getModel().getFiles().indexOf(o); return getModel().getFiles().indexOf(o);
} }
public Object getElementAt(int index) { public File getElementAt(int index) {
return getModel().getFiles().elementAt(index); return getModel().getFiles().elementAt(index);
} }
...@@ -773,7 +773,8 @@ public class MotifFileChooserUI extends BasicFileChooserUI { ...@@ -773,7 +773,8 @@ 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 implements ComboBoxModel, PropertyChangeListener { protected class FilterComboBoxModel extends AbstractListModel<FileFilter> implements ComboBoxModel<FileFilter>,
PropertyChangeListener {
protected FileFilter[] filters; protected FileFilter[] filters;
protected FilterComboBoxModel() { protected FilterComboBoxModel() {
super(); super();
...@@ -826,7 +827,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI { ...@@ -826,7 +827,7 @@ public class MotifFileChooserUI extends BasicFileChooserUI {
} }
} }
public Object getElementAt(int index) { public FileFilter getElementAt(int index) {
if(index > getSize() - 1) { if(index > getSize() - 1) {
// This shouldn't happen. Try to recover gracefully. // This shouldn't happen. Try to recover gracefully.
return getFileChooser().getFileFilter(); return getFileChooser().getFileFilter();
......
...@@ -60,7 +60,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { ...@@ -60,7 +60,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI {
private JPanel centerPanel; private JPanel centerPanel;
private JLabel lookInLabel; private JLabel lookInLabel;
private JComboBox directoryComboBox; private JComboBox<File> directoryComboBox;
private DirectoryComboBoxModel directoryComboBoxModel; private DirectoryComboBoxModel directoryComboBoxModel;
private ActionListener directoryComboBoxAction = new DirectoryComboBoxAction(); private ActionListener directoryComboBoxAction = new DirectoryComboBoxAction();
...@@ -76,7 +76,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { ...@@ -76,7 +76,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI {
private JPanel buttonPanel; private JPanel buttonPanel;
private JPanel bottomPanel; private JPanel bottomPanel;
private JComboBox filterComboBox; private JComboBox<FileFilter> filterComboBox;
private static final Dimension hstrut10 = new Dimension(10, 1); private static final Dimension hstrut10 = new Dimension(10, 1);
...@@ -245,7 +245,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { ...@@ -245,7 +245,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI {
topPanel.add(Box.createRigidArea(new Dimension(8,0))); topPanel.add(Box.createRigidArea(new Dimension(8,0)));
// CurrentDir ComboBox // CurrentDir ComboBox
directoryComboBox = new JComboBox() { directoryComboBox = new JComboBox<File>() {
public Dimension getMinimumSize() { public Dimension getMinimumSize() {
Dimension d = super.getMinimumSize(); Dimension d = super.getMinimumSize();
d.width = 60; d.width = 60;
...@@ -445,7 +445,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { ...@@ -445,7 +445,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI {
filterComboBoxModel = createFilterComboBoxModel(); filterComboBoxModel = createFilterComboBoxModel();
fc.addPropertyChangeListener(filterComboBoxModel); fc.addPropertyChangeListener(filterComboBoxModel);
filterComboBox = new JComboBox(filterComboBoxModel); filterComboBox = new JComboBox<FileFilter>(filterComboBoxModel);
ftl.setLabelFor(filterComboBox); ftl.setLabelFor(filterComboBox);
filterComboBox.setRenderer(createFilterComboBoxRenderer()); filterComboBox.setRenderer(createFilterComboBoxRenderer());
fileAndFilterPanel.add(filterComboBox); fileAndFilterPanel.add(filterComboBox);
...@@ -1032,7 +1032,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { ...@@ -1032,7 +1032,7 @@ 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 DirectoryComboBoxModel extends AbstractListModel implements ComboBoxModel { protected class DirectoryComboBoxModel extends AbstractListModel<File> implements ComboBoxModel<File> {
Vector<File> directories = new Vector<File>(); Vector<File> directories = new Vector<File>();
int[] depths = null; int[] depths = null;
File selectedDirectory = null; File selectedDirectory = null;
...@@ -1149,7 +1149,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { ...@@ -1149,7 +1149,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI {
return directories.size(); return directories.size();
} }
public Object getElementAt(int index) { public File getElementAt(int index) {
return directories.elementAt(index); return directories.elementAt(index);
} }
} }
...@@ -1189,7 +1189,8 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { ...@@ -1189,7 +1189,8 @@ 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 implements ComboBoxModel, PropertyChangeListener { protected class FilterComboBoxModel extends AbstractListModel<FileFilter> implements ComboBoxModel<FileFilter>,
PropertyChangeListener {
protected FileFilter[] filters; protected FileFilter[] filters;
protected FilterComboBoxModel() { protected FilterComboBoxModel() {
super(); super();
...@@ -1242,7 +1243,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { ...@@ -1242,7 +1243,7 @@ public class WindowsFileChooserUI extends BasicFileChooserUI {
} }
} }
public Object getElementAt(int index) { public FileFilter getElementAt(int index) {
if(index > getSize() - 1) { if(index > getSize() - 1) {
// This shouldn't happen. Try to recover gracefully. // This shouldn't happen. Try to recover gracefully.
return getFileChooser().getFileFilter(); return getFileChooser().getFileFilter();
......
...@@ -63,8 +63,7 @@ import java.io.Serializable; ...@@ -63,8 +63,7 @@ import java.io.Serializable;
public class BasicComboPopup extends JPopupMenu implements ComboPopup { public class BasicComboPopup extends JPopupMenu implements ComboPopup {
// An empty ListMode, this is used when the UI changes to allow // An empty ListMode, this is used when the UI changes to allow
// the JList to be gc'ed. // the JList to be gc'ed.
private static class EmptyListModelClass implements ListModel, private static class EmptyListModelClass implements ListModel<Object>, Serializable {
Serializable {
public int getSize() { return 0; } public int getSize() { return 0; }
public Object getElementAt(int index) { return null; } public Object getElementAt(int index) { return null; }
public void addListDataListener(ListDataListener l) {} public void addListDataListener(ListDataListener l) {}
......
...@@ -444,7 +444,7 @@ public class SynthComboBoxUI extends BasicComboBoxUI implements ...@@ -444,7 +444,7 @@ public class SynthComboBoxUI extends BasicComboBoxUI implements
* renderer installed on a Synth combo box is a JLabel. If this is changed, * renderer installed on a Synth combo box is a JLabel. If this is changed,
* then an assert will fail in SynthFileChooserUIImpl * then an assert will fail in SynthFileChooserUIImpl
*/ */
private class SynthComboBoxRenderer extends JLabel implements ListCellRenderer, UIResource { private class SynthComboBoxRenderer extends JLabel implements ListCellRenderer<Object>, UIResource {
public SynthComboBoxRenderer() { public SynthComboBoxRenderer() {
super(); super();
setName("ComboBox.renderer"); setName("ComboBox.renderer");
...@@ -452,7 +452,7 @@ public class SynthComboBoxUI extends BasicComboBoxUI implements ...@@ -452,7 +452,7 @@ public class SynthComboBoxUI extends BasicComboBoxUI implements
} }
@Override @Override
public Component getListCellRendererComponent(JList list, Object value, public Component getListCellRendererComponent(JList<?> list, Object value,
int index, boolean isSelected, boolean cellHasFocus) { int index, boolean isSelected, boolean cellHasFocus) {
setName("ComboBox.listRenderer"); setName("ComboBox.listRenderer");
SynthLookAndFeel.resetSelectedUI(); SynthLookAndFeel.resetSelectedUI();
......
...@@ -725,11 +725,11 @@ public class FormView extends ComponentView implements ActionListener { ...@@ -725,11 +725,11 @@ public class FormView extends ComponentView implements ActionListener {
} }
Object m = attr.getAttribute(StyleConstants.ModelAttribute); Object m = attr.getAttribute(StyleConstants.ModelAttribute);
if (m instanceof OptionListModel) { if (m instanceof OptionListModel) {
OptionListModel model = (OptionListModel)m; OptionListModel<Option> model = (OptionListModel<Option>) m;
for (int i = 0; i < model.getSize(); i++) { for (int i = 0; i < model.getSize(); i++) {
if (model.isSelectedIndex(i)) { if (model.isSelectedIndex(i)) {
Option option = (Option) model.getElementAt(i); Option option = model.getElementAt(i);
appendBuffer(buffer, name, option.getValue()); appendBuffer(buffer, name, option.getValue());
} }
} }
......
...@@ -3358,13 +3358,13 @@ public class HTMLDocument extends DefaultStyledDocument { ...@@ -3358,13 +3358,13 @@ public class HTMLDocument extends DefaultStyledDocument {
1); 1);
boolean multiple = attr.getAttribute(HTML.Attribute.MULTIPLE) != null; boolean multiple = attr.getAttribute(HTML.Attribute.MULTIPLE) != null;
if ((size > 1) || multiple) { if ((size > 1) || multiple) {
OptionListModel m = new OptionListModel(); OptionListModel<Option> m = new OptionListModel<Option>();
if (multiple) { if (multiple) {
m.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); m.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
} }
selectModel = m; selectModel = m;
} else { } else {
selectModel = new OptionComboBoxModel(); selectModel = new OptionComboBoxModel<Option>();
} }
attr.addAttribute(StyleConstants.ModelAttribute, attr.addAttribute(StyleConstants.ModelAttribute,
selectModel); selectModel);
...@@ -3376,14 +3376,14 @@ public class HTMLDocument extends DefaultStyledDocument { ...@@ -3376,14 +3376,14 @@ public class HTMLDocument extends DefaultStyledDocument {
option = new Option(attr); option = new Option(attr);
if (selectModel instanceof OptionListModel) { if (selectModel instanceof OptionListModel) {
OptionListModel m = (OptionListModel)selectModel; OptionListModel<Option> m = (OptionListModel<Option>) selectModel;
m.addElement(option); m.addElement(option);
if (option.isSelected()) { if (option.isSelected()) {
m.addSelectionInterval(optionCount, optionCount); m.addSelectionInterval(optionCount, optionCount);
m.setInitialSelection(optionCount); m.setInitialSelection(optionCount);
} }
} else if (selectModel instanceof OptionComboBoxModel) { } else if (selectModel instanceof OptionComboBoxModel) {
OptionComboBoxModel m = (OptionComboBoxModel)selectModel; OptionComboBoxModel<Option> m = (OptionComboBoxModel<Option>) selectModel;
m.addElement(option); m.addElement(option);
if (option.isSelected()) { if (option.isSelected()) {
m.setSelectedItem(option); m.setSelectedItem(option);
......
...@@ -527,17 +527,17 @@ public class HTMLWriter extends AbstractWriter { ...@@ -527,17 +527,17 @@ public class HTMLWriter extends AbstractWriter {
Object model = attr.getAttribute(StyleConstants.ModelAttribute); Object model = attr.getAttribute(StyleConstants.ModelAttribute);
incrIndent(); incrIndent();
if (model instanceof OptionListModel) { if (model instanceof OptionListModel) {
OptionListModel listModel = (OptionListModel)model; OptionListModel<Option> listModel = (OptionListModel<Option>) model;
int size = listModel.getSize(); int size = listModel.getSize();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Option option = (Option)listModel.getElementAt(i); Option option = listModel.getElementAt(i);
writeOption(option); writeOption(option);
} }
} else if (model instanceof OptionComboBoxModel) { } else if (model instanceof OptionComboBoxModel) {
OptionComboBoxModel comboBoxModel = (OptionComboBoxModel)model; OptionComboBoxModel<Option> comboBoxModel = (OptionComboBoxModel<Option>) model;
int size = comboBoxModel.getSize(); int size = comboBoxModel.getSize();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Option option = (Option)comboBoxModel.getElementAt(i); Option option = comboBoxModel.getElementAt(i);
writeOption(option); writeOption(option);
} }
} }
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
package javax.swing.text.html; package javax.swing.text.html;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*;
import java.io.Serializable; import java.io.Serializable;
...@@ -41,7 +40,7 @@ import java.io.Serializable; ...@@ -41,7 +40,7 @@ import java.io.Serializable;
@author Sunita Mani @author Sunita Mani
*/ */
class OptionComboBoxModel extends DefaultComboBoxModel implements Serializable { class OptionComboBoxModel<E> extends DefaultComboBoxModel<E> implements Serializable {
private Option selectedOption = null; private Option selectedOption = null;
......
...@@ -26,7 +26,6 @@ package javax.swing.text.html; ...@@ -26,7 +26,6 @@ package javax.swing.text.html;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*; import javax.swing.event.*;
import java.util.EventListener;
import java.util.BitSet; import java.util.BitSet;
import java.io.Serializable; import java.io.Serializable;
...@@ -44,7 +43,7 @@ import java.io.Serializable; ...@@ -44,7 +43,7 @@ import java.io.Serializable;
@author Sunita Mani @author Sunita Mani
*/ */
class OptionListModel extends DefaultListModel implements ListSelectionModel, Serializable { class OptionListModel<E> extends DefaultListModel<E> implements ListSelectionModel, Serializable {
private static final int MIN = -1; private static final int MIN = -1;
......
...@@ -570,7 +570,7 @@ public class FilePane extends JPanel implements PropertyChangeListener { ...@@ -570,7 +570,7 @@ public class FilePane extends JPanel implements PropertyChangeListener {
public JPanel createList() { public JPanel createList() {
JPanel p = new JPanel(new BorderLayout()); JPanel p = new JPanel(new BorderLayout());
final JFileChooser fileChooser = getFileChooser(); final JFileChooser fileChooser = getFileChooser();
final JList list = new JList() { final JList<Object> list = new JList<Object>() {
public int getNextMatch(String prefix, int startIndex, Position.Bias bias) { public int getNextMatch(String prefix, int startIndex, Position.Bias bias) {
ListModel model = getModel(); ListModel model = getModel();
int max = model.getSize(); int max = model.getSize();
...@@ -641,7 +641,7 @@ public class FilePane extends JPanel implements PropertyChangeListener { ...@@ -641,7 +641,7 @@ public class FilePane extends JPanel implements PropertyChangeListener {
/** /**
* This model allows for sorting JList * This model allows for sorting JList
*/ */
private class SortableListModel extends AbstractListModel private class SortableListModel extends AbstractListModel<Object>
implements TableModelListener, RowSorterListener { implements TableModelListener, RowSorterListener {
public SortableListModel() { public SortableListModel() {
......
...@@ -60,7 +60,7 @@ import sun.swing.*; ...@@ -60,7 +60,7 @@ import sun.swing.*;
*/ */
public class SynthFileChooserUIImpl extends SynthFileChooserUI { public class SynthFileChooserUIImpl extends SynthFileChooserUI {
private JLabel lookInLabel; private JLabel lookInLabel;
private JComboBox directoryComboBox; private JComboBox<File> directoryComboBox;
private DirectoryComboBoxModel directoryComboBoxModel; private DirectoryComboBoxModel directoryComboBoxModel;
private Action directoryComboBoxAction = new DirectoryComboBoxAction(); private Action directoryComboBoxAction = new DirectoryComboBoxAction();
...@@ -77,10 +77,9 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { ...@@ -77,10 +77,9 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI {
private JPanel buttonPanel; private JPanel buttonPanel;
private JPanel bottomPanel; private JPanel bottomPanel;
private JComboBox filterComboBox; private JComboBox<FileFilter> filterComboBox;
private static final Dimension hstrut5 = new Dimension(5, 1); private static final Dimension hstrut5 = new Dimension(5, 1);
private static final Dimension vstrut5 = new Dimension(1, 5);
private static final Insets shrinkwrap = new Insets(0,0,0,0); private static final Insets shrinkwrap = new Insets(0,0,0,0);
...@@ -217,7 +216,7 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { ...@@ -217,7 +216,7 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI {
topPanel.add(lookInLabel, BorderLayout.BEFORE_LINE_BEGINS); topPanel.add(lookInLabel, BorderLayout.BEFORE_LINE_BEGINS);
// CurrentDir ComboBox // CurrentDir ComboBox
directoryComboBox = new JComboBox(); directoryComboBox = new JComboBox<File>();
directoryComboBox.getAccessibleContext().setAccessibleDescription(lookInLabelText); directoryComboBox.getAccessibleContext().setAccessibleDescription(lookInLabelText);
directoryComboBox.putClientProperty( "JComboBox.isTableCellEditor", Boolean.TRUE ); directoryComboBox.putClientProperty( "JComboBox.isTableCellEditor", Boolean.TRUE );
lookInLabel.setLabelFor(directoryComboBox); lookInLabel.setLabelFor(directoryComboBox);
...@@ -394,7 +393,7 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { ...@@ -394,7 +393,7 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI {
filterComboBoxModel = createFilterComboBoxModel(); filterComboBoxModel = createFilterComboBoxModel();
fc.addPropertyChangeListener(filterComboBoxModel); fc.addPropertyChangeListener(filterComboBoxModel);
filterComboBox = new JComboBox(filterComboBoxModel); filterComboBox = new JComboBox<FileFilter>(filterComboBoxModel);
filterComboBox.getAccessibleContext().setAccessibleDescription(filesOfTypeLabelText); filterComboBox.getAccessibleContext().setAccessibleDescription(filesOfTypeLabelText);
filesOfTypeLabel.setLabelFor(filterComboBox); filesOfTypeLabel.setLabelFor(filterComboBox);
filterComboBox.setRenderer(createFilterComboBoxRenderer()); filterComboBox.setRenderer(createFilterComboBoxRenderer());
...@@ -671,16 +670,16 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { ...@@ -671,16 +670,16 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI {
// looking combo boxes. // looking combo boxes.
// So what we do here is delegate most jobs to the "real" or original renderer, // So what we do here is delegate most jobs to the "real" or original renderer,
// and simply monkey with the icon and text of the renderer. // and simply monkey with the icon and text of the renderer.
private class DirectoryComboBoxRenderer implements ListCellRenderer { private class DirectoryComboBoxRenderer implements ListCellRenderer<File> {
private ListCellRenderer delegate; private ListCellRenderer<? super File> delegate;
IndentIcon ii = new IndentIcon(); IndentIcon ii = new IndentIcon();
private DirectoryComboBoxRenderer(ListCellRenderer delegate) { private DirectoryComboBoxRenderer(ListCellRenderer<? super File> delegate) {
this.delegate = delegate; this.delegate = delegate;
} }
@Override @Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { public Component getListCellRendererComponent(JList<? extends File> list, File value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); Component c = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
assert c instanceof JLabel; assert c instanceof JLabel;
...@@ -689,9 +688,8 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { ...@@ -689,9 +688,8 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI {
label.setText(""); label.setText("");
return label; return label;
} }
File directory = (File) value; label.setText(getFileChooser().getName(value));
label.setText(getFileChooser().getName(directory)); Icon icon = getFileChooser().getIcon(value);
Icon icon = getFileChooser().getIcon(directory);
ii.icon = icon; ii.icon = icon;
ii.depth = directoryComboBoxModel.getDepth(index); ii.depth = directoryComboBoxModel.getDepth(index);
label.setIcon(ii); label.setIcon(ii);
...@@ -736,7 +734,7 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { ...@@ -736,7 +734,7 @@ 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 DirectoryComboBoxModel extends AbstractListModel implements ComboBoxModel { protected class DirectoryComboBoxModel extends AbstractListModel<File> implements ComboBoxModel<File> {
Vector<File> directories = new Vector<File>(); Vector<File> directories = new Vector<File>();
int[] depths = null; int[] depths = null;
File selectedDirectory = null; File selectedDirectory = null;
...@@ -857,7 +855,7 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { ...@@ -857,7 +855,7 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI {
return directories.size(); return directories.size();
} }
public Object getElementAt(int index) { public File getElementAt(int index) {
return directories.elementAt(index); return directories.elementAt(index);
} }
} }
...@@ -890,18 +888,19 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { ...@@ -890,18 +888,19 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI {
/** /**
* Render different type sizes and styles. * Render different type sizes and styles.
*/ */
public class FilterComboBoxRenderer implements ListCellRenderer { public class FilterComboBoxRenderer implements ListCellRenderer<FileFilter> {
private ListCellRenderer delegate; private ListCellRenderer<? super FileFilter> delegate;
private FilterComboBoxRenderer(ListCellRenderer delegate) { private FilterComboBoxRenderer(ListCellRenderer<? super FileFilter> delegate) {
this.delegate = delegate; this.delegate = delegate;
} }
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { public Component getListCellRendererComponent(JList<? extends FileFilter> list, FileFilter value, int index,
boolean isSelected, boolean cellHasFocus) {
Component c = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); Component c = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
String text = null; String text = null;
if (value != null && value instanceof FileFilter) { if (value != null) {
text = ((FileFilter) value).getDescription(); text = value.getDescription();
} }
//this should always be true, since SynthComboBoxUI's SynthComboBoxRenderer //this should always be true, since SynthComboBoxUI's SynthComboBoxRenderer
...@@ -924,7 +923,8 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { ...@@ -924,7 +923,8 @@ 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 implements ComboBoxModel, PropertyChangeListener { protected class FilterComboBoxModel extends AbstractListModel<FileFilter> implements ComboBoxModel<FileFilter>,
PropertyChangeListener {
protected FileFilter[] filters; protected FileFilter[] filters;
protected FilterComboBoxModel() { protected FilterComboBoxModel() {
super(); super();
...@@ -977,7 +977,7 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { ...@@ -977,7 +977,7 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI {
} }
} }
public Object getElementAt(int index) { public FileFilter getElementAt(int index) {
if(index > getSize() - 1) { if(index > getSize() - 1) {
// This shouldn't happen. Try to recover gracefully. // This shouldn't happen. Try to recover gracefully.
return getFileChooser().getFileFilter(); return getFileChooser().getFileFilter();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册