|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--java.awt.Panel | +--edu.hws.jcm.awt.Animator
An Animator can change a value continuously, without user intervention, by running a separate Thread. By default, an animator appears as a "Start" button. When the button is pressed, the value of the animator starts counting 0, 1, 2, ... The button changes to a "Stop" button. When this is pressed, the value stops changing. A Controller can be set, by calling the setOnChange() method, to be notified whenever the value is changed. If this is done, then the value of the Animator will only change when its checkInput() method is called, so it should be added to a Controller which will call this method.
The getValueAsVariable() method can be called to get a Variable whose value is the value of the Animator. This variable can then be added to a Parser, so it can be used in expressions. An Animator is "Tieable", so it can share its value with another InputObject, such as a VariableSlider or a VariableIput.
There are many options: If maximum and minimum values are both specified, then the value of the Animator ranges between these values. By default, this interval is divided into 100 sub-intervals, so that there are 101 frames. However, the number of intervals can also be set. If no min or max is specified but a number of intervals is specified, then the value is an integer which ranges from 0 up to the specified number of intervals. If the number of frames is finite, then there are three possibities when the last frame is reached: The animation can stop; it can loop back to the the starting frame, or it can reverse direction and cycle back and forth. The behavior is controlled with the setLoopStyle() method.
An Animator is actually a Panel which can contain other controls in addition to or instead of the Start/Stop button. For example, it can contain a "Next" button or a pop-up menu to control the speed.
Inner classes inherited from class java.awt.Panel |
java.awt.Panel.AccessibleAWTPanel |
Inner classes inherited from class java.awt.Container |
java.awt.Container.AccessibleAWTContainer |
Inner classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent |
Field Summary | |
static int |
BACK_AND_FORTH
Represents a loop style in which the animation is cycled back and forth. |
static int |
HORIZONTAL
Indicates that the components in the Animator panel are to be in a horizontal row. |
static int |
LOOP
Represents a loop style in which the animation is played repeatedly. |
static int |
LOOP_CHOICE
Used to add a component to the Animator Panel; can be used in a constructor or in the addControl() method. |
static int |
NEXT_BUTTON
Used to add a component to the Animator Panel; can be used in a constructor or in the addControl() method. |
static int |
ONCE
Represents a loop style in which the animation is played once. |
static int |
PAUSE_BUTTON
Used to add a component to the Animator Panel; can be used in a constructor or in the addControl() method. |
static int |
PREV_BUTTON
Used to add a component to the Animator Panel; can be used in a constructor or in the addControl() method. |
static int |
SPEED_CHOICE
Used to add a component to the Animator Panel; can be used in a constructor or in the addControl() method. |
static int |
START_BUTTON
Used to add a component to the Animator Panel; can be used in a constructor or in the addControl() method. |
static int |
START_STOP_BUTTON
Used to add a component to the Animator Panel; can be used in a constructor or in the addControl() method. |
static int |
STOP_BUTTON
Used to add a component to the Animator Panel; can be used in a constructor or in the addControl() method. |
static int |
VERTICAL
Indicates that the components in the Animator panel are to be stacked vertically. |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
Animator()
Create a default Animator. |
|
Animator(int controls)
Create an Animator containing the specified control. |
|
Animator(int controls,
int orientation)
Create an Animator containing specified controls. |
|
Animator(int controls,
int orientation,
Value min,
Value max,
Value intervals)
Create an Animator with specified controls, orienation, range limits and number of intervals |
Method Summary | |
void |
actionPerformed(java.awt.event.ActionEvent evt)
Respond to button clicks. |
java.awt.Component |
addControl(int controlCode)
Add one of the possible control buttons or pop-up menus to the Animator. |
void |
checkInput()
Part of the IputObject interface. |
java.awt.Component |
getControl(int controlCode)
Get one of controls associated with the Animator. |
Value |
getIntervals()
Get the Value object that specifies the number of frames in the animation. |
int |
getLoopStyle()
Get the loop style, which determines what happens when the final frame of the animation is reached. |
Value |
getMax()
Get the Value object that specifies the final value of the Animator. |
int |
getMillisPerFrame()
Get the nominal number of milliseconds per frame. |
Value |
getMin()
Get the Value object that specifies the starting value of the Animator. |
Computable |
getOnChange()
Get the Controller that is notified (by calling its compute() method) whenever the frame changes. |
int |
getOrientation()
Get the constant, VERTICAL or HORIZONTAL, that was used to specify whether the components in the animator are arranged veritcally or horizontally. |
long |
getSerialNumber()
Part of the Tieable interface. |
boolean |
getUndefinedWhenNotRunning()
Get the value of the undefinedWhenNotRunning property. |
double |
getVal()
Get the current value of the Animator. |
Variable |
getValueAsVariable()
Get a variable whose value is always equal to the value of the animator. |
Variable |
getValueAsVariable(java.lang.String name)
Get a variable whose value is always equal to the value of the animator. |
void |
itemStateChanged(java.awt.event.ItemEvent evt)
Respond to clicks on pop-up menus. |
void |
next()
Advance the animation by one frame. |
void |
notifyControllerOnChange(Controller c)
Method required by the InputObject interface. |
void |
pause()
Pause the animation, if it is running. |
void |
prev()
Advance the animation BACK one frame. |
void |
run()
The method that is run by the animation thread. |
void |
setIntervals(int intervals)
A convenience method that simply calls setIntervals(new Constant(d)). |
void |
setIntervals(Value intervals)
Set the Value object that specifies the number of frames in the animation. |
void |
setLoopStyle(int style)
Set the loop style, which determines what happens when the final frame of the animation is reached. |
void |
setMax(double d)
A convenience method that simply calls setMax(new Constant(d)). |
void |
setMax(Value max)
Set the Value object that gives the final value of the Animator. |
void |
setMillisPerFrame(int millis)
Set the nominal number of milliseconds per frame. |
void |
setMin(double d)
A convenience method that simply calls setMin(new Constant(d)). |
void |
setMin(Value min)
Set the Value object that gives the starting value of the Animator. |
void |
setOnChange(Computable onChange)
Set the Controller that is notified (by calling its compute() method) whenever the frame changes. |
void |
setOrientation(int orientation)
Set the orientation of the components in the Animator panel. |
void |
setStartButtonName(java.lang.String name)
The name of the Start/Stop button is managed by the Animator, so changing it directly makes no sense. |
void |
setStopButtonName(java.lang.String name)
The name of the Start/Stop button is managed by the Animator, so changing it directly makes no sense. |
void |
setUndefinedWhenNotRunning(boolean undefinedWhenNotRunning)
Set the value of the undefinedWhenNotRunning property. |
void |
setVal(double val)
Set the value of the animation. |
void |
start()
Start the animation from the first frame, or continue it if it was paused. |
void |
stop()
Stop the animation, if it is running or paused. |
void |
sync(Tie tie,
Tieable newest)
Part of the Tieable interface. |
Methods inherited from class java.awt.Panel |
addNotify, getAccessibleContext |
Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate, validateTree |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int START_STOP_BUTTON
public static final int START_BUTTON
public static final int PAUSE_BUTTON
public static final int STOP_BUTTON
public static final int NEXT_BUTTON
public static final int PREV_BUTTON
public static final int SPEED_CHOICE
public static final int LOOP_CHOICE
public static final int VERTICAL
public static final int HORIZONTAL
public static final int ONCE
public static final int LOOP
public static final int BACK_AND_FORTH
Constructor Detail |
public Animator()
public Animator(int controls)
public Animator(int controls, int orientation)
public Animator(int controls, int orientation, Value min, Value max, Value intervals)
controls
- Specify the controls to add to the Animator. Can consist of one or
more of the following constants, or'ed together: START_STOP_BUTTON, START_BUTTON, STOP_BUTTON,
PAUSE_BUTTON, NEXT_BUTTON, PREV_BUTTON, SPEED_CHOICE, LOOP_CHOICE.orientation
- How the controls are arranged in the panel. One of the constants VERTICAL or HORIZONTAL.min
- If BOTH min and max are non-null, they specify the range of values of the Animator.max
- If BOTH min and max are non-null, they specify the range of values of the Animator.intervals
- If non-null, specifies the number of intervals into which the range of values
is divided. Note that the value will be rounded to the nearest integer and clamped to the
range 0 to 100000. The number of frames is the number of intervals, plus one. If min and max are
non-null and intervals is null, then a default value of 100 is used. If either min or max is
null and intervals is non-null, then the Animator takes on the values 0, 1, 2, ..., intervals.Method Detail |
public java.awt.Component getControl(int controlCode)
public java.awt.Component addControl(int controlCode)
START_STOP_BUTTON: When clicked, animation starts and name of button changes; when clicked again, animation stops.
START_BUTTON: When clicked, animation starts.
STOP_BUTTON: When clicked, animaton stops.
PAUSE_BUTTON: When clicked, animation is paused; this is different from stopping the animation since a paused animation can be resumed from the same point while a stopped animation can only be restarted from the beginning.
NEXT_BUTTON: When clicked, the animation advances one frame; this is disabled when the animation is running.
PREV_BUTTON: When clicked, the animation is moved back one frame; this is disabled when the animation is running.
SPEED_CHOICE: A pop-up menu whose value controls the speed at which the animation plays.
LOOP_CHOICE: A pop-up menu that controls the style of animation, that is, what happens when the animation reaches its final frame; values are Play Once, Loop, and Back and Forth.
If the parameter is not one of these constants, then nothing is done. Ordinarily, this will be called during initialization. (If you call it at some other time, you will have to validate the panel yourself.) The return value is the component that is added, or null if the parameter value is not legal.
public void setStartButtonName(java.lang.String name)
public void setStopButtonName(java.lang.String name)
public int getOrientation()
public void setOrientation(int orientation)
public Value getMax()
public void setMax(Value max)
public void setMax(double d)
public Value getMin()
public void setMin(Value min)
public void setMin(double d)
public Value getIntervals()
public void setIntervals(Value intervals)
public void setIntervals(int intervals)
public int getMillisPerFrame()
public void setMillisPerFrame(int millis)
public int getLoopStyle()
public void setLoopStyle(int style)
public void setVal(double val)
public double getVal()
getVal
in interface Value
public Variable getValueAsVariable()
public Variable getValueAsVariable(java.lang.String name)
public Computable getOnChange()
public void setOnChange(Computable onChange)
public void notifyControllerOnChange(Controller c)
notifyControllerOnChange
in interface InputObject
public boolean getUndefinedWhenNotRunning()
public void setUndefinedWhenNotRunning(boolean undefinedWhenNotRunning)
public void start()
public void pause()
public void next()
public void prev()
public void stop()
public void actionPerformed(java.awt.event.ActionEvent evt)
actionPerformed
in interface java.awt.event.ActionListener
public void itemStateChanged(java.awt.event.ItemEvent evt)
itemStateChanged
in interface java.awt.event.ItemListener
public void checkInput()
checkInput
in interface InputObject
public long getSerialNumber()
getSerialNumber
in interface Tieable
public void sync(Tie tie, Tieable newest)
sync
in interface Tieable
public void run()
run
in interface java.lang.Runnable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |