org.zaval.lw
Class LwTracker

java.lang.Object
  |
  +--org.zaval.util.ValidationObject
        |
        +--org.zaval.lw.LwCanvas
              |
              +--org.zaval.lw.LwTracker
All Implemented Interfaces:
Drawable, java.util.EventListener, Layoutable, LwComponent, LwMouseListener, LwMouseMotionListener, TooltipInfo, Validationable

public class LwTracker
extends LwCanvas
implements LwMouseListener, LwMouseMotionListener, TooltipInfo

This is tracker component. The component is like slider component, but this is more complex:


Field Summary
static int BUNDLE_1
          Specifies type for leftmost and rightmost bundles.
static int BUNDLE_2
          Specifies type for bundles that are located between leftmost and rightmost bundles.
static int INNER_SCALE
          Specifies scale area that is placed between rightmost and left most bundles.
static int OUTER_SCALE
          Specifies scale area that is placed on the right and on the left of rightmost and left most bundles.
static int ST_ONSURFACE
          The ONSURFACE state.
static int ST_OUTSURFACE
          The OUTSURFACE state.
static int ST_PRESSED
          The PRESSED state.
static int ST_REMOVING
          The REMOVING state.
 
Fields inherited from class org.zaval.lw.LwCanvas
bits, height, insets, parent, psHeight, psWidth, skins, width, x, y
 
Fields inherited from class org.zaval.util.ValidationObject
isValidFlag
 
Constructor Summary
LwTracker()
          Constructs the class instance.
 
Method Summary
 void addTrackerListener(LwTrackerListener l)
          Adds the specified tracker listener.
protected  java.awt.Dimension calcPreferredSize()
          Gets the "pure" preferred size for this component.
 boolean canHaveFocus()
          Specifies if the component can have focus.
 void endDragged(LwMouseMotionEvent e)
          Invoked when the mouse ends dragged.
 int findNearest(int x, int y)
          Finds nearest tracker value where a bundle can be moved by the specified location.
 int getBundleIndex(int x, int y)
          Returns a bundle element index by the specified location.
 int getBundles()
          Gets a number of bundles elements.
protected  LwView getBundleView(int bundleIndex)
          Gets a view for the specified bundle.
 int getMax()
          Gets the maximal possible value.
 int getMax(int bundleIndex)
          Gets the maximal possible value for the specified bundle.
 int getMin()
          Gets a minimal possible value.
 int getMin(int bundleIndex)
          Gets a minimal possible value for the specified bundle.
 java.awt.Color getScaleColor(int type)
          Gets the scale color for the specified scale area.
 int getStep()
          Gets the exact step.
 LwTextRender getTitleRender()
          Gets the text render that is used to render the tracker titles.
 LwComponent getTooltip(int x, int y)
          Returns a component that should be used as a tooltip for the specified location of a target component.
 int getValue(int index)
          Gets the specified bundle value.
 LwView getView(int id, int state)
          Gets a view that is associated with the given state for the specified bundle type.
 int insertBundle(int value)
          Inserts a new bundle with the specified value.
 void invalidate()
          Invalidates this component.
 int loc2value(int x)
          Converts the specified location to a tracker value.
 void mouseClicked(LwMouseEvent e)
          Invoked when the mouse button has been clicked on a light weight component.
 void mouseDragged(LwMouseMotionEvent e)
          Invoked when a mouse button is pressed on a component and then dragged.
 void mouseEntered(LwMouseEvent e)
          Invoked when the mouse enters a light weight component.
 void mouseExited(LwMouseEvent e)
          Invoked when the mouse exits a light weight component.
 void mouseMoved(LwMouseMotionEvent e)
          Invoked when the mouse pointer has been moved on a light weight component (with no buttons no down).
 void mousePressed(LwMouseEvent e)
          Invoked when the mouse button has been pressed on a light weight component.
 void mouseReleased(LwMouseEvent e)
          Invoked when the mouse button has been released on a light weight component.
 void paint(java.awt.Graphics g)
          Paints this component.
