fds.micro.ui
Class Slider

java.lang.Object
  extended byfds.micro.ui.Component
      extended byfds.micro.ui.Slider

public class Slider
extends Component

This class implements a slider. It can be two forms: normal mode (displayed as a ruler), or field mode (displayed as a field with buttons to increment and decrement value).
An object of this class is dedicated to be used within an object of fds.micro.ui.AbstractPanel sub-class (J2ME).

Warning: Use this class only if you want to have control on rendering. If possible, always prefer javax.microedition.lcdui.Item sub-classes.

You can read below a typical use within a class that inherit fds.micro.ui.RowPanel:

Construction

 ...
 // Add a slider in field mode with values from 10 to 20.
 this.slider = new Slider(-1, 10, 20);
 this.slider.setFieldBackground(255, 255, 128);
 this.append(slider);
 ...
 
Usage
 ...
 // Here we get the slider value
 int value = this.slider.getValue();
 ...
 

Author:
Frédéric DE STEUR

Field Summary
 
Fields inherited from class fds.micro.ui.Component
INTERN_BOTTOM_VALIGN, INTERN_CENTER_HALIGN, INTERN_CENTER_VALIGN, INTERN_LEFT_HALIGN, INTERN_RIGHT_HALIGN, INTERN_TOP_VALIGN
 
Constructor Summary
Slider()
          Build a normal slider with a ruler of 50 pixels wide and range [0..100].
Slider(int rulerWidth)
          Build a normal slider with specified ruler (or field mode) and range [0..100].
Slider(int minValue, int maxValue)
          Build a normal slider with a ruler of 50 pixels wide and given range.
Slider(int rulerWidth, int minValue, int maxValue)
          Build a normal slider with specified ruler (or field mode) and given range.
 
Method Summary
 void addValueChangeListener(ValueChangeListener listener)
          Add a listener object that will receive events produced by this component when the value is changed.
 int getCursorPosition()
          Get the position of the cursor in field.
 javax.microedition.lcdui.Font getFont()
          Get the font used to display the value.
 int getMaxValue()
          Get the maximum possible value.
 int getMinValue()
          Get the minimum possible value.
 int getRulerWidth()
          Get the ruler width, or -1 if field mode is used.
 int getValue()
          Get the value.
 boolean isBoxOpaque()
          Get the entry zone opacity flag.
 boolean isValueShown()
          Get the value shown flag.
 void keyPressed(int keyCode, int gameAction)
          Called to notify the component that a key is pressed.
 void pointerPressed(int xpos, int ypos)
          Called to notify the component that pointer device was pressed.
 void removeValueChangListener(ValueChangeListener listener)
          Remove a listener.
 void setBackground(int red, int green, int blue)
          Set the component background color (under the component itself).
 void setBorderColor(int red, int green, int blue)
          Set the color for field border.
 void setBoxOpaque(boolean boxOpaque)
          Set a new value for entry zone opacity flag.
 void setCursorColor(int red, int green, int blue)
          Set the color for field cursor.
 void setCursorPosition(int cursorPosition)
          Change the position of the cursor in field.
 void setDisabled(boolean disabled)
          Disable/enable the component.
 void setFieldBackground(int red, int green, int blue)
          Set the color for field background.
 void setFieldBackgroundOff(int red, int green, int blue)
          Set the color for field background if component is disabled.
 void setFocusColor(int red, int green, int blue)
          Set the color for focus frame.
 void setFont(javax.microedition.lcdui.Font font)
          Change the font used to display the value.
 void setLocation(int x, int y)
          Change the location of this component.
 void setMaximumSize(int width, int height)
          Set the maximum size for this component.
 void setOpaque(boolean opaque)
          Set a new value for opaque flag.
 void setTextColor(int red, int green, int blue)
          Set the field value color.
 void setTextColorOff(int red, int green, int blue)
          Set the field value color if component is disabled.
 void setValue(int value)
          Set a new value.
 void setValueShown(boolean valueShown)
          Set a new value for value shown flag.
 
Methods inherited from class fds.micro.ui.Component
addFocusListener, addItemListener, equals, getHAlign, getHeight, getParent, getVAlign, getWidth, getX, getY, isDisabled, isHaveFocus, isHidden, isManageFocus, isOpaque, removeFocusListener, removeItemListener, setHAlign, setHidden, setManageFocus, setVAlign
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Slider

public Slider()
Build a normal slider with a ruler of 50 pixels wide and range [0..100].


Slider

public Slider(int rulerWidth)
Build a normal slider with specified ruler (or field mode) and range [0..100].

Parameters:
rulerWidth - The width of drawn ruler, or -1 if you want to use the field mode.

Slider

public Slider(int minValue,
              int maxValue)
Build a normal slider with a ruler of 50 pixels wide and given range.

Parameters:
minValue - The minimum possible value.
maxValue - The maximum possible value.

Slider

public Slider(int rulerWidth,
              int minValue,
              int maxValue)
Build a normal slider with specified ruler (or field mode) and given range.

Parameters:
rulerWidth - The width of drawn ruler, or -1 if you want to use the field mode.
minValue - The minimum possible value.
maxValue - The maximum possible value.
Method Detail

addValueChangeListener

public void addValueChangeListener(ValueChangeListener listener)
Add a listener object that will receive events produced by this component when the value is changed.

