com.threerings.opengl.gui
Class Component

java.lang.Object
  extended by com.threerings.opengl.gui.Component
All Implemented Interfaces:
ConfigUpdateListener<ManagedConfig>
Direct Known Subclasses:
ColorPicker, Container, HTMLView, RenderableView, Slider, Spacer, TextComponent

public class Component
extends Object
implements ConfigUpdateListener<ManagedConfig>

The basic entity in the UI user interface system. A hierarchy of components and component derivations make up a user interface.


Field Summary
static int DEFAULT
          The default component state.
static int DISABLED
          A component state indicating that the component is disabled.
static int HOVER
          A component state indicating that the mouse is hovering over the component.
 
Constructor Summary
Component(GlContext ctx)
          Creates a new component.
 
Method Summary
 boolean acceptsFocus()
          Returns whether or not this component accepts the keyboard focus.
 void addListener(ComponentListener listener)
          Adds a listener to this component.
 String boundsToString()
          Returns our bounds as a nicely formatted string.
 void configUpdated(ConfigEvent<ManagedConfig> event)
          Called when a configuration has been updated.
 boolean contains(int mx, int my)
          Determines whether this component contains the specified coordinates.
static Component createDefaultTooltipComponent(GlContext ctx, String tiptext)
          Creates a tooltip component of the default form with the default style.
