Class cubeWorker

java.lang.Object
  extended by cubeWorker

public class cubeWorker
extends java.lang.Object

This class holds all Data of the Application. Additionally it performs the transmission of animation data to/from the cube and saves/loads animations in/from a file.


Method Summary
 int addAnimation()
          Add an animation.
 int addFrame(int anim)
          Add a Frame to an animation.
 boolean changedStateSinceSave()
          Check if something changed after loading/saving.
 int downloadState(java.lang.String port)
          Get all animations from the cube, place it in this object
 int framesRemaining()
          Get the number of frames you can add until the Cubes memory is full.
 java.lang.String getAnimationName(int selectedAnimation)
          Get the name of an animation
 short[] getFrame(int anim, int frame)
          Get the data of a frame.
 java.lang.String getFrameName(int anim, int frame)
          Get the name of a frame.
 short getFrameTime(int anim, int frame)
          Get frame duration.
 java.lang.String[] getSerialPorts()
          Get the names of all available serial ports.
 int loadState(java.lang.String path)
          Loads an animation file into this worker.
 void moveAnimation(int dir, int selectedAnimation)
          Move an animation UP or DOWN.
 void moveFrame(int dir, int anim, int frame)
          Move a frame.
 int numOfAnimations()
          Get the number of animations in this worker.
 int numOfFrames(int selectedAnimation)
          Get the number of frames in an animation.
 boolean probeCubeConnected(java.lang.String port)
          Try to speak with the cube.
 void removeAnimation(int selectedAnimation)
          Remove an animation.
 void removeFrame(int anim, int frame)
          Remove a frame.
 int saveState(java.lang.String path)
          Save the state of this object into a file.
 void setAnimationName(java.lang.String s, int selectedAnimation)
          Set the name of an animation  @param s New name
 void setFrame(short[] data, int anim, int frame)
          Set the data of a frame
 void setFrameName(java.lang.String s, int anim, int frame)
          Set the name of a frame.
 void setFrameTime(short time, int anim, int frame)
          Set the frames duration.
 int uploadState(java.lang.String port)
          Send all animations to the cube.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

numOfAnimations

public int numOfAnimations()
Get the number of animations in this worker.

Returns:
number of animations

numOfFrames

public int numOfFrames(int selectedAnimation)
Get the number of frames in an animation.

Parameters:
selectedAnimation - the animation you want to check
Returns:
number of frames in this animation

framesRemaining

public int framesRemaining()
Get the number of frames you can add until the Cubes memory is full.

Returns:
number of frames remaining

addAnimation

public int addAnimation()
Add an animation.

Returns:
Index of new animation, or -1 if not enough space remaining.

removeAnimation

public void removeAnimation(int selectedAnimation)
Remove an animation.

Parameters:
selectedAnimation - the animation you want to delete

getAnimationName

public java.lang.String getAnimationName(int selectedAnimation)
Get the name of an animation

Parameters:
selectedAnimation - The animation you want to get the name from
Returns:
The name

setAnimationName

public void setAnimationName(java.lang.String s,
                             int selectedAnimation)
Set the name of an animation  @param s New name

Parameters:
selectedAnimation - Index of the animation you want to change

moveAnimation

public void moveAnimation(int dir,
                          int selectedAnimation)
Move an animation UP or DOWN.

Parameters:
dir - Direction. Use UP and DOWN defined in cubeWorker
selectedAnimation - Animation you want to move

getFrameName

public java.lang.String getFrameName(int anim,
                                     int frame)
Get the name of a frame.

Parameters:
anim - Animation the frame is in
frame - Index of the frame

setFrameName

public void setFrameName(java.lang.String s,
                         int anim,
                         int frame)
Set the name of a frame.

Parameters:
s - New name
anim - Animation Index
frame - Frame Index

addFrame

public int addFrame(int anim)
Add a Frame to an animation.

Parameters:
anim - Animation Index
Returns:
Index of new Frame or -1 if not enough space

removeFrame

public void removeFrame(int anim,
                        int frame)
Remove a frame.

Parameters:
anim - Animation Index
frame - Frame you want to remove

getFrame

public short[] getFrame(int anim,
                        int frame)
Get the data of a frame.

Parameters:
anim - Animation Index  @param frame Frame Index
Returns:
64 byte array with data (8 bits per byte => 512 bits)

setFrame

public void setFrame(short[] data,
                     int anim,
                     int frame)
Set the data of a frame

Parameters:
data - 64 byte array with data
anim - Animation Index
frame - Frame Index
See Also:
getFrame()

getFrameTime

public short getFrameTime(int anim,
                          int frame)
Get frame duration.

Parameters:
anim - Animation Index
frame - Frame Index
Returns:
Duration. 0 means 1/24th of a second.

setFrameTime

public void setFrameTime(short time,
                         int anim,
                         int frame)
Set the frames duration.

Parameters:
time - New duration
anim - Animation Index
frame - Frame Index
See Also:
getFrameTime()

moveFrame

public void moveFrame(int dir,
                      int anim,
                      int frame)
Move a frame.

Parameters:
dir - Direction to move. Use UP and DOWN from cubeWorker
anim - Animation Index
frame - Frame Index
See Also:
moveAnimation()

loadState

public int loadState(java.lang.String path)
Loads an animation file into this worker.

Parameters:
path - Path of file to load
Returns:
0 on success, -1 on error.

saveState

public int saveState(java.lang.String path)
Save the state of this object into a file.

Parameters:
path - Path to save file in
Returns:
0 on success, -1 on error

changedStateSinceSave

public boolean changedStateSinceSave()
Check if something changed after loading/saving.

Returns:
TRUE if something changed, FALSE otherwise

uploadState

public int uploadState(java.lang.String port)
Send all animations to the cube.

Parameters:
port - Name of serial port to use
Returns:
0 on success, -1 on error

downloadState

public int downloadState(java.lang.String port)
Get all animations from the cube, place it in this object

Parameters:
port - Name of serial port to use  @return 0 on success, -1 on error

probeCubeConnected

public boolean probeCubeConnected(java.lang.String port)
Try to speak with the cube.

Parameters:
port - Name of serial port
Returns:
TRUE if cube responds

getSerialPorts

public java.lang.String[] getSerialPorts()
Get the names of all available serial ports.

Returns:
Array of port names. First entry is always "Select serial port..."