charva.awt

Class Component

Known Direct Subclasses:
Container, JComponent, JSeparator, MultiLineLabel, TableHeader

public abstract class Component
extends java.lang.Object

Component is the abstract superclass of all the other CHARVA widgets.

Field Summary

static float
BOTTOM_ALIGNMENT
static float
CENTER_ALIGNMENT
static float
LEFT_ALIGNMENT
static float
RIGHT_ALIGNMENT
static float
TOP_ALIGNMENT
protected float
_alignmentX
the X-alignment of this component
protected float
_alignmentY
the Y-alignment of this component
protected Color
_background
If the background color is null, this component inherits the background color of its parent Container.
protected int
_cursesColor
The number of this component's color-pair, as computed by the ncurses COLOR_PAIR macro.
protected boolean
_enabled
This flag is true if this component can react to user input.
protected Vector
_focusListeners
A list of FocusListeners registered for this component.
protected Color
_foreground
If the foreground color is null, this component inherits the foreground color of its parent Container.
protected Vector
_keyListeners
A list of KeyListeners registered for this component.
protected Point
_origin
The coordinates of the top-left corner of the component, relative to its parent container.
protected WeakReference
_parent
A WeakReference to the Container (e.g Window, Panel or Dialog) that contains us.
protected boolean
_visible
A flag that determines whether this component should be displayed (if its parent is displayed).

Constructor Summary

Component()
Constructor

Method Summary

void
addFocusListener(FocusListener fl_)
Register a FocusListener object for this component.
void
addKeyListener(KeyListener kl_)
Register a KeyListener object for this component.
boolean
contains(Point p)
Checks whether this component "contains" the specified point, where the point's x and y coordinates are defined to be relative to the top left corner of the parent Container.
boolean
contains(int x, int y)
abstract void
debug(int level_)
abstract void
draw()
To be implemented by concrete subclasses.
float
getAlignmentX()
Returns the alignment along the X axis.
float
getAlignmentY()
Returns the alignment along the Y axis.
Window
getAncestorWindow()
Get the Window that contains this component.
Color
getBackground()
Get the background color of this component.
Rectangle
getBounds()
Get the bounding rectangle of this component, relative to the origin of its parent Container.
int
getCursesColor()
Color
getForeground()
Get the foreground color of this component.
abstract int
getHeight()
Point
getLocation()
Point
getLocationOnScreen()
Return the absolute coordinates of this component's origin.
String
getName()
Returns the name of the component.
protected Container
getParent()
Get the parent container of this component.
abstract Dimension
getSize()
abstract int
getWidth()
boolean
hasFocus()
Returns true if this Component has the keyboard input focus.
void
hide()
Deprecated. This method has been replaced by setVisible(boolean).
void
invalidate()
Marks the component and all parents above it as needing to be laid out again.
boolean
isDisplayed()
A component is "displayed" if it is contained within a displayed Window.
boolean
isEnabled()
Determine whether this component can react to user input.
boolean
isFocusTraversable()
Indicates whether this component can be traversed using Tab or Shift-Tab keyboard focus traversal.
boolean
isTotallyObscured()
Return true if this component is totally obscured by one or more windows that are stacked above it.
boolean
isValid()
Determines whether this component has a valid layout.
boolean
isVisible()
Returns true if this component is displayed when its parent container is displayed.
abstract Dimension
minimumSize()
protected void
processEvent(AWTEvent evt_)
Process events that are implemented by all components.
void
processFocusEvent(FocusEvent fe_)
Invoke all the FocusListener callbacks that may have been registered for this component.
void
processKeyEvent(KeyEvent ke_)
Invoke all the KeyListener callbacks that may have been registered for this component.
void
processMouseEvent(MouseEvent e)
Process a MouseEvent that was generated by clicking the mouse somewhere inside this component.
void
repaint()
Causes this component to be repainted as soon as possible (this is done by posting a RepaintEvent onto the system queue).
void
requestFocus()
This method should be invoked by all subclasses of Component which override this method; because this method generates the FOCUS_GAINED event when the component gains the keyboard focus.
void
requestSync()
Causes a SyncEvent to be posted onto the AWT queue, thus requesting a refresh of the physical screen.
void
setBackground(Color color_)
Set the background color of this component.
void
setEnabled(boolean flag_)
Enable this component to react to user input.
void
setForeground(Color color_)
Set the foreground color of this component.
void
setLocation(Point origin_)
void
setLocation(int x_, int y_)
void
setName(String name_)
Sets the name of the component.
void
setParent(Container container_)
Set the parent container of this component.
void
setVisible(boolean visible_)
Shows or hides this component depending on the value of the parameter visible_
void
show()
Deprecated. This method has been replaced by setVisible(boolean).
void
validate()
Ensures that this component is laid out correctly.
void
validateCursesColor()
Compute the component's ncurses color-pair from its foreground and background colors.

