com.jmex.bui
Class BComponent

java.lang.Object
  extended by com.jmex.bui.BComponent
Direct Known Subclasses:
BContainer, BGeomView, BSlider, BTextComponent, HTMLView, Spacer

public class BComponent
extends Object

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


Field Summary
protected  float _alpha
           
protected  BBackground[] _backgrounds
           
protected static IntBuffer _bbuf
          Temporary storage for scissor box queries.
protected  BBorder[] _borders
           
protected  ColorRGBA[] _colors
           
protected  BCursor _cursor
           
protected  boolean _enabled
           
protected  int _height
           
protected  boolean _hover
           
protected  Insets[] _insets
           
protected  ArrayList<ComponentListener> _listeners
           
protected  BContainer _parent
           
protected  Dimension _preferredSize
           
protected  HashMap<String,Object> _properties
           
protected  String _styleClass
           
protected  boolean _tipmouse
           
protected  String _tipStyle
           
protected  String _tiptext
           
protected  boolean _valid
           
protected  boolean _visible
           
protected  int _width
           
protected  int _x
           
protected  int _y
           
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.
protected static int STATE_COUNT
           
protected static String[] STATE_PCLASSES
           
 
Constructor Summary
BComponent()
           
 
Method Summary
 boolean acceptsFocus()
          Returns whether or not this component accepts the keyboard focus.
 void addListener(ComponentListener listener)
          Adds a listener to this component.
static void applyDefaultStates()
           
 String boundsToString()
          Returns our bounds as a nicely formatted string.
protected  boolean changeCursor()
          Returns true if the component should update the mouse cursor.
protected  Dimension computePreferredSize(int whint, int hhint)
          Computes and returns a preferred size for this component.
protected  void configureStyle(BStyleSheet style)
          Instructs this component to fetch its style configuration from the supplied style sheet.
protected  BComponent createTooltipComponent(String tiptext)
          Creates the component that will be used to display our tooltip.
 boolean dispatchEvent(BEvent event)
          Instructs this component to process the supplied event.
protected  boolean emitEvent(BEvent event)
          Dispatches an event emitted by this component.
 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.
 BBackground getBackground()
          Returns a reference to the background used by this component.
 BBorder getBorder()
          Returns the currently active border for this component.
 Rectangle getBounds()
          Returns the bounds of this component in a new rectangle.
 ColorRGBA getColor()
          Returns the (foreground) color configured for this component.
 BCursor getCursor()
          Returns a reference to the cursor used by this component.
protected  String getDefaultStyleClass()
          Returns the default stylesheet class to be used for all instances of this component.
 BComponent getFocusTarget()
          Returns the component that should receive focus if this component is clicked.
 int getHeight()
          Returns the height of this component.
 BComponent 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.
protected  BComponent getNextFocus()
          Searches for the next component that should receive the keyboard focus.
 BContainer 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.
protected  BComponent getPreviousFocus()
          Searches for the previous component that should receive the keyboard focus.
 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.
protected  int getStateCount()
          Returns the number of different states that this component can take.
protected  String getStatePseudoClass(int state)
          Returns the pseudoclass identifier for the specified component state.
 String getStyleClass()
          Returns the Style class to be used for this component.
 String getTooltipText()
          Returns the tooltip text configured for this component.
 int getWidth()
          Returns the width of this component.
protected  BWindow getWindow()
          Returns the window that defines the root of our component hierarchy.
 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.
protected static boolean intersectScissorBox(Rectangle store, int x, int y, int width, int height)
          Activates scissoring and sets the scissor region to the intersection of the current region (if any) and the specified rectangle.
 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 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.
protected  void layout()
          Instructs this component to lay itself out.
 void removeAllListeners()
          Removes all listeners registered on this component.
 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.jme.renderer.Renderer) to allow the component to render itself.
protected  void renderBackground(Renderer renderer)
          Renders the background for this component.
protected  void renderBorder(Renderer renderer)
          Renders the border for this component.
protected  void renderComponent(Renderer renderer)
          Renders any custom bits for this component.
 void requestFocus()
          Requests that this component be given the input focus.
