com.yospace.yae.yogi
Class ComponentUI

java.lang.Object
  |
  +--com.yospace.yae.yogi.ComponentUI
Direct Known Subclasses:
StandardComponentUI, StandardComponentUI

public abstract class ComponentUI
extends java.lang.Object

An adapter-style base class for YoGI UI classes.


Field Summary
static int KEY_PRESSED
          The constant for a key pressed event.
static int KEY_RELEASED
          The constant for a key released event.
static int KEY_REPEATED
          The constant for a key repeated event.
static int POINTER_DRAGGED
          The constant for a pointer dragged event.
static int POINTER_PRESSED
          The constant for a pointer pressed event.
static int POINTER_RELEASED
          The constant for a pointer released event.
 
Constructor Summary
ComponentUI()
           
 
Method Summary
 boolean contains(YogiComponent c, int x, int y)
          Detects whether the specified location is within the component's bounds.
abstract  int getDefaultBorderStyle(YogiComponent c)
          This method is called by the component where the application writer has not explicitly set the border style, either from within the XML or programmatically at a later stage.
abstract  int getDefaultColor(int index)
          This method is called by the component where the application writer has not explicitly set any of the colors in the color array, either from within the XML or programmatically at a later stage.
abstract  Font getDefaultFont(YogiComponent c)
          This method is called by the component where the application writer has not explicitly set the font, either from within the XML or programmatically at a later stage.
abstract  int getDefaultHeight(YogiComponent c)
          This method is called by the component where the application writer has not explicitly set the height, either from within the XML or programmatically at a later stage.
abstract  int getDefaultWidth(YogiComponent c)
          This method is called by the component where the application writer has not explicitly set the width, either from within the XML or programmatically at a later stage.
abstract  int getDefaultXInset(YogiComponent c)
          This method is called by the component where the application writer has not explicitly set the x inset, either from within the XML or programmatically at a later stage.
abstract  int getDefaultYInset(YogiComponent c)
          This method is called by the component where the application writer has not explicitly set the y inset, either from within the XML or programmatically at a later stage.
 ComponentUI getInstance()
          Used by the YoGI engine when a new component requires a default UI delegate.
 boolean isDefaultFocusTraversable(YogiComponent c)
          This method is called by a component when the component has its focus-traversability set to FOCUS_DEFAULT.
 void paintBackground(Graphics g, YogiComponent c)
          Default method.
 void paintBorder(Graphics g, YogiComponent c, int borderStyle, int strokeStyle, int borderColor)
          Default method.
 void paintForeground(Graphics g, YogiComponent c)
          Default method.
 void performDefaultAction(YogiComponent c)
          Default template method for performing hotkey actions.
 boolean processKeyEvent(YogiComponent c, int keyCode, int eventType)
          Default method for handling incoming keypad events.
 boolean processPointerEvent(YogiComponent c, int x, int y, int eventType)
          Default method for handling incoming pointer events.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_PRESSED

public static final int KEY_PRESSED
The constant for a key pressed event.

KEY_REPEATED

public static final int KEY_REPEATED
The constant for a key repeated event.

KEY_RELEASED

public static final int KEY_RELEASED
The constant for a key released event.

POINTER_PRESSED

public static final int POINTER_PRESSED
The constant for a pointer pressed event.

POINTER_DRAGGED

public static final int POINTER_DRAGGED
The constant for a pointer dragged event.

POINTER_RELEASED

public static final int POINTER_RELEASED
The constant for a pointer released event.
Constructor Detail

ComponentUI

public ComponentUI()
Method Detail

paintForeground

public void paintForeground(Graphics g,
                            YogiComponent c)
Default method. Does nothing.
Parameters:
g - the (clipped) graphics object to use.
c - the component to repaint.

paintBackground

public void paintBackground(Graphics g,
                            YogiComponent c)
Default method. Paints the background with the current background colour. Note that this method will not be called if the component is transparent. Thus, any drawing which should be preformed regardless of opacity should be done within the paintForeground method.
Parameters:
g - the (clipped) graphics object to use.
c - the component to repaint.

paintBorder

public void paintBorder(Graphics g,
                        YogiComponent c,
                        int borderStyle,
                        int strokeStyle,
                        int borderColor)
Default method. Paints a one pixel thick rectangle as a border according to the borderStyle, with the specified borderColor and strokeStyle. Note that this method operates using the style and color values supplied, rather than requesting them from the YogiComponent, so that subclasses can modify the border behavior without having to modify the border-style.
Parameters:
g - the graphics object to use.
c - the component whose border needs to be painted.
borderStyle - the style of border to use, one of BORDER_NONE, BORDER_PLAIN, BORDER_SOLID, BORDER_DOTTED, BORDER_ROUNDED.
strokeStyle - the border's pen style, one of SOLID or DOTTED.
borderColor - the color of the border

processPointerEvent

public boolean processPointerEvent(YogiComponent c,
                                   int x,
                                   int y,
                                   int eventType)
