|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JPanel net.sourceforge.webcompmath.awt.Animator
public class 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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JPanel |
---|
javax.swing.JPanel.AccessibleJPanel |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
javax.swing.JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
java.awt.Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
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
Specifies to add a loop choice menu; used in constructor, addControl(), or getControl() |
static int |
NEXT_BUTTON
Specifies to add a next button; used in constructor, addControl(), or getControl() |
static int |
ONCE
Represents a loop style in which the animation is played once. |
static int |
PAUSE_BUTTON
Specifies to add a soause button; used in constructor, addControl(), or getControl() |
static int |
PREV_BUTTON
Specifies to add a prev button; used in constructor, addControl(), or getControl() |
static int |
SPEED_CHOICE
Specifies to add a speed choice menu; used in constructor, addControl(), or getControl() |
static int |
START_BUTTON
Specifies to add a start button; used in constructor, addControl(), or getControl() |
static int |
START_STOP_BUTTON
Specifies to add a start/stop button; used in constructor, addControl(), or getControl() |
static int |
STOP_BUTTON
Specifies to add a stop button; used in constructor, addControl(), or getControl() |
static int |
VERTICAL
Indicates that the components in the Animator panel are to be stacked vertically. |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
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. |
javax.swing.JComponent |
addControl(int controlCode)
Add one of the possible control buttons or pop-up menus to the Animator. |
void |
checkInput()
Part of the IputObject interface. |
javax.swing.JComponent |
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. |
java.lang.String |
getStartButtonName()
Get the Start button name. |
java.lang.String |
getStopButtonName()
Get the name of the stop button; |
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. |
boolean |
hasControl(int controlCode)
Tells whether the control has been added. |
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 |
removeControl(int controlCode)
Remove the control, if it has already been added. |
void |
run()
The method that is run by the animation thread. |
void |
setForeground(java.awt.Color fg)
Set the foreground color of the animator's components. |
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 javax.swing.JPanel |
---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
Methods inherited from class javax.swing.JComponent |
---|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
Methods inherited from class java.awt.Container |
---|
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle |
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)
controls
- specifies the controls to addpublic Animator(int controls, int orientation)
controls
- specifies the controls to addorientation
- vertical or horizontalpublic 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 javax.swing.JComponent getControl(int controlCode)
controlCode
- specifies the control
public javax.swing.JComponent 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.
controlCode
- specifies the control to add
public boolean hasControl(int controlCode)
controlCode
- the control in question.
public void removeControl(int controlCode)
controlCode
- the control to remove.public void setStartButtonName(java.lang.String name)
name
- the name of the buttonpublic java.lang.String getStartButtonName()
public void setStopButtonName(java.lang.String name)
name
- the name of the buttonpublic java.lang.String getStopButtonName()
public int getOrientation()
public void setOrientation(int orientation)
orientation
- vertical or horizontalpublic Value getMax()
public void setMax(Value max)
max
- value object specifying the max valuepublic void setMax(double d)
d
- the desired max value for the animatorpublic Value getMin()
public void setMin(Value min)
min
- the desired min valuepublic void setMin(double d)
d
- the desired min valuepublic Value getIntervals()
public void setIntervals(Value intervals)
intervals
- the desired number of framespublic void setIntervals(int intervals)
intervals
- the desired number of framespublic int getMillisPerFrame()
public void setMillisPerFrame(int millis)
millis
- the desired milliseconds per framepublic int getLoopStyle()
public void setLoopStyle(int style)
style
- the desired looping stylepublic void setVal(double val)
val
- the desired valuepublic double getVal()
getVal
in interface Value
public Variable getValueAsVariable()
public Variable getValueAsVariable(java.lang.String name)
name
- name of the variable
public Computable getOnChange()
public void setOnChange(Computable onChange)
onChange
- the controller to usepublic void notifyControllerOnChange(Controller c)
notifyControllerOnChange
in interface InputObject
c
- the controller to notifypublic boolean getUndefinedWhenNotRunning()
public void setUndefinedWhenNotRunning(boolean undefinedWhenNotRunning)
undefinedWhenNotRunning
- true or falsepublic void setForeground(java.awt.Color fg)
setForeground
in class javax.swing.JComponent
fg
- the new foreground colorJComponent.setForeground(java.awt.Color)
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
evt
- the event created when user clicks a buttonpublic void itemStateChanged(java.awt.event.ItemEvent evt)
itemStateChanged
in interface java.awt.event.ItemListener
evt
- the event created when user makes a menu selectionpublic void checkInput()
checkInput
in interface InputObject
public long getSerialNumber()
getSerialNumber
in interface Tieable
public void sync(Tie tie, Tieable newest)
sync
in interface Tieable
tie
- the tie connecting the objectsnewest
- the object to synch withpublic void run()
run
in interface java.lang.Runnable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |