com.yospace.yae.yogi
Class YogiComponent

java.lang.Object
  |
  +--com.yospace.yae.yogi.YogiComponent
Direct Known Subclasses:
AbstractTable, YogiContentPane, YogiDashBar, YogiImageComponent, YogiLayeredPane, YogiMenuBar, YogiPanel, YogiPopup, YogiRange, YogiRootWindow, YogiScrollContentPane, YogiScrollPane, YogiSpin, YogiTabbedPane, YogiTextField, YogiTitleBar, YogiWindow

public class YogiComponent
extends java.lang.Object

YogiComponent is a general-purpose component class, designed to manage focus, events, location, painting, and the delegation of core functions to a UI delegate. A YogiComponent may have child components, and thus fulfills the role of a Container in a containment hierarchy. It can also act as a focus-domain root, which allows its descendents to remember the current focus even when the focus-domain root is not focussed.

All YogiComponents expect to own or share a UI delegate, which is a subclass of ComponentUI. This object represents the visible, active part of the component, and is responsible for the appearance and event handling. Thus, as with Java's Swing package, the YogiComponent only represents the Model of the component, while the pluggable ComponentUI represents its View.

The choice of the UI is determined by the UIManager instance that is currently installed in the Toolkit.

A new component can be created by building a subclass of YogiComponent to hold any new state information, and then implementing the look and feel by creating a subclass of ComponentUI. The UI should normally be registered with the UIManager.


Field Summary
static int ALIGN_CENTER
          Alignment constant used for setting center alignment in some components, such as YogiLabel.
static int ALIGN_LEFT
          Alignment constant used for setting left alignment in some components, such as YogiLabel.
static int ALIGN_RIGHT
          Alignment constants used for setting right alignment in some components, such as YogiLabel.
static int BORDER_DOTTED
          A border-style constant representing a dotted border in the current border color.
static int BORDER_NONE
          A border-style constant representing "no border".
static int BORDER_PLAIN
          A border-style constant representing a simple border line in the current background color.
static int BORDER_ROUNDED
          A border-style constant representing a round cornered border in the current border color.
static int BORDER_SOLID
          A border-style constant representing a simple border line in the current border color.
static int COLOR_BACKGROUND
          Color-type constant used for setting and retrieving the background color, typically used for filling the space behind the detail of this component.
static int COLOR_BORDER
          Color-type constants used for setting and retrieving the border color when borders are enabled.
static int COLOR_FOREGROUND
          Color-type constant used for setting and retrieving the foreground color, typically used for coloring text or other details.
static int FOCUS_DEFAULT
          A focus-type constant - indicates that this component should use the focus traversability state as indicated by its UI delegate.
static int FOCUS_OFF
          A focus-type constant - indicates that this component should not be focus traversable.
static int FOCUS_ON
          A focus-type constant - indicates that this component should be focus traversable.
static int PROPERTY_ALIGN
          Constant for the alignment property
static int PROPERTY_BORDER_STYLE
          Constant for the border style property
static int PROPERTY_BOUNDS
          Constant for the bounds property
static int PROPERTY_COLOR
          Constant for the color property
static int PROPERTY_CONTEXT_ENABLED
          Constant for the context enabled property
static int PROPERTY_ENABLED
          Constant for the enabled property
static int PROPERTY_FOCUS
          Constant for the focus property
static int PROPERTY_FOCUS_INDEX
          Constant for the focus index property
static int PROPERTY_FOCUS_TRAVERSABLE
          Constant for the focus traversability property
static int PROPERTY_FONT
          Constant for the font property
static int PROPERTY_HOTKEY
          Constant for the hotkey property
static int PROPERTY_LOCATION
          Constant for the location property
static int PROPERTY_OPAQUE
          Constant for the opaque property
static int PROPERTY_SIZE
          Constant for the size property
static int PROPERTY_VISIBLE
          Constant for the visibility property
static int PROPERTY_X_INSET
          Constant for the x inset property
static int PROPERTY_Y_INSET
          Constant for the y inset property
 
Constructor Summary
YogiComponent()
          Default constructor does nothing.
 
Method Summary
 void _debugPrintComponents()
           
 void add(YogiComponent comp)
          Add a component to this container.
 void addPropertyChangeListener(PropertyChangeListener newPcl)
          Adds a listener for any of the various property change events that components can produce.
 void bringForwards(YogiComponent c)
          This method moves the given component one position forwards in the child component's pile.
 void bringInFrontOf(YogiComponent firstComp, YogiComponent secondComp)
          This method moves the first component one position to the front of the second component.
 void bringToFront(YogiComponent c)
          This method puts the given component on top of the child components pile.
 boolean contains(int xp, int yp)
          Detects whether the specified location is within our bounds.
 boolean containsComponent(YogiComponent c)
          Finds whether the given component is contained, at some level in the component hierarchy, by this one.
 void ensureVisible(int fx, int fy, int fw, int fh)
          Ensures that the specified area of this component is visible, where possible.
