org.zaval.lw
Class LwSlider

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

public class LwSlider
extends LwCanvas
implements LwKeyListener, LwMouseListener, LwMouseMotionListener, LwViewProvider

This is slider component that can be used to select a value from the specified integer interval. The minimum, maximum, intervals sizes and other properties are specified by setValues method. The table below explains the properties meaning in more detail:
Property Description
max This is maximum possible value of the slider interval. Use getMax method to get the property value. It is impossible to set a slider value that is greater than the maximum.
min This is minimum possible value of the slider interval. Use getMin method to get the property value. It is impossible to set a slider value that is less than the minimum.
roughStep This property defines a rough step that is used to change current slider value for none-interval slider model. The step is used (to change the slider value) when the left mouse button has been pressed.
exactStep This property defines an exact step that is used to change current slider value for none-interval slider model. The step is used (to change the slider value) when appropriate key has been pressed or mouse drag event has been performed.
interval[] This property defines slider intervals sizes. The intervals are used to navigate through the slider component for interval model. The painting process uses the intervals to render scale and the scale titles.
isIntervalModel This property defines navigation model. There are two possible models:
  • None-interval model (if the property is false). In this case the slider changes its value using the defined steps properties (roughStep and exactStep steps).
  • Interval model (if the property is true). In this case the slider changes its value using the interval sizes as the step.

The basic components features are described below:


Field Summary
static int BUNDLE_VIEW
          The bundle view id.
static int GAUGE_VIEW
          The gauge view id.
 
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
LwSlider()
          Constructs a slider.
LwSlider(int o)
          Constructs a slider with the specified orientation.
 
Method Summary
 void addActionListener(LwActionListener l)
          Adds the specified action listener to receive action events from this slider.
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 slider value where a bundle can be moved by the specified location.
 int getIntervals()
          Gets the number of the slider intervals.
 int getIntervalSize(int i)
          Gets the specified interval size.
 int getMax()
          Gets the maximal possible value.
 int getMin()
          Gets the minimal possible value.
 int getOrientation()
          Gets the slider orientation.
 int getPointValue(int i)
          Gets the start value for the specified interval.
 java.awt.Color getScaleColor()
          Gets the scale color.
 int getScaleGap()
          Gets the scale gap.
 int getValue()
          Gets the current slider value.
 LwView getView(Drawable d, java.lang.Object o)
          Gets the view for the specified object of the specified component.
 LwView getView(int id)
          Gets the view of the specified slider element.
 void invalidate()
          Invalidates this component.
 boolean isIntervalModel()
          Tests if the interval model is used to navigate through the slider.
 boolean isJumpOnPress()
          Tests if the slider value will be changed according to the mouse cursor location by mouse presssed event.
 void jumpOnPress(boolean b)
          Sets if the slider value should be changed according to the mouse cursor location by mouse presssed event.
 void keyPressed(LwKeyEvent e)
          Invoked when a key has been pressed.
 void keyReleased(LwKeyEvent e)
          Invoked when a key has been released.
 void keyTyped(LwKeyEvent e)
          Invoked when a key has been typed.
 int loc2value(int xy)
          Converts the specified location to a slider 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 recalc()
          Invoked with validate method only if the component is not valid.
 void removeActionListener(LwActionListener l)
          Removes the specified action listener so it no longer receives action events from this component.
 void setOrientation(int o)
          Sets the specified slider orientation.
 void setScaleColor(java.awt.Color c)
          Sets the scale color.
 void setScaleGap(int g)
          Sets the specified scale gap.
 void setScaleStep(int s)
          Sets the scale step.
 void setValue(int v)
          Sets the specified slider value.
 void setValues(int min, int max, int[] intervals, int roughStep, int exactStep)
          Sets the slider properties.
 void setView(int id, LwView v)
          Sets the view for the specified slider element.
 void setViewProvider(LwViewProvider p)
          Sets the specified titles views provider.
 void showScale(boolean b)
          Sets the scale element visibility.
 void showTitle(boolean b)
          Sets the slider title visibility.
 void startDragged(LwMouseMotionEvent e)
          Invoked when the mouse starts dragged.
 void useIntervalModel(boolean b)
          Sets the specified navigation model.
 int value2loc(int v)
          Converts the specified slider 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

BUNDLE_VIEW

public static final int BUNDLE_VIEW
The bundle view id.

GAUGE_VIEW

public static final int GAUGE_VIEW
The gauge view id.
Constructor Detail

LwSlider

public LwSlider()
Constructs a slider. The slider will use horizontal orientation.

LwSlider

public LwSlider(int o)
Constructs a slider with the specified orientation. Use LwToolkit.HORIZONTAL or LwToolkit.VERTICAL constant as the orientation property value.
Parameters:
o - the specified orientation.
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.

getScaleGap

public int getScaleGap()
Gets the scale gap. The gap defines distance between the bundle element and the scale element.
Returns:
a gap.

setScaleGap

public void setScaleGap(int g)
Sets the specified scale gap. The gap defines distance between the bundle element and the scale element.
Parameters:
g - the specified scale gap.

getScaleColor

public java.awt.Color getScaleColor()
Gets the scale color.
Returns:
a scale color.

setScaleColor

public void setScaleColor(java.awt.Color c)
Sets the scale color.
Parameters:
c - the scale color.

