org.zaval.lw
Class LwCanvas
java.lang.Object
|
+--org.zaval.lw.LwCanvas
- All Implemented Interfaces:
- Layoutable, LwComponent, Validationable
- Direct Known Subclasses:
- LwGridCaption, LwImage, LwLabel, LwLine, LwPanel, LwProgress, LwSlider, LwStButton, LwTracker
- public class LwCanvas
- extends java.lang.Object
- 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 the following steps:
-
Inherit the class for your lightweight component.
-
Implement necessary events listeners interfaces, to have ability handling
required lightweight events.
-
Override (if it is necessary)
paint method to define the component face.
-
Override (if it is necessary)
update method to define the component
background.
-
Override (if it is necessary)
recalc method to calculate the component
metrics. For example, you can calculate "pure" preferred size inside the method or
some metrical characteristics that are used to calculate the preferred size.
-
Override (if it is necessary)
calcPreferredSize method to define "pure"
preferred size of the component face.
|
Method Summary |
protected int |
calcInsets(int type,
int ci,
int bi)
Calculates and returns the given inset. |
protected java.awt.Dimension |
calcPreferredSize()
Gets the "pure" preferred size for this component. |
boolean |
canHaveFocus()
Specifies if the component can have focus. |
protected void |
customize(int id)
|
protected java.awt.Rectangle |
cvp(java.awt.Rectangle r)
Calculates and returns the visiable area of the component.
|
java.awt.Color |
getBackground()
Gets the background color of this lightweight component. |
int |
getBottom()
Returns the inset from the bottom. |
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. |
int |
getLeft()
Returns the inset from the left. |
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. |
protected java.awt.Dimension |
getPSImpl()
Invoked to calculate and return the component preferred size. |
int |
getRight()
Returns the inset from the right. |
java.awt.Dimension |
getSize()
Returns a size of this component. |
int |
getTop()
Returns the inset from the top. |
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 |
isValid()
Checks if this object is valid. |
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(boolean b)
Invoked whenever the component got or lost the focus. |
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. |
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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
isValidValue
protected boolean isValidValue
bits
protected int 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
top
protected int top
left
protected int left
bottom
protected int bottom
right
protected int right
parent
protected LwContainer parent
- The component parent.
skins
protected LwViewMan skins
- The component view manager.
temporary
protected static java.awt.Rectangle temporary
LwCanvas
public LwCanvas()
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:
- a
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)
- Description copied from interface:
LwComponent
- Sets the specified insets for the component.
- Specified by:
setInsets in interface LwComponent
- Following copied from interface:
org.zaval.lw.LwComponent
- 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 represented 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()
- Description copied from interface:
LwComponent
- Returns the bounding rectangle of the visible part for the component.
- Specified by:
getVisiblePart in interface LwComponent
- Following copied from interface:
org.zaval.lw.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 LwComponent
- Returns:
- a component 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 LwVCLEvent.
- 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 LwComponent
- 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 LwVCLEvent.
- 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
isValid
public boolean isValid()
- Description copied from interface:
Validationable
- Checks if this object is valid.
- Specified by:
isValid in interface Validationable
- Following copied from interface:
org.zaval.util.Validationable
- Returns:
- a valid state of the object. The object is valid if the method returns
true.
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
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 are 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 should be overridden 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.
repaint
public void repaint(boolean b)
- Description copied from interface:
LwComponent
- Invoked whenever the component got or lost the focus. The method is supposed to optimize
the performance of the focus marker, since in most cases it is not necessary to repaint
all component area. By default the method repaint all component area.
- Specified by:
repaint in interface LwComponent
- Following copied from interface:
org.zaval.lw.LwComponent
- Parameters:
b - true if the component has got the focus, and false
if the component lost the focus.
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 LwComponent
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 LwComponent
- Parameters:
x - the x coordinate.y - the y coordinate.w - the width.h - the height.
cvp
protected java.awt.Rectangle cvp(java.awt.Rectangle r)
- Calculates and returns the visiable area of the component.
The method doesn't create additional Rectangle object to have
better performance, so the method returns the input argument
instance or
null if the component doesn't have a
visible area.
- Parameters:
r - the instance of the Rectangle class where the result will be put.- Returns:
null if the component doesn't have a visible area, otherwise
the method returns the input argument the visible area bounds are put.
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 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 LwComponent
- 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 LwComponent
- 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.
getTop
public int getTop()
- Returns the inset from the top.
- Returns:
- an inset from the top.
getLeft
public int getLeft()
- Returns the inset from the left.
- Returns:
- an inset from the left.
getBottom
public int getBottom()
- Returns the inset from the bottom.
- Returns:
- an inset from the bottom.
getRight
public int getRight()
- Returns the inset from the right.
- Returns:
- an inset from the right.
calcPreferredSize
protected java.awt.Dimension calcPreferredSize()
- Gets the "pure" preferred size for this component. The method should be overridden 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 LwComponent
- 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 LwComponent
- 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 LwComponent
- Returns:
- an origin of the component.
viewManChanged
protected void viewManChanged()
- Invoked whenever the view manager has been changed. The method can be overridden to listen
when the view manager is re-set.
vrp
protected void vrp()
- Invalidates and then repaints the component.
getPSImpl
protected java.awt.Dimension getPSImpl()
- Invoked to calculate and return the component preferred size. The method defines
the preferred size calculation algorithm.
- Returns:
- a preferred size of the component.
calcInsets
protected int calcInsets(int type,
int ci,
int bi)
- Calculates and returns the given inset.
- Parameters:
type - the inset type. Use LwToolkit.TOP, LwToolkit.LEFT, LwToolkit.RIGHT, LwToolkit.BOTTOM
as the argument value.ci - the component inset.bi - the border inset.- Returns:
- an inset.
customize
protected void customize(int id)
|