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

Print this page

        

@@ -57,11 +57,11 @@
 public class BasicListUI extends ListUI
 {
     private static final StringBuilder BASELINE_COMPONENT_KEY =
         new StringBuilder("List.baselineComponent");
 
-    protected JList list = null;
+    protected JList<Object> list = null;
     protected CellRendererPane rendererPane;
 
     // Listeners that this UI attaches to the JList
     protected FocusListener focusListener;
     protected MouseInputListener mouseInputListener;

@@ -194,12 +194,12 @@
      */
     protected void paintCell(
         Graphics g,
         int row,
         Rectangle rowBounds,
-        ListCellRenderer cellRenderer,
-        ListModel dataModel,
+        ListCellRenderer<Object> cellRenderer,
+        ListModel<Object> dataModel,
         ListSelectionModel selModel,
         int leadIndex)
     {
         Object value = dataModel.getElementAt(row);
         boolean cellHasFocus = list.hasFocus() && (row == leadIndex);

@@ -261,12 +261,12 @@
         default:
             break;
         }
         maybeUpdateLayoutState();
 
-        ListCellRenderer renderer = list.getCellRenderer();
-        ListModel dataModel = list.getModel();
+        ListCellRenderer<Object> renderer = list.getCellRenderer();
+        ListModel<Object> dataModel = list.getModel();
         ListSelectionModel selModel = list.getSelectionModel();
         int size;
 
         if ((renderer == null) || (size = dataModel.getSize()) == 0) {
             return;

@@ -476,11 +476,12 @@
         int rowHeight = list.getFixedCellHeight();
         UIDefaults lafDefaults = UIManager.getLookAndFeelDefaults();
         Component renderer = (Component)lafDefaults.get(
                 BASELINE_COMPONENT_KEY);
         if (renderer == null) {
-            ListCellRenderer lcr = (ListCellRenderer)UIManager.get(
+            @SuppressWarnings("unchecked")
+            ListCellRenderer<Object> lcr = (ListCellRenderer)UIManager.get(
                     "List.cellRenderer");
 
             // fix for 6711072 some LAFs like Nimbus do not provide this
             // UIManager key and we should not through a NPE here because of it
             if (lcr == null) {

@@ -713,11 +714,11 @@
         list.addMouseListener(mouseInputListener);
         list.addMouseMotionListener(mouseInputListener);
         list.addPropertyChangeListener(propertyChangeListener);
         list.addKeyListener(getHandler());
 
-        ListModel model = list.getModel();
+        ListModel<Object> model = list.getModel();
         if (model != null) {
             model.addListDataListener(listDataListener);
         }
 
         ListSelectionModel selectionModel = list.getSelectionModel();

@@ -742,11 +743,11 @@
         list.removeMouseListener(mouseInputListener);
         list.removeMouseMotionListener(mouseInputListener);
         list.removePropertyChangeListener(propertyChangeListener);
         list.removeKeyListener(getHandler());
 
-        ListModel model = list.getModel();
+        ListModel<Object> model = list.getModel();
         if (model != null) {
             model.removeListDataListener(listDataListener);
         }
 
         ListSelectionModel selectionModel = list.getSelectionModel();

@@ -783,11 +784,13 @@
         LookAndFeel.installColorsAndFont(list, "List.background", "List.foreground", "List.font");
 
         LookAndFeel.installProperty(list, "opaque", Boolean.TRUE);
 
         if (list.getCellRenderer() == null) {
-            list.setCellRenderer((ListCellRenderer)(UIManager.get("List.cellRenderer")));
+            @SuppressWarnings("unchecked")
+            ListCellRenderer<Object> tmp = (ListCellRenderer)(UIManager.get("List.cellRenderer"));
+            list.setCellRenderer(tmp);
         }
 
         Color sbg = list.getSelectionBackground();
         if (sbg == null || sbg instanceof UIResource) {
             list.setSelectionBackground(UIManager.getColor("List.selectionBackground"));

@@ -864,11 +867,13 @@
      * @see #installListeners
      * @see #installKeyboardActions
      */
     public void installUI(JComponent c)
     {
-        list = (JList)c;
+        @SuppressWarnings("unchecked")
+        JList<Object> tmp = (JList)c;
+        list = tmp;
 
         layoutOrientation = list.getLayoutOrientation();
 
         rendererPane = new CellRendererPane();
         list.add(rendererPane);

@@ -923,20 +928,20 @@
 
     /**
      * {@inheritDoc}
      * @throws NullPointerException {@inheritDoc}
      */
-    public int locationToIndex(JList list, Point location) {
+    public int locationToIndex(JList<?> list, Point location) {
         maybeUpdateLayoutState();
         return convertLocationToModel(location.x, location.y);
     }
 
 
     /**
      * {@inheritDoc}
      */
-    public Point indexToLocation(JList list, int index) {
+    public Point indexToLocation(JList<?> list, int index) {
         maybeUpdateLayoutState();
         Rectangle rect = getCellBounds(list, index, index);
 
         if (rect != null) {
             return new Point(rect.x, rect.y);

@@ -946,11 +951,11 @@
 
 
     /**
      * {@inheritDoc}
      */
-    public Rectangle getCellBounds(JList list, int index1, int index2) {
+    public Rectangle getCellBounds(JList<?> list, int index1, int index2) {
         maybeUpdateLayoutState();
 
         int minIndex = Math.min(index1, index2);
         int maxIndex = Math.max(index1, index2);
 

@@ -990,11 +995,11 @@
 
     /**
      * Gets the bounds of the specified model index, returning the resulting
      * bounds, or null if <code>index</code> is not valid.
      */
-    private Rectangle getCellBounds(JList list, int index) {
+    private Rectangle getCellBounds(JList<?> list, int index) {
         maybeUpdateLayoutState();
 
         int row = convertModelToRow(index);
         int column = convertModelToColumn(index);
 

@@ -1349,13 +1354,13 @@
          * if they're not set already.
          */
 
         if ((fixedCellWidth == -1) || (fixedCellHeight == -1)) {
 
-            ListModel dataModel = list.getModel();
+            ListModel<Object> dataModel = list.getModel();
             int dataModelSize = dataModel.getSize();
-            ListCellRenderer renderer = list.getCellRenderer();
+            ListCellRenderer<Object> renderer = list.getCellRenderer();
 
             if (renderer != null) {
                 for(int index = 0; index < dataModelSize; index++) {
                     Object value = dataModel.getElementAt(index);
                     Component c = renderer.getListCellRendererComponent(list, value, index, false, false);

@@ -1836,11 +1841,12 @@
         Actions(String name) {
             super(name);
         }
         public void actionPerformed(ActionEvent e) {
             String name = getName();
-            JList list = (JList)e.getSource();
+            @SuppressWarnings("unchecked")
+            JList<Object> list = (JList)e.getSource();
             BasicListUI ui = (BasicListUI)BasicLookAndFeel.getUIOfType(
                      list.getUI(), BasicListUI.class);
 
             if (name == SELECT_PREVIOUS_COLUMN) {
                 changeSelection(list, CHANGE_SELECTION,

@@ -1995,15 +2001,15 @@
             }
 
             return true;
         }
 
-        private void clearSelection(JList list) {
+        private void clearSelection(JList<?> list) {
             list.clearSelection();
         }
 
-        private void selectAll(JList list) {
+        private void selectAll(JList<?> list) {
             int size = list.getModel().getSize();
             if (size > 0) {
                 ListSelectionModel lsm = list.getSelectionModel();
                 int lead = adjustIndex(lsm.getLeadSelectionIndex(), list);
 

@@ -2028,11 +2034,11 @@
                     list.setValueIsAdjusting(false);
                 }
             }
         }
 
-        private int getNextPageIndex(JList list, int direction) {
+        private int getNextPageIndex(JList<?> list, int direction) {
             if (list.getModel().getSize() == 0) {
                 return -1;
             }
 
             int index = -1;

@@ -2153,11 +2159,11 @@
                 }
             }
             return index;
         }
 
-        private void changeSelection(JList list, int type,
+        private void changeSelection(JList<?> list, int type,
                                      int index, int direction) {
             if (index >= 0 && index < list.getModel().getSize()) {
                 ListSelectionModel lsm = list.getSelectionModel();
 
                 // CHANGE_LEAD is only valid with multiple interval selection

@@ -2196,11 +2202,11 @@
         /**
          * When scroll down makes selected index the last completely visible
          * index. When scroll up makes selected index the first visible index.
          * Adjust visible rectangle respect to list's component orientation.
          */
-        private void adjustScrollPositionIfNecessary(JList list, int index,
+        private void adjustScrollPositionIfNecessary(JList<?> list, int index,
                                                      int direction) {
             if (direction == 0) {
                 return;
             }
             Rectangle cellBounds = list.getCellBounds(index, index);

@@ -2284,11 +2290,11 @@
                 }
                 list.scrollRectToVisible(cellBounds);
             }
         }
 
-        private int getNextColumnIndex(JList list, BasicListUI ui,
+        private int getNextColumnIndex(JList<?> list, BasicListUI ui,
                                        int amount) {
             if (list.getLayoutOrientation() != JList.VERTICAL) {
                 int index = adjustIndex(list.getLeadSelectionIndex(), list);
                 int size = list.getModel().getSize();
 

@@ -2317,11 +2323,11 @@
             }
             // Won't change the selection.
             return -1;
         }
 
-        private int getNextIndex(JList list, BasicListUI ui, int amount) {
+        private int getNextIndex(JList<?> list, BasicListUI ui, int amount) {
             int index = adjustIndex(list.getLeadSelectionIndex(), list);
             int size = list.getModel().getSize();
 
             if (index == -1) {
                 if (size > 0) {

@@ -2369,12 +2375,12 @@
          * focus to the next object that starts with the same letter until another
          * key is pressed, then it is treated as the prefix with appropriate number
          * of the same letters followed by first typed another letter.
          */
         public void keyTyped(KeyEvent e) {
-            JList src = (JList)e.getSource();
-            ListModel model = src.getModel();
+            JList<?> src = (JList)e.getSource();
+            ListModel<?> model = src.getModel();
 
             if (model.getSize() == 0 || e.isAltDown() ||
                     BasicGraphicsUtils.isMenuShortcutKeyDown(e) ||
                     isNavigationKey(e)) {
                 // Nothing to select

@@ -2466,12 +2472,14 @@
 
             /* If the JList.model property changes, remove our listener,
              * listDataListener from the old model and add it to the new one.
              */
             if (propertyName == "model") {
-                ListModel oldModel = (ListModel)e.getOldValue();
-                ListModel newModel = (ListModel)e.getNewValue();
+                @SuppressWarnings("unchecked")
+                ListModel<?> oldModel = (ListModel)e.getOldValue();
+                @SuppressWarnings("unchecked")
+                ListModel<?> newModel = (ListModel)e.getNewValue();
                 if (oldModel != null) {
                     oldModel.removeListDataListener(listDataListener);
                 }
                 if (newModel != null) {
                     newModel.addListDataListener(listDataListener);

@@ -2826,11 +2834,11 @@
         public void focusLost(FocusEvent e) {
             repaintCellFocus();
         }
     }
 
-    private static int adjustIndex(int index, JList list) {
+    private static int adjustIndex(int index, JList<?> list) {
         return index < list.getModel().getSize() ? index : -1;
     }
 
     private static final TransferHandler defaultTransferHandler = new ListTransferHandler();
 

@@ -2846,11 +2854,11 @@
          * @return  The representation of the data to be transfered.
          *
          */
         protected Transferable createTransferable(JComponent c) {
             if (c instanceof JList) {
-                JList list = (JList) c;
+                JList<?> list = (JList) c;
                 Object[] values = list.getSelectedValues();
 
                 if (values == null || values.length == 0) {
                     return null;
                 }