Fields Summary |
---|
static final ListModel | EmptyListModel |
private static Border | LIST_BORDER |
protected JComboBox | comboBox |
protected JList | listThis protected field is implementation specific. Do not access directly
or override. Use the accessor methods instead. |
protected JScrollPane | scrollerThis protected field is implementation specific. Do not access directly
or override. Use the create method instead |
protected boolean | valueIsAdjustingAs of Java 2 platform v1.4 this previously undocumented field is no
longer used. |
private Handler | handlerImplementation of all the listener classes. |
protected MouseMotionListener | mouseMotionListenerThis protected field is implementation specific. Do not access directly
or override. Use the accessor or create methods instead. |
protected MouseListener | mouseListenerThis protected field is implementation specific. Do not access directly
or override. Use the accessor or create methods instead. |
protected KeyListener | keyListenerThis protected field is implementation specific. Do not access directly
or override. Use the accessor or create methods instead. |
protected ListSelectionListener | listSelectionListenerThis protected field is implementation specific. Do not access directly
or override. Use the create method instead. |
protected MouseListener | listMouseListenerThis protected field is implementation specific. Do not access directly
or override. Use the create method instead. |
protected MouseMotionListener | listMouseMotionListenerThis protected field is implementation specific. Do not access directly
or override. Use the create method instead |
protected PropertyChangeListener | propertyChangeListenerThis protected field is implementation specific. Do not access directly
or override. Use the create method instead |
protected ListDataListener | listDataListenerThis protected field is implementation specific. Do not access directly
or override. Use the create method instead |
protected ItemListener | itemListenerThis protected field is implementation specific. Do not access directly
or override. Use the create method instead |
protected Timer | autoscrollTimerThis protected field is implementation specific. Do not access directly
or override. |
protected boolean | hasEntered |
protected boolean | isAutoScrolling |
protected int | scrollDirection |
protected static final int | SCROLL_UP |
protected static final int | SCROLL_DOWN |
Methods Summary |
---|
protected void | autoScrollDown()This protected method is implementation specific and should be private.
do not call or override.
int index = list.getSelectedIndex();
int lastItem = list.getModel().getSize() - 1;
if ( index < lastItem ) {
list.setSelectedIndex( index + 1 );
list.ensureIndexIsVisible( index + 1 );
}
|
protected void | autoScrollUp()This protected method is implementation specific and should be private.
do not call or override.
int index = list.getSelectedIndex();
if ( index > 0 ) {
list.setSelectedIndex( index - 1 );
list.ensureIndexIsVisible( index - 1 );
}
|
protected java.awt.Rectangle | computePopupBounds(int px, int py, int pw, int ph)Calculate the placement and size of the popup portion of the combo box based
on the combo box location and the enclosing screen bounds. If
no transformations are required, then the returned rectangle will
have the same values as the parameters.
Toolkit toolkit = Toolkit.getDefaultToolkit();
Rectangle screenBounds;
// Calculate the desktop dimensions relative to the combo box.
GraphicsConfiguration gc = comboBox.getGraphicsConfiguration();
Point p = new Point();
SwingUtilities.convertPointFromScreen(p, comboBox);
if (gc != null) {
Insets screenInsets = toolkit.getScreenInsets(gc);
screenBounds = gc.getBounds();
screenBounds.width -= (screenInsets.left + screenInsets.right);
screenBounds.height -= (screenInsets.top + screenInsets.bottom);
screenBounds.x += (p.x + screenInsets.left);
screenBounds.y += (p.y + screenInsets.top);
}
else {
screenBounds = new Rectangle(p, toolkit.getScreenSize());
}
Rectangle rect = new Rectangle(px,py,pw,ph);
if (py+ph > screenBounds.y+screenBounds.height
&& ph < screenBounds.height) {
rect.y = -rect.height;
}
return rect;
|
protected void | configureList()Configures the list which is used to hold the combo box items in the
popup. This method is called when the UI class
is created.
list.setFont( comboBox.getFont() );
list.setForeground( comboBox.getForeground() );
list.setBackground( comboBox.getBackground() );
list.setSelectionForeground( UIManager.getColor( "ComboBox.selectionForeground" ) );
list.setSelectionBackground( UIManager.getColor( "ComboBox.selectionBackground" ) );
list.setBorder( null );
list.setCellRenderer( comboBox.getRenderer() );
list.setFocusable( false );
list.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
setListSelection( comboBox.getSelectedIndex() );
installListListeners();
|
protected void | configurePopup()Configures the popup portion of the combo box. This method is called
when the UI class is created.
setLayout( new BoxLayout( this, BoxLayout.Y_AXIS ) );
setBorderPainted( true );
setBorder(LIST_BORDER);
setOpaque( false );
add( scroller );
setDoubleBuffered( true );
setFocusable( false );
|
protected void | configureScroller()Configures the scrollable portion which holds the list within
the combo box popup. This method is called when the UI class
is created.
scroller.setFocusable( false );
scroller.getVerticalScrollBar().setFocusable( false );
scroller.setBorder( null );
|
protected java.awt.event.MouseEvent | convertMouseEvent(java.awt.event.MouseEvent e)
Point convertedPoint = SwingUtilities.convertPoint( (Component)e.getSource(),
e.getPoint(), list );
MouseEvent newEvent = new MouseEvent( (Component)e.getSource(),
e.getID(),
e.getWhen(),
e.getModifiers(),
convertedPoint.x,
convertedPoint.y,
e.getXOnScreen(),
e.getYOnScreen(),
e.getClickCount(),
e.isPopupTrigger(),
MouseEvent.NOBUTTON );
return newEvent;
|
protected java.awt.event.ItemListener | createItemListener()Creates an ItemListener which will be added to the
combo box. If this method returns null then it will not
be added to the combo box.
Subclasses may override this method to return instances of their own
ItemEvent handlers.
return getHandler();
|
protected java.awt.event.KeyListener | createKeyListener()Creates the key listener that will be added to the combo box. If
this method returns null then it will not be added to the combo box.
return null;
|
protected javax.swing.JList | createList()Creates the JList used in the popup to display
the items in the combo box model. This method is called when the UI class
is created.
return new JList( comboBox.getModel() ) {
public void processMouseEvent(MouseEvent e) {
if (e.isControlDown()) {
// Fix for 4234053. Filter out the Control Key from the list.
// ie., don't allow CTRL key deselection.
e = new MouseEvent((Component)e.getSource(), e.getID(), e.getWhen(),
e.getModifiers() ^ InputEvent.CTRL_MASK,
e.getX(), e.getY(),
e.getXOnScreen(), e.getYOnScreen(),
e.getClickCount(),
e.isPopupTrigger(),
MouseEvent.NOBUTTON);
}
super.processMouseEvent(e);
}
};
|
protected javax.swing.event.ListDataListener | createListDataListener()Creates a list data listener which will be added to the
ComboBoxModel . If this method returns null then
it will not be added to the combo box model.
return null;
|
protected java.awt.event.MouseListener | createListMouseListener()Creates a mouse listener that watches for mouse events in
the popup's list. If this method returns null then it will
not be added to the combo box.
return getHandler();
|
protected java.awt.event.MouseMotionListener | createListMouseMotionListener()Creates a mouse motion listener that watches for mouse motion
events in the popup's list. If this method returns null then it will
not be added to the combo box.
return getHandler();
|
protected javax.swing.event.ListSelectionListener | createListSelectionListener()Creates a list selection listener that watches for selection changes in
the popup's list. If this method returns null then it will not
be added to the popup list.
return null;
|
protected java.awt.event.MouseListener | createMouseListener()Creates a listener
that will watch for mouse-press and release events on the combo box.
Warning:
When overriding this method, make sure to maintain the existing
behavior.
return getHandler();
|
protected java.awt.event.MouseMotionListener | createMouseMotionListener()Creates the mouse motion listener which will be added to the combo
box.
Warning:
When overriding this method, make sure to maintain the existing
behavior.
return getHandler();
|
protected java.beans.PropertyChangeListener | createPropertyChangeListener()Creates a PropertyChangeListener which will be added to
the combo box. If this method returns null then it will not
be added to the combo box.
return getHandler();
|
protected javax.swing.JScrollPane | createScroller()Creates the scroll pane which houses the scrollable list.
JScrollPane sp = new JScrollPane( list,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER );
sp.setHorizontalScrollBar(null);
return sp;
|
protected void | delegateFocus(java.awt.event.MouseEvent e)This is is a utility method that helps event handlers figure out where to
send the focus when the popup is brought up. The standard implementation
delegates the focus to the editor (if the combo box is editable) or to
the JComboBox if it is not editable.
if ( comboBox.isEditable() ) {
Component comp = comboBox.getEditor().getEditorComponent();
if ((!(comp instanceof JComponent)) || ((JComponent)comp).isRequestFocusEnabled()) {
comp.requestFocus();
}
}
else if (comboBox.isRequestFocusEnabled()) {
comboBox.requestFocus();
}
|
protected void | firePopupMenuCanceled()
super.firePopupMenuCanceled();
comboBox.firePopupMenuCanceled();
|
protected void | firePopupMenuWillBecomeInvisible()
super.firePopupMenuWillBecomeInvisible();
comboBox.firePopupMenuWillBecomeInvisible();
|
protected void | firePopupMenuWillBecomeVisible()
super.firePopupMenuWillBecomeVisible();
comboBox.firePopupMenuWillBecomeVisible();
|
public javax.accessibility.AccessibleContext | getAccessibleContext()Gets the AccessibleContext associated with this BasicComboPopup.
The AccessibleContext will have its parent set to the ComboBox.
AccessibleContext context = super.getAccessibleContext();
context.setAccessibleParent(comboBox);
return context;
|
private javax.swing.plaf.basic.BasicComboPopup$Handler | getHandler()
if (handler == null) {
handler = new Handler();
}
return handler;
|
public java.awt.event.KeyListener | getKeyListener()Implementation of ComboPopup.getKeyListener().
if (keyListener == null) {
keyListener = createKeyListener();
}
return keyListener;
|
public javax.swing.JList | getList()Implementation of ComboPopup.getList().
return list;
|
public java.awt.event.MouseListener | getMouseListener()Implementation of ComboPopup.getMouseListener().
if (mouseListener == null) {
mouseListener = createMouseListener();
}
return mouseListener;
|
public java.awt.event.MouseMotionListener | getMouseMotionListener()Implementation of ComboPopup.getMouseMotionListener().
if (mouseMotionListener == null) {
mouseMotionListener = createMouseMotionListener();
}
return mouseMotionListener;
|
protected int | getPopupHeightForRowCount(int maxRowCount)Retrieves the height of the popup based on the current
ListCellRenderer and the maximum row count.
// Set the cached value of the minimum row count
int minRowCount = Math.min( maxRowCount, comboBox.getItemCount() );
int height = 0;
ListCellRenderer renderer = list.getCellRenderer();
Object value = null;
for ( int i = 0; i < minRowCount; ++i ) {
value = list.getModel().getElementAt( i );
Component c = renderer.getListCellRendererComponent( list, value, i, false, false );
height += c.getPreferredSize().height;
}
if (height == 0) {
height = comboBox.getHeight();
}
Border border = scroller.getViewportBorder();
if (border != null) {
Insets insets = border.getBorderInsets(null);
height += insets.top + insets.bottom;
}
border = scroller.getBorder();
if (border != null) {
Insets insets = border.getBorderInsets(null);
height += insets.top + insets.bottom;
}
return height;
|
private java.awt.Point | getPopupLocation()Calculates the upper left location of the Popup.
Dimension popupSize = comboBox.getSize();
Insets insets = getInsets();
// reduce the width of the scrollpane by the insets so that the popup
// is the same width as the combo box.
popupSize.setSize(popupSize.width - (insets.right + insets.left),
getPopupHeightForRowCount( comboBox.getMaximumRowCount()));
Rectangle popupBounds = computePopupBounds( 0, comboBox.getBounds().height,
popupSize.width, popupSize.height);
Dimension scrollSize = popupBounds.getSize();
Point popupLocation = popupBounds.getLocation();
scroller.setMaximumSize( scrollSize );
scroller.setPreferredSize( scrollSize );
scroller.setMinimumSize( scrollSize );
list.revalidate();
return popupLocation;
|
public void | hide()Implementation of ComboPopup.hide().
MenuSelectionManager manager = MenuSelectionManager.defaultManager();
MenuElement [] selection = manager.getSelectedPath();
for ( int i = 0 ; i < selection.length ; i++ ) {
if ( selection[i] == this ) {
manager.clearSelectedPath();
break;
}
}
if (selection.length > 0) {
comboBox.repaint();
}
|
protected void | installComboBoxListeners()This method adds the necessary listeners to the JComboBox.
if ((propertyChangeListener = createPropertyChangeListener()) != null) {
comboBox.addPropertyChangeListener(propertyChangeListener);
}
if ((itemListener = createItemListener()) != null) {
comboBox.addItemListener(itemListener);
}
installComboBoxModelListeners(comboBox.getModel());
|
protected void | installComboBoxModelListeners(javax.swing.ComboBoxModel model)Installs the listeners on the combo box model. Any listeners installed
on the combo box model should be removed in
uninstallComboBoxModelListeners .
if (model != null && (listDataListener = createListDataListener()) != null) {
model.addListDataListener(listDataListener);
}
|
protected void | installKeyboardActions()
/* XXX - shouldn't call this method. take it out for testing.
ActionListener action = new ActionListener() {
public void actionPerformed(ActionEvent e){
}
};
comboBox.registerKeyboardAction( action,
KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, 0 ),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); */
|
protected void | installListListeners()Adds the listeners to the list control.
if ((listMouseListener = createListMouseListener()) != null) {
list.addMouseListener( listMouseListener );
}
if ((listMouseMotionListener = createListMouseMotionListener()) != null) {
list.addMouseMotionListener( listMouseMotionListener );
}
if ((listSelectionListener = createListSelectionListener()) != null) {
list.addListSelectionListener( listSelectionListener );
}
|
public boolean | isFocusTraversable()Overridden to unconditionally return false.
return false;
|
private void | setListSelection(int selectedIndex)Sets the list selection index to the selectedIndex. This
method is used to synchronize the list selection with the
combo box selection.
if ( selectedIndex == -1 ) {
list.clearSelection();
}
else {
list.setSelectedIndex( selectedIndex );
list.ensureIndexIsVisible( selectedIndex );
}
|
public void | show()Implementation of ComboPopup.show().
//========================================
// begin ComboPopup method implementations
//
setListSelection(comboBox.getSelectedIndex());
Point location = getPopupLocation();
show( comboBox, location.x, location.y );
|
protected void | startAutoScrolling(int direction)This protected method is implementation specific and should be private.
do not call or override.
// XXX - should be a private method within InvocationMouseMotionHandler
// if possible.
if ( isAutoScrolling ) {
autoscrollTimer.stop();
}
isAutoScrolling = true;
if ( direction == SCROLL_UP ) {
scrollDirection = SCROLL_UP;
Point convertedPoint = SwingUtilities.convertPoint( scroller, new Point( 1, 1 ), list );
int top = list.locationToIndex( convertedPoint );
list.setSelectedIndex( top );
autoscrollTimer = new Timer( 100, new AutoScrollActionHandler(
SCROLL_UP) );
}
else if ( direction == SCROLL_DOWN ) {
scrollDirection = SCROLL_DOWN;
Dimension size = scroller.getSize();
Point convertedPoint = SwingUtilities.convertPoint( scroller,
new Point( 1, (size.height - 1) - 2 ),
list );
int bottom = list.locationToIndex( convertedPoint );
list.setSelectedIndex( bottom );
autoscrollTimer = new Timer(100, new AutoScrollActionHandler(
SCROLL_DOWN));
}
autoscrollTimer.start();
|
protected void | stopAutoScrolling()This protected method is implementation specific and should be private.
do not call or override.
isAutoScrolling = false;
if ( autoscrollTimer != null ) {
autoscrollTimer.stop();
autoscrollTimer = null;
}
|
protected void | togglePopup()Makes the popup visible if it is hidden and makes it hidden if it is
visible.
if ( isVisible() ) {
hide();
}
else {
show();
}
|
protected void | uninstallComboBoxModelListeners(javax.swing.ComboBoxModel model)Removes the listeners from the combo box model
if (model != null && listDataListener != null) {
model.removeListDataListener(listDataListener);
}
|
protected void | uninstallKeyboardActions()
// XXX - shouldn't call this method
// comboBox.unregisterKeyboardAction( KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, 0 ) );
|
void | uninstallListListeners()
if (listMouseListener != null) {
list.removeMouseListener(listMouseListener);
listMouseListener = null;
}
if (listMouseMotionListener != null) {
list.removeMouseMotionListener(listMouseMotionListener);
listMouseMotionListener = null;
}
if (listSelectionListener != null) {
list.removeListSelectionListener(listSelectionListener);
listSelectionListener = null;
}
handler = null;
|
public void | uninstallingUI()Called when the UI is uninstalling. Since this popup isn't in the component
tree, it won't get it's uninstallUI() called. It removes the listeners that
were added in addComboBoxListeners().
if (propertyChangeListener != null) {
comboBox.removePropertyChangeListener( propertyChangeListener );
}
if (itemListener != null) {
comboBox.removeItemListener( itemListener );
}
uninstallComboBoxModelListeners(comboBox.getModel());
uninstallKeyboardActions();
uninstallListListeners();
// We do this, otherwise the listener the ui installs on
// the model (the combobox model in this case) will keep a
// reference to the list, causing the list (and us) to never get gced.
list.setModel(EmptyListModel);
|
protected void | updateListBoxSelectionForEvent(java.awt.event.MouseEvent anEvent, boolean shouldScroll)A utility method used by the event listeners. Given a mouse event, it changes
the list selection to the list item below the mouse.
// XXX - only seems to be called from this class. shouldScroll flag is
// never true
Point location = anEvent.getPoint();
if ( list == null )
return;
int index = list.locationToIndex(location);
if ( index == -1 ) {
if ( location.y < 0 )
index = 0;
else
index = comboBox.getModel().getSize() - 1;
}
if ( list.getSelectedIndex() != index ) {
list.setSelectedIndex(index);
if ( shouldScroll )
list.ensureIndexIsVisible(index);
}
|