org.zaval.lw
Class LwView

java.lang.Object
  |
  +--org.zaval.util.ValidationObject
        |
        +--org.zaval.lw.LwView
All Implemented Interfaces:
Validationable
Direct Known Subclasses:
LwBorder, LwCursorView, LwRender

public abstract class LwView
extends ValidationObject

This abstract class is used as base for lightweight views implementations. A view is used to provide painting for a decorative element (box, border and so on). To develop a view it is necessary to pass through following steps:


Field Summary
static int MOSAIC
          The mosaic type of the view.
static int ORIGINAL
          The original type of the view.
static int STRETCH
          The stretch type of the view.
 
Fields inherited from class org.zaval.util.ValidationObject
isValidFlag
 
Constructor Summary
LwView()
          Constructs the view.
LwView(int type)
          Constructs the view with the specified view type.
 
Method Summary
protected  java.awt.Dimension calcPreferredSize()
          Calculates and returns the view preferred size.
 java.awt.Insets getInsets()
          Gets the view insets.
 java.awt.Dimension getPreferredSize()
          Gets the view preferred size.
 int getType()
          Gets the type of the view.
protected  void ownerChanged(Validationable v)
          The method is called whenever the view owner has been changed.
 void paint(java.awt.Graphics g, int x, int y, Drawable d)
          Paints the view using the preferred size of the view.
abstract  void paint(java.awt.Graphics g, int x, int y, int w, int h, Drawable d)
          Paints the view using a given width and height.
protected  void recalc()
          Invoked with validate method if the view is invalid.
 void setType(int t)
          Sets the specified type of the view.
 
Methods inherited from class org.zaval.util.ValidationObject
invalidate, isValid, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STRETCH

public static final int STRETCH
The stretch type of the view.

MOSAIC

public static final int MOSAIC
The mosaic type of the view.

ORIGINAL

public static final int ORIGINAL
The original type of the view.
Constructor Detail

LwView

public LwView()
Constructs the view. The view will use mosaic type as a default view type.

LwView

public LwView(int type)
Constructs the view with the specified view type.
Parameters:
type - the view type.
Method Detail

getType

public int getType()
Gets the type of the view.
Returns:
a type of the view.

setType

public void setType(int t)
Sets the specified type of the view. The view can have stretch, mosaic or original type (the types are defined with the appropriate constants of the class), otherwise the method performs IllegalArgumentException exception. The type defines an algorithm that is used to paint the view, the short descriptions of the possible view types are shown below:
Parameters:
t - the specified view type.

getInsets

public java.awt.Insets getInsets()
Gets the view insets. The insets is used to calculate the owner component insets.
Returns:
an insets of the view.

getPreferredSize

public java.awt.Dimension getPreferredSize()
Gets the view preferred size. The size is calculated as amount of a "pure" preferred size (that is returned with calcPreferredSize method) and the view insets. The preferred size is used with an owner component to compute own preferred size.
Returns:
a preferred size of the view.

calcPreferredSize

protected java.awt.Dimension calcPreferredSize()
Calculates and returns the view preferred size. The method has not to use the view insets to compute the preferred size.
Returns:
a "pure" preferred size of the view.

recalc

protected void recalc()
Invoked with validate method if the view is invalid. The method can be overrided to calculate metrical characteristics of the view and the method is called only if it is realy necessary, so there is not necessaty to care about superfluous calling and computing.
Overrides:
recalc in class ValidationObject

paint

public void paint(java.awt.Graphics g,
                  int x,
                  int y,
                  Drawable d)
Paints the view using the preferred size of the view. The location where the view has to be painted is determined with x and y coordinates.
Parameters:
g - the specified context to be used for painting.
x - the x coordinate.
y - the y coordinate.
d - the owner component.

paint

public abstract void paint(java.awt.Graphics g,
                           int x,
                           int y,
                           int w,
                           int h,
                           Drawable d)
Paints the view using a given width and height. The location where the view has to be painted is determined with x and y coordinates. This abstract method has to be implmented to define a "face" for the view.
Parameters:
g - the specified context to be used for painting.
x - the x coordinate.
y - the y coordinate.
w - the width of the view.
h - the height of the view.
d - the owner component.

ownerChanged

protected void ownerChanged(Validationable v)
The method is called whenever the view owner has been changed. It allows to store the owner reference for a given view if it is necessary. For example, if the view preferred size has been changed so in this case the view owner component should be invalidated, because the owner preferred size depends on the view.
Parameters:
v - the new view owner.


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