com.threerings.opengl.gui
Class ColorPicker

java.lang.Object
  extended by com.threerings.opengl.gui.Component
      extended by com.threerings.opengl.gui.ColorPicker
All Implemented Interfaces:
ConfigUpdateListener<ManagedConfig>, Selectable<ColorPository.ColorRecord>

public class ColorPicker
extends Component
implements Selectable<ColorPository.ColorRecord>

Allows the selection of a single color from a set of swatches.


Field Summary
protected  Color4f[] _colorizedRoots
          The colorized roots corresponding to each record.
protected  ColorPository.ColorRecord[] _colors
          The colors available for selection.
protected  int _sidx
          The currently selected index.
protected  int _swatchHeight
          The dimensions of the swatches.
protected  int _swatchWidth
          The dimensions of the swatches.
 
Fields inherited from class com.threerings.opengl.gui.Component
_alpha, _backgrounds, _borders, _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
 
Constructor Summary
ColorPicker(GlContext ctx)
          Creates an uninitialized color picker.
ColorPicker(GlContext ctx, String colorClass, int swatchWidth, int swatchHeight)
          Creates a new color picker.
 
Method Summary
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  String getDefaultStyleConfig()
          Returns the name of the default config to be used for all instances of this component.
 ColorPository.ColorRecord getSelected()
          Get the selected item, if any.
 ColorPository.ColorRecord getSelectedColor()
          Deprecated. 
 int getSelectedIndex()
          Get the index of the selected item, or -1.
protected  void renderComponent(Renderer renderer)
          Renders any custom bits for this component.
 void setColorClass(String colorClass)
          Sets the color class from which we select.
 void setColorClass(String colorClass, boolean starters)
          Sets the color class from which we select.
 void setSelected(ColorPository.ColorRecord color)
          Set the selected item.
 void setSelectedColor(ColorPository.ColorRecord color)
          Deprecated. 
 void setSelectedIndex(int sidx)
          Set the index of the selected item.
 void setSwatchSize(int swatchWidth, int swatchHeight)
          Sets the dimensions of the swatches.
 
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, layout, 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, updateFromStyleConfig, validate, wasAdded, wasRemoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_colors

protected ColorPository.ColorRecord[] _colors
The colors available for selection.


_colorizedRoots

protected Color4f[] _colorizedRoots
The colorized roots corresponding to each record.


_swatchWidth

protected int _swatchWidth
The dimensions of the swatches.


_swatchHeight

protected int _swatchHeight
The dimensions of the swatches.


_sidx

protected int _sidx
The currently selected index.

Constructor Detail

ColorPicker

public ColorPicker(GlContext ctx,
                   String colorClass,
                   int swatchWidth,
                   int swatchHeight)
Creates a new color picker.

Parameters:
colorClass - the color class from which we select.
swatchWidth - the width of the swatches.
swatchHeight - the height of the swatches.

ColorPicker

public ColorPicker(GlContext ctx)
Creates an uninitialized color picker.

Method Detail

setColorClass

public void setColorClass(String colorClass)
Sets the color class from which we select.


setColorClass

public void setColorClass(String colorClass,
                          boolean starters)
Sets the color class from which we select.

Parameters:
starters - if true, only allow the starter colors.

setSwatchSize

public void setSwatchSize(int swatchWidth,
                          int swatchHeight)
Sets the dimensions of the swatches.


getSelected

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

Specified by:
getSelected in interface Selectable<ColorPository.ColorRecord>

setSelected

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

Specified by:
setSelected in interface Selectable<ColorPository.ColorRecord>

setSelectedColor

@Deprecated
public void setSelectedColor(ColorPository.ColorRecord color)
Deprecated. 


getSelectedColor

@Deprecated
public ColorPository.ColorRecord getSelectedColor()
Deprecated. 


setSelectedIndex

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

Specified by:
setSelectedIndex in interface Selectable<ColorPository.ColorRecord>

getSelectedIndex

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

Specified by:
getSelectedIndex in interface Selectable<ColorPository.ColorRecord>

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 Component

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 Component
Returns:
the computed preferred size of this component in a newly created Dimension instance which will be adopted (and modified) by the caller.

renderComponent

protected void renderComponent(Renderer renderer)
Description copied from class: Component
Renders any custom bits for this component. This is called with the graphics context translated to (0, 0) relative to this component.

Overrides:
renderComponent in class Component