protected  void ensureVisible(YogiComponent child, int fx, int fy, int fw, int fh)
          Ensures that the specified area of this component is visible, where possible; if there is a choice (perhaps because this component supports layers), then the supplied child component is the one that should be shown.
 YogiComponent findComponentAt(int xp, int yp)
          Searches the component hierarchy for the component that contains the specified point relative to this component.
static YogiComponent findCurrentFocus(YogiComponent fdRoot, boolean recurse)
          Searches below fdRoot (which must be a focus-domain root) and locates the current focussed component.
static YogiComponent findFirstFocus(YogiComponent fdRoot, int distance)
          Locates the first (or distanceth) focusable component on from this one within this focus-domain.
 YogiComponent findFocusDomainRoot(YogiRootWindow key)
          This method locates this component's closest focus-domain root component.
protected  YogiComponent findFocusDomainRootImpl()
           
 YogiComponent findHotkeyComponent(int key)
          If this component is a focus-domain root, this method will search the focusable children for one with the specified hotkey.
static YogiComponent findNextFocus(YogiComponent fdRoot, int distance)
          Locates the distanceth focusable component within the focus-domain owned by fdRoot, relative to the currently focussed item.
 void fireActionPerformedEvent()
          This method fires an action event to the action listener (if any).
 void firePropertyChangeEvent(int propertyCode)
          This method is used to send a notification to any registered PropertyChangeListeners to say that the specified property has changed.
 int getAlign()
          Gets the current alignment.
 int getBorderStyle()
          Gets the current border style for the component.
 Rectangle getBounds()
          Gets a Rectangle representing this component's bounds relative to the parent's coordinate space.
 int getColor(int index)
          For the given index in the color set, returns the relevant color value.
 java.lang.String getColors()
          Utility method which concatenates the currently set colors in this component into a readable, ';'-separated string.
 YogiComponent getComponent(int n)
          Finds the nth immediate child of this one.
 YogiComponent getComponent(java.lang.String id)
          Gets the descendant component whose id is equal to the supplied string.
 int getComponentCount()
          Returns the number of child components associated with this component.
 int getComponentIndex(YogiComponent yc)
          Finds the index of the given component within this component's child list.
 YogiComponent[] getComponents()
          Creates an array of all of the immediate children of this component.
 Rectangle getFocusBounds()
          This method returns the bounding region of this component that, if possible, would most prefer to be visible.
 int getFocusIndex()
          Gets the focus index of the current component.
 Font getFont()
          Gets the current font for the component.
 Point getGlobalLocation()
          Calculates the location of this component on the root window.
 int getHeight()
          Gets the number of pixels representing the component's height.
 int getHotkey()
          Determines the current hotkey associated with this component.
 java.lang.String getId()
          Returns the component's ID string.
 YogiComponent getParent()
          Gets the parent container of the component.
 YogiComponent getParent(YogiRootWindow key)
          Gets the parent container of the component if the key is not null.
 java.lang.Object getTreeLock()
          Returns the synchronizable Object which is used as the tree lock.
 ComponentUI getUI()
          Gets the UI delegate component associated with this component.
 int getWidth()
          Gets the number of pixels representing the component's width.
 int getX()
          Gets the number of pixels from the left edge of this component's parent to its own left edge.
 int getXInset()
          Returns the horizontal inset for this component.
 int getY()
          Gets the number of pixels from the top edge of this component's parent to its own top edge.
 int getYInset()
          Returns the vertical inset for this component.
 boolean hasFocus(boolean global)
          Tests whether this component has the focus.
 boolean isActive()
          Determines whether this component is "active".
 boolean isContextEnabled()
          Determines the "contextEnabled" state, which is true if and only if the component's ancestors are all enabled.
 boolean isEnabled()
          Determines whether this component is interested in receiving events.
 boolean isFocusDomainRoot()
          Tests whether this component is a focus-domain root
 boolean isFocusTraversable()
          Returns the focus traversability of this component.
 boolean isOpaque()
          Determines whether the component is opaque or transparent.
 boolean isVisible()
          Determines whether this component has been set to be visible.
 boolean keyPressed(YogiComponent source, int keyCode)
          The keyPressed method is called when a key pressed event is detected and this component has the focus.
 boolean keyReleased(YogiComponent source, int keyCode)
          The keyReleased method is called when a key released event is detected and this component has the focus.
 boolean keyRepeated(YogiComponent source, int keyCode)
          The keyRepeated method is called when a key repeated event is detected and this component has the focus.
 void paint(Graphics g, Rectangle damage)
          This method causes this component and all of its children to be checked for painting.
 void paintBackground(Graphics g)
          This method paints the component's background for opaque components.
 void paintBorder(Graphics g)
          This method paints the component's border.
 void paintForeground(Graphics g)
          This method paints the component's foreground.
 boolean pointerDragged(YogiComponent source, int x, int y)
          The pointerDragged method is called when a pointer dragged event is detected.
 boolean pointerPressed(YogiComponent source, int x, int y)
          The pointerPressed method is called when a pointer pressed event is detected.
 boolean pointerReleased(YogiComponent source, int x, int y)
          The pointerReleased method is called when a pointer released event is detected.
 void remove(int index)
          Remove the indexth component from this container.
 void remove(YogiComponent comp)
          Remove a component from this container.
 void removeAll()
          Removes all child components from this YogiComponent
 void removePropertyChangeListener(PropertyChangeListener oldPcl)
          This method removes a PropertyChangeListener that may have been registered previously.
 void repaint()
          Marks this component as needing repainting.
 void repaint(int px, int py, int pWidth, int pHeight)
          This method marks the supplied region of this component as needing repainting.
