Class Slider

java.lang.Object
  extended by greenfoot.Actor
      extended by Slider

public class Slider
extends greenfoot.Actor

A slider to allow a user to select a number in a given range. Create a Slider by calling new Slider() (for the default size) or new Slider(int, int) (for a custom size). Set teh maximum value that the user can select by calling setMaximumValue(int), set the initial value by calling setValue(int) and add it to the world by calling the addObject(Actor, int, int) method on the World. You can also set how the slider should display by calling the other methods. This should be done before adding the slider to the world, but does not need to be

Version:
29-01-2008
Author:
mBread

Constructor Summary
Slider()
          Create a new slider with the default size.
Slider(int width, int height)
          Create a new slider.
 
Method Summary
 void act()
          This method is called by Greenfoot, and updates the slider if the user has dragged the slider.
 void addedToWorld(greenfoot.World world)
          This method is called by the World class when the slider is added to the world.
 int getMajorSections()
          Get the number of major sections that are marked.
 int getMaximumValue()
          Get the current maximum value which the user can select
 int getMinorSections()
          Get the number of minor sections that are marked.
 int getValue()
          Get the current value.
 boolean isShowingPercentage()
          Check whether the slider is set to display the value as a percentage.
 boolean isShowingValue()
          Check whether the slider is set to display the value.
 void setMajorSections(int sections)
          Set the number of major sections to be marked.
 void setMaximumValue(int value)
          Set the maximum value that the user can select.
 void setMinorSections(int sections)
          Set the number of minor sections to be marked per major secton.
 void setValue(int value)
          Set the current selected value of the slider.
 void showPercentage(boolean show)
          Set whether the value will be displayed next to the slider as a percentage.
 void showValue(boolean show)
          Set whether the value should be displayed next to the slider.
 
Methods inherited from class greenfoot.Actor
getImage, getIntersectingObjects, getNeighbours, getObjectsAtOffset, getObjectsInRange, getOneIntersectingObject, getOneObjectAtOffset, getRotation, getWorld, getX, getY, intersects, setImage, setImage, setLocation, setRotation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Slider

public Slider()
Create a new slider with the default size. It will be 200 pixels wide by 20 pixels high.


Slider

public Slider(int width,
              int height)
Create a new slider.

Parameters:
width - The width of the slider in pixels
height - The height of th slider in pixels
Method Detail

act

public void act()
This method is called by Greenfoot, and updates the slider if the user has dragged the slider.

Overrides:
act in class greenfoot.Actor

addedToWorld

public void addedToWorld(greenfoot.World world)
This method is called by the World class when the slider is added to the world. You will not need to call this method.

Overrides:
addedToWorld in class greenfoot.Actor
Parameters:
world - The world

getMajorSections

public int getMajorSections()
Get the number of major sections that are marked.

Returns:
The number of major sections that are marked
See Also:
setMajorSections(int)

getMaximumValue

public int getMaximumValue()
Get the current maximum value which the user can select

Returns:
The maximum value

getMinorSections

public int getMinorSections()
Get the number of minor sections that are marked.

Returns:
The number of minor sections that are marked
See Also:
setMinorSections(int)

getValue

public int getValue()
Get the current value.

Returns:
The current selected value

isShowingPercentage

public boolean isShowingPercentage()
Check whether the slider is set to display the value as a percentage.

Returns:
true if the percentage is being displayed, false if it is not
See Also:
showPercentage(boolean), isShowingValue()

isShowingValue

public boolean isShowingValue()
Check whether the slider is set to display the value.

Returns:
true if the value is being displayed, false if it is not
See Also:
showValue(boolean), isShowingPercentage()

setMajorSections

public void setMajorSections(int sections)
Set the number of major sections to be marked. Set the number of sections to zero to not display any major markers. There will be 1 more marker than sections as there is a marker at both ends as well as between each section

Parameters:
sections - The number of major sections to display
See Also:
setMinorSections(int)

setMaximumValue

public void setMaximumValue(int value)
Set the maximum value that the user can select.

Parameters:
value - The new maximum value

setMinorSections

public void setMinorSections(int sections)
Set the number of minor sections to be marked per major secton. Set this to zero or 1 to not display any minor markers. There will be one less minor marker (per major section) than the number of minor sections as there is not a marker at each end due to the major markers being there.

Parameters:
sections - The number of minor sections to mark per major section
See Also:
setMajorSections(int)

setValue

public void setValue(int value)
Set the current selected value of the slider. The display will change to represent this new value.

Parameters:
value - The new value

showPercentage

public void showPercentage(boolean show)
Set whether the value will be displayed next to the slider as a percentage. This method will take precedence over showValue(boolean). If both are set to true, the percentage is shown. If both are true and showPercentage(false) is called then the value will be shown. If both are true and showValue(false) is called then neither the value nor percentage is shown.

Parameters:
show - true if the value should be displayed as a percentage of the maximum value, false if it should not.
See Also:
showValue(boolean), isShowingPercentage()

showValue

public void showValue(boolean show)
Set whether the value should be displayed next to the slider. If this method is called with false as the parameter then it will also set shoePercentage(boolean) will also be set to false.

Parameters:
show - true if the value should be displayed as text, false if it should not be
See Also:
showPercentage(boolean)