com.threerings.opengl.gui
Class Root

java.lang.Object
  extended by com.threerings.opengl.util.SimpleRenderable
      extended by com.threerings.opengl.util.SimpleOverlay
          extended by com.threerings.opengl.gui.Root
All Implemented Interfaces:
Compositable, Enqueueable, Tickable
Direct Known Subclasses:
CanvasRoot, DisplayRoot

public abstract class Root
extends SimpleOverlay
implements Tickable

Connects the BUI system into the JME scene graph.


Nested Class Summary
protected  class Root.ButtonRecord
          Contains the state of a mouse button.
protected  class Root.KeyRecord
          Describes a key being held down.
protected static class Root.TickOp
          Used to notify the tick participants.
 
Field Summary
protected  Root.ButtonRecord[] _buttons
          Mouse button information.
protected  Component _ccomponent
           
protected  Clipboard _clipboard
           
protected  Cursor _cursor
          The cursor being displayed.
protected  int _daction
          When dragging, the drag action.
protected  Transferable _ddata
          When dragging, the drag data.
protected  ArrayList<Component> _defaults
           
protected  TransferHandler _dhandler
          When dragging, the transfer handler.
protected  Icon _dicon
          When dragging, the visual representation of the dragged data.
protected  Component _dsource
          When dragging, the drag source component.
protected  Component _focus
           
protected  CopyOnWriteArrayList<EventListener> _globals
           
protected  Component _hcomponent
           
protected  ArrayList<Component> _invalidRoots
           
protected  float _lastMoveTime
           
protected  float _lastTipTime
           
protected  Color4f _modalShade
           
protected  int _modifiers
           
protected  int _mouseX
           
protected  int _mouseY
           
protected  HashIntMap<Root.KeyRecord> _pressedKeys
          Keys currently pressed, mapped by key code.
protected  int _px
          The location at which the last press occurred, for drag tracking.
protected  int _py
          The location at which the last press occurred, for drag tracking.
protected  SoundGroup _soundGroup
          A sound group for feedback effects.
protected  Root.TickOp _tickOp
           
protected  ObserverList<Tickable> _tickParticipants
           
protected  long _tickStamp
           
protected  float _tipTime
           
protected  int _tipWidth
           
protected  Window _tipwin
           
protected  ArrayList<Window> _windows
           
protected static long CLICK_CHAIN_INTERVAL
          Clicks this close to one another are chained together for counting purposes.
protected static long CLICK_INTERVAL
          Mouse buttons released within this interval after being pressed are counted as clicks.
static String DEFAULT_CURSOR
          The name of the default cursor config.
protected static int DRAG_DISTANCE
          The distance from the press location at which we can start a drag operation.
protected static long KEY_REPEAT_DELAY
          The delay in milliseconds before auto-repeated key presses will begin.
protected static int KEY_REPEAT_RATE
          The key press repeat rate.
protected static int SOUND_SOURCES
          The number of sound sources to allocate.
protected static float TIP_MODE_RESET
           
 
Fields inherited from class com.threerings.opengl.util.SimpleRenderable
_batch, _ctx, _priority, _queue
 
Constructor Summary
Root(GlContext ctx)
           
 
Method Summary
 void addGlobalEventListener(EventListener listener)
          Registers a listener that will be notified of all events prior to their being dispatched normally.
 void addTickParticipant(Tickable participant)
          Adds a tick participant to the list.
 void addWindow(Window window)
          Registers a top-level window with the input system.
 void addWindow(Window window, boolean topLayer)
          Registers a top-level window with the input system.
protected  boolean checkMouseMoved(int x, int y)
          Checks for a change to the mouse location, calling mouseDidMove(int, int) and returning true if the mouse moved.
 void clearDrag()
          Clears out any drag operation in progress.
protected  void clearTipWindow()
           
protected  boolean dispatchEvent(Component target, Event event)
          Dispatches an event to the specified target (which may be null).