protected  void perform(int bi, int v, int pv, int id)
          Performs a tracker event for the specified bundle with the specified event id and event parameters.
protected  void recalc()
          Invoked with validate method only if the component is not valid.
 void removeBundle(int index)
          Removes a bundle at the specified index.
 void removeTrackerListener(LwTrackerListener l)
          Removes the specified tracker listener so it no longer receives tracker events from this component.
 void setScaleColor(int type, java.awt.Color c)
          Sets the scale color for the specified scale area.
 void setScaleStep(int s)
          Sets the scale step.
 void setStep(int step)
          Sets the specified exact step.
 void setTooltip(int index, LwComponent c)
          Sets the given component as tooltip for the specified bundle.
 void setValue(int index, int value)
          Sets the given value for the specified bundle.
 void setValues(int min, int max, int[] intervals, int[] values, int step)
          Sets the tracker properties.
 void setView(int id, int state, LwView v)
          Sets the given view for the given state and the specified bundle type.
 void showTitle(boolean b)
          Sets the tracker title visibility.
 void startDragged(LwMouseMotionEvent e)
          Invoked when the mouse starts dragged.
 int value2loc(int v)
          Converts the specified tracker value to a location.
 
Methods inherited from class org.zaval.lw.LwCanvas
getBackground, getBounds, getHeight, getInsets, getLocation, getLwComponentAt, getLwParent, getOrigin, getPreferredSize, getSize, getViewMan, getVisiblePart, getWidth, getX, getY, hasFocus, isEnabled, isOpaque, isVisible, repaint, repaint, requestFocus, setBackground, setEnabled, setInsets, setLocation, setLwParent, setOpaque, setPSSize, setSize, setViewMan, setVisible, toString, update, validate, viewManChanged, vrp
 
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

ST_ONSURFACE

public static final int ST_ONSURFACE
The ONSURFACE state.

ST_PRESSED

public static final int ST_PRESSED
The PRESSED state.

ST_OUTSURFACE

public static final int ST_OUTSURFACE
The OUTSURFACE state.

ST_REMOVING

public static final int ST_REMOVING
The REMOVING state.

BUNDLE_1

public static final int BUNDLE_1
Specifies type for leftmost and rightmost bundles. It is used to customize views for the bundle type.

BUNDLE_2

public static final int BUNDLE_2
Specifies type for bundles that are located between leftmost and rightmost bundles. It is used to customize views for the bundle type.

OUTER_SCALE

public static final int OUTER_SCALE
Specifies scale area that is placed on the right and on the left of rightmost and left most bundles. It is used to customize color for the scale area.

INNER_SCALE

public static final int INNER_SCALE
Specifies scale area that is placed between rightmost and left most bundles. It is used to customize color for the scale area.
Constructor Detail

LwTracker

public LwTracker()
Constructs the class instance.
Method Detail

canHaveFocus

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

showTitle

public void showTitle(boolean b)
Sets the tracker title visibility.
Parameters:
b - the tracker title visibility.

setTooltip

public void setTooltip(int index,
                       LwComponent c)
Sets the given component as tooltip for the specified bundle.
Parameters:
index - the specified bundle index.
c - the specified component to be used as tooltip.

getTitleRender

public LwTextRender getTitleRender()
Gets the text render that is used to render the tracker titles.
Returns:
a titles render.

getView

public LwView getView(int id,
                      int state)
Gets a view that is associated with the given state for the specified bundle type.
Parameters:
id - the specified bundle type. Use BUNDLE_1 or BUNDLE_2 as the argument value.
state - the bundle state. Depending on the bundle type the state can be as follow:
  • BUNDLE_1 (leftmost and rightmost bundles): ST_ONSURFACE,ST_PRESSED,ST_OUTSURFACE.
  • BUNDLE_2: ST_ONSURFACE,ST_PRESSED,ST_OUTSURFACE,ST_REMOVING.
Returns:
the view.

setView

public void setView(int id,
                    int state,
                    LwView v)
