src/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java

Print this page

        

@@ -59,11 +59,11 @@
  * @author Arnaud Weber
  * @author Tom Santos
  * @author Mark Davidson
  */
 public class BasicComboBoxUI extends ComboBoxUI {
-    protected JComboBox comboBox;
+    protected JComboBox<Object> comboBox;
     /**
      * This protected field is implementation specific. Do not access directly
      * or override.
      */
     protected boolean   hasFocus = false;

@@ -72,11 +72,11 @@
     // in the JTable DefaultCellEditor.
     private boolean isTableCellEditor = false;
     private static final String IS_TABLE_CELL_EDITOR = "JComboBox.isTableCellEditor";
 
     // This list is for drawing the current item in the combo box.
-    protected JList   listBox;
+    protected JList<Object>   listBox;
 
     // Used to render the currently selected item in the combo box.
     // It doesn't have anything to do with the popup's rendering.
     protected CellRendererPane currentValuePane = new CellRendererPane();
 

@@ -201,12 +201,13 @@
      * @since 1.7
      */
     protected Insets padding;
 
     // Used for calculating the default size.
-    private static ListCellRenderer getDefaultListCellRenderer() {
-        ListCellRenderer renderer = (ListCellRenderer)AppContext.
+    private static ListCellRenderer<Object> getDefaultListCellRenderer() {
+        @SuppressWarnings("unchecked")
+        ListCellRenderer<Object> renderer = (ListCellRenderer)AppContext.
                          getAppContext().get(COMBO_UI_LIST_CELL_RENDERER_KEY);
 
         if (renderer == null) {
             renderer = new DefaultListCellRenderer();
             AppContext.getAppContext().put(COMBO_UI_LIST_CELL_RENDERER_KEY,

@@ -243,11 +244,13 @@
 
     @Override
     public void installUI( JComponent c ) {
         isMinimumSizeDirty = true;
 
-        comboBox = (JComboBox)c;
+        @SuppressWarnings("unchecked")
+        JComboBox<Object> tmp = (JComboBox)c;
+        comboBox = tmp;
         installDefaults();
         popup = createPopup();
         listBox = popup.getList();
 
         // Is this combo box a cell editor?

@@ -506,11 +509,11 @@
      * explicitly set with <code>setRenderer</code>.
      *
      * @return a <code>ListCellRender</code> used for the combo box
      * @see javax.swing.JComboBox#setRenderer
      */
-    protected ListCellRenderer createRenderer() {
+    protected ListCellRenderer<Object> createRenderer() {
         return new BasicComboBoxRenderer.UIResource();
     }
 
     /**
      * Creates the default editor that will be used in editable combo boxes.

@@ -863,18 +866,18 @@
     //
 
     /**
      * Tells if the popup is visible or not.
      */
-    public boolean isPopupVisible( JComboBox c ) {
+    public boolean isPopupVisible( JComboBox<?> c ) {
         return popup.isVisible();
     }
 
     /**
      * Hides the popup.
      */
-    public void setPopupVisible( JComboBox c, boolean v ) {
+    public void setPopupVisible( JComboBox<?> c, boolean v ) {
         if ( v ) {
             popup.show();
         } else {
             popup.hide();
         }

@@ -882,11 +885,11 @@
 
     /**
      * Determines if the JComboBox is focus traversable.  If the JComboBox is editable
      * this returns false, otherwise it returns true.
      */
-    public boolean isFocusTraversable( JComboBox c ) {
+    public boolean isFocusTraversable( JComboBox<?> c ) {
         return !comboBox.isEditable();
     }
 
     //
     // end ComboBoxUI Implementation

@@ -954,11 +957,11 @@
         getDisplaySize();
         if (sameBaseline) {
             Insets insets = c.getInsets();
             height = height - insets.top - insets.bottom;
             if (!comboBox.isEditable()) {
-                ListCellRenderer renderer = comboBox.getRenderer();
+                ListCellRenderer<Object> renderer = comboBox.getRenderer();
                 if (renderer == null)  {
                     renderer = new DefaultListCellRenderer();
                 }
                 Object value = null;
                 Object prototypeValue = comboBox.getPrototypeDisplayValue();

@@ -1011,11 +1014,11 @@
         getDisplaySize();
         if (comboBox.isEditable()) {
             return editor.getBaselineResizeBehavior();
         }
         else if (sameBaseline) {
-            ListCellRenderer renderer = comboBox.getRenderer();
+            ListCellRenderer<Object> renderer = comboBox.getRenderer();
             if (renderer == null)  {
                 renderer = new DefaultListCellRenderer();
             }
             Object value = null;
             Object prototypeValue = comboBox.getPrototypeDisplayValue();

@@ -1203,11 +1206,11 @@
 
     /**
      * Paints the currently selected item.
      */
     public void paintCurrentValue(Graphics g,Rectangle bounds,boolean hasFocus) {
-        ListCellRenderer renderer = comboBox.getRenderer();
+        ListCellRenderer<Object> renderer = comboBox.getRenderer();
         Component c;
 
         if ( hasFocus && !isPopupVisible(comboBox) ) {
             c = renderer.getListCellRendererComponent( listBox,
                                                        comboBox.getSelectedItem(),

@@ -1320,11 +1323,11 @@
         if (!isDisplaySizeDirty)  {
             return new Dimension(cachedDisplaySize);
         }
         Dimension result = new Dimension();
 
-        ListCellRenderer renderer = comboBox.getRenderer();
+        ListCellRenderer<Object> renderer = comboBox.getRenderer();
         if (renderer == null)  {
             renderer = new DefaultListCellRenderer();
         }
 
         sameBaseline = true;

@@ -1336,11 +1339,11 @@
                                                                                prototypeValue,
                                                                                -1, false, false));
         } else {
             // Calculate the dimension by iterating over all the elements in the combo
             // box list.
-            ComboBoxModel model = comboBox.getModel();
+            ComboBoxModel<Object> model = comboBox.getModel();
             int modelSize = model.getSize();
             int baseline = -1;
             Dimension d;
 
             Component cpn;

@@ -1482,11 +1485,12 @@
             super(name);
         }
 
         public void actionPerformed( ActionEvent e ) {
             String key = getName();
-            JComboBox comboBox = (JComboBox)e.getSource();
+            @SuppressWarnings("unchecked")
+            JComboBox<Object> comboBox = (JComboBox)e.getSource();
             BasicComboBoxUI ui = (BasicComboBoxUI)BasicLookAndFeel.getUIOfType(
                                   comboBox.getUI(), BasicComboBoxUI.class);
             if (key == HIDE) {
                 comboBox.firePopupMenuCanceled();
                 comboBox.setPopupVisible(false);

@@ -1623,11 +1627,11 @@
                     }
                 }
             }
         }
 
-        private int getNextIndex(JComboBox comboBox, String key) {
+        private int getNextIndex(JComboBox<?> comboBox, String key) {
             int listHeight = comboBox.getMaximumRowCount();
 
             int selectedIndex = comboBox.getSelectedIndex();
             if (UIManager.getBoolean("ComboBox.noActionOnKeyNavigation")
                     && (comboBox.getUI() instanceof BasicComboBoxUI)) {

@@ -1683,14 +1687,17 @@
                     isMinimumSizeDirty = true;
                     isDisplaySizeDirty = true;
                     comboBox.revalidate();
                 }
             } else {
-                JComboBox comboBox = (JComboBox)e.getSource();
+                @SuppressWarnings("unchecked")
+                JComboBox<?> comboBox = (JComboBox)e.getSource();
                 if ( propertyName == "model" ) {
-                    ComboBoxModel newModel = (ComboBoxModel)e.getNewValue();
-                    ComboBoxModel oldModel = (ComboBoxModel)e.getOldValue();
+                    @SuppressWarnings("unchecked")
+                    ComboBoxModel<?> newModel = (ComboBoxModel)e.getNewValue();
+                    @SuppressWarnings("unchecked")
+                    ComboBoxModel<?> oldModel = (ComboBoxModel)e.getOldValue();
 
                     if ( oldModel != null && listDataListener != null ) {
                         oldModel.removeListDataListener( listDataListener );
                     }
 

@@ -1895,11 +1902,12 @@
         public Dimension minimumLayoutSize(Container parent) {
             return parent.getMinimumSize();
         }
 
         public void layoutContainer(Container parent) {
-            JComboBox cb = (JComboBox)parent;
+            @SuppressWarnings("unchecked")
+            JComboBox<?> cb = (JComboBox)parent;
             int width = cb.getWidth();
             int height = cb.getHeight();
 
             Insets insets = getInsets();
             int buttonHeight = height - (insets.top + insets.bottom);

@@ -1957,11 +1965,11 @@
 
     class DefaultKeySelectionManager implements JComboBox.KeySelectionManager, UIResource {
         private String prefix = "";
         private String typedString = "";
 
-        public int selectionForKey(char aKey,ComboBoxModel aModel) {
+        public int selectionForKey(char aKey,ComboBoxModel<?> aModel) {
             if (lastTime == 0L) {
                 prefix = "";
                 typedString = "";
             }
             boolean startingFromSelection = true;