protected  boolean dispatchKeyEvent(Component target, KeyEvent event)
          Dispatches a key event, performing extra processing for key repeats.
protected  boolean dispatchMouseEvent(Component target, MouseEvent event)
          Dispatches a mouse event, performing extra processing for clicks.
 void dispose()
          Releases the resources held by this root.
protected  void draw()
          Draws the geometry in immediate mode.
 Clipboard getClipboard()
          Returns a reference to the clipboard.
 String getClipboardText()
          Returns the text in the clipboard, or null for none.
protected  Cursor getDefaultCursor()
          Returns a reference to the default cursor, or null to use the operating system default.
abstract  int getDisplayHeight()
          Returns the height of the display area.
abstract  int getDisplayWidth()
          Returns the width of the display area.
 Component getFocus()
          Returns the component that currently has the focus, or null.
 int getModifiers()
          Returns the current set of event modifiers.
 int getMouseX()
          Returns the x coordinate of the mouse cursor.
 int getMouseY()
          Returns the y coordinate of the mouse cursor.
 Sound getSound(String path)
          Retrieves an instance of the sound at the specified path from the sound group.
 SoundGroup getSoundGroup()
          Returns the sound group to use for feedback effects.
protected  Component getTargetComponent()
           
 long getTickStamp()
          Returns the current timestamp used to stamp event times.
 float getTooltipTimeout()
          Returns the tool tip timeout.
 Window getTopWindow()
          Returns a reference to the topmost window, or null if there are no windows.
 Window getWindow(int index)
          Returns the window at the specified index.
 int getWindowCount()
          Returns the total number of windows added to this node.
 boolean isDragging()
          Checks whether a drag operation is in progress.
 boolean isOnTop(Window window)
          Returns true if the specified window is on top.
protected  void keyPressed(long when, char keyChar, int keyCode, boolean consume)
          Handles a key press event.
protected  void keyReleased(long when, char keyChar, int keyCode, boolean consume)
          Handles a key release event.
protected  void mouseDidMove(int mouseX, int mouseY)
           
protected  void mouseMoved(long when, int x, int y, boolean consume)
          Handles a mouse moved/dragged event.
protected  void mousePressed(long when, int button, int x, int y, boolean consume)
          Handles a mouse pressed event.
protected  void mouseReleased(long when, int button, int x, int y, boolean consume)
          Handles a mouse released event.
protected  void mouseWheeled(long when, int x, int y, int delta, boolean consume)
          Handles a mouse wheel event.
 void moveToTop(Window window)
          Ensures that the specified window is on top.
 void playSound(String path)
          Plays a sound by path.
 void popDefaultEventTarget(Component component)
          Pops the default event target off the stack.
 void pushDefaultEventTarget(Component component)
          Configures a component to receive all events that are not sent to some other component.
 void removeAllWindows()
          Removes all windows from the root node.
 void removeGlobalEventListener(EventListener listener)
          Removes a global event listener registration.
 void removeTickParticipant(Tickable participant)
          Removes a tick participant from the list.
 void removeWindow(Window window)
          Removes a window from participation in the input system.
protected  void renderModalShade(Renderer renderer)
           
 void requestFocus(Component component)
          Requests that the specified component be given the input focus.
 void resortWindows()
          Called when an added window's layer is changed.
 void rootInvalidated(Component root)
          This is called by a window or a scroll pane when it has become invalid.
 void setClipboardText(String text)
          Sets the text in the clipboard.
 void setCursor(Cursor cursor)
          Sets the cursor to display (or null to use the default cursor).
