| Method from javax.swing.plaf.basic.BasicComboPopup Detail: |
protected void autoScrollDown() {
int index = list.getSelectedIndex();
int lastItem = list.getModel().getSize() - 1;
if ( index < lastItem ) {
list.setSelectedIndex( index + 1 );
list.ensureIndexIsVisible( index + 1 );
}
}
This protected method is implementation specific and should be private.
do not call or override. |
protected void autoScrollUp() {
int index = list.getSelectedIndex();
if ( index > 0 ) {
list.setSelectedIndex( index - 1 );
list.ensureIndexIsVisible( index - 1 );
}
}
This protected method is implementation specific and should be private.
do not call or override. |
protected Rectangle computePopupBounds(int px,
int py,
int pw,
int ph) {
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;
}
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. |
protected void configureList() {
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();
}
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. |
protected void configurePopup() {
setLayout( new BoxLayout( this, BoxLayout.Y_AXIS ) );
setBorderPainted( true );
setBorder(LIST_BORDER);
setOpaque( false );
add( scroller );
setDoubleBuffered( true );
setFocusable( false );
}
Configures the popup portion of the combo box. This method is called
when the UI class is created. |
protected void configureScroller() {
scroller.setFocusable( false );
scroller.getVerticalScrollBar().setFocusable( false );
scroller.setBorder( null );
}
Configures the scrollable portion which holds the list within
the combo box popup. This method is called when the UI class
is created. |
protected MouseEvent convertMouseEvent(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 ItemListener createItemListener() {
return getHandler();
}
|
protected KeyListener createKeyListener() {
return null;
}
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. |
protected JList createList() {
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);
}
};
}
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. |
protected ListDataListener createListDataListener() {
return null;
}
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. |
protected MouseListener createListMouseListener() {
return getHandler();
}
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. |
protected MouseMotionListener createListMouseMotionListener() {
return getHandler();
}
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. |
protected ListSelectionListener createListSelectionListener() {
return null;
}
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. |
protected MouseListener createMouseListener() {
return getHandler();
}
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. |
protected MouseMotionListener createMouseMotionListener() {
return getHandler();
}
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. |
protected PropertyChangeListener createPropertyChangeListener() {
return getHandler();
}
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. |
protected JScrollPane createScroller() {
JScrollPane sp = new JScrollPane( list,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER );
sp.setHorizontalScrollBar(null);
return sp;
}
Creates the scroll pane which houses the scrollable list. |
protected void delegateFocus(MouseEvent e) {
if ( comboBox.isEditable() ) {
Component comp = comboBox.getEditor().getEditorComponent();
if ((!(comp instanceof JComponent)) || ((JComponent)comp).isRequestFocusEnabled()) {
comp.requestFocus();
}
}
else if (comboBox.isRequestFocusEnabled()) {
comboBox.requestFocus();
}
}
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. |
protected void firePopupMenuCanceled() {
super.firePopupMenuCanceled();
comboBox.firePopupMenuCanceled();
}
|
protected void firePopupMenuWillBecomeInvisible() {
super.firePopupMenuWillBecomeInvisible();
comboBox.firePopupMenuWillBecomeInvisible();
}
|
protected void firePopupMenuWillBecomeVisible() {
super.firePopupMenuWillBecomeVisible();
comboBox.firePopupMenuWillBecomeVisible();
}
|
public AccessibleContext getAccessibleContext() {
AccessibleContext context = super.getAccessibleContext();
context.setAccessibleParent(comboBox);
return context;
}
Gets the AccessibleContext associated with this BasicComboPopup.
The AccessibleContext will have its parent set to the ComboBox. |
public KeyListener getKeyListener() {
if (keyListener == null) {
keyListener = createKeyListener();
}
return keyListener;
}
Implementation of ComboPopup.getKeyListener(). |
public JList getList() {
return list;
}
Implementation of ComboPopup.getList(). |
public MouseListener getMouseListener() {
if (mouseListener == null) {
mouseListener = createMouseListener();
}
return mouseListener;
}
Implementation of ComboPopup.getMouseListener(). |
public MouseMotionListener getMouseMotionListener() {
if (mouseMotionListener == null) {
mouseMotionListener = createMouseMotionListener();
}
return mouseMotionListener;
}
Implementation of ComboPopup.getMouseMotionListener(). |
protected int getPopupHeightForRowCount(int maxRowCount) {
// 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;
}
Retrieves the height of the popup based on the current
ListCellRenderer and the maximum row count. |
public void 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();
}
}
Implementation of ComboPopup.hide(). |
protected void installComboBoxListeners() {
if ((propertyChangeListener = createPropertyChangeListener()) != null) {
comboBox.addPropertyChangeListener(propertyChangeListener);
}
if ((itemListener = createItemListener()) != null) {
comboBox.addItemListener(itemListener);
}
installComboBoxModelListeners(comboBox.getModel());
}
This method adds the necessary listeners to the JComboBox. |
protected void installComboBoxModelListeners(ComboBoxModel model) {
if (model != null && (listDataListener = createListDataListener()) != null) {
model.addListDataListener(listDataListener);
}
}
Installs the listeners on the combo box model. Any listeners installed
on the combo box model should be removed in
uninstallComboBoxModelListeners. |
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() {
if ((listMouseListener = createListMouseListener()) != null) {
list.addMouseListener( listMouseListener );
}
if ((listMouseMotionListener = createListMouseMotionListener()) != null) {
list.addMouseMotionListener( listMouseMotionListener );
}
if ((listSelectionListener = createListSelectionListener()) != null) {
list.addListSelectionListener( listSelectionListener );
}
}
Adds the listeners to the list control. |
public boolean isFocusTraversable() {
return false;
}
Overridden to unconditionally return false. |
public void show() {
//========================================
// begin ComboPopup method implementations
//
setListSelection(comboBox.getSelectedIndex());
Point location = getPopupLocation();
show( comboBox, location.x, location.y );
}
Implementation of ComboPopup.show(). |
protected void startAutoScrolling(int direction) {
// 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();
}
This protected method is implementation specific and should be private.
do not call or override. |
protected void stopAutoScrolling() {
isAutoScrolling = false;
if ( autoscrollTimer != null ) {
autoscrollTimer.stop();
autoscrollTimer = null;
}
}
This protected method is implementation specific and should be private.
do not call or override. |
protected void togglePopup() {
if ( isVisible() ) {
hide();
}
else {
show();
}
}
Makes the popup visible if it is hidden and makes it hidden if it is
visible. |
protected void uninstallComboBoxModelListeners(ComboBoxModel model) {
if (model != null && listDataListener != null) {
model.removeListDataListener(listDataListener);
}
}
Removes the listeners from the combo box model |
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() {
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);
}
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(). |
protected void updateListBoxSelectionForEvent(MouseEvent anEvent,
boolean shouldScroll) {
// 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);
}
}
A utility method used by the event listeners. Given a mouse event, it changes
the list selection to the list item below the mouse. |