PulpCore

pulpcore.sprite
Class Slider

java.lang.Object
  extended by pulpcore.sprite.Sprite
      extended by pulpcore.sprite.Slider
All Implemented Interfaces:
PropertyListener

public class Slider
extends Sprite

A Slider is a widget that lets the user select a value by sliding a knob.


Field Summary
static int HORIZONTAL
          Horizontal orientation.
 Fixed value
          The value of this Slider, initially set to 50.
static int VERTICAL
          Vertical orientation.
 
Fields inherited from class pulpcore.sprite.Sprite
alpha, anchorX, anchorY, angle, CENTER, DEFAULT, EAST, enabled, height, NORTH, NORTH_EAST, NORTH_WEST, pixelSnapping, SOUTH, SOUTH_EAST, SOUTH_WEST, visible, WEST, width, x, y
 
Constructor Summary
Slider(CoreImage backgroundImage, CoreImage knobImage, int x, int y)
          Creates a Slider with a background image and a knob image.
Slider(String backgroundImage, String knobImage, int x, int y)
          Creates a Slider with a background image and a knob image.
 
Method Summary
protected  void drawSprite(CoreGraphics g)
          Draws the sprite.
 int getExtent()
          Gets the extent (inner range) of the internal data model of this Slider.
 int getMax()
          Gets the maximum value of the internal data model of this Slider.
 int getMin()
          Gets the minimum value of the internal data model of this Slider.
protected  int getNaturalHeight()
          Gets the fixed-point value of the Sprite's natural height.
protected  int getNaturalWidth()
          Gets the fixed-point value of the Sprite's natural width.
 int getOrientation()
          Gets the orientation of this Slider.
 boolean isAdjusting()
           
 void propertyChange(Property property)
          On a property change this Sprite is marked as dirty.
 void scroll(int units)
          Changes the value by the specified number of units, animating the change if the unit animation duration is defined.
 void scrollDown()
          Increases the value by 1, animating the change if the unit animation duration is defined.
 void scrollEnd()
          Sets the value to (maximum - extent).
 void scrollHome()
          Sets the value to the minimum.
 void scrollPageDown()
          Decreases the value by the extent, animating the change if the page animation duration is defined.
 void scrollPageUp()
          Decreases the value by the extent, animating the change if the page animation duration is defined.
 void scrollUp()
          Decreases the value by 1, animating the change if the unit animation duration is defined.
 void setAnimationDuration(int unitDuration, int pageDuration)
          Sets the duration, in milliseconds, to animate when the value is changed when the gutter (the background of the Slider outside the knob) is clicked or when the scrollUp(), scrollDown(), scrollPageUp(), or scrollPageDown() methods are called.
 void setInsets(int top, int left, int bottom, int right)
          Sets the visual insets that the knob image is bound to.
 void setKnob(CoreImage knobImage)
          Sets the knob image.
 void setOrientation(int orientation)
          Sets the orientation of this Slider: either HORIZONTAL or VERTICAL.
 void setRange(int min, int max)
          Sets the internal data model for this Slider.
 void setRange(int min, int max, int extent)
          Sets the internal data model for this Slider.
 void update(int elapsedTime)
          Updates all of this Sprite's properties.
 
Methods inherited from class pulpcore.sprite.Sprite
bindLocationTo, bindSizeTo, clearCursor, clearDirtyRect, contains, draw, getBlendMode, getCursor, getDirtyRect, getFilter, getLocalX, getLocalY, getParent, getPixelLevelChecks, getRoot, getScene2D, getTag, getViewX, getViewX, getViewY, getViewY, intersects, isDirty, isEnabled, isEnabledAndVisible, isMouseDoubleClicked, isMouseDown, isMouseHover, isMouseOver, isMousePressed, isMouseReleased, isMouseTripleClicked, isMouseWheelRotated, isOpaque, isPick, isPickEnabledAndVisible, isTransparent, move, move, move, move, move, move, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, removeFromParent, scale, scale, scale, scale, scale, scale, scaleTo, scaleTo, scaleTo, scaleTo, scaleTo, scaleTo, setAnchor, setAnchor, setBlendMode, setCursor, setDirty, setFilter, setLocation, setLocation, setSize, setSize, setTag, translate, translate, updateDirtyRect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HORIZONTAL

public static final int HORIZONTAL
Horizontal orientation.

See Also:
Constant Field Values

VERTICAL

public static final int VERTICAL
Vertical orientation.

See Also:
Constant Field Values

value

public final Fixed value
The value of this Slider, initially set to 50. The value is a Fixed for animation purposes, but the Slider's internal methods ensure the end result (after animation) is always an integer.

Constructor Detail

Slider

public Slider(String backgroundImage,
              String knobImage,
              int x,
              int y)
Creates a Slider with a background image and a knob image.


Slider

public Slider(CoreImage backgroundImage,
              CoreImage knobImage,
              int x,
              int y)
Creates a Slider with a background image and a knob image.

Method Detail

isAdjusting

public boolean isAdjusting()
Returns:
True if the slider knob is being dragged.

propertyChange

public void propertyChange(Property property)
Description copied from class: Sprite
On a property change this Sprite is marked as dirty.

Specified by:
propertyChange in interface PropertyListener
Overrides:
propertyChange in class Sprite
Parameters:
property - the property whose value has changed.