Parameters:
listener - The listener to add.

getCursorPosition

public int getCursorPosition()
Get the position of the cursor in field. Only relevant if field mode is used.

Returns:
Returns the cursor position. Returns zero if the cursor is on the left. Returns -1 if not in field mode.

getFont

public javax.microedition.lcdui.Font getFont()
Get the font used to display the value.

Returns:
Returns the font.

getMaxValue

public int getMaxValue()
Get the maximum possible value.

Returns:
Returns the maximum possible value.

getMinValue

public int getMinValue()
Get the minimum possible value.

Returns:
Returns the minimum possible value.

getRulerWidth

public int getRulerWidth()
Get the ruler width, or -1 if field mode is used.

Returns:
Returns the ruler width in pixels.

getValue

public int getValue()
Get the value.

Returns:
Returns the value.

isBoxOpaque

public boolean isBoxOpaque()
Get the entry zone opacity flag. Only relevant when in field mode.

Returns:
Returns true if background of entry zone is painted, otherwise false.

isValueShown

public boolean isValueShown()
Get the value shown flag. Only significant if normal mode is used. i.e. no meaning if field mode is used.

Returns:
Returns true if the value is shown.

keyPressed

public void keyPressed(int keyCode,
                       int gameAction)
Called to notify the component that a key is pressed.

Specified by:
keyPressed in class Component
Parameters:
keyCode - The key code.
gameAction - Game action corresponding to the key code.

pointerPressed

public void pointerPressed(int xpos,
                           int ypos)
Called to notify the component that pointer device was pressed.

Specified by:
pointerPressed in class Component
Parameters:
xpos - The X position of pointer on parent Canvas.
ypos - The Y position of pointer on parent Canvas.

removeValueChangListener

public void removeValueChangListener(ValueChangeListener listener)
Remove a listener.

Parameters:
listener - The listener to remove.

setBackground

public void setBackground(int red,
                          int green,
                          int blue)
Set the component background color (under the component itself).

Overrides:
setBackground in class Component
Parameters:
red - The red component of the color to set.
green - The green component of the color to set.
blue - The blue component of the color to set.

setBorderColor

public void setBorderColor(int red,
                           int green,
                           int blue)
Set the color for field border.

Parameters:
red - The red component of the color.
green - The green component of the color.
blue - The blue component of the color.

setBoxOpaque

public void setBoxOpaque(boolean boxOpaque)
Set a new value for entry zone opacity flag. Have an effect only if field mode is used.

Parameters:
boxOpaque - Must be true to paint background of entry zone, and false to not paint it.

setCursorColor

public void setCursorColor(int red,
                           int green,
                           int blue)
Set the color for field cursor.

Parameters:
red - The red component of the color.
green - The green component of the color.
blue - The blue component of the color.

setCursorPosition

public void setCursorPosition(int cursorPosition)
Change the position of the cursor in field. Have an effect only if field mode is used. Do nothing if given position is out of range.

Parameters:
cursorPosition - The cursor position. Must be zero for the cursor to be on the left.

setDisabled

public void setDisabled(boolean disabled)
Disable/enable the component.

Overrides:
setDisabled in class Component
Parameters:
disabled - Must be true to disabled the component, and false enabled to enable it.

setFieldBackground

public void setFieldBackground(int red,
                               int green,
                               int blue)
Set the color for field background.

Parameters:
red - The red component of the color.
green - The green component of the color.
blue - The blue component of the color.

setFieldBackgroundOff

public void setFieldBackgroundOff(int red,
                                  int green,
                                  int blue)
Set the color for field background if component is disabled.

Parameters:
red - The red component of the color.
green - The green component of the color.
blue - The blue component of the color.

setFocusColor

public void setFocusColor(int red,
                          int green,
                          int blue)
Set the color for focus frame.

Overrides:
setFocusColor in class Component
Parameters:
red - The red component of the color.
green - The green component of the color.
blue - The blue component of the color.

setFont

public void setFont(javax.microedition.lcdui.Font font)
Change the font used to display the value.

Parameters:
font - The font to set.

setLocation

public void setLocation(int x,
                        int y)
Change the location of this component.

Overrides:
setLocation in class Component
Parameters:
x - The new x coordinate.
y - The new y coordinate.

setMaximumSize

public void setMaximumSize(int width,
                           int height)
Set the maximum size for this component.

Overrides:
setMaximumSize in class Component
Parameters:
width - The maximum width.
height - The maximum height.

setOpaque

public void setOpaque(boolean opaque)
Set a new value for opaque flag.

Overrides:
setOpaque in class Component
Parameters:
opaque - Must be true for the component to paint a background.

setTextColor

public void setTextColor(int red,
                         int green,
                         int blue)
Set the field value color.

Parameters:
red - The red component of the color.
green - The green component of the color.
blue - The blue component of the color.

setTextColorOff

public void setTextColorOff(int red,
                            int green,
                            int blue)
Set the field value color if component is disabled.

Parameters:
red - The red component of the color.
green - The green component of the color.
blue - The blue component of the color.

setValue

public void setValue(int value)
Set a new value. It have not effect if given value is out of range.

Parameters:
value - The value to set.

setValueShown

public void setValueShown(boolean valueShown)
Set a new value for value shown flag.

Parameters:
valueShown - Must be true to show the value. Otherwise the value will not be displayed.