static Component createDefaultTooltipComponent(GlContext ctx, String tiptext, ConfigReference<StyleConfig> tipstyle)
          Creates a tooltip component of the default form.
 boolean dispatchEvent(Event event)
          Instructs this component to process the supplied event.
 int getAbsoluteX()
          Returns the x position of this component in absolute screen coordinates.
 int getAbsoluteY()
          Returns the y position of this component in absolute screen coordinates.
 float getAlpha()
          Returns the alpha transparency of this component.
 Background getBackground()
          Returns a reference to the background used by this component.
 Border getBorder()
          Returns the currently active border for this component.
 Rectangle getBounds()
          Returns the bounds of this component in a new rectangle.
 Color4f getColor()
          Returns the (foreground) color configured for this component.
 GlContext getContext()
          Returns a reference to the component context.
 Cursor getCursor()
          Returns a reference to the cursor used by this component.
 Component getFocusTarget()
          Returns the component that should receive focus if this component is clicked.
 int getHeight()
          Returns the height of this component.
 Component getHitComponent(int mx, int my)
          Returns the component "hit" by the specified mouse coordinates which might be this component or any of its children.
 Insets getInsets()
          Returns the insets configured on this component.
 Container getParent()
          Returns the parent of this component in the interface hierarchy.
 Dimension getPreferredSize(int whint, int hhint)
          Returns the preferred size of this component, supplying a width and or height hint to the component to inform it of restrictions in one of the two dimensions.
 Object getProperty(String key)
          Returns the user defined property mapped to the specified key, or null.
 int getState()
          Returns the state of this component, either DEFAULT or DISABLED.
 StyleConfig[] getStyleConfigs()
          Returns a reference to the component's array of style configs.
 String getTooltipText()
          Returns the tooltip text configured for this component.
 float getTooltipTimeout()
          Returns the component's tooltip timeout, or -1 to use the default.
 String getTooltipWindowStyle()
          Returns a reference to the component's tooltip window style config.
 TransferHandler getTransferHandler()
          Returns the transfer handler for this component.
 int getWidth()
          Returns the width of this component.
 int getX()
          Returns the x coordinate of this component.
 int getY()
          Returns the y coordinate of this component.
 boolean hasFocus()
          Returns true if this component has the focus.
 void invalidate()
          Marks this component as invalid and needing a relayout.
 boolean isAdded()
          Returns true if this component is added to a hierarchy of components that culminates in a top-level window.
 boolean isEnabled()
          Returns true if this component is enabled and responding to user interaction, false if not.
 boolean isHoverable()
          Returns this component's hoverability state.
 boolean isShowing()
          Returns true if this component is both added to the interface hierarchy and visible, false if not.
 boolean isTooltipRelativeToMouse()
          Returns true if the tooltip window should be position relative to the mouse.
 boolean isValid()
          Returns true if this component has been validated and laid out.
 boolean isVisible()
          Returns true if this component is visible, false if it is not.
 void removeAllListeners()
          Removes all listeners registered on this component.
 void removeAllListeners(Class<? extends ComponentListener> clazz)
          Removes all listeners of the specified class.
 boolean removeListener(ComponentListener listener)
          Removes a listener from this component.
 void render(Renderer renderer)
          Translates into the component's coordinate space, renders the background and border and then calls renderComponent(com.threerings.opengl.renderer.Renderer) to allow the component to render itself.
 void requestFocus()
          Requests that this component be given the input focus.
 void scrollRectToVisible(int x, int y, int w, int h)
          Request to have the specified rectangle, in this component's coordinate space, scrolled into view.
 void setAlpha(float alpha)
          Sets the alpha level for this component.
 void setBackground(int state, Background background)
          Configures the background for this component for the specified state.
 void setBounds(int x, int y, int width, int height)
          Sets the bounds of this component in screen coordinates.
 void setCursor(Cursor cursor)
          Configures the cursor for this component.
 void setEnabled(boolean enabled)
          Sets this components enabled state.
 void setHoverable(boolean hoverable)
          Sets this component's hoverability state.
 void setLocation(int x, int y)
          Sets the upper left position of this component in absolute screen coordinates.
 void setParent(Container parent)
          Informs this component of its parent in the interface heirarchy.
 void setPreferredSize(Dimension preferredSize)
          Configures the preferred size of this component.
 void setPreferredSize(int width, int height)
          Configures the preferred size of this component.
 void setProperty(String key, Object value)
          Sets a user defined property on this component.
 void setSize(int width, int height)
          Sets the width and height of this component in screen coordinates.
 void setStyleConfig(ConfigReference<StyleConfig> ref)
          Sets the style configuration.
 void setStyleConfig(String name)
          Sets the style configuration.
 void setStyleConfig(String name, String firstKey, Object firstValue, Object... otherArgs)
          Sets the style configuration.
 void setStyleConfigs(StyleConfig... styleConfigs)
          Sets the style configurations.
 void setTooltipRelativeToMouse(boolean mouse)
          Sets where to position the tooltip window.
 void setTooltipText(String text)
          Configures the tooltip text for this component.
 void setTransferHandler(TransferHandler handler)
          Sets the transfer handler for this component.
 void setVisible(boolean visible)
          Sets this component's visibility state.
 void validate()
          Instructs this component to lay itself out and then mark itself as valid.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

public static final int DEFAULT
The default component state. This is used to select the component's style pseudoclass among other things.

See Also:
Constant Field Values

HOVER

public static final int HOVER
A component state indicating that the mouse is hovering over the component. This is used to select the component's style pseudoclass among other things.

See Also:
Constant Field Values

DISABLED

public static final int DISABLED
A component state indicating that the component is disabled. This is used to select the component's style pseudoclass among other things.

See Also:
Constant Field Values
Constructor Detail

Component

public Component(GlContext ctx)
Creates a new component.

Method Detail

createDefaultTooltipComponent

public static Component createDefaultTooltipComponent(GlContext ctx,
                                                      String tiptext)
Creates a tooltip component of the default form with the default style.


createDefaultTooltipComponent

public static Component createDefaultTooltipComponent(GlContext ctx,
                                                      String tiptext,
                                                      ConfigReference<StyleConfig> tipstyle)
Creates a tooltip component of the default form.


getContext

public GlContext getContext()
Returns a reference to the component context.


setStyleConfig

public void setStyleConfig(String name)
Sets the style configuration.


setStyleConfig

public void setStyleConfig(String name,
                           String firstKey,
                           Object firstValue,
                           Object... otherArgs)
Sets the style configuration.