protected  void repaintAfterRebounding(int oldX, int oldY, int oldWidth, int oldHeight, boolean mustRepaint)
          Utility method for ensuring that a component's parent is properly repainted after any operation that may have exposed some part of it.
 boolean requestFocus()
          Allows a component to request the focus of its focus-domain.
 boolean requestFocus(boolean global)
          Allows a component to request the focus, either of its immediate focus-domain alone, or of the entire component hierarchy.
 void sendBackwards(YogiComponent c)
          This method moves the given component one position backwards in the child components pile.
 void sendBehind(YogiComponent firstComp, YogiComponent secondComp)
          This method moves the first component to one position behind the second component.
 void sendToBack(YogiComponent c)
          This method sends the given component to the bottom of the child components pile.
 void setActionListener(ActionListener actionListener)
          Sets the ActionListener on the component.
 void setActive(boolean newActive)
          Sets the "activity" state of the component.
 void setAlign(int align)
          Sets the alignment currently associated with this component.
 void setBorderStyle(int style)
          Set the style for the border of the component.
 void setBounds(int newX, int newY, int newWidth, int newHeight)
          Moves and resizes this component.
 void setColor(int index, int newColor)
          Sets the color value for the color associated with the given index.
 void setColors(java.lang.String colors)
          Takes a semicolon-delimited list of colors (in String representation) and sets the corresponding elements in this component's colors set accordingly.
 void setContextEnabled(boolean newContextEnabled)
          Forceably sets the contextEnabled flag for the current component.
 void setDefaultColor(int index)
          This method resets the indexth color back to the UI delegate's default value.
 void setEnabled(boolean newEnabled)
          Sets this component's "enabled" state.
 void setFocusDomainRoot(boolean fd)
          Configures whether this component is a focus-domain root.
 void setFocusIndex(int newIndex)
          Sets this component's focus index.
 void setFocusTraversable(int newState)
          Sets the focus-traversability of this component.
 void setFont(Font font)
          Sets the current font to be used by this component.
 void setHotkey(int newKey)
          Sets the hotkey to be associated with this component.
 void setId(java.lang.String id)
          Sets the component's ID string.
 void setLocation(int newX, int newY)
          Sets the new (x, y) location of this component, relative to its parent.
static boolean setNoFocus(YogiComponent fdRoot)
          This method sets the focus-domain fdRoot to have no current focus.
 void setOpaque(boolean opaque)
          Sets the opacity of this component.
 boolean setProperty(java.lang.String propertyName, java.lang.String value)
          The setProperty method is the top-level method for setting any component property for a YoBean.
 void setSize(int newWidth, int newHeight)
          Sets the width and height of this component.
 void setUI(ComponentUI newUI)
          Set this component's UI delegate.
 void setVisible(boolean newVisible)
          Sets the visibility of this component.
 void setXInset(int xInset)
          Sets the horizontal inset for this component.
 void setYInset(int yInset)
          Sets the vertical inset for this component.
protected  void updateUI()
          Sets the component's UI delegate based on the defaults set up for the current device type etc.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_ALIGN

public static final int PROPERTY_ALIGN
Constant for the alignment property

PROPERTY_BORDER_STYLE

public static final int PROPERTY_BORDER_STYLE
Constant for the border style property

PROPERTY_BOUNDS

public static final int PROPERTY_BOUNDS
Constant for the bounds property

PROPERTY_COLOR

public static final int PROPERTY_COLOR
Constant for the color property

PROPERTY_CONTEXT_ENABLED

public static final int PROPERTY_CONTEXT_ENABLED
Constant for the context enabled property

PROPERTY_ENABLED

public static final int PROPERTY_ENABLED
Constant for the enabled property

PROPERTY_FOCUS

public static final int PROPERTY_FOCUS
Constant for the focus property

PROPERTY_FOCUS_INDEX

public static final int PROPERTY_FOCUS_INDEX
Constant for the focus index property

PROPERTY_FOCUS_TRAVERSABLE

public static final int PROPERTY_FOCUS_TRAVERSABLE
Constant for the focus traversability property

PROPERTY_FONT

public static final int PROPERTY_FONT
Constant for the font property

PROPERTY_HOTKEY

public static final int PROPERTY_HOTKEY
Constant for the hotkey property

PROPERTY_LOCATION

