com.threerings.opengl.gui
Class ComboBox

java.lang.Object
  extended by com.threerings.opengl.gui.Component
      extended by com.threerings.opengl.gui.TextComponent
          extended by com.threerings.opengl.gui.Label
              extended by com.threerings.opengl.gui.ComboBox
All Implemented Interfaces:
ConfigUpdateListener<ManagedConfig>, Selectable<Object>, UIConstants

public class ComboBox
extends Label
implements Selectable<Object>

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


Nested Class Summary
protected static class ComboBox.ComboMenuItem
           
protected  class ComboBox.ComboPopupMenu
           
static class ComboBox.DefaultFormatter
          The default formatter for a ComboBox.
static interface ComboBox.Formatter
          Formats the items held in a ComboBox into their icon and label.
static class ComboBox.Item
          Used for displaying a label that is associated with a particular non-displayable value.
 
Nested classes/interfaces inherited from class com.threerings.opengl.gui.Label
Label.Fit
 
Field Summary
protected  int _columns
          Our preferred number of rows and columns for the popup menu.
protected  ComboBox.Formatter _formatter
          Our item formatter.
protected  List<ComboBox.ComboMenuItem> _items
          The list of items in this combo box.
protected  ComboBox.ComboPopupMenu _menu
          A cached popup menu containing our items.
protected  Dimension _psize
          Our cached preferred size.
protected  int _rows
          Our preferred number of rows and columns for the popup menu.
protected  int _selidx
          The index of the currently selected item.
 
Fields inherited from class com.threerings.opengl.gui.Label
_label
 
Fields inherited from class com.threerings.opengl.gui.TextComponent
_effcols, _effsizes, _haligns, _lineSpacings, _teffects, _textfacts, _valigns
 
Fields inherited from class com.threerings.opengl.gui.Component
_alpha, _backgrounds, _borders, _colors, _ctx, _cursor, _enabled, _height, _hover, _hoverable, _insets, _listeners, _parent, _preferredSize, _properties, _rect, _styleConfigs, _tipmouse, _tiptext, _tooltipStyle, _transferHandler, _valid, _visible, _width, _x, _y, DEFAULT, DISABLED, HOVER, STATE_COUNT, STATE_PCLASSES
 
Fields inherited from interface com.threerings.opengl.gui.Selectable
SELECT
 
Fields inherited from interface com.threerings.opengl.gui.UIConstants
BOTTOM, CENTER, DEFAULT_SIZE, DEFAULT_SPACING, GLOW, HORIZONTAL, LEFT, NORMAL, OUTLINE, OVERLAPPING, PLAIN, RIGHT, SHADOW, TOP, VERTICAL
 
Constructor Summary
ComboBox(GlContext ctx)
          Creates an empty combo box.
ComboBox(GlContext ctx, Iterable<?> items)
          Creates a combo box with the supplied set of items.