protected  void setFocus(Component focus)
          Configures the component that has keyboard focus.
 void setModalShade(Color4f color)
          Sets the color of the shade behind the first active modal window.
 void setMouseDown(int button)
          Sets the mouse as being pressed at the current position.
 void setMousePosition(int x, int y)
          Sets the mouse position.
 void setMouseUp(int button)
          Sets the mouse as being released at the current position.
 void setTooltipPreferredWidth(int width)
          Sets the preferred width of tooltip windows.
 void setTooltipTimeout(float seconds)
          Configures the number of seconds that the mouse must rest over a component to trigger a tooltip.
 void startDrag(TransferHandler handler, Component source, int action)
          Initiates a drag operation.
 void tick(float elapsed)
          Updates the state of this object based on the elapsed time in seconds.
 void tipTextChanged(Component component)
          A large component that changes its tooltip while it is the hover component in the normal course of events can call this method to force an update to the tooltip window.
 String toString()
          Generates a string representation of this instance.
protected abstract  void updateCursor(Cursor cursor)
          Updates the cursor.
protected  void updateHoverComponent(int mx, int my)
          Recomputes the component over which the mouse is hovering, generating mouse exit and entry events as necessary.
protected  void windowDidMove(Window window)
          Called by a window when its position changes.
 
Methods inherited from class com.threerings.opengl.util.SimpleOverlay
composite, createStates
 
Methods inherited from class com.threerings.opengl.util.SimpleRenderable
createBatch, enqueue, getStates
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_CURSOR

public static final String DEFAULT_CURSOR
The name of the default cursor config.

See Also:
Constant Field Values

_tickStamp

protected long _tickStamp

_modifiers

protected int _modifiers

_mouseX

protected int _mouseX

_mouseY

protected int _mouseY

_clipboard

protected Clipboard _clipboard

_tipwin

protected Window _tipwin

_lastMoveTime

protected float _lastMoveTime

_tipTime

protected float _tipTime

_lastTipTime

protected float _lastTipTime

_tipWidth

protected int _tipWidth

_modalShade

protected Color4f _modalShade

_windows

protected ArrayList<Window> _windows

_hcomponent

protected Component _hcomponent

_ccomponent

protected Component _ccomponent

_focus

protected Component _focus

_defaults

protected ArrayList<Component> _defaults

_tickParticipants

protected ObserverList<Tickable> _tickParticipants

_tickOp

protected Root.TickOp _tickOp

_globals

protected CopyOnWriteArrayList<EventListener> _globals

_invalidRoots

protected ArrayList<Component> _invalidRoots

_soundGroup

protected SoundGroup _soundGroup
A sound group for feedback effects.


_cursor

protected Cursor _cursor
The cursor being displayed.


_buttons

protected Root.ButtonRecord[] _buttons
Mouse button information.


_pressedKeys

protected HashIntMap<Root.KeyRecord> _pressedKeys
Keys currently pressed, mapped by key code.


_px

protected int _px
The location at which the last press occurred, for drag tracking.


_py

protected int _py
The location at which the last press occurred, for drag tracking.


_dhandler

protected TransferHandler _dhandler
When dragging, the transfer handler.


_dsource

protected Component _dsource
When dragging, the drag source component.


_ddata

protected Transferable _ddata
When dragging, the drag data.


_daction

protected int _daction
When dragging, the drag action.


_dicon

protected Icon _dicon
When dragging, the visual representation of the dragged data.


TIP_MODE_RESET

protected static final float TIP_MODE_RESET
See Also:
Constant Field Values

CLICK_INTERVAL

protected static final long CLICK_INTERVAL
Mouse buttons released within this interval after being pressed are counted as clicks.

See Also:
Constant Field Values

CLICK_CHAIN_INTERVAL

protected static final long CLICK_CHAIN_INTERVAL
Clicks this close to one another are chained together for counting purposes.

See Also:
Constant Field Values

KEY_REPEAT_RATE

protected static final int KEY_REPEAT_RATE
The key press repeat rate.

See Also:
Constant Field Values

KEY_REPEAT_DELAY

protected static final long KEY_REPEAT_DELAY
The delay in milliseconds before auto-repeated key presses will begin.

See Also:
Constant Field Values

DRAG_DISTANCE

protected static final int DRAG_DISTANCE
The distance from the press location at which we can start a drag operation.

See Also:
Constant Field Values

SOUND_SOURCES