public static final int PROPERTY_LOCATION
Constant for the location property

PROPERTY_OPAQUE

public static final int PROPERTY_OPAQUE
Constant for the opaque property

PROPERTY_SIZE

public static final int PROPERTY_SIZE
Constant for the size property

PROPERTY_VISIBLE

public static final int PROPERTY_VISIBLE
Constant for the visibility property

PROPERTY_X_INSET

public static final int PROPERTY_X_INSET
Constant for the x inset property

PROPERTY_Y_INSET

public static final int PROPERTY_Y_INSET
Constant for the y inset property

ALIGN_CENTER

public static final int ALIGN_CENTER
Alignment constant used for setting center alignment in some components, such as YogiLabel.
See Also:
setAlign(int), getAlign()

ALIGN_LEFT

public static final int ALIGN_LEFT
Alignment constant used for setting left alignment in some components, such as YogiLabel.
See Also:
setAlign(int), getAlign()

ALIGN_RIGHT

public static final int ALIGN_RIGHT
Alignment constants used for setting right alignment in some components, such as YogiLabel.
See Also:
setAlign(int), getAlign()

COLOR_BACKGROUND

public static final int COLOR_BACKGROUND
Color-type constant used for setting and retrieving the background color, typically used for filling the space behind the detail of this component.
See Also:
setColor(int,int), getColor(int)

COLOR_FOREGROUND

public static final int COLOR_FOREGROUND
Color-type constant used for setting and retrieving the foreground color, typically used for coloring text or other details.
See Also:
setColor(int,int), getColor(int)

COLOR_BORDER

public static final int COLOR_BORDER
Color-type constants used for setting and retrieving the border color when borders are enabled.
See Also:
setColor(int,int), getColor(int), setBorderStyle(int)

BORDER_NONE

public static final int BORDER_NONE
A border-style constant representing "no border".
See Also:
setBorderStyle(int), getBorderStyle()

BORDER_PLAIN

public static final int BORDER_PLAIN
A border-style constant representing a simple border line in the current background color.
See Also:
setBorderStyle(int), getBorderStyle()

BORDER_SOLID

public static final int BORDER_SOLID
A border-style constant representing a simple border line in the current border color.
See Also:
setBorderStyle(int), getBorderStyle()

BORDER_DOTTED

public static final int BORDER_DOTTED
A border-style constant representing a dotted border in the current border color.
See Also:
setBorderStyle(int), getBorderStyle()

BORDER_ROUNDED

public static final int BORDER_ROUNDED
A border-style constant representing a round cornered border in the current border color.
See Also:
setBorderStyle(int), getBorderStyle()

FOCUS_DEFAULT

public static final int FOCUS_DEFAULT
A focus-type constant - indicates that this component should use the focus traversability state as indicated by its UI delegate.
See Also:
setFocusTraversable(int), isFocusTraversable()

FOCUS_OFF

public static final int FOCUS_OFF
A focus-type constant - indicates that this component should not be focus traversable.
See Also:
setFocusTraversable(int), isFocusTraversable()

FOCUS_ON

public static final int FOCUS_ON
A focus-type constant - indicates that this component should be focus traversable.
See Also:
setFocusTraversable(int), isFocusTraversable()
Constructor Detail

YogiComponent

public YogiComponent()
Default constructor does nothing.
Method Detail

getTreeLock

public java.lang.Object getTreeLock()
Returns the synchronizable Object which is used as the tree lock. The Lock is mainly used in this class, so this method is required for different package subclasses etc. Developers should not normally need to use this.
Returns:
the Object on which code should synchronize to in order for 'safe' component tree manipulations to commence.

getGlobalLocation

public final Point getGlobalLocation()
Calculates the location of this component on the root window. It iterates up through the component hierarchy adding in the successive (x, y) offsets of its ancestors.
Returns:
a Point object containing the location of this component relative to its most distant ancestor's top-left corner.

contains

public final boolean contains(int xp,
                              int yp)
Detects whether the specified location is within our bounds. By default, this method delegates to our UI component, or, if none exists, it performs naive Rectangle detection.
Parameters:
xp - the x coordinate of the point being tested
yp - 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
See Also:
ComponentUI.contains(com.yospace.yae.yogi.YogiComponent,int,int)

findComponentAt

public final YogiComponent findComponentAt(int xp,
                                           int yp)
Searches the component hierarchy for the component that contains the specified point relative to this component. Note that this point corresponds to global coordinates only if this component is the Root Window. This method is used for locating the component under a pointer click.
Parameters:
xp - the x coordinate of a point in this component's coordinate space
yp - the y coordinate of a point in this component's coordinate space
Returns:
the most deeply descended visible component below this one which encloses the specified point. If this component has no children that enclose the point, then this component is returned, and if this component does not enclose the point, then null is returned.
See Also:
contains(int,int)

getX

public int getX()
Gets the number of pixels from the left edge of this component's parent to its own left edge.
Returns:
the x-location of the component, relative to the parent's coordinate system.

getY

