org.zaval.lw
Class LwCanvas

java.lang.Object
  |
  +--org.zaval.util.ValidationObject
        |
        +--org.zaval.lw.LwCanvas
All Implemented Interfaces:
Drawable, Layoutable, LwComponent, Validationable
Direct Known Subclasses:
LwGridCaption, LwImage, LwLabel, LwLine, LwPanel, LwProgress, LwSlider, LwStButton, LwTracker, LwTree

public class LwCanvas
extends ValidationObject
implements LwComponent

This is basic implemenation of the light weight component interface that should be used to develop own light weight component. As rule when you develop a lightweight components it is necessary to pass through following steps:


Field Summary
protected  short bits
           
protected  int height
           
protected  long insets
           
protected  LwComponent parent
          The component parent.
protected  int psHeight
           
protected  int psWidth
           
protected  LwViewMan skins
          The component view manager.
protected  int width
           
protected  int x
           
protected  int y
           
 
Fields inherited from class org.zaval.util.ValidationObject
isValidFlag
 
Constructor Summary
LwCanvas()
           
 
Method Summary
protected  java.awt.Dimension calcPreferredSize()
          Gets the "pure" preferred size for this component.
 boolean canHaveFocus()
          Specifies if the component can have focus.
 java.awt.Color getBackground()
          Gets the background color of this lightweight component.
 java.awt.Rectangle getBounds()
          Gets the bounds of this component.
 int getHeight()
          Gets the height of this component.
 java.awt.Insets getInsets()
          Calculates and returns the insets of this component.
 java.awt.Point getLocation()
          Gets the location of this component point specifying the component top-left corner.
 LwComponent getLwComponentAt(int xx, int yy)
          Determines if the component or an immediate child component contains the (xx, yy) location in its visible part and if so, returns the component.
 LwComponent getLwParent()
          Gets the lightweight parent of this component.
 java.awt.Point getOrigin()
          Returns an origin of the component.
 java.awt.Dimension getPreferredSize()
          Gets the preferred size of this component.
 java.awt.Dimension getSize()
          Returns a size of this component.
 LwViewMan getViewMan(boolean autoCreate)
          Returns a view manager of the component.
 java.awt.Rectangle getVisiblePart()
          Returns the bounding rectangle of the visible part for the component.
 int getWidth()
          Gets the width of this component.
 int getX()
          Gets the x location of this component specifying the component top-left corner.
 int getY()
          Gets the y location of this component specifying the component top-left corner.
 boolean hasFocus()
          Tests if the component is a focus owner.
 void invalidate()
          Invalidates this component.
 boolean isEnabled()
          Determines whether this component is enabled.
 boolean isOpaque()
          Gets the opaque of this component.
 boolean isVisible()
          Determines if this component is visible.
 void paint(java.awt.Graphics g)
          Paints this component.
protected  void recalc()
          Invoked with validate method only if the component is not valid.
 void repaint()
          Performs repainting process of this component.
 void repaint(int x, int y, int w, int h)
          Performs repainting process of the specified rectangle.
 void requestFocus()
          Requests focus for this component.
 void setBackground(java.awt.Color c)
          Sets the background color of this component.
 void setEnabled(boolean b)
          Enables or disables this component.
 void setInsets(int top, int left, int bottom, int right)
          Sets the specified insets for the component.
 void setLocation(int xx, int yy)
          Sets a new location for this component.
 void setLwParent(LwComponent o)
          Sets the lightweight parent of this component.
 void setOpaque(boolean b)
          Sets the opaque of this component.
 void setPSSize(int w, int h)
          Sets the specified preferred size for the component.
 void setSize(int w, int h)
          Sets the specified size for this component.
 void setViewMan(LwViewMan man)
          Sets the specified view manager for the component.
 void setVisible(boolean b)
          Shows or hides this lightweight component depending on the value of parameter b.
 java.lang.String toString()
          Returns a string representation of the object.
 void update(java.awt.Graphics g)
          Updates this component.
 void validate()
          Validates this component.
protected  void viewManChanged()
          Invoked whenever the view manager has been changed.
