PenProfile 2.x

com.livescribe.ext.ui
Class SlotMachine

java.lang.Object
  extended by com.livescribe.display.Displayable
      extended by com.livescribe.display.Canvas
          extended by com.livescribe.ext.ui.SlotMachine

public class SlotMachine
extends Canvas

This class enables most types of displays that involves N scrolling reels with a number of items in each reel. Each reel can be in a selected or unselected state, with a different image displayed for both.

A reel is like a virtual cylinder, where the last item wraps around to the first (index zero). It can be positioned exactly at an item, or in between two items, by using a floating-point number.

Since:
2.4

Constructor Summary
SlotMachine()
          Creates a new slot machine UI having its drawing offset at zero.
SlotMachine(int startX)
          Creates a new slot machine UI having the specified drawing offset.
 
Method Summary
 void addReel(Image[] normalImages)
          Adds a reel containing the specified images.
 void addReel(Image[] unselected, Image[] selected)
          Adds a reel containing the specified unselected and selected images.
 void addSeparator(Image separator)
          Adds a separator image.
 int getReelCount()
          Gets the number of reels.
 float getReelPosition(int n)
          Gets the reel position as a floating-point value.
 void moveReel(int n, float delta)
          Moves the reel a specified amount.
protected  void paint(Graphics g)
          Paints this UI component.
 void selectReel(int n, boolean flag)
          Selects the specified reel.
 void setReelPosition(int n, float position)
          Sets the location for the specified reel.
 
Methods inherited from class com.livescribe.display.Canvas
repaint
 
Methods inherited from class com.livescribe.display.Displayable
getSurface, isCurrent, notifyHidden, notifyShown, notifySystemTrayHidden, notifySystemTrayShown
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SlotMachine

public SlotMachine()
Creates a new slot machine UI having its drawing offset at zero.


SlotMachine

public SlotMachine(int startX)
Creates a new slot machine UI having the specified drawing offset.

Parameters:
startX - start offset in pixels from the left side of the canvas
Method Detail

addReel

public void addReel(Image[] normalImages)
Adds a reel containing the specified images. The number of items on the reel will be equal to the number of images and its width will be the maximum width of all the images.

There will be no selected images.

Parameters:
normalImages - the array of unselected images
See Also:
addReel(Image[], Image[])

addReel

public void addReel(Image[] unselected,
                    Image[] selected)
Adds a reel containing the specified unselected and selected images. The number of items on the reel will be equal to the number of images and its width will be the maximum width of all the images. The selected images are alternates that will be used if the reel is not set to a fractional position and if the reel is selected.

Parameters:
unselected - the array of normal images
selected - the array of selected images, may be null
Throws:
NullPointerException - if normal is null.
IllegalArgumentException - if the selected image array size is not equal to the normal image array size.

addSeparator

public void addSeparator(Image separator)
Adds a separator image.

Parameters:
separator - the separator image

getReelPosition

public float getReelPosition(int n)
Gets the reel position as a floating-point value. If the fraction part is zero then the reel is exactly in the middle of one of its elements.

Note that the position will be in the range 0–N, not including N, where N is the reel count.

Parameters:
n - the reel number
Returns:
the reel location, a floating-point value.
Throws:
IndexOutOfBoundsException - if the reel number is out of range.

getReelCount

public int getReelCount()
Gets the number of reels.

Returns:
the number of reels.
See Also:
addReel(Image[], Image[])

setReelPosition

public void setReelPosition(int n,
                            float position)
Sets the location for the specified reel. The location is specified as a floating-point value, with non-integer numbers representing positions between two items on the reel. Its value starts at zero.

Note that the position properly wraps around the "cylinder". It is not necessary to worry about keeping track of numbers that are outside of the range 0–N (where N is the reel count.

For example, a position of 2 will show image 2 of reel n. A position of 2.4 will show the same image, but scrolled up a farther 40% of its height.

Parameters:
n - the reel number
position - the new position, a floating-point value
Throws:
IndexOutOfBoundsException - if the reel number is out of range.
See Also:
getReelCount()

moveReel

public void moveReel(int n,
                     float delta)
Moves the reel a specified amount. A positive value moves the image up and a negative value moves the image down.

Parameters:
n - the reel number
delta - move the reel by this amount
Throws:
IndexOutOfBoundsException - if the reel number is out of range.
See Also:
getReelCount(), setReelPosition(int, float)

selectReel

public void selectReel(int n,
                       boolean flag)
Selects the specified reel. Note that this does not unselect the other reels.

Parameters:
n - the reel number
flag - indicates whether to select the reel
Throws:
IndexOutOfBoundsException - if the reel number is out of range.
See Also:
getReelCount()

paint

protected void paint(Graphics g)
Paints this UI component.

Specified by:
paint in class Displayable
Parameters:
g - the graphics context

PenProfile 2.x

Copyright © 2010 Livescribe Inc. All Rights Reserved.
Confidential and subject to NDA.