public int getY()
Gets the number of pixels from the top edge of this component's parent to its own top edge.
Returns:
the y-location of the component, relative to the parent's coordinate system.

getWidth

public final int getWidth()
Gets the number of pixels representing the component's width.
Returns:
the width as an integer number of pixels. The default (set in the UI delegate) is returned if one has not been set.
See Also:
ComponentUI.getDefaultWidth(com.yospace.yae.yogi.YogiComponent), setSize(int,int)

getHeight

public final int getHeight()
Gets the number of pixels representing the component's height.
Returns:
the height as an integer number of pixels. The default (set in the UI delegate) is returned if one has not been set.
See Also:
ComponentUI.getDefaultHeight(com.yospace.yae.yogi.YogiComponent), setSize(int,int)

getBounds

public Rectangle getBounds()
Gets a Rectangle representing this component's bounds relative to the parent's coordinate space.
Returns:
the bounding Rectangle.
See Also:
getX(), getY(), getWidth(), getHeight()

setBounds

public void setBounds(int newX,
                      int newY,
                      int newWidth,
                      int newHeight)
Moves and resizes this component.

This method fires a PROPERTY_BOUNDS change event if the values change.

Parameters:
newX - the desired x value.
newY - the desired y value.
newWidth - the desired width, or -1 to restore to UI defaults.
newHeight - the desired height, or -1 to restore to UI defaults.

setSize

public void setSize(int newWidth,
                    int newHeight)
Sets the width and height of this component.

This method fires a PROPERTY_SIZE change event if the value changes.

Parameters:
newWidth - the new width in pixels, or -1 to restore to UI defaults.
newHeight - the new height in pixels, or -1 to restore to UI defaults.

setLocation

public void setLocation(int newX,
                        int newY)
Sets the new (x, y) location of this component, relative to its parent.

This method fires a PROPERTY_LOCATION change event if the value changes.

Parameters:
newX - the new x location in pixels
newY - the new y location in pixels

getAlign

public int getAlign()
Gets the current alignment. Some UIs will use this to decide where to place content.
Returns:
the current alignment: one of ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT

setAlign

public void setAlign(int align)
Sets the alignment currently associated with this component. Some UIs will use this to decide where to place content.

This method fires a PROPERTY_ALIGN change event if the value changes

Parameters:
align - the required alignment: one of ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT

getXInset

public int getXInset()
Returns the horizontal inset for this component. This is used to inset the left and right edges of the display area when painting the foreground of the component. If not set explicitly, then the UI delegate's default value is used.
Returns:
the horizontal inset for the foreground detail
See Also:
ComponentUI.getDefaultXInset(com.yospace.yae.yogi.YogiComponent), paintForeground(com.yospace.yae.yogi.Graphics), getYInset()

getYInset

public int getYInset()
Returns the vertical inset for this component. This is used to inset the top and bottom edges of the display area when painting the foreground of the component. If not set explicitly, then the UI delegate's default value is used.
Returns:
the vertical inset for the foreground detail
See Also:
ComponentUI.getDefaultYInset(com.yospace.yae.yogi.YogiComponent), paintForeground(com.yospace.yae.yogi.Graphics), getXInset()

setXInset

public void setXInset(int xInset)
Sets the horizontal inset for this component. This is used to inset the left and right edges of the display area when painting the foreground of the component. If not set explicitly, then the UI delegate's default value is used.

This method fires a PROPERTY_X_INSET change event if the value changes

Parameters:
xInset - the new horizontal inset value, or -1 to restore to UI delegate's default value.
See Also:
ComponentUI.getDefaultXInset(com.yospace.yae.yogi.YogiComponent), paintForeground(com.yospace.yae.yogi.Graphics), setYInset(int), getXInset()

setYInset

public void setYInset(int yInset)
Sets the vertical inset for this component. This is used to inset the top and bottom edges of the display area when painting the foreground of the component. If not set explicitly, then the UI delegate's default value is used.

This method fires a PROPERTY_X_INSET change event if the value changes

Parameters:
yInset - the new vertical inset value, or -1 to restore to UI delegate's default value.
See Also:
ComponentUI.getDefaultXInset(com.yospace.yae.yogi.YogiComponent), paintForeground(com.yospace.yae.yogi.Graphics), setXInset(int), getYInset()

getId

public final java.lang.String getId()
Returns the component's ID string.
Returns:
the ID string, or null if none set.
See Also:
getComponent(java.lang.String), setId(java.lang.String)

setId

public final void setId(java.lang.String id)
Sets the component's ID string.
Parameters:
id - the new ID string, or null
See Also:
getComponent(java.lang.String), getId()

isVisible

public final boolean isVisible()
Determines whether this component has been set to be visible. Note that the component will only be shown if it and all of its parent containers are visible, all the way up to the root window.
Returns:
true if the component is visible, false otherwise
See Also:
setVisible(boolean)

setVisible

public final void setVisible(boolean newVisible)
Sets the visibility of this component.