protected  void vrp()
          Invalidates and then repaints the component.
 
Methods inherited from class org.zaval.util.ValidationObject
isValid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.zaval.util.Validationable
isValid
 

Field Detail

insets

protected long insets

bits

protected short bits

x

protected int x

y

protected int y

width

protected int width

height

protected int height

psWidth

protected int psWidth

psHeight

protected int psHeight

parent

protected LwComponent parent
The component parent.

skins

protected LwViewMan skins
The component view manager.
Constructor Detail

LwCanvas

public LwCanvas()
Method Detail

getInsets

public java.awt.Insets getInsets()
Calculates and returns the insets of this component. Take care that insets for lightweight components differ from Java AWT components. The lightweight insets defines indents from "left", "top", "right" and "bottom" of the component view. Don't override the method. If you want to define insets use setInsets method.
Specified by:
getInsets in interface Layoutable
Returns:
the insets of this component.

getX

public int getX()
Description copied from interface: Layoutable
Gets the x location of this component specifying the component top-left corner. The location is relative to the parent component coordinate space.
Specified by:
getX in interface Layoutable
Following copied from interface: org.zaval.lw.Layoutable
Returns:
an x coordinate representing the top-left corner of the component bounds in the coordinate space of the component parent.

getY

public int getY()
Description copied from interface: Layoutable
Gets the y location of this component specifying the component top-left corner. The location is relative to the parent component coordinate space.
Specified by:
getY in interface Layoutable
Following copied from interface: org.zaval.lw.Layoutable
Returns:
an y coordinate representing the top-left corner of the component bounds in the coordinate space of the component parent.

getWidth

public int getWidth()
Description copied from interface: Layoutable
Gets the width of this component.
Specified by:
getWidth in interface Layoutable
Following copied from interface: org.zaval.lw.Layoutable
Returns:
a width of the component.

getHeight

public int getHeight()
Description copied from interface: Layoutable
Gets the height of this component.
Specified by:
getHeight in interface Layoutable
Following copied from interface: org.zaval.lw.Layoutable
Returns:
a height of the component.

setInsets

public void setInsets(int top,
                      int left,
                      int bottom,
                      int right)
Sets the specified insets for the component.
Parameters:
top - the top indent.
left - the left indent.
bottom - the bottom indent.
right - the right indent.

getSize

public java.awt.Dimension getSize()
Returns a size of this component. The size is reperesented with java.awt.Dimension class.
Specified by:
getSize in interface Layoutable
Returns:
a Dimension object that indicates the size of this component.

getVisiblePart

public java.awt.Rectangle getVisiblePart()
Returns the bounding rectangle of the visible part for the component.
Specified by:
getVisiblePart in interface LwComponent
Returns:
a visible part bounding rectangle.

setLwParent

public void setLwParent(LwComponent o)
Sets the lightweight parent of this component. It is supposed that the parent implements LwContainer interface. The method is provided for lightweight core usage to support components hierarchy, not for applications that base on the library. Don't touch the method.
Specified by:
setLwParent in interface LwComponent
Parameters:
o - the parent component of this lightweight component.

getLocation

public java.awt.Point getLocation()
Gets the location of this component point specifying the component top-left corner. The location is relative to the parent component coordinate space.
Specified by:
getLocation in interface Layoutable
Returns:
an instance of Point representing the top-left corner of the component bounds in the coordinate space of the component parent.

getBackground

public java.awt.Color getBackground()
Gets the background color of this lightweight component.
Specified by:
getBackground in interface Drawable
Returns:
a componen background color.

isVisible

public boolean isVisible()
Determines if this component is visible. The component is visible if the visibility flag is true.
Specified by:
isVisible in interface Layoutable
Returns:
true if the component is visible; false otherwise.

setVisible

public void setVisible(boolean b)
Shows or hides this lightweight component depending on the value of parameter b. The method performs appropriate LwComponentEvent.
Specified by:
setVisible in interface LwComponent
Parameters:
b - if it is true, shows this component; otherwise, hides this component.

isEnabled