setStyleConfig

public void setStyleConfig(ConfigReference<StyleConfig> ref)
Sets the style configuration.


setStyleConfigs

public void setStyleConfigs(StyleConfig... styleConfigs)
Sets the style configurations.


getStyleConfigs

public StyleConfig[] getStyleConfigs()
Returns a reference to the component's array of style configs.


getTooltipWindowStyle

public String getTooltipWindowStyle()
Returns a reference to the component's tooltip window style config.


setParent

public void setParent(Container parent)
Informs this component of its parent in the interface heirarchy.


getParent

public Container getParent()
Returns the parent of this component in the interface hierarchy.


getPreferredSize

public Dimension getPreferredSize(int whint,
                                  int hhint)
Returns the preferred size of this component, supplying a width and or height hint to the component to inform it of restrictions in one of the two dimensions. Not all components will make use of the hints, but layout managers should provide them if they know the component will be forced to a particular width or height regardless of what it prefers.


setPreferredSize

public void setPreferredSize(Dimension preferredSize)
Configures the preferred size of this component. This will override any information provided by derived classes that have opinions about their preferred size. Either the width or the height can be configured as -1 in which case the computed preferred size will be used for that dimension.


setPreferredSize

public void setPreferredSize(int width,
                             int height)
Configures the preferred size of this component. See setPreferredSize(Dimension).


getX

public int getX()
Returns the x coordinate of this component.


getY

public int getY()
Returns the y coordinate of this component.


getWidth

public int getWidth()
Returns the width of this component.


getHeight

public int getHeight()
Returns the height of this component.


getAbsoluteX

public int getAbsoluteX()
Returns the x position of this component in absolute screen coordinates.


getAbsoluteY

public int getAbsoluteY()
Returns the y position of this component in absolute screen coordinates.


getBounds

public Rectangle getBounds()
Returns the bounds of this component in a new rectangle.


getInsets

public Insets getInsets()
Returns the insets configured on this component. null will never be returned, an Insets instance with all fields set to zero will be returned instead.


getColor

public Color4f getColor()
Returns the (foreground) color configured for this component.


boundsToString

public String boundsToString()
Returns our bounds as a nicely formatted string.


getBorder

public Border getBorder()
Returns the currently active border for this component.


getBackground

public Background getBackground()
Returns a reference to the background used by this component.


setBackground

public void setBackground(int state,
                          Background background)
Configures the background for this component for the specified state.


getCursor

public Cursor getCursor()
Returns a reference to the cursor used by this component.


setCursor

public void setCursor(Cursor cursor)
Configures the cursor for this component. This must only be called after the component has been added to the interface hierarchy or the value will be overridden by the stylesheet associated with this component.


setAlpha

public void setAlpha(float alpha)
Sets the alpha level for this component.


getAlpha

public float getAlpha()
Returns the alpha transparency of this component.


setEnabled

public void setEnabled(boolean enabled)
Sets this components enabled state. A component that is not enabled should not respond to user interaction and should render itself in such a way as not to afford user interaction.


isEnabled

public boolean isEnabled()
Returns true if this component is enabled and responding to user interaction, false if not.


setVisible

public void setVisible(boolean visible)
Sets this component's visibility state. A component that is invisible is not rendered and does not contribute to the layout.


isVisible

public boolean isVisible()
Returns true if this component is visible, false if it is not.


setHoverable

public void setHoverable(boolean hoverable)
Sets this component's hoverability state.


isHoverable

public boolean isHoverable()
Returns this component's hoverability state.


isShowing

public boolean isShowing()
Returns true if this component is both added to the interface hierarchy and visible, false if not.


getState

public int getState()
Returns the state of this component, either DEFAULT or DISABLED.


setProperty

public void setProperty(String key,
                        Object value)
Sets a user defined property on this component. User defined properties allow the association of arbitrary additional data with a component for application specific purposes.


getProperty

public Object getProperty(String key)
Returns the user defined property mapped to the specified key, or null.