This method fires a PROPERTY_VISIBLE change event if the value changes.

Parameters:
newVisible - the desired visibility of the component.
See Also:
isVisible()

isEnabled

public final boolean isEnabled()
Determines whether this component is interested in receiving events. A disabled component will usually be rendered in a "grayed-out" style.
Returns:
true if the component is currently enabled, false otherwise.
See Also:
setEnabled(boolean)

isContextEnabled

public final boolean isContextEnabled()
Determines the "contextEnabled" state, which is true if and only if the component's ancestors are all enabled.
Returns:
true if the component is enabled, false otherwise.

setEnabled

public final void setEnabled(boolean newEnabled)
Sets this component's "enabled" state.

This method fires a PROPERTY_ENABLED change event if the value changes.

Parameters:
newEnabled - the desired enablement state.
See Also:
isEnabled()

setContextEnabled

public final void setContextEnabled(boolean newContextEnabled)
Forceably sets the contextEnabled flag for the current component. This method allows components to become enabled even though they are not in an enabled context, (eg. cell cenderers mimic the enabled state of their 'parent' components by calling this method, whilst not actually being children).
Parameters:
newContextEnabled - the desired state setting.
See Also:
isContextEnabled()

isOpaque

public boolean isOpaque()
Determines whether the component is opaque or transparent. Components are generally opaque by default.
Returns:
true if the component is opaque, false otherwise.
See Also:
setOpaque(boolean)

setOpaque

public void setOpaque(boolean opaque)
Sets the opacity of this component.

This method fires a PROPERTY_OPAQUE change event if the value changes.

Parameters:
opaque - the desired opacity of the component.
See Also:
isOpaque()

getFont

public Font getFont()
Gets the current font for the component. If none has been set, then the UI delegate's default value is used.
Returns:
the current font for the component
See Also:
ComponentUI.getDefaultFont(com.yospace.yae.yogi.YogiComponent), setFont(com.yospace.yae.yogi.Font)

setFont

public void setFont(Font font)
Sets the current font to be used by this component.

This method fires a PROPERTY_FONT change event if the value changes.

Parameters:
font - the new font to be used, or null to restore to the UI delegate's default font.
See Also:
ComponentUI.getDefaultFont(com.yospace.yae.yogi.YogiComponent), getFont()

getBorderStyle

public int getBorderStyle()
Gets the current border style for the component. If none has been set, then the UI delegate is called.
Returns:
the current border style, which is one of BORDER_NONE, BORDER_PLAIN, BORDER_SOLID, BORDER_DOTTED, BORDER_ROUNDED
See Also:
ComponentUI.getDefaultBorderStyle(com.yospace.yae.yogi.YogiComponent)

setBorderStyle

public void setBorderStyle(int style)
Set the style for the border of the component. The style can be BORDER_NONE, BORDER_PLAIN, BORDER_SOLID, BORDER_DOTTED, BORDER_ROUNDED.

This method fires a PROPERTY_BORDER_STYLE change event if the value changes.

Parameters:
style - the desired style for the border of the component, or -1 to restore to UI delegate's default style.
See Also:
ComponentUI.getDefaultBorderStyle(com.yospace.yae.yogi.YogiComponent), getBorderStyle()

getUI

public ComponentUI getUI()
Gets the UI delegate component associated with this component.
Returns:
the UI delegate object associated with this component

setUI

public void setUI(ComponentUI newUI)
Set this component's UI delegate. Note that a default UI delegate is set up when the component is constructed, so this method is used to change to a custom UI delegate.
Parameters:
newUI - the new UI delegate to be used - cannot be null

updateUI

protected void updateUI()
Sets the component's UI delegate based on the defaults set up for the current device type etc. This method is always called if a component currently has no UI delegate.

sendToBack

public void sendToBack(YogiComponent c)
This method sends the given component to the bottom of the child components pile. All other children will appear in front of it if they overlap.
Parameters:
c - the (child) component to be moved. If it is not an immediate child of this component, then the method does nothing.

bringToFront

public void bringToFront(YogiComponent c)
This method puts the given component on top of the child components pile. All other children will appear behind it if they overlap.
Parameters:
c - the (child) component to be moved. If it is not an immediate child of this component, then the method does nothing.

sendBackwards

public void sendBackwards(YogiComponent c)
This method moves the given component one position backwards in the child components pile. The sibling component that was immediately behind (if they overlap) will now appear in front.
Parameters:
c - the (child) component to be moved. If it is not an immediate child of this component, then the method does nothing.

bringForwards

public void bringForwards(YogiComponent c)
This method moves the given component one position forwards in the child component's pile. The sibling component that was immediately in front (if they overlap) will now appear behind.
Parameters:
c - the (child) component to be moved. If it is not an immediate child of this component, then the method does nothing.

bringInFrontOf

public void bringInFrontOf(YogiComponent firstComp,
                           YogiComponent secondComp)
This method moves the first component one position to the front of the second component.
Parameters:
firstComp - the (child) component to be moved.
secondComp - the (child) component that the firstComp should be moved ahead of in the z-ordering.