public boolean isEnabled()
Determines whether this component is enabled. If the method returns true than the component is enabled and can participate in event handling and performing processes. Components are enabled initially by default. A component can be enabled or disabled by calling its setEnabled method.
Specified by:
isEnabled in interface Drawable
Returns:
true if the component is enabled; false otherwise.

setEnabled

public void setEnabled(boolean b)
Enables or disables this component. An enabled component can participate in events handling and performing processes. Component is enabled initially by default. The method performs appropriate LwComponentEvent.
Specified by:
setEnabled in interface LwComponent
Parameters:
b - if true, this component is enabled; otherwise this component is disabled.

setBackground

public void setBackground(java.awt.Color c)
Sets the background color of this component. The color is used to fill the component background in case if it is not transparent.
Specified by:
setBackground in interface LwComponent
Parameters:
c - the color to become this component background color. Use null as the color value to set the background to the default color value.

invalidate

public void invalidate()
Invalidates this component. The parent will be invalidated with this component too.
Specified by:
invalidate in interface Validationable
Overrides:
invalidate in class ValidationObject

validate

public void validate()
Validates this component. The method initiates validation process only if it is necessary. It means that you don't need to care about frequency the method executing. The method executes recalc method to calculate the component metrics if it is necessary. So, override the method (recalc method) to calculate some metrical characteristics to minimize the computation time.
Specified by:
validate in interface Validationable
Overrides:
validate in class ValidationObject

setLocation

public void setLocation(int xx,
                        int yy)
Sets a new location for this component. The top-left corner of the new location is specified by the x and y parameters in the coordinate space of this component parent.
Specified by:
setLocation in interface Layoutable
Parameters:
xx - the x-coordinate of the new location top-left corner in the parent coordinate space.
yy - The y-coordinate of the new location top-left corner in the parent coordinate space.

setSize

public void setSize(int w,
                    int h)
Sets the specified size for this component.
Specified by:
setSize in interface Layoutable
Parameters:
w - the width of this component.
h - the height of this component.

getBounds

public java.awt.Rectangle getBounds()
Gets the bounds of this component. The bounds is represented with java.awt.Rectangle class.
Specified by:
getBounds in interface Layoutable
Returns:
a rectangle indicating this component bounds.

getLwComponentAt

public LwComponent getLwComponentAt(int xx,
                                    int yy)
Determines if the component or an immediate child component contains the (xx, yy) location in its visible part and if so, returns the component.
Specified by:
getLwComponentAt in interface LwComponent
Parameters:
xx - the x coordinate.
yy - the y coordinate.
Returns:
the component or sub-component that contains the (x, y) location; null if the location doesn't belong to visible part of this component.

getLwParent

public LwComponent getLwParent()
Gets the lightweight parent of this component. It is supposed that the parent implements LwContainer interface.
Specified by:
getLwParent in interface LwComponent
Returns:
a parent container of this component.

recalc

protected void recalc()
Invoked with validate method only if the component is not valid. The method shoud be overrided to calculate metrical characteristics of the component to minimize computation time of the preferred size for the component. For example, you can calculate a preferred size inside the method and just return it by calcPreferredSize method.
Overrides:
recalc in class ValidationObject

repaint

public void repaint()
Performs repainting process of this component. The method causes calling of update and than paint methods. The method bases on appropriate method of LwPaintManager.
Specified by:
repaint in interface Drawable

repaint

public void repaint(int x,
                    int y,
                    int w,
                    int h)
Performs repainting process of the specified rectangle. The method causes calling of update and than paint methods. The method bases on appropriate method of LwPaintManager.
Specified by:
repaint in interface Drawable
Parameters:
x - the x coordinate.
y - the y coordinate.
w - the width.
h - the height.

update

public void update(java.awt.Graphics g)
Updates this component. The calling of the method precedes the calling of paint method and it is performed with repaint method. The method can be used to fill the drawable component with the background color if the component is opaque. In the implementation light weight component is updated (using the background color) with LwPaintManager, so it is not necessary to care about it.

You can use the method to define own background pattern.

Specified by:
update in interface Drawable
Parameters:
g - the specified context to be used for updating.

