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

Print this page

        

*** 57,67 **** public class BasicListUI extends ListUI { private static final StringBuilder BASELINE_COMPONENT_KEY = new StringBuilder("List.baselineComponent"); ! protected JList list = null; protected CellRendererPane rendererPane; // Listeners that this UI attaches to the JList protected FocusListener focusListener; protected MouseInputListener mouseInputListener; --- 57,67 ---- public class BasicListUI extends ListUI { private static final StringBuilder BASELINE_COMPONENT_KEY = new StringBuilder("List.baselineComponent"); ! protected JList<Object> list = null; protected CellRendererPane rendererPane; // Listeners that this UI attaches to the JList protected FocusListener focusListener; protected MouseInputListener mouseInputListener;
*** 194,205 **** */ protected void paintCell( Graphics g, int row, Rectangle rowBounds, ! ListCellRenderer cellRenderer, ! ListModel dataModel, ListSelectionModel selModel, int leadIndex) { Object value = dataModel.getElementAt(row); boolean cellHasFocus = list.hasFocus() && (row == leadIndex); --- 194,205 ---- */ protected void paintCell( Graphics g, int row, Rectangle rowBounds, ! ListCellRenderer<Object> cellRenderer, ! ListModel<Object> dataModel, ListSelectionModel selModel, int leadIndex) { Object value = dataModel.getElementAt(row); boolean cellHasFocus = list.hasFocus() && (row == leadIndex);
*** 261,272 **** default: break; } maybeUpdateLayoutState(); ! ListCellRenderer renderer = list.getCellRenderer(); ! ListModel dataModel = list.getModel(); ListSelectionModel selModel = list.getSelectionModel(); int size; if ((renderer == null) || (size = dataModel.getSize()) == 0) { return; --- 261,272 ---- default: break; } maybeUpdateLayoutState(); ! 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,486 **** int rowHeight = list.getFixedCellHeight(); UIDefaults lafDefaults = UIManager.getLookAndFeelDefaults(); Component renderer = (Component)lafDefaults.get( BASELINE_COMPONENT_KEY); if (renderer == null) { ! ListCellRenderer 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) { --- 476,487 ---- int rowHeight = list.getFixedCellHeight(); UIDefaults lafDefaults = UIManager.getLookAndFeelDefaults(); Component renderer = (Component)lafDefaults.get( BASELINE_COMPONENT_KEY); if (renderer == null) { ! @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,723 **** list.addMouseListener(mouseInputListener); list.addMouseMotionListener(mouseInputListener); list.addPropertyChangeListener(propertyChangeListener); list.addKeyListener(getHandler()); ! ListModel model = list.getModel(); if (model != null) { model.addListDataListener(listDataListener); } ListSelectionModel selectionModel = list.getSelectionModel(); --- 714,724 ---- list.addMouseListener(mouseInputListener); list.addMouseMotionListener(mouseInputListener); list.addPropertyChangeListener(propertyChangeListener); list.addKeyListener(getHandler()); ! ListModel<Object> model = list.getModel(); if (model != null) { model.addListDataListener(listDataListener); } ListSelectionModel selectionModel = list.getSelectionModel();
*** 742,752 **** list.removeMouseListener(mouseInputListener); list.removeMouseMotionListener(mouseInputListener); list.removePropertyChangeListener(propertyChangeListener); list.removeKeyListener(getHandler()); ! ListModel model = list.getModel(); if (model != null) { model.removeListDataListener(listDataListener); } ListSelectionModel selectionModel = list.getSelectionModel(); --- 743,753 ---- list.removeMouseListener(mouseInputListener); list.removeMouseMotionListener(mouseInputListener); list.removePropertyChangeListener(propertyChangeListener); list.removeKeyListener(getHandler()); ! ListModel<Object> model = list.getModel(); if (model != null) { model.removeListDataListener(listDataListener); } ListSelectionModel selectionModel = list.getSelectionModel();
*** 783,793 **** 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"))); } Color sbg = list.getSelectionBackground(); if (sbg == null || sbg instanceof UIResource) { list.setSelectionBackground(UIManager.getColor("List.selectionBackground")); --- 784,796 ---- LookAndFeel.installColorsAndFont(list, "List.background", "List.foreground", "List.font"); LookAndFeel.installProperty(list, "opaque", Boolean.TRUE); if (list.getCellRenderer() == null) { ! @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,874 **** * @see #installListeners * @see #installKeyboardActions */ public void installUI(JComponent c) { ! list = (JList)c; layoutOrientation = list.getLayoutOrientation(); rendererPane = new CellRendererPane(); list.add(rendererPane); --- 867,879 ---- * @see #installListeners * @see #installKeyboardActions */ public void installUI(JComponent c) { ! @SuppressWarnings("unchecked") ! JList<Object> tmp = (JList)c; ! list = tmp; layoutOrientation = list.getLayoutOrientation(); rendererPane = new CellRendererPane(); list.add(rendererPane);
*** 923,942 **** /** * {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ ! public int locationToIndex(JList list, Point location) { maybeUpdateLayoutState(); return convertLocationToModel(location.x, location.y); } /** * {@inheritDoc} */ ! public Point indexToLocation(JList list, int index) { maybeUpdateLayoutState(); Rectangle rect = getCellBounds(list, index, index); if (rect != null) { return new Point(rect.x, rect.y); --- 928,947 ---- /** * {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ ! public int locationToIndex(JList<?> list, Point location) { maybeUpdateLayoutState(); return convertLocationToModel(location.x, location.y); } /** * {@inheritDoc} */ ! 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,956 **** /** * {@inheritDoc} */ ! public Rectangle getCellBounds(JList list, int index1, int index2) { maybeUpdateLayoutState(); int minIndex = Math.min(index1, index2); int maxIndex = Math.max(index1, index2); --- 951,961 ---- /** * {@inheritDoc} */ ! public Rectangle getCellBounds(JList<?> list, int index1, int index2) { maybeUpdateLayoutState(); int minIndex = Math.min(index1, index2); int maxIndex = Math.max(index1, index2);
*** 990,1000 **** /** * 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) { maybeUpdateLayoutState(); int row = convertModelToRow(index); int column = convertModelToColumn(index); --- 995,1005 ---- /** * 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) { maybeUpdateLayoutState(); int row = convertModelToRow(index); int column = convertModelToColumn(index);
*** 1349,1361 **** * if they're not set already. */ if ((fixedCellWidth == -1) || (fixedCellHeight == -1)) { ! ListModel dataModel = list.getModel(); int dataModelSize = dataModel.getSize(); ! ListCellRenderer 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); --- 1354,1366 ---- * if they're not set already. */ if ((fixedCellWidth == -1) || (fixedCellHeight == -1)) { ! ListModel<Object> dataModel = list.getModel(); int dataModelSize = dataModel.getSize(); ! 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,1846 **** Actions(String name) { super(name); } public void actionPerformed(ActionEvent e) { String name = getName(); ! JList list = (JList)e.getSource(); BasicListUI ui = (BasicListUI)BasicLookAndFeel.getUIOfType( list.getUI(), BasicListUI.class); if (name == SELECT_PREVIOUS_COLUMN) { changeSelection(list, CHANGE_SELECTION, --- 1841,1852 ---- Actions(String name) { super(name); } public void actionPerformed(ActionEvent e) { String name = getName(); ! @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,2009 **** } return true; } ! private void clearSelection(JList list) { list.clearSelection(); } ! private void selectAll(JList list) { int size = list.getModel().getSize(); if (size > 0) { ListSelectionModel lsm = list.getSelectionModel(); int lead = adjustIndex(lsm.getLeadSelectionIndex(), list); --- 2001,2015 ---- } return true; } ! private void clearSelection(JList<?> list) { list.clearSelection(); } ! private void selectAll(JList<?> list) { int size = list.getModel().getSize(); if (size > 0) { ListSelectionModel lsm = list.getSelectionModel(); int lead = adjustIndex(lsm.getLeadSelectionIndex(), list);
*** 2028,2038 **** list.setValueIsAdjusting(false); } } } ! private int getNextPageIndex(JList list, int direction) { if (list.getModel().getSize() == 0) { return -1; } int index = -1; --- 2034,2044 ---- list.setValueIsAdjusting(false); } } } ! private int getNextPageIndex(JList<?> list, int direction) { if (list.getModel().getSize() == 0) { return -1; } int index = -1;
*** 2153,2163 **** } } return index; } ! 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 --- 2159,2169 ---- } } return index; } ! 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,2206 **** /** * 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, int direction) { if (direction == 0) { return; } Rectangle cellBounds = list.getCellBounds(index, index); --- 2202,2212 ---- /** * 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, int direction) { if (direction == 0) { return; } Rectangle cellBounds = list.getCellBounds(index, index);
*** 2284,2294 **** } list.scrollRectToVisible(cellBounds); } } ! 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(); --- 2290,2300 ---- } list.scrollRectToVisible(cellBounds); } } ! 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,2327 **** } // Won't change the selection. return -1; } ! 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) { --- 2323,2333 ---- } // Won't change the selection. return -1; } ! 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,2380 **** * 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(); if (model.getSize() == 0 || e.isAltDown() || BasicGraphicsUtils.isMenuShortcutKeyDown(e) || isNavigationKey(e)) { // Nothing to select --- 2375,2386 ---- * 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(); if (model.getSize() == 0 || e.isAltDown() || BasicGraphicsUtils.isMenuShortcutKeyDown(e) || isNavigationKey(e)) { // Nothing to select
*** 2466,2477 **** /* 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(); if (oldModel != null) { oldModel.removeListDataListener(listDataListener); } if (newModel != null) { newModel.addListDataListener(listDataListener); --- 2472,2485 ---- /* If the JList.model property changes, remove our listener, * listDataListener from the old model and add it to the new one. */ if (propertyName == "model") { ! @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,2836 **** public void focusLost(FocusEvent e) { repaintCellFocus(); } } ! private static int adjustIndex(int index, JList list) { return index < list.getModel().getSize() ? index : -1; } private static final TransferHandler defaultTransferHandler = new ListTransferHandler(); --- 2834,2844 ---- public void focusLost(FocusEvent e) { repaintCellFocus(); } } ! private static int adjustIndex(int index, JList<?> list) { return index < list.getModel().getSize() ? index : -1; } private static final TransferHandler defaultTransferHandler = new ListTransferHandler();
*** 2846,2856 **** * @return The representation of the data to be transfered. * */ protected Transferable createTransferable(JComponent c) { if (c instanceof JList) { ! JList list = (JList) c; Object[] values = list.getSelectedValues(); if (values == null || values.length == 0) { return null; } --- 2854,2864 ---- * @return The representation of the data to be transfered. * */ protected Transferable createTransferable(JComponent c) { if (c instanceof JList) { ! JList<?> list = (JList) c; Object[] values = list.getSelectedValues(); if (values == null || values.length == 0) { return null; }