protected static void restoreScissorState(boolean enabled, Rectangle rect)
          Restores the previous scissor state after a call to intersectScissorBox(com.jmex.bui.util.Rectangle, int, int, int, int).
 void setAlpha(float alpha)
          Sets the alpha level for this component.
 void setBackground(int state, BBackground 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(BCursor cursor)
          Configures the cursor for this component.
 void setEnabled(boolean enabled)
          Sets this components enabled state.
 void setLocation(int x, int y)
          Sets the upper left position of this component in absolute screen coordinates.
 void setParent(BContainer 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 setStyleClass(String styleClass)
          Configures this component with a custom stylesheet class.
 void setTooltipRelativeToMouse(boolean mouse)
          Sets where to position the tooltip window.
 void setTooltipText(String text)
          Configures the tooltip text for this component.
 void setVisible(boolean visible)
          Sets this component's visibility state.
protected  void stateDidChange()
          Called when the component's state has changed.
protected  void updateCursor(BCursor cursor)
          Updates the mouse cursor with the supplied cursor.
 void validate()
          Instructs this component to lay itself out and then mark itself as valid.
protected  void wasAdded()
          This method is called when we are added to a hierarchy that is connected to a top-level window (at which point we can rely on having a look and feel and can set ourselves up).
protected  void wasRemoved()
          This method is called when we are removed from a hierarchy that is connected to a top-level window.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, 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

_parent

protected BContainer _parent

_styleClass

protected String _styleClass

_preferredSize

protected Dimension _preferredSize

_x

protected int _x

_y

protected int _y

_width

protected int _width

_height

protected int _height

_listeners

protected ArrayList<ComponentListener> _listeners

_properties

protected HashMap<String,Object> _properties

_tiptext

protected String _tiptext

_tipStyle

protected String _tipStyle

_tipmouse

protected boolean _tipmouse

_valid

protected boolean _valid

_enabled

protected boolean _enabled

_visible

protected boolean _visible

_hover

protected boolean _hover

_alpha

protected float _alpha

_colors

protected ColorRGBA[] _colors

_insets

protected Insets[] _insets

_borders

protected BBorder[] _borders

_backgrounds

protected BBackground[] _backgrounds

_cursor

protected BCursor _cursor

_bbuf

protected static IntBuffer _bbuf
Temporary storage for scissor box queries.


STATE_COUNT

protected static final int STATE_COUNT
See Also:
Constant Field Values

STATE_PCLASSES

protected static final String[] STATE_PCLASSES
Constructor Detail

BComponent

public BComponent()
Method Detail

applyDefaultStates

public static void applyDefaultStates()

setStyleClass

public void setStyleClass(String styleClass)
Configures this component with a custom stylesheet class. By default a component's class is defined by its component type (label, button, checkbox, etc.) but one can provide custom style information to a component by configuring it with a custom class and defining that class in the applicable stylesheet.


getStyleClass

public String getStyleClass()
Returns the Style class to be used for this component.


setParent

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


getParent

public BContainer 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 ColorRGBA getColor()
Returns the (foreground) color configured for this component.


boundsToString

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


getBorder

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


getBackground

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


setBackground

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


getCursor

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


setCursor

public void setCursor(BCursor 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.


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 BComponent 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.


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 BLabel.


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.


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.jme.renderer.Renderer) to allow the component to render itself.


getHitComponent

public BComponent 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.


dispatchEvent

public boolean dispatchEvent(BEvent 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.

layout

protected void layout()
Instructs this component to lay itself out. This is called as a result of the component changing size.


computePreferredSize

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

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

wasAdded

protected void wasAdded()
This method is called when we are added to a hierarchy that is connected to a top-level window (at which point we can rely on having a look and feel and can set ourselves up).


configureStyle

protected void configureStyle(BStyleSheet style)
Instructs this component to fetch its style configuration from the supplied style sheet. This method is called when a component is added to the interface hierarchy.


wasRemoved

protected void wasRemoved()
This method is called when we are removed from a hierarchy that is connected to a top-level window. If we wish to clean up after things done in wasAdded(), this is a fine place to do so.


createTooltipComponent

protected BComponent createTooltipComponent(String tiptext)
Creates the component that will be used to display our tooltip. This method will only be called if getTooltipText() returns non-null text.


renderBackground

protected void renderBackground(Renderer renderer)
Renders the background for this component.


renderBorder

protected void renderBorder(Renderer renderer)
Renders the border for this component.


renderComponent

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


getDefaultStyleClass

protected String getDefaultStyleClass()
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.


getStateCount

protected int getStateCount()
Returns the number of different states that this component can take. These states correspond to stylesheet pseudoclasses that allow components to customize their configuration based on whether they are enabled or disabled, or pressed if they are a button, etc.


getStatePseudoClass

protected String getStatePseudoClass(int state)
Returns the pseudoclass identifier for the specified component state. This string will be the way that the state is identified in the associated stylesheet. For example, the DISABLED state maps to disabled and is configured like so:
 component:disabled {
    color: #CCCCCC; // etc.
 }
 


stateDidChange

protected void stateDidChange()
Called when the component's state has changed.


changeCursor

protected boolean changeCursor()
Returns true if the component should update the mouse cursor.


updateCursor

protected void updateCursor(BCursor cursor)
Updates the mouse cursor with the supplied cursor.


getWindow

protected BWindow getWindow()
Returns the window that defines the root of our component hierarchy.


getNextFocus

protected BComponent getNextFocus()
Searches for the next component that should receive the keyboard focus. If such a component can be found, it will be returned. If no other focusable component can be found and this component is focusable, this component will be returned. Otherwise, null will be returned.


getPreviousFocus

protected BComponent getPreviousFocus()
Searches for the previous component that should receive the keyboard focus. If such a component can be found, it will be returned. If no other focusable component can be found and this component is focusable, this component will be returned. Otherwise, null will be returned.


emitEvent

protected boolean emitEvent(BEvent event)
Dispatches an event emitted by this component. The event is given to the root node for processing though in general it will result in an immediate call to dispatchEvent(com.jmex.bui.event.BEvent) with the event.

Returns:
true if the event was emitted, false if it was dropped because we are not currently added to the interface hierarchy.

intersectScissorBox

protected static boolean intersectScissorBox(Rectangle store,
                                             int x,
                                             int y,
                                             int width,
                                             int height)
Activates scissoring and sets the scissor region to the intersection of the current region (if any) and the specified rectangle. After rendering the scissored region, call restoreScissorState(boolean, com.jmex.bui.util.Rectangle) to restore the previous state.

Parameters:
store - a rectangle to hold the previous scissor region for later restoration
Returns:
true if scissoring was already enabled, false if it was not.

restoreScissorState

protected static void restoreScissorState(boolean enabled,
                                          Rectangle rect)
Restores the previous scissor state after a call to intersectScissorBox(com.jmex.bui.util.Rectangle, int, int, int, int).

Parameters:
enabled - the value returned by intersectScissorBox(com.jmex.bui.util.Rectangle, int, int, int, int), indicating whether or not scissoring was enabled
rect - the scissor box to restore


Copyright © 2008 Michael Bayne. All Rights Reserved.