changeset 4402:c05b36e4749e

7031941: Use generificated JComboBox and JList in core libraries Reviewed-by: alexp
author rupashka
date Mon, 18 Jul 2011 18:21:31 +0400
parents 3ac81907aa7d
children 190b11164876 34fdcdb70d20
files src/share/classes/com/sun/java/swing/plaf/motif/MotifFileChooserUI.java src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java src/share/classes/javax/swing/plaf/basic/BasicComboPopup.java src/share/classes/javax/swing/plaf/synth/SynthComboBoxUI.java src/share/classes/javax/swing/text/html/FormView.java src/share/classes/javax/swing/text/html/HTMLDocument.java src/share/classes/javax/swing/text/html/HTMLWriter.java src/share/classes/javax/swing/text/html/OptionComboBoxModel.java src/share/classes/javax/swing/text/html/OptionListModel.java src/share/classes/sun/swing/FilePane.java src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java
diffstat 11 files changed, 62 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/java/swing/plaf/motif/MotifFileChooserUI.java	Mon Jul 18 17:40:12 2011 +0400
+++ b/src/share/classes/com/sun/java/swing/plaf/motif/MotifFileChooserUI.java	Mon Jul 18 18:21:31 2011 +0400
@@ -49,11 +49,11 @@
 
     private FilterComboBoxModel filterComboBoxModel;
 
-    protected JList directoryList = null;
-    protected JList fileList = null;
+    protected JList<File> directoryList = null;
+    protected JList<File> fileList = null;
 
     protected JTextField pathField = null;
-    protected JComboBox filterComboBox = null;
+    protected JComboBox<FileFilter> filterComboBox = null;
     protected JTextField filenameTextField = null;
 
     private static final Dimension hstrut10 = new Dimension(10, 1);
@@ -337,7 +337,7 @@
         align(l);
         leftPanel.add(l);
 