Sets the given view for the given state and the specified bundle type.
Parameters:
id - the specified bundle type. Use BUNDLE_1 or BUNDLE_2 as the argument value.
state - the bundle state. Depending on the bundle type the state can be as follow:
  • BUNDLE_1 (leftmost and rightmost bundles): ST_ONSURFACE,ST_PRESSED,ST_OUTSURFACE.
  • BUNDLE_2: ST_ONSURFACE,ST_PRESSED,ST_OUTSURFACE,ST_REMOVING.
v - the specified view.

getScaleColor

public java.awt.Color getScaleColor(int type)
Gets the scale color for the specified scale area.
Returns:
a scale color.

setScaleColor

public void setScaleColor(int type,
                          java.awt.Color c)
Sets the scale color for the specified scale area.
Parameters:
type - the specified scale area. Use INNER_SCALE (scale area that is located between leftmost and rightmost bundles) or OUTER_SCALE. as the parameter value.
c - the scale color.

setScaleStep

public void setScaleStep(int s)
Sets the scale step.
Parameters:
s - the scale step.

setValues

public void setValues(int min,
                      int max,
                      int[] intervals,
                      int[] values,
                      int step)
Sets the tracker properties.
Parameters:
min - the specified minimal possible value.
max - the specified maximal possible value.
intervals - the specified intervals sizes array.
values - the specified bundles values.
step - the specified step.

getBundles

public int getBundles()
Gets a number of bundles elements.
Returns:
the number of bundles elements.

removeBundle

public void removeBundle(int index)
Removes a bundle at the specified index.
Parameters:
index - the specified index.

insertBundle

public int insertBundle(int value)
Inserts a new bundle with the specified value. The method calculates the new bundle element index basing on the value and after that inserts the new bundle in the bundle list at the found index.
Parameters:
value - the specified bundle value.

getMin

public int getMin()
Gets a minimal possible value.
Returns:
the minimal possible value.

getMin

public int getMin(int bundleIndex)
Gets a minimal possible value for the specified bundle.
Parameters:
bundleIndex - the specified bundle index.
Returns:
the minimal possible value.

getMax

public int getMax()
Gets the maximal possible value.
Returns:
a maximal possible value.

getMax

public int getMax(int bundleIndex)
Gets the maximal possible value for the specified bundle.
Parameters:
bundleIndex - the specified bundle index.
Returns:
a maximal possible value.

setValue

public void setValue(int index,
                     int value)
Sets the given value for the specified bundle. The value should be less than nearest right bundle value and greater than nearest left bundle value.
Parameters:
index - the specified bundle index.
value - the specified value.

getValue

public int getValue(int index)
Gets the specified bundle value.
Parameters:
index - the specified bundle index.
Returns:
a value.

addTrackerListener

public void addTrackerListener(LwTrackerListener l)
Adds the specified tracker listener. Using the listener it possible to be notified whenever a bundle value has been changed, a new bundle has been added or removed or tracker has provide value info.
Parameters:
l - the specified tracker listener.

removeTrackerListener

public void removeTrackerListener(LwTrackerListener l)
Removes the specified tracker listener so it no longer receives tracker events from this component.
Parameters:
l - the specified tracker listener.

paint

public void paint(java.awt.Graphics g)
Description copied from class: LwCanvas
Paints this component. You can use the method to define a face of the component
Overrides:
paint in class LwCanvas
Following copied from class: org.zaval.lw.LwCanvas
Parameters:
g - the graphics context to be used for painting.

startDragged

public void startDragged(LwMouseMotionEvent e)
Description copied from interface: LwMouseMotionListener
Invoked when the mouse starts dragged.
Specified by:
startDragged in interface LwMouseMotionListener
Following copied from interface: org.zaval.lw.event.LwMouseMotionListener
Parameters:
e - the specified mouse motion event.

endDragged

public void endDragged(LwMouseMotionEvent e)
Description copied from interface: LwMouseMotionListener
Invoked when the mouse ends dragged.
Specified by:
endDragged in interface LwMouseMotionListener
Following copied from interface: org.zaval.lw.event.LwMouseMotionListener
Parameters:
e - the specified mouse motion event.