sendBehind

public void sendBehind(YogiComponent firstComp,
                       YogiComponent secondComp)
This method moves the first component to one position behind the second component.
Parameters:
firstComp - the (child) component to be moved.
secondComp - the (child) component that the firstComp should be moved behind in the z-ordering.

getParent

public YogiComponent getParent()
Gets the parent container of the component.
Returns:
this component's parent, or null if this component does not currently have one.

getParent

public final YogiComponent getParent(YogiRootWindow key)
Gets the parent container of the component if the key is not null. This method is used by the various YoGI managers to access component parents beyond popup modal root boundaries.
Parameters:
key - the key (the unique YogiRootWindow Object).
Returns:
this component's parent, or null if this component does not currently have one.

getComponent

public final YogiComponent getComponent(java.lang.String id)
                                 throws java.lang.Exception
Gets the descendant component whose id is equal to the supplied string. This method recurses through all children.
Parameters:
id - the ID to search for.
Returns:
the component whose ID matches the supplied string
Throws:
java.lang.Exception - if no matching component is found

containsComponent

public final boolean containsComponent(YogiComponent c)
Finds whether the given component is contained, at some level in the component hierarchy, by this one.
Parameters:
c - the component to find.
Returns:
true if the given component was found to be contained by this one, false otherwise.

getComponent

public YogiComponent getComponent(int n)
Finds the nth immediate child of this one.
Parameters:
n - the index of the child to be returned
Returns:
the nth child component, or null if n is out of range.

getComponentIndex

public int getComponentIndex(YogiComponent yc)
Finds the index of the given component within this component's child list.
Parameters:
yc - the component to find, or null.
Returns:
the index in the child components list, or -1 if not found or yc is null.

getComponentCount

public int getComponentCount()
Returns the number of child components associated with this component.
Returns:
the number of children owned by this component.

add

public void add(YogiComponent comp)
Add a component to this container. This method handles the focus management for the new component.
Parameters:
comp - the component to add.
Throws:
IllegalStateException - if the component comp already has a parent.

remove

public void remove(YogiComponent comp)
Remove a component from this container.
Parameters:
comp - the component to remove. If the component is not registered as a child, calls to this method have no effect.

remove

public void remove(int index)
Remove the indexth component from this container.
Parameters:
index - the index of the component to remove. If the component index is out of range, calls to this method have no effect.

getComponents

public YogiComponent[] getComponents()
Creates an array of all of the immediate children of this component.
Returns:
all the child YogiComponents that have been added to this one.

removeAll

public void removeAll()
Removes all child components from this YogiComponent

_debugPrintComponents

public void _debugPrintComponents()

getColor

public int getColor(int index)
For the given index in the color set, returns the relevant color value.
Parameters:
index - the index in the color set to be returned. Should be one of COLOR_BACKGROUND, COLOR_FOREGROUND or COLOR_BORDER, or some sub-component specific value.
Returns:
the color for that index. If no color has been set, the default value for that index is fetched from the component's UI delegate.
Throws:
ArrayIndexOutOfBoundsException - if the index is out of range for this component
IllegalStateException - if there is no associated UI for this component, and a color index is requested that has not been set.

setDefaultColor

public void setDefaultColor(int index)
This method resets the indexth color back to the UI delegate's default value.
Parameters:
index - the color to be reset. Should be one of COLOR_BACKGROUND, COLOR_FOREGROUND or COLOR_BORDER, or some sub-component specific value.

setColor

public void setColor(int index,
                     int newColor)
Sets the color value for the color associated with the given index. If the index is larger than the current size of the color array, the color set is increased so as to accommodate this new index. Thus, new values can be added at higher indices, allowing for custom state to be added to the component and used within custom UIs.

This method fires a PROPERTY_COLOR change event if the value changes

Parameters:
index - the index number in the color array. Must be in the range 0 to 31.
newColor - the color that that index should be set to.

setColors

public void setColors(java.lang.String colors)
Takes a semicolon-delimited list of colors (in String representation) and sets the corresponding elements in this component's colors set accordingly.
For example, the String "red;green;;blue" will cause element 0 of the color set to have the it's value set to ColorUtil.parseColor("red"); i.e. the integer representation of the color red. Similarly, element 1 of the color set will be set to the numeric equivalent of the color "green". The numeric equivalent of the color "blue" will be placed in element 3 of the color set, not element 2 as the double semicolon in the input string indicates that we should skip element 2 and move on to setting element 3.

The set of acceptable colors is defined in the ColorUtil class.

Parameters:
colors - the String representation, including semicolon delimiters, of the values that should be entered into the colors set.

getColors

public final java.lang.String getColors()
Utility method which concatenates the currently set colors in this component into a readable, ';'-separated string. Colors that have not been set explicitly (and therefore default to the UI setting) are left as null entries. For example, if this component has an explicit backgraound and border color, then the String might appear as "blue;;red".