acceptsFocus

public boolean acceptsFocus()
Returns whether or not this component accepts the keyboard focus.


hasFocus

public boolean hasFocus()
Returns true if this component has the focus.


getFocusTarget

public Component getFocusTarget()
Returns the component that should receive focus if this component is clicked. If this component does not accept focus, its parent will be checked and so on.


requestFocus

public void requestFocus()
Requests that this component be given the input focus.


setLocation

public void setLocation(int x,
                        int y)
Sets the upper left position of this component in absolute screen coordinates.


setSize

public void setSize(int width,
                    int height)
Sets the width and height of this component in screen coordinates.


setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Sets the bounds of this component in screen coordinates.

See Also:
setLocation(int, int), setSize(int, int)

addListener

public void addListener(ComponentListener listener)
Adds a listener to this component. The listener will be notified when events of the appropriate type are dispatched on this component.


removeListener

public boolean removeListener(ComponentListener listener)
Removes a listener from this component. Returns true if the listener was in fact in the listener list for this component, false if not.


removeAllListeners

public void removeAllListeners()
Removes all listeners registered on this component.


removeAllListeners

public void removeAllListeners(Class<? extends ComponentListener> clazz)
Removes all listeners of the specified class.


setTooltipText

public void setTooltipText(String text)
Configures the tooltip text for this component. If the text starts with <html> then the tooltip will be displayed with an @{link HTMLView} otherwise it will be displayed with a Label.


getTooltipText

public String getTooltipText()
Returns the tooltip text configured for this component.


setTooltipRelativeToMouse

public void setTooltipRelativeToMouse(boolean mouse)
Sets where to position the tooltip window.

Parameters:
mouse - if true, the window will appear relative to the mouse position, if false, the window will appear relative to the component bounds.

isTooltipRelativeToMouse

public boolean isTooltipRelativeToMouse()
Returns true if the tooltip window should be position relative to the mouse.


getTooltipTimeout

public float getTooltipTimeout()
Returns the component's tooltip timeout, or -1 to use the default.


setTransferHandler

public void setTransferHandler(TransferHandler handler)
Sets the transfer handler for this component.


getTransferHandler

public TransferHandler getTransferHandler()
Returns the transfer handler for this component. If this component has no handler of its own, then the request will be forwarded to the parent, and so on.


isAdded

public boolean isAdded()
Returns true if this component is added to a hierarchy of components that culminates in a top-level window.


isValid

public boolean isValid()
Returns true if this component has been validated and laid out.


validate

public void validate()
Instructs this component to lay itself out and then mark itself as valid.


invalidate

public void invalidate()
Marks this component as invalid and needing a relayout. If the component is valid, its parent will also be marked as invalid.


render

public void render(Renderer renderer)
Translates into the component's coordinate space, renders the background and border and then calls renderComponent(com.threerings.opengl.renderer.Renderer) to allow the component to render itself.


getHitComponent

public Component getHitComponent(int mx,
                                 int my)
Returns the component "hit" by the specified mouse coordinates which might be this component or any of its children. This method should return null if the supplied mouse coordinates are outside the bounds of this component.


contains

public boolean contains(int mx,
                        int my)
Determines whether this component contains the specified coordinates.


scrollRectToVisible

public void scrollRectToVisible(int x,
                                int y,
                                int w,
                                int h)
Request to have the specified rectangle, in this component's coordinate space, scrolled into view. This request will be repeatedly forwarded to parent containers until one can handle the request. If no ScrollPane's viewport contains this component then this request is unlikely to do anything.


dispatchEvent

public boolean dispatchEvent(Event event)
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".

Returns:
true if this event was consumed, false if not.

configUpdated

public void configUpdated(ConfigEvent<ManagedConfig> event)
Description copied from interface: ConfigUpdateListener
Called when a configuration has been updated.

Specified by:
configUpdated in interface ConfigUpdateListener<ManagedConfig>


Copyright © 2011. All Rights Reserved.