setScaleStep

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

showScale

public void showScale(boolean b)
Sets the scale element visibility.
Parameters:
b - the scale element visibility.

isJumpOnPress

public boolean isJumpOnPress()
Tests if the slider value will be changed according to the mouse cursor location by mouse presssed event.
Returns:
true if the slider value is changed by mouse pressed event according to the mouse cursor location.

jumpOnPress

public void jumpOnPress(boolean b)
Sets if the slider value should be changed according to the mouse cursor location by mouse presssed event.
Parameters:
b - use true as the argument value to allow the slider value changing by mouse pressed event according to the mouse cursor location.

showTitle

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

setViewProvider

public void setViewProvider(LwViewProvider p)
Sets the specified titles views provider. The provider defines views for the slider titles that are used to render the titles.
Parameters:
p - the specified titles views provider.

getView

public LwView getView(Drawable d,
                      java.lang.Object o)
Description copied from interface: LwViewProvider
Gets the view for the specified object of the specified component.
Specified by:
getView in interface LwViewProvider
Following copied from interface: org.zaval.lw.LwViewProvider
Parameters:
d - the specified component.
obj - the specified object.
Returns:
a view.

setOrientation

public void setOrientation(int o)
Sets the specified slider orientation. It is possible to use LwToolkit.HORIZONTAL or LwToolkit.VERTICAL as the orientation value. Draw attention that the method restores appropriate bundle view.
Parameters:
o - the specified slider orientation.

getOrientation

public int getOrientation()
Gets the slider orientation.
Returns:
a slider orientation.

getView

public LwView getView(int id)
Gets the view of the specified slider element.
Parameters:
id - the specified slider element id.
Returns:
a view that is used to render the slider element.

setView

public void setView(int id,
                    LwView v)
Sets the view for the specified slider element. There are two elements views can be specified by the method: BUNDLE_VIEW and GAUGE_VIEW.
Parameters:
id - the specified slider element id.
v - the specified view.

isIntervalModel

public boolean isIntervalModel()
Tests if the interval model is used to navigate through the slider. The interval model defines that navigation possible only between slider intervals.
Returns:
true if the interval model is used; otherwise false.

useIntervalModel

public void useIntervalModel(boolean b)
Sets the specified navigation model.
Parameters:
b - specified navigation model. Use true to set interval model; otherwise false.

getValue

public int getValue()
Gets the current slider value.
Returns:
a current slider value.

setValue

public void setValue(int v)
Sets the specified slider value. The value should be less than maximal and greater than minimal possible properties.
Parameters:
v - the specified slider value.

getMax

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

getMin

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

getIntervals

public int getIntervals()
Gets the number of the slider intervals.
Returns:
a number of the slider intervals.

getIntervalSize

public int getIntervalSize(int i)
Gets the specified interval size.
Parameters:
i - the specified interval index.
Returns:
an interval size.

setValues

public void setValues(int min,
                      int max,
                      int[] intervals,
                      int roughStep,
                      int exactStep)
Sets the slider properties.
Parameters:
min - the specified minimal possible value.
max - the specified maximal possible value.
intervals - the specified intervals sizes array.
roughStep - the specified rough step. The step is used to change the slider value whenever the mouse button has been pressed.
exactStep - the specified exact step. The step is used to change the slider value whenever the mouse has been dragged or appropriate key has been pressed.

getPointValue

public int getPointValue(int i)
Gets the start value for the specified interval.
Parameters:
i - the specified interval index.
Returns:
a start value for the specified interval.

addActionListener

public void addActionListener(LwActionListener l)
Adds the specified action listener to receive action events from this slider. The event is performed when the slider value has been changed.
Parameters:
l - the specified action listener.

removeActionListener

public void removeActionListener(LwActionListener l)
Removes the specified action listener so it no longer receives action events from this component.
Parameters:
l - the specified action listener.

keyPressed

public void keyPressed(LwKeyEvent e)
Description copied from interface: LwKeyListener
Invoked when a key has been pressed.
Specified by:
keyPressed in interface LwKeyListener
Following copied from interface: org.zaval.lw.event.LwKeyListener
Parameters:
e - the specified key 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.

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.

keyReleased

public void keyReleased(LwKeyEvent e)
Description copied from interface: LwKeyListener
Invoked when a key has been released.
Specified by:
keyReleased in interface LwKeyListener
Following copied from interface: org.zaval.lw.event.LwKeyListener
Parameters:
e - the specified key event.

keyTyped

public void keyTyped(LwKeyEvent e)
Description copied from interface: LwKeyListener
Invoked when a key has been typed.
Specified by:
keyTyped in interface LwKeyListener
Following copied from interface: org.zaval.lw.event.LwKeyListener
Parameters:
e - the specified key 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.

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.

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.

findNearest

public int findNearest(int x,
                       int y)
Finds nearest slider 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 slider value to a location. The method returns "x" coordinate for horizontal aligned slider or "y" coordinate for vertical aligned slider.
Parameters:
v - the specified slider value.
Returns:
a "x" or "y" location depending on the slider alignment.

loc2value

public int loc2value(int xy)
Converts the specified location to a slider value. The specified location is "x" coordinate for horizontal aligned slider and "y" coordinate otherwise.
Parameters:
xy - the specified location.
Returns:
a slider value.

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

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.

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