The returned string has no trailing ';' chars, and will return an empty string if there are no set colors. The color strings are those known about by the ColorUtil class, so unknown colors will appear as 0x-hexdigit strings.

Returns:
this component's colors, as a string of ';'-separated color identifiers.

setProperty

public boolean setProperty(java.lang.String propertyName,
                           java.lang.String value)
The setProperty method is the top-level method for setting any component property for a YoBean. If extending a component and adding any new set methods which set a new component property then this method should be overridden. However, super.setProperty should always be called first, before dealing with any new properties. For example:
public boolean setProperty(String propertyName, String value)
{
boolean success = super.setProperty(propertyName, value);

if (!success)
{
if (propertyName.equals(PROPERTY_TEXT))
{
setText(value);
success = true;
}
else if (propertyName.equals(PROPERTY_IMAGE))
{
setImage(value);
success = true;
}
else if (propertyName.equals(PROPERTY_TEXT_PLACEMENT))
{
setTextOnRight("right".equals(value));
success = true;
}
}
return success;
}

Where possible, use the PROPERTY_XXXX constants for the propertyName parameter, as they dramatically improve the efficiency of this method. This method is a stub for YoBeans to extend and should not be used for core YogiComponents.

Parameters:
propertyName - the code of the property to be set
value - the new value as a String
Returns:
true if the property has been set; false otherwise (for instance, if the specified property does not exist, or the format of the value is wrong).

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener newPcl)
Adds a listener for any of the various property change events that components can produce. A component does not guarantee the order in which listeners are notified. If it is absolutely necessary that a particular order be maintained, then the two listeners are not independent, and thus the first listener should probably be alerting the second.
Parameters:
newPcl - the property change listener to be added. If it is already a listener, then this method does nothing.

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener oldPcl)
This method removes a PropertyChangeListener that may have been registered previously. If no such listener was registered, then this method does nothing.
Parameters:
oldPcl - the listener to be removed.

firePropertyChangeEvent

public void firePropertyChangeEvent(int propertyCode)
This method is used to send a notification to any registered PropertyChangeListeners to say that the specified property has changed.
Parameters:
propertyCode - the code for the property that has changed. For maximum efficiency, this should be one of the PROPERTY_XXXXX constants.

setActionListener

public void setActionListener(ActionListener actionListener)
Sets the ActionListener on the component. Some components will need to have actions associated with them. For those components, YogiComponent provides a single reference to a ActionListener, which can be notified when actions take place.
Parameters:
actionListener - the new actionListener, or null (to unset it).
See Also:
fireActionPerformedEvent()

fireActionPerformedEvent

public void fireActionPerformedEvent()
This method fires an action event to the action listener (if any).
See Also:
setActionListener(com.yospace.yae.yogi.ActionListener)

keyPressed

public boolean keyPressed(YogiComponent source,
                          int keyCode)
The keyPressed method is called when a key pressed event is detected and this component has the focus. Usually, event detection is performed by the component's UI delegate, so this method should only be overridden for very obscure, non-UI specific event handling.

The default implementation of this method in YogiComponent returns false.

Parameters:
source - the component that was in focus at the time of the event. This is almost certainly "this" component; however, more elaborate Focus Managers may deviate from this.
keyCode - the key that was pressed
Returns:
true if the event was consumed and should not be propagated further, false otherwise.

keyRepeated

public boolean keyRepeated(YogiComponent source,
                           int keyCode)
The keyRepeated method is called when a key repeated event is detected and this component has the focus. Usually, event detection is performed by the component's UI delegate, so this method should only be overridden for very obscure, non-UI specific event handling.

The default implementation of this method in YogiComponent returns false.

Parameters:
source - the component that was in focus at the time of the event. This is almost certainly "this" component; however, more elaborate Focus Managers may deviate from this.
keyCode - the key that was repeated
Returns:
true if the event was consumed and should not be propagated further, false otherwise.

keyReleased

public boolean keyReleased(YogiComponent source,
                           int keyCode)
The keyReleased method is called when a key released event is detected and this component has the focus. Usually, event detection is performed by the component's UI delegate, so this method should only be overridden for very obscure, non-UI specific event handling.

The default implementation of this method in YogiComponent returns false.

Parameters:
source - the component that was in focus at the time of the event. This is almost certainly "this" component; however, more elaborate Focus Managers may deviate from this.
keyCode - the key that was released
Returns:
true if the event was consumed and should not be propagated further, false otherwise.

pointerPressed

public boolean pointerPressed(YogiComponent source,
                              int x,
                              int y)
The pointerPressed method is called when a pointer pressed event is detected. Usually, event detection is performed by the component's UI delegate, so this method should only be overridden for very obscure, non-UI specific event handling.

The default implementation of this method in YogiComponent returns false.

Parameters:
source - the component that was under the pointer. This is almost certainly "this" component; however, more elaborate Focus Managers may deviate from this.
x - the x coordinate of the pointer press, in this component's coordinate space.
y - the y coordinate of the pointer p