update

public void update(int elapsedTime)
Description copied from class: Sprite
Updates all of this Sprite's properties. Subclasses that override this method should call super.update().

Overrides:
update in class Sprite

getNaturalWidth

protected int getNaturalWidth()
Description copied from class: Sprite
Gets the fixed-point value of the Sprite's natural width. Subclasses will override this method to specify the natural width. The natural width is the width of the Sprite if no scaling is applied - for an ImageSprite, the natural width is the width of the image.

Overrides:
getNaturalWidth in class Sprite

getNaturalHeight

protected int getNaturalHeight()
Description copied from class: Sprite
Gets the fixed-point value of the Sprite's natural height. Subclasses will override this method to specify the natural height. The natural height is the height of the Sprite if no scaling is applied - for an ImageSprite, the natural height is the height of the image.

Overrides:
getNaturalHeight in class Sprite

setKnob

public void setKnob(CoreImage knobImage)
Sets the knob image.


setInsets

public void setInsets(int top,
                      int left,
                      int bottom,
                      int right)
Sets the visual insets that the knob image is bound to.

If an inset is positive, it is used as inner boundry within the background image. If an inset is negative, the the knob can extend outisde the background image by that amount.

For horizontal sliders, the left and right insets are use as boundaries, and the knob is centered vertically between the top and bottom insets.

For vertical sliders, the top and bottom insets are use as boundaries, and the knob is centered horizontally between the left and right insets.


drawSprite

protected void drawSprite(CoreGraphics g)
Description copied from class: Sprite
Draws the sprite. The graphic context's alpha is set to this sprite's alpha, and it's translation is offset by this sprite's location. This method is not called if the sprite is not visible or it's alpha is less than or equal to zero.

This method may be called multiple times for each dirty rectangle. The clip of the graphics context will be set to the current dirty rectangle.

When the contents of this sprite change (in another words, the graphic output of this method will be different from the last time it is called), subclasses should call setDirty(true).

Implementors should not save a reference to the graphics context as it can change between calls to this method.

Specified by:
drawSprite in class Sprite

setOrientation

public void setOrientation(int orientation)
Sets the orientation of this Slider: either HORIZONTAL or VERTICAL. By default, the Slider is horizontal.


getOrientation

public int getOrientation()
Gets the orientation of this Slider.

Returns:
either HORIZONTAL or VERTICAL.

setRange

public void setRange(int min,
                     int max)
Sets the internal data model for this Slider. The range of the value is set have a bounds of the specified minimum and maximum values. The extent is set to zero.

The minimum and maximum can be any integer, and do not correspond to any pixel value. By default, the minimum is 0, the maximum is 100, and the extent is 0.

See Also:
value, setRange(int, int, int)

setRange

public void setRange(int min,
                     int max,
                     int extent)
Sets the internal data model for this Slider. The range of the value is set have a bounds of the specified minimum and maximum values. The extent is the inner range that this Slider covers, such that: minimum <= value <= value+extent <= maximum

The minimum, maximum, and extent can be any integer, and do not correspond to any pixel value. By default, the minimum is 0, the maximum is 100, and the extent is 0.

See Also:
value, setRange(int, int)

getMin

public int getMin()
Gets the minimum value of the internal data model of this Slider. The default minimum value is 0.

See Also:
setRange(int, int), setRange(int, int, int)

getMax

public int getMax()
Gets the maximum value of the internal data model of this Slider. The default maximum value is 100.

See Also:
setRange(int, int), setRange(int, int, int)

getExtent

public int getExtent()
Gets the extent (inner range) of the internal data model of this Slider. The default extent is 0.

See Also:
setRange(int, int), setRange(int, int, int)

setAnimationDuration

public void setAnimationDuration(int unitDuration,
                                 int pageDuration)
Sets the duration, in milliseconds, to animate when the value is changed when the gutter (the background of the Slider outside the knob) is clicked or when the scrollUp(), scrollDown(), scrollPageUp(), or scrollPageDown() methods are called.

The page duration is only used if the extent is non-zero. By default, both animation durations are set to zero.


scrollHome

public void scrollHome()
Sets the value to the minimum. No animation is performed.


scrollEnd

public void scrollEnd()
Sets the value to (maximum - extent). No animation is performed.


scroll

public void scroll(int units)
Changes the value by the specified number of units, animating the change if the unit animation duration is defined.

See Also:
setAnimationDuration(int, int)

scrollUp

public void scrollUp()
Decreases the value by 1, animating the change if the unit animation duration is defined.

See Also:
setAnimationDuration(int, int)

scrollDown

public void scrollDown()
Increases the value by 1, animating the change if the unit animation duration is defined.

See Also:
setAnimationDuration(int, int)

scrollPageUp

public void scrollPageUp()
Decreases the value by the extent, animating the change if the page animation duration is defined. If the extent is zero, this method does nothing.

See Also:
setAnimationDuration(int, int)

scrollPageDown

public void scrollPageDown()
Decreases the value by the extent, animating the change if the page animation duration is defined. If the extent is zero, this method does nothing.

See Also:
setAnimationDuration(int, int)

PulpCore

Copyright © 2007-2009 Interactive Pulp, LLC.