Field Details

BOTTOM_ALIGNMENT

public static final float BOTTOM_ALIGNMENT
Field Value:
1.0f

CENTER_ALIGNMENT

public static final float CENTER_ALIGNMENT
Field Value:
0.0f

LEFT_ALIGNMENT

public static final float LEFT_ALIGNMENT
Field Value:
0.0f

RIGHT_ALIGNMENT

public static final float RIGHT_ALIGNMENT
Field Value:
1.0f

TOP_ALIGNMENT

public static final float TOP_ALIGNMENT
Field Value:
0.0f

_alignmentX

protected float _alignmentX
the X-alignment of this component

_alignmentY

protected float _alignmentY
the Y-alignment of this component

_background

protected Color _background
If the background color is null, this component inherits the background color of its parent Container.

_cursesColor

protected int _cursesColor
The number of this component's color-pair, as computed by the ncurses COLOR_PAIR macro. This is set when the component is added to a container and whenever the colors are changed after that, so we don't have to re-determine it every time we draw the component.

A value of -1 indicates that the color-pair number needs to be recomputed.


_enabled

protected boolean _enabled
This flag is true if this component can react to user input.

_focusListeners

protected Vector _focusListeners
A list of FocusListeners registered for this component.

_foreground

protected Color _foreground
If the foreground color is null, this component inherits the foreground color of its parent Container.

_keyListeners

protected Vector _keyListeners
A list of KeyListeners registered for this component.

_origin

protected Point _origin
The coordinates of the top-left corner of the component, relative to its parent container.

_parent

protected WeakReference _parent
A WeakReference to the Container (e.g Window, Panel or Dialog) that contains us. The reason that we use a WeakReference is to allow the parent to be garbage-collected when there are no more strong references to it.

_visible

protected boolean _visible
A flag that determines whether this component should be displayed (if its parent is displayed). This flag is set to true by default, except for Window which is initially invisible.

Constructor Details

Component

public Component()
Constructor

Method Details

addFocusListener

public void addFocusListener(FocusListener fl_)
Register a FocusListener object for this component.

addKeyListener

public void addKeyListener(KeyListener kl_)
Register a KeyListener object for this component.

contains

public boolean contains(Point p)
Checks whether this component "contains" the specified point, where the point's x and y coordinates are defined to be relative to the top left corner of the parent Container.

contains

public boolean contains(int x,
                        int y)

debug

public abstract void debug(int level_)

draw

public abstract void draw()
To be implemented by concrete subclasses.

getAlignmentX

public float getAlignmentX()
Returns the alignment along the X axis. This indicates how the component would like to be aligned relative to ther components. 0 indicates left-aligned, 0.5 indicates centered and 1 indicates right-aligned.

getAlignmentY

public float getAlignmentY()
Returns the alignment along the Y axis. This indicates how the component would like to be aligned relative to ther components. 0 indicates top-aligned, 0.5 indicates centered and 1 indicates bottom-aligned.

getAncestorWindow

public Window getAncestorWindow()
Get the Window that contains this component.

getBackground

public Color getBackground()
Get the background color of this component. If it is null, the component will inherit the background color of its parent container.

getBounds

public Rectangle getBounds()
Get the bounding rectangle of this component, relative to the origin of its parent Container.

getCursesColor

public int getCursesColor()

getForeground

public Color getForeground()
Get the foreground color of this component. If it is null, the component will inherit the foreground color of its parent container.