-        filterComboBox = new JComboBox() {
+        filterComboBox = new JComboBox<FileFilter>() {
             public Dimension getMaximumSize() {
                 Dimension d = super.getMaximumSize();
                 d.height = getPreferredSize().height;
@@ -557,7 +557,7 @@
     }
 
     protected JScrollPane createFilesList() {
-        fileList = new JList();
+        fileList = new JList<File>();
 
         if(getFileChooser().isMultiSelectionEnabled()) {
             fileList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
@@ -576,7 +576,7 @@
                 if (SwingUtilities.isLeftMouseButton(e) && !chooser.isMultiSelectionEnabled()) {
                     int index = SwingUtilities2.loc2IndexFileList(fileList, e.getPoint());
                     if (index >= 0) {
-                        File file = (File) fileList.getModel().getElementAt(index);
+                        File file = fileList.getModel().getElementAt(index);
                         setFileName(chooser.getName(file));
                     }
                 }
@@ -593,7 +593,7 @@
     }
 
     protected JScrollPane createDirectoryList() {
-        directoryList = new JList();
+        directoryList = new JList<File>();
         align(directoryList);
 
         directoryList.setCellRenderer(new DirectoryCellRenderer());
@@ -658,7 +658,7 @@
         }
     }
 
-    protected class MotifDirectoryListModel extends AbstractListModel implements ListDataListener {
+    protected class MotifDirectoryListModel extends AbstractListModel<File> implements ListDataListener {
         public MotifDirectoryListModel() {
             getModel().addListDataListener(this);
         }
@@ -667,7 +667,7 @@
             return getModel().getDirectories().size();
         }
 
-        public Object getElementAt(int index) {
+        public File getElementAt(int index) {
             return getModel().getDirectories().elementAt(index);
         }
 
@@ -694,7 +694,7 @@
 
     }
 
-    protected class MotifFileListModel extends AbstractListModel implements ListDataListener {
+    protected class MotifFileListModel extends AbstractListModel<File> implements ListDataListener {
         public MotifFileListModel() {
             getModel().addListDataListener(this);
         }
@@ -711,7 +711,7 @@
             return getModel().getFiles().indexOf(o);
         }
 
-        public Object getElementAt(int index) {
+        public File getElementAt(int index) {
             return getModel().getFiles().elementAt(index);
         }
 
@@ -773,7 +773,8 @@
     /**
      * 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 FilterComboBoxModel() {
             super();
@@ -826,7 +827,7 @@
             }
         }
 
-        public Object getElementAt(int index) {
+        public FileFilter getElementAt(int index) {
             if(index > getSize() - 1) {
                 // This shouldn't happen. Try to recover gracefully.
                 return getFileChooser().getFileFilter();
--- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java	Mon Jul 18 17:40:12 2011 +0400
+++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsFileChooserUI.java	Mon Jul 18 18:21:31 2011 +0400
@@ -60,7 +60,7 @@
     private JPanel centerPanel;
 
     private JLabel lookInLabel;
-    private JComboBox directoryComboBox;
+    private JComboBox<File> directoryComboBox;
     private DirectoryComboBoxModel directoryComboBoxModel;
     private ActionListener directoryComboBoxAction = new DirectoryComboBoxAction();
 
@@ -76,7 +76,7 @@
     private JPanel buttonPanel;
     private JPanel bottomPanel;
 
-    private JComboBox filterComboBox;
+    private JComboBox<FileFilter> filterComboBox;
 
     private static final Dimension hstrut10 = new Dimension(10, 1);
 
@@ -245,7 +245,7 @@
         topPanel.add(Box.createRigidArea(new Dimension(8,0)));
 
         // CurrentDir ComboBox
-        directoryComboBox = new JComboBox() {
+        directoryComboBox = new JComboBox<File>() {
             public Dimension getMinimumSize() {
                 Dimension d = super.getMinimumSize();
                 d.width = 60;
@@ -445,7 +445,7 @@
 
         filterComboBoxModel = createFilterComboBoxModel();
         fc.addPropertyChangeListener(filterComboBoxModel);
-        filterComboBox = new JComboBox(filterComboBoxModel);
+        filterComboBox = new JComboBox<FileFilter>(filterComboBoxModel);
         ftl.setLabelFor(filterComboBox);
         filterComboBox.setRenderer(createFilterComboBoxRenderer());
         fileAndFilterPanel.add(filterComboBox);
@@ -1032,7 +1032,7 @@
     /**
      * 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>();
         int[] depths = null;
         File selectedDirectory = null;
@@ -1149,7 +1149,7 @@
             return directories.size();
         }
 
-        public Object getElementAt(int index) {
+        public File getElementAt(int index) {
             return directories.elementAt(index);
         }
     }
@@ -1189,7 +1189,8 @@
     /**
      * 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 FilterComboBoxModel() {
             super();
@@ -1242,7 +1243,7 @@
             }
         }
 
-        public Object getElementAt(int index) {
+        public FileFilter getElementAt(int index) {
             if(index > getSize() - 1) {
                 // This shouldn't happen. Try to recover gracefully.
                 return getFileChooser().getFileFilter();
--- a/src/share/classes/javax/swing/plaf/basic/BasicComboPopup.java	Mon Jul 18 17:40:12 2011 +0400
+++ b/src/share/classes/javax/swing/plaf/basic/BasicComboPopup.java	Mon Jul 18 18:21:31 2011 +0400
@@ -63,8 +63,7 @@
 public class BasicComboPopup extends JPopupMenu implements ComboPopup {
     // An empty ListMode, this is used when the UI changes to allow
     // the JList to be gc'ed.
-    private static class EmptyListModelClass implements ListModel,
-                                                        Serializable {
+    private static class EmptyListModelClass implements ListModel<Object>, Serializable {
         public int getSize() { return 0; }
         public Object getElementAt(int index) { return null; }
         public void addListDataListener(ListDataListener l) {}
--- a/src/share/classes/javax/swing/plaf/synth/SynthComboBoxUI.java	Mon Jul 18 17:40:12 2011 +0400
+++ b/src/share/classes/javax/swing/plaf/synth/SynthComboBoxUI.java	Mon Jul 18 18:21:31 2011 +0400
@@ -444,7 +444,7 @@
      * renderer installed on a Synth combo box is a JLabel. If this is changed,
      * 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() {
             super();
             setName("ComboBox.renderer");
@@ -452,7 +452,7 @@
         }
 
         @Override
-        public Component getListCellRendererComponent(JList list, Object value,
+        public Component getListCellRendererComponent(JList<?> list, Object value,
                          int index, boolean isSelected, boolean cellHasFocus) {
             setName("ComboBox.listRenderer");
             SynthLookAndFeel.resetSelectedUI();
--- a/src/share/classes/javax/swing/text/html/FormView.java	Mon Jul 18 17:40:12 2011 +0400
+++ b/src/share/classes/javax/swing/text/html/FormView.java	Mon Jul 18 18:21:31 2011 +0400
@@ -725,11 +725,11 @@
         }
         Object m = attr.getAttribute(StyleConstants.ModelAttribute);
         if (m instanceof OptionListModel) {
-            OptionListModel model = (OptionListModel)m;
+            OptionListModel<Option> model = (OptionListModel<Option>) m;
 
             for (int i = 0; i < model.getSize(); i++) {
                 if (model.isSelectedIndex(i)) {
-                    Option option = (Option) model.getElementAt(i);
+                    Option option = model.getElementAt(i);
                     appendBuffer(buffer, name, option.getValue());
                 }
             }
--- a/src/share/classes/javax/swing/text/html/HTMLDocument.java	Mon Jul 18 17:40:12 2011 +0400
+++ b/src/share/classes/javax/swing/text/html/HTMLDocument.java	Mon Jul 18 18:21:31 2011 +0400
@@ -3358,13 +3358,13 @@
                                                              1);
                     boolean multiple = attr.getAttribute(HTML.Attribute.MULTIPLE) != null;
                     if ((size > 1) || multiple) {
-                        OptionListModel m = new OptionListModel();
+                        OptionListModel<Option> m = new OptionListModel<Option>();
                         if (multiple) {
                             m.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
                         }
                         selectModel = m;
                     } else {
-                        selectModel = new OptionComboBoxModel();
+                        selectModel = new OptionComboBoxModel<Option>();
                     }
                     attr.addAttribute(StyleConstants.ModelAttribute,
                                       selectModel);
@@ -3376,14 +3376,14 @@
                     option = new Option(attr);
 
                     if (selectModel instanceof OptionListModel) {
-                        OptionListModel m = (OptionListModel)selectModel;
+                        OptionListModel<Option> m = (OptionListModel<Option>) selectModel;
                         m.addElement(option);
                         if (option.isSelected()) {
                             m.addSelectionInterval(optionCount, optionCount);
                             m.setInitialSelection(optionCount);
                         }
                     } else if (selectModel instanceof OptionComboBoxModel) {
-                        OptionComboBoxModel m = (OptionComboBoxModel)selectModel;
+                        OptionComboBoxModel<Option> m = (OptionComboBoxModel<Option>) selectModel;
                         m.addElement(option);
                         if (option.isSelected()) {
                             m.setSelectedItem(option);
--- a/src/share/classes/javax/swing/text/html/HTMLWriter.java	Mon Jul 18 17:40:12 2011 +0400
+++ b/src/share/classes/javax/swing/text/html/HTMLWriter.java	Mon Jul 18 18:21:31 2011 +0400
@@ -527,17 +527,17 @@
         Object model = attr.getAttribute(StyleConstants.ModelAttribute);
         incrIndent();
         if (model instanceof OptionListModel) {
-            OptionListModel listModel = (OptionListModel)model;
+            OptionListModel<Option> listModel = (OptionListModel<Option>) model;
             int size = listModel.getSize();
             for (int i = 0; i < size; i++) {
-                Option option = (Option)listModel.getElementAt(i);
+                Option option = listModel.getElementAt(i);
                 writeOption(option);
             }
         } else if (model instanceof OptionComboBoxModel) {
-            OptionComboBoxModel comboBoxModel = (OptionComboBoxModel)model;
+            OptionComboBoxModel<Option> comboBoxModel = (OptionComboBoxModel<Option>) model;
             int size = comboBoxModel.getSize();
             for (int i = 0; i < size; i++) {
-                Option option = (Option)comboBoxModel.getElementAt(i);
+                Option option = comboBoxModel.getElementAt(i);
                 writeOption(option);
             }
         }
--- a/src/share/classes/javax/swing/text/html/OptionComboBoxModel.java	Mon Jul 18 17:40:12 2011 +0400
+++ b/src/share/classes/javax/swing/text/html/OptionComboBoxModel.java	Mon Jul 18 18:21:31 2011 +0400
@@ -25,7 +25,6 @@
 package javax.swing.text.html;
 
 import javax.swing.*;
-import javax.swing.event.*;
 import java.io.Serializable;
 
 
@@ -41,7 +40,7 @@
   @author Sunita Mani
  */
 
-class OptionComboBoxModel extends DefaultComboBoxModel implements Serializable {
+class OptionComboBoxModel<E> extends DefaultComboBoxModel<E> implements Serializable {
 
     private Option selectedOption = null;
 
--- a/src/share/classes/javax/swing/text/html/OptionListModel.java	Mon Jul 18 17:40:12 2011 +0400
+++ b/src/share/classes/javax/swing/text/html/OptionListModel.java	Mon Jul 18 18:21:31 2011 +0400
@@ -26,7 +26,6 @@
 
 import javax.swing.*;
 import javax.swing.event.*;
-import java.util.EventListener;
 import java.util.BitSet;
 import java.io.Serializable;
 
@@ -44,7 +43,7 @@
   @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;
--- a/src/share/classes/sun/swing/FilePane.java	Mon Jul 18 17:40:12 2011 +0400
+++ b/src/share/classes/sun/swing/FilePane.java	Mon Jul 18 18:21:31 2011 +0400
@@ -570,7 +570,7 @@
     public JPanel createList() {
         JPanel p = new JPanel(new BorderLayout());
         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) {
                 ListModel model = getModel();
                 int max = model.getSize();
@@ -641,7 +641,7 @@
     /**
      * This model allows for sorting JList
      */
-    private class SortableListModel extends AbstractListModel
+    private class SortableListModel extends AbstractListModel<Object>
             implements TableModelListener, RowSorterListener {
 
         public SortableListModel() {
--- a/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java	Mon Jul 18 17:40:12 2011 +0400
+++ b/src/share/classes/sun/swing/plaf/synth/SynthFileChooserUIImpl.java	Mon Jul 18 18:21:31 2011 +0400
@@ -60,7 +60,7 @@
  */
 public class SynthFileChooserUIImpl extends SynthFileChooserUI {
     private JLabel lookInLabel;
-    private JComboBox directoryComboBox;
+    private JComboBox<File> directoryComboBox;
     private DirectoryComboBoxModel directoryComboBoxModel;
     private Action directoryComboBoxAction = new DirectoryComboBoxAction();
 
@@ -77,10 +77,9 @@
     private JPanel buttonPanel;
     private JPanel bottomPanel;
 
-    private JComboBox filterComboBox;
+    private JComboBox<FileFilter> filterComboBox;
 
     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);
 
@@ -217,7 +216,7 @@
         topPanel.add(lookInLabel, BorderLayout.BEFORE_LINE_BEGINS);
 
         // CurrentDir ComboBox
-        directoryComboBox = new JComboBox();
+        directoryComboBox = new JComboBox<File>();
         directoryComboBox.getAccessibleContext().setAccessibleDescription(lookInLabelText);
         directoryComboBox.putClientProperty( "JComboBox.isTableCellEditor", Boolean.TRUE );
         lookInLabel.setLabelFor(directoryComboBox);
@@ -394,7 +393,7 @@
 
         filterComboBoxModel = createFilterComboBoxModel();
         fc.addPropertyChangeListener(filterComboBoxModel);
-        filterComboBox = new JComboBox(filterComboBoxModel);
+        filterComboBox = new JComboBox<FileFilter>(filterComboBoxModel);
         filterComboBox.getAccessibleContext().setAccessibleDescription(filesOfTypeLabelText);
         filesOfTypeLabel.setLabelFor(filterComboBox);
         filterComboBox.setRenderer(createFilterComboBoxRenderer());
@@ -671,16 +670,16 @@
     // looking combo boxes.
     // 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.
-    private class DirectoryComboBoxRenderer implements ListCellRenderer {
-        private ListCellRenderer delegate;
+    private class DirectoryComboBoxRenderer implements ListCellRenderer<File> {
+        private ListCellRenderer<? super File> delegate;
         IndentIcon ii = new IndentIcon();
 
-        private DirectoryComboBoxRenderer(ListCellRenderer delegate) {
+        private DirectoryComboBoxRenderer(ListCellRenderer<? super File> delegate) {
             this.delegate = delegate;
         }
 
         @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);
 
             assert c instanceof JLabel;
@@ -689,9 +688,8 @@
                 label.setText("");
                 return label;
             }
-            File directory = (File) value;
-            label.setText(getFileChooser().getName(directory));
-            Icon icon = getFileChooser().getIcon(directory);
+            label.setText(getFileChooser().getName(value));
+            Icon icon = getFileChooser().getIcon(value);
             ii.icon = icon;
             ii.depth = directoryComboBoxModel.getDepth(index);
             label.setIcon(ii);
@@ -736,7 +734,7 @@
     /**
      * 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>();
         int[] depths = null;
         File selectedDirectory = null;
@@ -857,7 +855,7 @@
             return directories.size();
         }
 
-        public Object getElementAt(int index) {
+        public File getElementAt(int index) {
             return directories.elementAt(index);
         }
     }
@@ -890,18 +888,19 @@
     /**
      * Render different type sizes and styles.
      */
-    public class FilterComboBoxRenderer implements ListCellRenderer {
-        private ListCellRenderer delegate;
-        private FilterComboBoxRenderer(ListCellRenderer delegate) {
+    public class FilterComboBoxRenderer implements ListCellRenderer<FileFilter> {
+        private ListCellRenderer<? super FileFilter> delegate;
+        private FilterComboBoxRenderer(ListCellRenderer<? super FileFilter> 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);
 
             String text = null;
-            if (value != null && value instanceof FileFilter) {
-                text = ((FileFilter) value).getDescription();
+            if (value != null) {
+                text = value.getDescription();
             }
 
             //this should always be true, since SynthComboBoxUI's SynthComboBoxRenderer
@@ -924,7 +923,8 @@
     /**
      * 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 FilterComboBoxModel() {
             super();
@@ -977,7 +977,7 @@
             }
         }
 
-        public Object getElementAt(int index) {
+        public FileFilter getElementAt(int index) {
             if(index > getSize() - 1) {
                 // This shouldn't happen. Try to recover gracefully.
                 return getFileChooser().getFileFilter();