Spec-Zone .ru
спецификации, руководства, описания, API
JavaTM 2 Platform
Standard Edition

javax.swing.plaf.basic
Class BasicComboPopup

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPopupMenu
                          |
                          +--javax.swing.plaf.basic.BasicComboPopup
Direct Known Subclasses:
MetalComboBoxUI.MetalComboPopup

public class BasicComboPopup
extends JPopupMenu
implements ComboPopup

This is an implementation of the ComboPopup interface. It is primarily for use by BasicComboBoxUI and its subclasses. BasicComboPopup extends JPopupMenu because most combo boxes use a popup menu to display the list of possible selections. BasicComboBoxUI only requires a ComboPopup, so subclasses of BasicComboBoxUI aren't required to use this class. All event handling is handled by createxxxListener() methods and internal classes. You can change the behavior of this class by overriding the createxxxListener() methods and supplying your own event listeners or subclassing from the ones supplied in this class. Inner classes for handling events: InvocationMouseHandler InvocationMouseMotionHandler InvocationKeyHandler ListSelectionHandler ListDataHandler ListMouseHandler ListMouseMotionHandler PropertyChangeHandler ItemHandler

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. A future release of Swing will provide support for long term persistence.

See Also:
Serialized Form

Inner Class Summary
 class BasicComboPopup.InvocationKeyHandler
          This listener watches for the spacebar being pressed and shows/hides the popup accordingly.
protected  class BasicComboPopup.InvocationMouseHandler
          This listener knows how and when to invoke this popup menu.
protected  class BasicComboPopup.InvocationMouseMotionHandler
          This listener watches for dragging and updates the current selection in the list if it is dragging over the list.
protected  class BasicComboPopup.ItemHandler
          This listener watches for changes in the JComboBox's selection.
 class BasicComboPopup.ListDataHandler
          Keeps the selected index in the list in-sync with the combo box's selection.
protected  class BasicComboPopup.ListMouseHandler
          This listener hides the popup when the mouse is released in the list.
protected  class BasicComboPopup.ListMouseMotionHandler
          This listener changes the selected item as you move the mouse over the list.
protected  class BasicComboPopup.ListSelectionHandler
          This listener watches for changes in the list's selection and reports them to the combo box.
protected  class BasicComboPopup.PropertyChangeHandler
          This listener watches for bound property changes in JComboBox.
 
Inner classes inherited from class javax.swing.JPopupMenu
JPopupMenu.AccessibleJPopupMenu, JPopupMenu.Separator
 
Inner classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Field Summary
protected  Timer autoscrollTimer
           
protected  JComboBox comboBox
           
protected  boolean hasEntered
           
protected  boolean isAutoScrolling
           
protected  ItemListener itemListener
           
protected  KeyListener keyListener
           
protected  JList list
           
protected  ListDataListener listDataListener
           
protected  MouseListener listMouseListener
           
protected  MouseMotionListener listMouseMotionListener
           
protected  ListSelectionListener listSelectionListener
           
protected  MouseListener mouseListener
           
protected  MouseMotionListener mouseMotionListener
           
protected  PropertyChangeListener propertyChangeListener
           
protected static int SCROLL_DOWN
           
protected static int SCROLL_UP
           
protected  int scrollDirection
           
protected  JScrollPane scroller
           
protected  boolean valueIsAdjusting
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
BasicComboPopup(JComboBox combo)
           
 
Method Summary
protected  void autoScrollDown()
           
protected  void autoScrollUp()
           
protected  Rectangle computePopupBounds(int px, int py, int pw, int ph)
           
protected  void configureList()
          Called to configure the list created by createList().
protected  void configurePopup()
          Called to configure this JPopupMenu (BasicComboPopup is a JPopupMenu).
protected  void configureScroller()
          Called to configure the JScrollPane created by createScroller().
protected  MouseEvent convertMouseEvent(MouseEvent e)
           
protected  ItemListener createItemListener()
          Creates an item listener that watches for changes in the selected item in the JComboBox.
protected  KeyListener createKeyListener()
          Creates the key listener that is returned by ComboPopup.getKeyListener().
protected  JList createList()
          Creates the JList that is used in the popup to display the items in the model.
protected  ListDataListener createListDataListener()
          Creates a list data listener that watches for inserted and removed items from the combo box model.
protected  MouseListener createListMouseListener()
          Creates a mouse listener that watches for mouse events in the popup's list.
protected  MouseMotionListener createListMouseMotionListener()
          Creates a mouse motion listener that watches for mouse events in the popup's list.