getHeight

public abstract int getHeight()

getLocation

public Point getLocation()

getLocationOnScreen

public Point getLocationOnScreen()
Return the absolute coordinates of this component's origin. Note that Window (which is a subclass of Container) has a _parent value of null, but it overrides this method.

getName

public String getName()
Returns the name of the component.

getParent

protected Container getParent()
Get the parent container of this component. Can return null if the component has no parent.

getSize

public abstract Dimension getSize()

getWidth

public abstract int getWidth()

hasFocus

public boolean hasFocus()
Returns true if this Component has the keyboard input focus.

hide

public void hide()

Deprecated. This method has been replaced by setVisible(boolean).


invalidate

public void invalidate()
Marks the component and all parents above it as needing to be laid out again. This method is overridden by Container.

isDisplayed

public boolean isDisplayed()
A component is "displayed" if it is contained within a displayed Window. Even though it may be "displayed", it may be obscured by other Windows that are on top of it; and it may not be visible to the user because the _visible flag may be false.

isEnabled

public boolean isEnabled()
Determine whether this component can react to user input.

isFocusTraversable

public boolean isFocusTraversable()
Indicates whether this component can be traversed using Tab or Shift-Tab keyboard focus traversal. If this method returns "false" it can still request focus using requestFocus(), but it will not automatically be assigned focus during keyboard focus traversal.

isTotallyObscured

public boolean isTotallyObscured()
Return true if this component is totally obscured by one or more windows that are stacked above it.

isValid

public boolean isValid()
Determines whether this component has a valid layout. A component is valid when it is correctly sized and positioned within its parent container and all its children (in the case of a Container) are also valid. The default implementation returns true; this method is overridden by Container.

isVisible

public boolean isVisible()
Returns true if this component is displayed when its parent container is displayed.

minimumSize

public abstract Dimension minimumSize()

processEvent

protected void processEvent(AWTEvent evt_)
Process events that are implemented by all components. This can be overridden by subclasses, to handle custom events.

processFocusEvent

public void processFocusEvent(FocusEvent fe_)
Invoke all the FocusListener callbacks that may have been registered for this component.

processKeyEvent

public void processKeyEvent(KeyEvent ke_)
Invoke all the KeyListener callbacks that may have been registered for this component. The KeyListener objects may modify the keycodes, and can also set the "consumed" flag.

processMouseEvent

public void processMouseEvent(MouseEvent e)
Process a MouseEvent that was generated by clicking the mouse somewhere inside this component.

repaint

public void repaint()
Causes this component to be repainted as soon as possible (this is done by posting a RepaintEvent onto the system queue).

requestFocus

public void requestFocus()
This method should be invoked by all subclasses of Component which override this method; because this method generates the FOCUS_GAINED event when the component gains the keyboard focus.

requestSync

public void requestSync()
Causes a SyncEvent to be posted onto the AWT queue, thus requesting a refresh of the physical screen.

setBackground

public void setBackground(Color color_)
Set the background color of this component.

setEnabled

public void setEnabled(boolean flag_)
Enable this component to react to user input. Components are enabled by default.

setForeground

public void setForeground(Color color_)
Set the foreground color of this component.

setLocation

public void setLocation(Point origin_)

setLocation

public void setLocation(int x_,
                        int y_)

setName

public void setName(String name_)
Sets the name of the component.

setParent

public void setParent(Container container_)
Set the parent container of this component. This is intended to be called by Container objects only. Note that we use a WeakReference so that the parent can be garbage- collected when there are no more strong references to it.

setVisible

public void setVisible(boolean visible_)
Shows or hides this component depending on the value of the parameter visible_

show

public void show()

Deprecated. This method has been replaced by setVisible(boolean).


validate

public void validate()
Ensures that this component is laid out correctly. This method is primarily intended to be used on instances of Container. The default implementation does nothing; it is overridden by Container.

validateCursesColor

public void validateCursesColor()
Compute the component's ncurses color-pair from its foreground and background colors. If either color is null, it means that the component has not been added to a container yet, so don't do anything (the colors will be validated when the component is added to the container).