com.jmex.bui
Class BComboBox

java.lang.Object
  extended by com.jmex.bui.BComponent
      extended by com.jmex.bui.BTextComponent
          extended by com.jmex.bui.BLabel
              extended by com.jmex.bui.BComboBox
All Implemented Interfaces:
BConstants

public class BComboBox
extends BLabel

Displays a selected value and allows that value to be changed by selecting from a popup menu.


Nested Class Summary
protected  class BComboBox.ComboMenuItem
           
protected  class BComboBox.ComboPopupMenu
           
static class BComboBox.Item
          Used for displaying a label that is associated with a particular non-displayable value.
 
Nested classes/interfaces inherited from class com.jmex.bui.BLabel
BLabel.Fit
 
Field Summary
protected  int _columns
          Our preferred number of columns for the popup menu.
protected  ArrayList<BComboBox.ComboMenuItem> _items
          The list of items in this combo box.
protected  BComboBox.ComboPopupMenu _menu
          A cached popup menu containing our items.
protected  Dimension _psize
          Our cached preferred size.
protected  int _selidx
          The index of the currently selected item.
 
Fields inherited from class com.jmex.bui.BLabel
_label
 
Fields inherited from class com.jmex.bui.BTextComponent
_effcols, _effsizes, _haligns, _lineSpacings, _teffects, _textfacts, _valigns
 
Fields inherited from class com.jmex.bui.BComponent
_alpha, _backgrounds, _bbuf, _borders, _colors, _cursor, _enabled, _height, _hover, _insets, _listeners, _parent, _preferredSize, _properties, _styleClass, _tipmouse, _tipStyle, _tiptext, _valid, _visible, _width, _x, _y, DEFAULT, DISABLED, HOVER, STATE_COUNT, STATE_PCLASSES
 
Fields inherited from interface com.jmex.bui.BConstants
BOTTOM, CENTER, DEFAULT_SIZE, DEFAULT_SPACING, GLOW, HORIZONTAL, LEFT, NORMAL, OUTLINE, OVERLAPPING, PLAIN, RIGHT, SHADOW, TOP, VERTICAL
 
Constructor Summary
BComboBox()
          Creates an empty combo box.
BComboBox(Iterable<?> items)
          Creates a combo box with the supplied set of items.
BComboBox(Object[] items)
          Creates a combo box with the supplied set of items.
 
Method Summary
 void addItem(int index, Object item)
          Inserts an item into our list of items at the specified position (zero being before all other items and so forth).
 void addItem(Object item)
          Appends an item to our list of items.
protected  void clearCache()
           
 void clearItems()
          Removes all items from this combo box.
protected  Dimension computePreferredSize(int whint, int hhint)
          Computes and returns a preferred size for this component.
 boolean dispatchEvent(BEvent event)
          Instructs this component to process the supplied event.
protected  String getDefaultStyleClass()
          Returns the default stylesheet class to be used for all instances of this component.
 Object getItem(int index)
          Returns the item at the specified index.
 int getItemCount()
          Returns the number of items in this combo box.
 int getSelectedIndex()
          Returns the index of the selected item or -1 if no item is selected.
 Object getSelectedItem()
          Returns the selected item or null if no item is selected.
 Object getSelectedValue()
          Requires that the combo box be configured with BComboBox.Item items, returns the BComboBox.Item.value of the currently selected item.
 Object getValue(int index)
          Returns the value at the specified index, the item must be an instance of BComboBox.Item.
 void selectItem(int index)
          Selects the item with the specified index.
protected  void selectItem(int index, long when, int modifiers)
           
 void selectItem(Object item)
          Selects the item with the specified index.
 void selectValue(Object value)
          Requires that the combo box be configured with BComboBox.Item items, selects the item with a BComboBox.Item.value equal to the supplied value.
 void setItems(Iterable<?> items)
          Replaces any existing items in this combo box with the supplied items.
 void setItems(Object[] items)
          Replaces any existing items in this combo box with the supplied items.
 void setPreferredColumns(int columns)
          Sets the preferred number of columns in the popup menu.
 
Methods inherited from class com.jmex.bui.BLabel
getFit, getIcon, getIconTextGap, getText, layout, renderComponent, setFit, setIcon, setIconTextGap, setOrientation, setText, wasAdded, wasRemoved
 
Methods inherited from class com.jmex.bui.BTextComponent
checkNonDefault, checkNonDefaultInt, checkNonDefaultVal, configureStyle, getEffectColor, getEffectSize, getHorizontalAlignment, getLabelConfig, getLineSpacing, getTextEffect, getTextFactory, getTextFactory, getVerticalAlignment
 