protected static final int SOUND_SOURCES
The number of sound sources to allocate.

See Also:
Constant Field Values
Constructor Detail

Root

public Root(GlContext ctx)
Method Detail

dispose

public void dispose()
Releases the resources held by this root.


getSoundGroup

public SoundGroup getSoundGroup()
Returns the sound group to use for feedback effects.


playSound

public void playSound(String path)
Plays a sound by path.


getSound

public Sound getSound(String path)
Retrieves an instance of the sound at the specified path from the sound group.


getTickStamp

public long getTickStamp()
Returns the current timestamp used to stamp event times.


getModifiers

public int getModifiers()
Returns the current set of event modifiers.


getClipboard

public Clipboard getClipboard()
Returns a reference to the clipboard.


getClipboardText

public String getClipboardText()
Returns the text in the clipboard, or null for none.


setClipboardText

public void setClipboardText(String text)
Sets the text in the clipboard.


addWindow

public void addWindow(Window window)
Registers a top-level window with the input system.


addWindow

public void addWindow(Window window,
                      boolean topLayer)
Registers a top-level window with the input system.

Parameters:
topLayer - if true, will set the window layer to the top most layer if it's current layer is less than that.

isOnTop

public boolean isOnTop(Window window)
Returns true if the specified window is on top.


moveToTop

public void moveToTop(Window window)
Ensures that the specified window is on top.


getTopWindow

public Window getTopWindow()
Returns a reference to the topmost window, or null if there are no windows.


resortWindows

public void resortWindows()
Called when an added window's layer is changed. Adjusts the ordering of the windows in the stack.


removeAllWindows

public void removeAllWindows()
Removes all windows from the root node.


removeWindow

public void removeWindow(Window window)
Removes a window from participation in the input system.


addTickParticipant

public void addTickParticipant(Tickable participant)
Adds a tick participant to the list.


removeTickParticipant

public void removeTickParticipant(Tickable participant)
Removes a tick participant from the list.


setTooltipTimeout

public void setTooltipTimeout(float seconds)
Configures the number of seconds that the mouse must rest over a component to trigger a tooltip. If the value is set to zero, tips will appear immediately.


getTooltipTimeout

public float getTooltipTimeout()
Returns the tool tip timeout. See setTooltipTimeout(float) for details.


setTooltipPreferredWidth

public void setTooltipPreferredWidth(int width)
Sets the preferred width of tooltip windows. The default is to prefer a width slightly less wide that the entire window.


addGlobalEventListener

public void addGlobalEventListener(EventListener listener)
Registers a listener that will be notified of all events prior to their being dispatched normally.


removeGlobalEventListener

public void removeGlobalEventListener(EventListener listener)
Removes a global event listener registration.


rootInvalidated

public void rootInvalidated(Component root)
This is called by a window or a scroll pane when it has become invalid. The root node should schedule a revalidation of this component on the next tick or the next time an event is processed.


pushDefaultEventTarget

public void pushDefaultEventTarget(Component component)
Configures a component to receive all events that are not sent to some other component. When an event is not consumed during normal processing, it is sent to the default event targets, most recently registered to least recently registered.


popDefaultEventTarget

public void popDefaultEventTarget(Component component)
Pops the default event target off the stack.


requestFocus

public void requestFocus(Component component)
Requests that the specified component be given the input focus. Pass null to clear the focus.


getFocus

public Component getFocus()
Returns the component that currently has the focus, or null.


getWindowCount

public int getWindowCount()
Returns the total number of windows added to this node.


getWindow

public Window getWindow(int index)
Returns the window at the specified index.


getDisplayWidth

public abstract int getDisplayWidth()
Returns the width of the display area.


getDisplayHeight

public abstract int getDisplayHeight()
Returns the height of the display area.


setCursor

public void setCursor(Cursor cursor)
Sets the cursor to display (or null to use the default cursor).


setMousePosition

public void setMousePosition(int x,
                             int y)
Sets the mouse position.


setMouseDown