paint

public void paint(java.awt.Graphics g)
Paints this component. You can use the method to define a face of the component
Specified by:
paint in interface Drawable
Parameters:
g - the graphics context to be used for painting.

getPreferredSize

public java.awt.Dimension getPreferredSize()
Gets the preferred size of this component. The method computes the preferred size as a sum of the component insets (returned with getInsets method) and a "pure" preferred size (returned with calcPreferredSize method). You should not override the method, use calcPreferredSize method to define the "pure" preferred size of this component.
Specified by:
getPreferredSize in interface Layoutable
Returns:
a dimension object indicating this component preferred size.

getViewMan

public LwViewMan getViewMan(boolean autoCreate)
Returns a view manager of the component. The view manager can be null. The input argument autoCreate defines if the view manager has to be created automatically in a case if it has not been determined before. It means, if the argument is true and the view manager is null, than the component will try to create and initialize its view manager by a default view manager. If the argument is false than the method returns the component view manager as is.
Specified by:
getViewMan in interface LwComponent
Parameters:
autoCreate - the flag defines if the view manager should be created automatically.
Returns:
a view manager for the component.

setViewMan

public void setViewMan(LwViewMan man)
Sets the specified view manager for the component.
Specified by:
setViewMan in interface LwComponent
Parameters:
man - the view manager to set for the component.

toString

public java.lang.String toString()
Returns a string representation of the object.
Overrides:
toString in class java.lang.Object
Returns:
a string representation of this instance.

calcPreferredSize

protected java.awt.Dimension calcPreferredSize()
Gets the "pure" preferred size for this component. The method should be overrided to define the component preferred size. Don't use insets to calculate the preferred size, the insets will be added with getPreferredSize method.
Returns:
a "pure" preferred size.

canHaveFocus

public boolean canHaveFocus()
Description copied from interface: LwComponent
Specifies if the component can have focus.
Specified by:
canHaveFocus in interface LwComponent
Following copied from interface: org.zaval.lw.LwComponent
Returns:
true if the component can have the focus.

hasFocus

public boolean hasFocus()
Tests if the component is a focus owner. The method uses current LwFocusManager manager to define a focus owner.
Returns:
true if the component is a focus owner; otherwise false

requestFocus

public void requestFocus()
Requests focus for this component. The method uses current LwFocusManager manager to request a focus. The component can be a focus owner if it implements LwFocusListener interface.

setOpaque

public void setOpaque(boolean b)
Sets the opaque of this component. Use false argument value to make a transparent component from this component. The painting process will not use update method and the background view for a transparent component.
Specified by:
setOpaque in interface Drawable
Parameters:
b - the opaque flag.

isOpaque

public boolean isOpaque()
Gets the opaque of this component. If the method returns false than the component is transparent, in this case update method has not be called during painting process and LwPaintManager doesn't clear the component with the background color.
Specified by:
isOpaque in interface Drawable
Returns:
true if the component is opaque; otherwise false.

setPSSize

public void setPSSize(int w,
                      int h)
Sets the specified preferred size for the component. Using the method it is possible to fix the preferred size with the given width and height. In this case getPreferredSize method returns the fixed size.
Parameters:
w - the width to be used as the preferred size width. If the width is less zero than the width will be calculated basing on the component insets and the returned by calcPreferredSize width.
h - the height to be used as the preferred size height. If the height is less zero than the height will be calculated basing on the component insets and the returned by calcPreferredSize height.

getOrigin

public java.awt.Point getOrigin()
Returns an origin of the component. The origin defines an offset of the component view relatively the component point of origin. The origin can be used to scroll the component view. The default origin value is null, in this case the origin is (0, 0).
Specified by:
getOrigin in interface Drawable
Returns:
an origin of the component.

viewManChanged

protected void viewManChanged()
Invoked whenever the view manager has been changed. The method can be overrided to listen when the view manager is re-set.

vrp

protected void vrp()
Invalidates and then repaints the component.


Copyright © Zaval Creative Engineering Group, 2000-2005.
http://www.zaval.org