protected  ListSelectionListener createListSelectionListener()
          Creates a list selection listener that watches for selection changes in the popup's list.
protected  MouseListener createMouseListener()
          Creates the mouse listener that is returned by ComboPopup.getMouseListener().
protected  MouseMotionListener createMouseMotionListener()
          Creates the mouse motion listener that is returned by ComboPopup.getMouseMotionListener().
protected  PropertyChangeListener createPropertyChangeListener()
          Creates a property change listener that watches for changes in the bound properties in the JComboBox.
protected  JScrollPane createScroller()
          Creates the JScrollPane that is used in the popup to hold the list.
protected  void delegateFocus(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.
 KeyListener getKeyListener()
          Implementation of ComboPopup.getKeyListener().
 JList getList()
          Implementation of ComboPopup.getList().
 MouseListener getMouseListener()
          Implementation of ComboPopup.getMouseListener().
 MouseMotionListener getMouseMotionListener()
          Implementation of ComboPopup.getMouseMotionListener().
protected  int getPopupHeightForRowCount(int maxRowCount)
           
 void hide()
          Implementation of ComboPopup.hide().
protected  void installComboBoxListeners()
          This method adds the necessary listeners to the JComboBox.
protected  void installComboBoxModelListeners(ComboBoxModel model)
           
protected  void installKeyboardActions()
           
protected  void installListListeners()
          Called by configureList() to add the necessary listeners to the list.
 boolean isFocusTraversable()
          Overridden to unconditionally return false.
 void show()
          Implementation of ComboPopup.show().
protected  void startAutoScrolling(int direction)
          Called by BasicComboPopup$InvocationMouseMotionHandler to handle auto- scrolling the list.
protected  void stopAutoScrolling()
           
protected  void togglePopup()
          Makes the popup visible if it is hidden and makes it hidden if it is visible.
protected  void uninstallComboBoxModelListeners(ComboBoxModel model)
           
 void uninstallingUI()
          Called when the UI is uninstalling.
protected  void uninstallKeyboardActions()
           
protected  void updateListBoxSelectionForEvent(MouseEvent anEvent, boolean shouldScroll)
          A utility method used by the event listeners.
 
Methods inherited from class javax.swing.JPopupMenu
add, add, add, addPopupMenuListener, addSeparator, createActionChangeListener, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getComponent, getComponentAtIndex, getComponentIndex, getDefaultLightWeightPopupEnabled, getInvoker, getLabel, getMargin, getSelectionModel, getSubElements, getUI, getUIClassID, insert, insert, isBorderPainted, isLightWeightPopupEnabled, isVisible, menuSelectionChanged, pack, paintBorder, paramString, processKeyEvent, processMouseEvent, remove, remove, removePopupMenuListener, setBorderPainted, setDefaultLightWeightPopupEnabled, setInvoker, setLabel, setLightWeightPopupEnabled, setLocation, setPopupSize, setPopupSize, setSelected, setSelectionModel, setUI, setVisible, show, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, removeAll, removeContainerListener, setCursor, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setDropTarget, setLocale, setLocation, setName, setSize, setSize, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

comboBox

protected JComboBox comboBox

list

protected JList list

scroller

protected JScrollPane scroller

valueIsAdjusting

protected boolean valueIsAdjusting

mouseMotionListener

protected MouseMotionListener mouseMotionListener

mouseListener

protected MouseListener mouseListener

keyListener

protected KeyListener keyListener

listSelectionListener

protected ListSelectionListener listSelectionListener

listDataListener

protected ListDataListener listDataListener

listMouseListener

protected MouseListener listMouseListener

listMouseMotionListener

protected MouseMotionListener listMouseMotionListener

propertyChangeListener

protected PropertyChangeListener propertyChangeListener

itemListener

protected ItemListener itemListener

autoscrollTimer

protected Timer autoscrollTimer

hasEntered

protected boolean hasEntered

isAutoScrolling

protected boolean isAutoScrolling

scrollDirection

protected int scrollDirection

SCROLL_UP

protected static final int SCROLL_UP

SCROLL_DOWN

protected static final int SCROLL_DOWN
Constructor Detail

BasicComboPopup

public BasicComboPopup(JComboBox combo)
Method Detail

show

public void show()
Implementation of ComboPopup.show().
Specified by:
show in interface ComboPopup
Overrides:
show in class Component

hide

public void hide()
Implementation of ComboPopup.hide().
Specified by:
hide in interface ComboPopup
Overrides:
hide in class Component

getList

public JList getList()
Implementation of ComboPopup.getList().
Specified by:
getList in interface ComboPopup

getMouseListener

public MouseListener getMouseListener()
Implementation of ComboPopup.getMouseListener().
Specified by:
getMouseListener in interface ComboPopup

getMouseMotionListener

public MouseMotionListener getMouseMotionListener()
Implementation of ComboPopup.getMouseMotionListener().
Specified by:
getMouseMotionListener in interface ComboPopup

getKeyListener

public KeyListener getKeyListener()
Implementation of ComboPopup.getKeyListener().
Specified by:
getKeyListener in interface ComboPopup

uninstallingUI

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().
Specified by:
uninstallingUI in interface ComboPopup

uninstallComboBoxModelListeners

protected void uninstallComboBoxModelListeners(ComboBoxModel model)

uninstallKeyboardActions

protected void uninstallKeyboardActions()

createMouseListener

protected MouseListener createMouseListener()
Creates the mouse listener that is returned by ComboPopup.getMouseListener(). Returns an instance of BasicComboPopup$InvocationMouseHandler.

createMouseMotionListener

protected MouseMotionListener createMouseMotionListener()
Creates the mouse motion listener that is returned by ComboPopup.getMouseMotionListener(). Returns an instance of BasicComboPopup$InvocationMouseMotionListener.

createKeyListener

protected KeyListener createKeyListener()
Creates the key listener that is returned by ComboPopup.getKeyListener(). Returns an instance of BasicComboPopup$InvocationKeyHandler.

createListSelectionListener

protected ListSelectionListener createListSelectionListener()
Creates a list selection listener that watches for selection changes in the popup's list. Returns an instance of BasicComboPopup$ListSelectionHandler.

createListDataListener

protected ListDataListener createListDataListener()
Creates a list data listener that watches for inserted and removed items from the combo box model.

createListMouseListener

protected MouseListener createListMouseListener()
Creates a mouse listener that watches for mouse events in the popup's list. Returns an instance of BasicComboPopup$ListMouseHandler.

createListMouseMotionListener

protected MouseMotionListener createListMouseMotionListener()
Creates a mouse motion listener that watches for mouse events in the popup's list. Returns an instance of BasicComboPopup$ListMouseMotionHandler.

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()
Creates a property change listener that watches for changes in the bound properties in the JComboBox. Returns an instance of BasicComboPopup$PropertyChangeHandler.

createItemListener

protected ItemListener createItemListener()
Creates an item listener that watches for changes in the selected item in the JComboBox. Returns an instance of BasicComboPopup$ItemHandler.

createList

protected JList createList()
Creates the JList that is used in the popup to display the items in the model.

configureList

protected void configureList()
Called to configure the list created by createList().

installListListeners

protected void installListListeners()
Called by configureList() to add the necessary listeners to the list.

createScroller

protected JScrollPane createScroller()
Creates the JScrollPane that is used in the popup to hold the list.

configureScroller

protected void configureScroller()
Called to configure the JScrollPane created by createScroller().

configurePopup

protected void configurePopup()
Called to configure this JPopupMenu (BasicComboPopup is a JPopupMenu).

installComboBoxListeners

protected void installComboBoxListeners()
This method adds the necessary listeners to the JComboBox.

installComboBoxModelListeners

protected void installComboBoxModelListeners(ComboBoxModel model)

installKeyboardActions

protected void installKeyboardActions()

isFocusTraversable

public boolean isFocusTraversable()
Overridden to unconditionally return false.
Overrides:
isFocusTraversable in class JComponent
Tags copied from class: JComponent
Returns:
true if this component can receive the focus

startAutoScrolling

protected void startAutoScrolling(int direction)
Called by BasicComboPopup$InvocationMouseMotionHandler to handle auto- scrolling the list.

stopAutoScrolling

protected void stopAutoScrolling()

autoScrollUp

protected void autoScrollUp()

autoScrollDown

protected void autoScrollDown()

delegateFocus

protected void delegateFocus(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.

togglePopup

protected void togglePopup()
Makes the popup visible if it is hidden and makes it hidden if it is visible.

convertMouseEvent

protected MouseEvent convertMouseEvent(MouseEvent e)

getPopupHeightForRowCount

protected int getPopupHeightForRowCount(int maxRowCount)

computePopupBounds

protected Rectangle computePopupBounds(int px,
                                       int py,
                                       int pw,
                                       int ph)

updateListBoxSelectionForEvent

protected void updateListBoxSelectionForEvent(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.

JavaTM 2 Platform
Standard Edition

Submit a bug or feature
Java, Java 2D, and JDBC are a trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.