@Beta
public void setMouseDown(int button)
Sets the mouse as being pressed at the current position.


setMouseUp

@Beta
public void setMouseUp(int button)
Sets the mouse as being released at the current position.


getMouseX

public int getMouseX()
Returns the x coordinate of the mouse cursor.


getMouseY

public int getMouseY()
Returns the y coordinate of the mouse cursor.


toString

public String toString()
Generates a string representation of this instance.

Overrides:
toString in class Object

tipTextChanged

public void tipTextChanged(Component component)
A large component that changes its tooltip while it is the hover component in the normal course of events can call this method to force an update to the tooltip window.


setModalShade

public void setModalShade(Color4f color)
Sets the color of the shade behind the first active modal window.


startDrag

public void startDrag(TransferHandler handler,
                      Component source,
                      int action)
Initiates a drag operation.


clearDrag

public void clearDrag()
Clears out any drag operation in progress.


isDragging

public boolean isDragging()
Checks whether a drag operation is in progress.


tick

public void tick(float elapsed)
Description copied from interface: Tickable
Updates the state of this object based on the elapsed time in seconds.

Specified by:
tick in interface Tickable

draw

protected void draw()
Description copied from class: SimpleRenderable
Draws the geometry in immediate mode.

Overrides:
draw in class SimpleRenderable

updateCursor

protected abstract void updateCursor(Cursor cursor)
Updates the cursor.


getDefaultCursor

protected Cursor getDefaultCursor()
Returns a reference to the default cursor, or null to use the operating system default.


mousePressed

protected void mousePressed(long when,
                            int button,
                            int x,
                            int y,
                            boolean consume)
Handles a mouse pressed event.


mouseReleased

protected void mouseReleased(long when,
                             int button,
                             int x,
                             int y,
                             boolean consume)
Handles a mouse released event.


mouseMoved

protected void mouseMoved(long when,
                          int x,
                          int y,
                          boolean consume)
Handles a mouse moved/dragged event.


mouseWheeled

protected void mouseWheeled(long when,
                            int x,
                            int y,
                            int delta,
                            boolean consume)
Handles a mouse wheel event.


checkMouseMoved

protected boolean checkMouseMoved(int x,
                                  int y)
Checks for a change to the mouse location, calling mouseDidMove(int, int) and returning true if the mouse moved.


keyPressed

protected void keyPressed(long when,
                          char keyChar,
                          int keyCode,
                          boolean consume)
Handles a key press event.


keyReleased

protected void keyReleased(long when,
                           char keyChar,
                           int keyCode,
                           boolean consume)
Handles a key release event.


dispatchMouseEvent

protected boolean dispatchMouseEvent(Component target,
                                     MouseEvent event)
Dispatches a mouse event, performing extra processing for clicks.


dispatchKeyEvent

protected boolean dispatchKeyEvent(Component target,
                                   KeyEvent event)
Dispatches a key event, performing extra processing for key repeats.


dispatchEvent

protected boolean dispatchEvent(Component target,
                                Event event)
Dispatches an event to the specified target (which may be null). If the target is null, or did not consume the event, it will be passed on to the most recently opened modal window if one exists (and the supplied target component was not a child of that window) and then to the default event targets if the event is still unconsumed.

Returns:
true if the event was dispatched, false if not.

setFocus

protected void setFocus(Component focus)
Configures the component that has keyboard focus.


windowDidMove

protected void windowDidMove(Window window)
Called by a window when its position changes. This triggers a recomputation of the hover component as the window may have moved out from under or under the mouse.


mouseDidMove

protected void mouseDidMove(int mouseX,
                            int mouseY)

updateHoverComponent

protected void updateHoverComponent(int mx,
                                    int my)
Recomputes the component over which the mouse is hovering, generating mouse exit and entry events as necessary.


getTargetComponent

protected Component getTargetComponent()

clearTipWindow

protected void clearTipWindow()

renderModalShade

protected void renderModalShade(Renderer renderer)