Methods inherited from class com.jmex.bui.BComponent
acceptsFocus, addListener, applyDefaultStates, boundsToString, changeCursor, createTooltipComponent, emitEvent, getAbsoluteX, getAbsoluteY, getAlpha, getBackground, getBorder, getBounds, getColor, getCursor, getFocusTarget, getHeight, getHitComponent, getInsets, getNextFocus, getParent, getPreferredSize, getPreviousFocus, getProperty, getState, getStateCount, getStatePseudoClass, getStyleClass, getTooltipText, getWidth, getWindow, getX, getY, hasFocus, intersectScissorBox, invalidate, isAdded, isEnabled, isShowing, isTooltipRelativeToMouse, isValid, isVisible, removeAllListeners, removeListener, render, renderBackground, renderBorder, requestFocus, restoreScissorState, setAlpha, setBackground, setBounds, setCursor, setEnabled, setLocation, setParent, setPreferredSize, setPreferredSize, setProperty, setSize, setStyleClass, setTooltipRelativeToMouse, setTooltipText, setVisible, stateDidChange, updateCursor, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_selidx

protected int _selidx
The index of the currently selected item.


_items

protected ArrayList<BComboBox.ComboMenuItem> _items
The list of items in this combo box.


_menu

protected BComboBox.ComboPopupMenu _menu
A cached popup menu containing our items.


_psize

protected Dimension _psize
Our cached preferred size.


_columns

protected int _columns
Our preferred number of columns for the popup menu.

Constructor Detail

BComboBox

public BComboBox()
Creates an empty combo box.


BComboBox

public BComboBox(Object[] items)
Creates a combo box with the supplied set of items. The result of Object.toString() for each item will be displayed in the list.


BComboBox

public BComboBox(Iterable<?> items)
Creates a combo box with the supplied set of items. The result of Object.toString() for each item will be displayed in the list.

Method Detail

addItem

public void addItem(Object item)
Appends an item to our list of items. The result of Object.toString() for the item will be displayed in the list.


addItem

public void addItem(int index,
                    Object item)
Inserts an item into our list of items at the specified position (zero being before all other items and so forth). The result of Object.toString() for the item will be displayed in the list.


setItems

public void setItems(Iterable<?> items)
Replaces any existing items in this combo box with the supplied items.


setItems

public void setItems(Object[] items)
Replaces any existing items in this combo box with the supplied items.


getSelectedIndex

public int getSelectedIndex()
Returns the index of the selected item or -1 if no item is selected.


getSelectedItem

public Object getSelectedItem()
Returns the selected item or null if no item is selected.


getSelectedValue

public Object getSelectedValue()
Requires that the combo box be configured with BComboBox.Item items, returns the BComboBox.Item.value of the currently selected item.


selectItem

public void selectItem(int index)
Selects the item with the specified index.


selectItem

public void selectItem(Object item)
Selects the item with the specified index. Note: the supplied item is compared with the item list using Object.equals(java.lang.Object).


selectValue

public void selectValue(Object value)
Requires that the combo box be configured with BComboBox.Item items, selects the item with a BComboBox.Item.value equal to the supplied value.


getItemCount

public int getItemCount()
Returns the number of items in this combo box.


getItem

public Object getItem(int index)
Returns the item at the specified index.


getValue

public Object getValue(int index)
Returns the value at the specified index, the item must be an instance of BComboBox.Item.


clearItems

public void clearItems()
Removes all items from this combo box.


setPreferredColumns

public void setPreferredColumns(int columns)
Sets the preferred number of columns in the popup menu.


dispatchEvent

public boolean dispatchEvent(BEvent event)
Description copied from class: BComponent
Instructs this component to process the supplied event. If the event is not processed, it will be passed up to its parent component for processing. Derived classes should thus only call super.dispatchEvent for events that they did not "consume".

Overrides:
dispatchEvent in class BComponent
Returns:
true if this event was consumed, false if not.

getDefaultStyleClass

protected String getDefaultStyleClass()
Description copied from class: BComponent
Returns the default stylesheet class to be used for all instances of this component. Derived classes will likely want to override this method and set up a default class for their type of component.

Overrides:
getDefaultStyleClass in class BLabel

computePreferredSize

protected Dimension computePreferredSize(int whint,
                                         int hhint)
Description copied from class: BComponent
Computes and returns a preferred size for this component. This method is called if no overriding preferred size has been supplied.

Overrides:
computePreferredSize in class BLabel
Returns:
the computed preferred size of this component in a newly created Dimension instance which will be adopted (and modified) by the caller.

selectItem

protected void selectItem(int index,
                          long when,
                          int modifiers)

clearCache

protected void clearCache()


Copyright © 2008 Michael Bayne. All Rights Reserved.