ComboBox(GlContext ctx, 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(Event event)
          Instructs this component to process the supplied event.
protected  void format(Label label, Object item)
          Format the specified label.
protected  String getDefaultStyleConfig()
          Returns the name of the default config 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.
protected  List<Object> getItems()
          Get the raw list of items.
 Object getSelected()
          Get the selected item, if any.
 int getSelectedIndex()
          Get the index of the selected item, or -1.
 Object getSelectedItem()
          Deprecated. 
 Object getSelectedValue()
          Requires that the combo box be configured with ComboBox.Item items, returns the ComboBox.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 ComboBox.Item.
 void selectItem(int index)
          Deprecated. 
protected  void selectItem(int index, long when, int modifiers)
           
 void selectItem(Object item)
          Deprecated. 
 void selectValue(Object value)
          Requires that the combo box be configured with ComboBox.Item items, selects the item with a ComboBox.Item.value equal to the supplied value.
 void setFormatter(ComboBox.Formatter formatter)
          Set the formatter that determines how items are labeled.
 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 setPreferredDimensions(int rows, int columns)
          Sets the preferred number of columns in the popup menu.
 void setSelected(Object item)
          Set the selected item.
 void setSelectedIndex(int index)
          Set the index of the selected item.
 
Methods inherited from class com.threerings.opengl.gui.Label
getFit, getIcon, getIconTextGap, getLabelRenderer, getText, layout, renderComponent, setFit, setIcon, setIconTextGap, setOrientation, setPreferredWidth, setText, setTextRotation
 
Methods inherited from class com.threerings.opengl.gui.TextComponent
getEffectColor, getEffectSize, getHorizontalAlignment, getLabelRendererConfig, getLineSpacing, getTextEffect, getTextFactory, getTextFactory, getVerticalAlignment, updateFromStyleConfig
 
Methods inherited from class com.threerings.opengl.gui.Component
acceptsFocus, addListener, boundsToString, changeCursor, configUpdated, contains, createDefaultTooltipComponent, createDefaultTooltipComponent, createTooltipComponent, emitEvent, getAbsoluteX, getAbsoluteY, getAlpha, getBackground, getBorder, getBounds, getColor, getContext, getCursor, getFallbackState, getFirstDescendantFocus, getFocusTarget, getHeight, getHitComponent, getInsets, getLastDescendantFocus, getNextFocus, getParent, getPreferredSize, getPreviousFocus, getProperty, getState, getStateCount, getStatePseudoClass, getStyleConfigs, getTooltipText, getTooltipTimeout, getTooltipWindowStyle, getTransferHandler, getWidth, getWindow, getX, getY, hasFocus, intersectScissor, invalidate, isAdded, isEnabled, isHoverable, isShowing, isTooltipRelativeToMouse, isValid, isVisible, removeAllListeners, removeAllListeners, removeListener, render, renderBackground, renderBorder, requestFocus, scrollRectToVisible, scrollRectToVisible, setAlpha, setBackground, setBounds, setCursor, setEnabled, setHoverable, setLocation, setParent, setPreferredSize, setPreferredSize, setProperty, setSize, setStyleConfig, setStyleConfig, setStyleConfig, setStyleConfigs, setTooltipRelativeToMouse, setTooltipText, setTransferHandler, setVisible, stateDidChange, updateCursor, updateFromStyleConfig, validate, wasAdded, wasRemoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_formatter

protected ComboBox.Formatter _formatter
Our item formatter.


_selidx

protected int _selidx
The index of the currently selected item.


_items

protected List<ComboBox.ComboMenuItem> _items
The list of items in this combo box.


_menu

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


_psize

protected Dimension _psize
Our cached preferred size.


_rows

protected int _rows
Our preferred number of rows and columns for the popup menu.


_columns

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

Constructor Detail

ComboBox

public ComboBox(GlContext ctx)
Creates an empty combo box.


ComboBox

public ComboBox(GlContext ctx,
                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.


ComboBox

public ComboBox(GlContext ctx,
                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

setFormatter

public void setFormatter(ComboBox.Formatter formatter)
Set the formatter that determines how items are labeled.


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.


getSelected

public Object getSelected()
Description copied from interface: Selectable
Get the selected item, if any.

Specified by:
getSelected in interface Selectable<Object>

setSelected

public void setSelected(Object item)
Description copied from interface: Selectable
Set the selected item.

Specified by:
setSelected in interface Selectable<Object>

getSelectedIndex

public int getSelectedIndex()
Description copied from interface: Selectable
Get the index of the selected item, or -1.

Specified by:
getSelectedIndex in interface Selectable<Object>

setSelectedIndex

public void setSelectedIndex(int index)
Description copied from interface: Selectable
Set the index of the selected item.

Specified by:
setSelectedIndex in interface Selectable<Object>

getSelectedItem

@Deprecated
public Object getSelectedItem()
Deprecated. 


getSelectedValue

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


selectItem

@Deprecated
public void selectItem(int index)
Deprecated. 


selectItem

@Deprecated
public void selectItem(Object item)
Deprecated. 


selectValue

public void selectValue(Object value)
Requires that the combo box be configured with ComboBox.Item items, selects the item with a ComboBox.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 ComboBox.Item.


clearItems

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


setPreferredDimensions

public void setPreferredDimensions(int rows,
                                   int columns)
Sets the preferred number of columns in the popup menu.


dispatchEvent

public boolean dispatchEvent(Event event)
Description copied from class: Component
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 Component
Returns:
true if this event was consumed, false if not.

getDefaultStyleConfig

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

Overrides:
getDefaultStyleConfig in class Label

computePreferredSize

protected Dimension computePreferredSize(int whint,
                                         int hhint)
Description copied from class: Component
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 Label
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()

format

protected void format(Label label,
                      Object item)
Format the specified label.


getItems

protected List<Object> getItems()
Get the raw list of items.