mouseDragged

public void mouseDragged(LwMouseMotionEvent e)
Description copied from interface: LwMouseMotionListener
Invoked when a mouse button is pressed on a component and then dragged. Mouse drag events will continue to be delivered to the component where the first originated until the mouse button is released (regardless of whether the mouse position is within the bounds of the component).
Specified by:
mouseDragged in interface LwMouseMotionListener
Following copied from interface: org.zaval.lw.event.LwMouseMotionListener
Parameters:
e - the specified mouse motion event.

mousePressed

public void mousePressed(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse button has been pressed on a light weight component.
Specified by:
mousePressed in interface LwMouseListener
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

mouseReleased

public void mouseReleased(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse button has been released on a light weight component.
Specified by:
mouseReleased in interface LwMouseListener
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

mouseMoved

public void mouseMoved(LwMouseMotionEvent e)
Description copied from interface: LwMouseMotionListener
Invoked when the mouse pointer has been moved on a light weight component (with no buttons no down).
Specified by:
mouseMoved in interface LwMouseMotionListener
Following copied from interface: org.zaval.lw.event.LwMouseMotionListener
Parameters:
e - the specified mouse motion event.

mouseClicked

public void mouseClicked(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse button has been clicked on a light weight component.
Specified by:
mouseClicked in interface LwMouseListener
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

mouseEntered

public void mouseEntered(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse enters a light weight component.
Specified by:
mouseEntered in interface LwMouseListener
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

mouseExited

public void mouseExited(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse exits a light weight component.
Specified by:
mouseExited in interface LwMouseListener
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

invalidate

public void invalidate()
Description copied from class: LwCanvas
Invalidates this component. The parent will be invalidated with this component too.
Overrides:
invalidate in class LwCanvas

getTooltip

public LwComponent getTooltip(int x,
                              int y)
Description copied from interface: TooltipInfo
Returns a component that should be used as a tooltip for the specified location of a target component.
Specified by:
getTooltip in interface TooltipInfo
Following copied from interface: org.zaval.lw.TooltipInfo
Parameters:
x - the x coordinate of the location.
y - the y coordinate of the location.
Returns:
the tooltip component.

getBundleIndex

public int getBundleIndex(int x,
                          int y)
Returns a bundle element index by the specified location.
Parameters:
x - the specified x coordinate.
y - the specified y coordinate.
Returns:
a bundle element index. The index is -1 if there is not any bundle that contains the location.

findNearest

public int findNearest(int x,
                       int y)
Finds nearest tracker value where a bundle can be moved by the specified location.
Parameters:
x - the specified x coordinate.
y - the specified y coordinate.
Returns:
a nearest value.

value2loc

public int value2loc(int v)
Converts the specified tracker value to a location.
Parameters:
v - the specified value.
Returns:
a "x" location.

loc2value

public int loc2value(int x)
Converts the specified location to a tracker value.
Parameters:
x - the specified location. The location is "x" coordinate.
Returns:
a tracker value.

setStep

public void setStep(int step)
Sets the specified exact step.
Parameters:
step - the specified exact step.

getStep

public int getStep()
Gets the exact step.
Returns:
a exact step value.

calcPreferredSize

protected java.awt.Dimension calcPreferredSize()
Description copied from class: LwCanvas
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.
Overrides:
calcPreferredSize in class LwCanvas
Following copied from class: org.zaval.lw.LwCanvas
Returns:
a "pure" preferred size.

getBundleView

protected LwView getBundleView(int bundleIndex)
Gets a view for the specified bundle.
Parameters:
bundleIndex - the specified bundle index.
Returns:
the bundle view.

perform

protected void perform(int bi,
                       int v,
                       int pv,
                       int id)
Performs a tracker event for the specified bundle with the specified event id and event parameters.
Parameters:
bi - the specified bundle index.
v - the specified bundle value.
pv - the specified previous bundle value.
id - the specified tracker event id.

recalc

protected void recalc()
Description copied from class: LwCanvas
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 LwCanvas


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