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

Print this page

        

*** 59,69 **** * @author Arnaud Weber * @author Tom Santos * @author Mark Davidson */ public class BasicComboBoxUI extends ComboBoxUI { ! protected JComboBox comboBox; /** * This protected field is implementation specific. Do not access directly * or override. */ protected boolean hasFocus = false; --- 59,69 ---- * @author Arnaud Weber * @author Tom Santos * @author Mark Davidson */ public class BasicComboBoxUI extends ComboBoxUI { ! protected JComboBox<Object> comboBox; /** * This protected field is implementation specific. Do not access directly * or override. */ protected boolean hasFocus = false;
*** 72,82 **** // 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; // 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(); --- 72,82 ---- // 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<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,212 **** * @since 1.7 */ protected Insets padding; // Used for calculating the default size. ! private static ListCellRenderer getDefaultListCellRenderer() { ! ListCellRenderer 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, --- 201,213 ---- * @since 1.7 */ protected Insets padding; // Used for calculating the default size. ! 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,253 **** @Override public void installUI( JComponent c ) { isMinimumSizeDirty = true; ! comboBox = (JComboBox)c; installDefaults(); popup = createPopup(); listBox = popup.getList(); // Is this combo box a cell editor? --- 244,256 ---- @Override public void installUI( JComponent c ) { isMinimumSizeDirty = true; ! @SuppressWarnings("unchecked") ! JComboBox<Object> tmp = (JComboBox)c; ! comboBox = tmp; installDefaults(); popup = createPopup(); listBox = popup.getList(); // Is this combo box a cell editor?
*** 506,516 **** * explicitly set with <code>setRenderer</code>. * * @return a <code>ListCellRender</code> used for the combo box * @see javax.swing.JComboBox#setRenderer */ ! protected ListCellRenderer createRenderer() { return new BasicComboBoxRenderer.UIResource(); } /** * Creates the default editor that will be used in editable combo boxes. --- 509,519 ---- * explicitly set with <code>setRenderer</code>. * * @return a <code>ListCellRender</code> used for the combo box * @see javax.swing.JComboBox#setRenderer */ ! protected ListCellRenderer<Object> createRenderer() { return new BasicComboBoxRenderer.UIResource(); } /** * Creates the default editor that will be used in editable combo boxes.
*** 863,880 **** // /** * Tells if the popup is visible or not. */ ! public boolean isPopupVisible( JComboBox c ) { return popup.isVisible(); } /** * Hides the popup. */ ! public void setPopupVisible( JComboBox c, boolean v ) { if ( v ) { popup.show(); } else { popup.hide(); } --- 866,883 ---- // /** * Tells if the popup is visible or not. */ ! public boolean isPopupVisible( JComboBox<?> c ) { return popup.isVisible(); } /** * Hides the popup. */ ! public void setPopupVisible( JComboBox<?> c, boolean v ) { if ( v ) { popup.show(); } else { popup.hide(); }
*** 882,892 **** /** * Determines if the JComboBox is focus traversable. If the JComboBox is editable * this returns false, otherwise it returns true. */ ! public boolean isFocusTraversable( JComboBox c ) { return !comboBox.isEditable(); } // // end ComboBoxUI Implementation --- 885,895 ---- /** * Determines if the JComboBox is focus traversable. If the JComboBox is editable * this returns false, otherwise it returns true. */ ! public boolean isFocusTraversable( JComboBox<?> c ) { return !comboBox.isEditable(); } // // end ComboBoxUI Implementation
*** 954,964 **** getDisplaySize(); if (sameBaseline) { Insets insets = c.getInsets(); height = height - insets.top - insets.bottom; if (!comboBox.isEditable()) { ! ListCellRenderer renderer = comboBox.getRenderer(); if (renderer == null) { renderer = new DefaultListCellRenderer(); } Object value = null; Object prototypeValue = comboBox.getPrototypeDisplayValue(); --- 957,967 ---- getDisplaySize(); if (sameBaseline) { Insets insets = c.getInsets(); height = height - insets.top - insets.bottom; if (!comboBox.isEditable()) { ! ListCellRenderer<Object> renderer = comboBox.getRenderer(); if (renderer == null) { renderer = new DefaultListCellRenderer(); } Object value = null; Object prototypeValue = comboBox.getPrototypeDisplayValue();
*** 1011,1021 **** getDisplaySize(); if (comboBox.isEditable()) { return editor.getBaselineResizeBehavior(); } else if (sameBaseline) { ! ListCellRenderer renderer = comboBox.getRenderer(); if (renderer == null) { renderer = new DefaultListCellRenderer(); } Object value = null; Object prototypeValue = comboBox.getPrototypeDisplayValue(); --- 1014,1024 ---- getDisplaySize(); if (comboBox.isEditable()) { return editor.getBaselineResizeBehavior(); } else if (sameBaseline) { ! ListCellRenderer<Object> renderer = comboBox.getRenderer(); if (renderer == null) { renderer = new DefaultListCellRenderer(); } Object value = null; Object prototypeValue = comboBox.getPrototypeDisplayValue();
*** 1203,1213 **** /** * Paints the currently selected item. */ public void paintCurrentValue(Graphics g,Rectangle bounds,boolean hasFocus) { ! ListCellRenderer renderer = comboBox.getRenderer(); Component c; if ( hasFocus && !isPopupVisible(comboBox) ) { c = renderer.getListCellRendererComponent( listBox, comboBox.getSelectedItem(), --- 1206,1216 ---- /** * Paints the currently selected item. */ public void paintCurrentValue(Graphics g,Rectangle bounds,boolean hasFocus) { ! ListCellRenderer<Object> renderer = comboBox.getRenderer(); Component c; if ( hasFocus && !isPopupVisible(comboBox) ) { c = renderer.getListCellRendererComponent( listBox, comboBox.getSelectedItem(),
*** 1320,1330 **** if (!isDisplaySizeDirty) { return new Dimension(cachedDisplaySize); } Dimension result = new Dimension(); ! ListCellRenderer renderer = comboBox.getRenderer(); if (renderer == null) { renderer = new DefaultListCellRenderer(); } sameBaseline = true; --- 1323,1333 ---- if (!isDisplaySizeDirty) { return new Dimension(cachedDisplaySize); } Dimension result = new Dimension(); ! ListCellRenderer<Object> renderer = comboBox.getRenderer(); if (renderer == null) { renderer = new DefaultListCellRenderer(); } sameBaseline = true;
*** 1336,1346 **** prototypeValue, -1, false, false)); } else { // Calculate the dimension by iterating over all the elements in the combo // box list. ! ComboBoxModel model = comboBox.getModel(); int modelSize = model.getSize(); int baseline = -1; Dimension d; Component cpn; --- 1339,1349 ---- prototypeValue, -1, false, false)); } else { // Calculate the dimension by iterating over all the elements in the combo // box list. ! ComboBoxModel<Object> model = comboBox.getModel(); int modelSize = model.getSize(); int baseline = -1; Dimension d; Component cpn;
*** 1482,1492 **** super(name); } public void actionPerformed( ActionEvent e ) { String key = getName(); ! JComboBox comboBox = (JComboBox)e.getSource(); BasicComboBoxUI ui = (BasicComboBoxUI)BasicLookAndFeel.getUIOfType( comboBox.getUI(), BasicComboBoxUI.class); if (key == HIDE) { comboBox.firePopupMenuCanceled(); comboBox.setPopupVisible(false); --- 1485,1496 ---- super(name); } public void actionPerformed( ActionEvent e ) { String key = getName(); ! @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,1633 **** } } } } ! private int getNextIndex(JComboBox comboBox, String key) { int listHeight = comboBox.getMaximumRowCount(); int selectedIndex = comboBox.getSelectedIndex(); if (UIManager.getBoolean("ComboBox.noActionOnKeyNavigation") && (comboBox.getUI() instanceof BasicComboBoxUI)) { --- 1627,1637 ---- } } } } ! 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,1696 **** isMinimumSizeDirty = true; isDisplaySizeDirty = true; comboBox.revalidate(); } } else { ! JComboBox comboBox = (JComboBox)e.getSource(); if ( propertyName == "model" ) { ! ComboBoxModel newModel = (ComboBoxModel)e.getNewValue(); ! ComboBoxModel oldModel = (ComboBoxModel)e.getOldValue(); if ( oldModel != null && listDataListener != null ) { oldModel.removeListDataListener( listDataListener ); } --- 1687,1703 ---- isMinimumSizeDirty = true; isDisplaySizeDirty = true; comboBox.revalidate(); } } else { ! @SuppressWarnings("unchecked") ! JComboBox<?> comboBox = (JComboBox)e.getSource(); if ( propertyName == "model" ) { ! @SuppressWarnings("unchecked") ! ComboBoxModel<?> newModel = (ComboBoxModel)e.getNewValue(); ! @SuppressWarnings("unchecked") ! ComboBoxModel<?> oldModel = (ComboBoxModel)e.getOldValue(); if ( oldModel != null && listDataListener != null ) { oldModel.removeListDataListener( listDataListener ); }
*** 1895,1905 **** public Dimension minimumLayoutSize(Container parent) { return parent.getMinimumSize(); } public void layoutContainer(Container parent) { ! JComboBox cb = (JComboBox)parent; int width = cb.getWidth(); int height = cb.getHeight(); Insets insets = getInsets(); int buttonHeight = height - (insets.top + insets.bottom); --- 1902,1913 ---- public Dimension minimumLayoutSize(Container parent) { return parent.getMinimumSize(); } public void layoutContainer(Container 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,1967 **** class DefaultKeySelectionManager implements JComboBox.KeySelectionManager, UIResource { private String prefix = ""; private String typedString = ""; ! public int selectionForKey(char aKey,ComboBoxModel aModel) { if (lastTime == 0L) { prefix = ""; typedString = ""; } boolean startingFromSelection = true; --- 1965,1975 ---- class DefaultKeySelectionManager implements JComboBox.KeySelectionManager, UIResource { private String prefix = ""; private String typedString = ""; ! public int selectionForKey(char aKey,ComboBoxModel<?> aModel) { if (lastTime == 0L) { prefix = ""; typedString = ""; } boolean startingFromSelection = true;