Default method for handling incoming pointer events. ComponentUI version is empty.
Parameters:
c - the owner component which is to handle the event
x - the x coord of the pointer (where the top left of the component is at (0,0)).
y - the y coord of the pointer (where the top left of the component is at (0,0)).
eventType - an indication of whether the pointer has been pressed, dragged or released: one of POINTER_PRESSED, POINTER_DRAGGED, or POINTER_RELEASED.
Returns:
true if the event is consumed by this method; false otherwise. Default in ComponentUI returns false.

processKeyEvent

public boolean processKeyEvent(YogiComponent c,
                               int keyCode,
                               int eventType)
Default method for handling incoming keypad events. ComponentUI version is empty.
Parameters:
c - the owner component which is to handle the event
keyCode - the character code of the key - see Canvas
eventType - an indication of whether the pointer has been pressed, dragged or released: one of POINTER_PRESSED, POINTER_DRAGGED, or POINTER_RELEASED.
Returns:
true if the event is consumed by this method; false otherwise. Default in ComponentUI returns false.

performDefaultAction

public void performDefaultAction(YogiComponent c)
Default template method for performing hotkey actions. This method should be overridden to do whatever is expected when a hotkey is triggered.

The ComponentUI version fires the action performed notification (which only does anything if there is a ActionListener attached). This means that it does the right thing for "action" components like YogiButton and inactive components like YogiLabel and YogiPanel. It generally needs overriding for stateful components like YogiCheckBox and for "penetrable" components like YogiSpin.

Parameters:
c - the component which has been triggered.

contains

public boolean contains(YogiComponent c,
                        int x,
                        int y)
Detects whether the specified location is within the component's bounds. By default, this method performs naive Rectangle detection, but could be overridden to allow for more ornate shapes such as circles or triangles. In particular, this allows for overlapping non-opaque components that interlock (eg buttons that make up the up-down-left-right arrows in a circular thumbstick component). It is used to detect whether a pointer is within this component's bounds for event transmission
Parameters:
c - the component that is being tested.
x - the x coordinate of the point being tested.
y - the y coordinate of the point being tested.
Returns:
true if this component contains the specified point (with respect to its own coordinate origin); false otherwise.

getInstance

public ComponentUI getInstance()
Used by the YoGI engine when a new component requires a default UI delegate. Should return a self-reference where the UI delegate maintains no state, and a new instance where state is held.
Returns:
a new instance or self reference of the same type as this UI delegate.

getDefaultWidth

public abstract int getDefaultWidth(YogiComponent c)
This method is called by the component where the application writer has not explicitly set the width, either from within the XML or programmatically at a later stage. The plaf specific XxxComponentUI delegate should implement this method so that a plaf-set specific default width can be established. This method might return a width based on other characteristics of the component, and therefore is takes as a parameter the caller component.

getDefaultHeight

public abstract int getDefaultHeight(YogiComponent c)
This method is called by the component where the application writer has not explicitly set the height, either from within the XML or programmatically at a later stage. The plaf specific XxxComponentUI delegate should implement this method so that a plaf-set specific default height can be established. This method might return a height based on other characteristics of the component, and therefore is takes as a parameter the caller component.

getDefaultXInset

public abstract int getDefaultXInset(YogiComponent c)
This method is called by the component where the application writer has not explicitly set the x inset, either from within the XML or programmatically at a later stage. The plaf specific XxxComponentUI delegate should implement this method so that a plaf-set specific default x inset can be established. This method might return an x inset based on other characteristics of the component, and therefore is takes as a parameter the caller component.

getDefaultYInset

public abstract int getDefaultYInset(YogiComponent c)
This method is called by the component where the application writer has not explicitly set the y inset, either from within the XML or programmatically at a later stage. The plaf specific XxxComponentUI delegate should implement this method so that a plaf-set specific default y inset can be established. This method might return a y inset based on other characteristics of the component, and therefore is takes as a parameter the caller component.

getDefaultFont

public abstract Font getDefaultFont(YogiComponent c)
This method is called by the component where the application writer has not explicitly set the font, either from within the XML or programmatically at a later stage. The plaf specific XxxComponentUI delegate should implement this method so that a plaf-set specific default font can be established. This method might return a font based on other characteristics of the component, and therefore is takes as a parameter the caller component.

getDefaultBorderStyle

public abstract int getDefaultBorderStyle(YogiComponent c)
This method is called by the component where the application writer has not explicitly set the border style, either from within the XML or programmatically at a later stage. The plaf specific XxxComponentUI delegate should implement this method so that a plaf-set specific default border style can be established. This method might return a border style based on other characteristics of the component, and therefore is takes as a parameter the caller component.

getDefaultColor

public abstract int getDefaultColor(int index)
This method is called by the component where the application writer has not explicitly set any of the colors in the color array, either from within the XML or programmatically at a later stage. The plaf specific XxxComponentUI delegate should implement this method so that a plaf-set specific default color can be established. This method might return a color based on other characteristics of the component, and therefore is takes as a parameter the caller component.

isDefaultFocusTraversable

public boolean isDefaultFocusTraversable(YogiComponent c)
This method is called by a component when the component has its focus-traversability set to FOCUS_DEFAULT.
Parameters:
c - the component that is being checked
Returns:
false

Copyright 2002 Yospace Holdings Ltd. All Rights Reserved.