|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.media.TimerView
public class TimerView
A generic timer class that can be rendered on screen. NOTE: This base class doesn't actually render anything, but it's still useful for triggering user supplied callback functions. Derived classes are more than welcome to setup their own rendering, of course.
| Field Summary | |
|---|---|
protected Rectangle |
_bounds
The screen coordinates of the timer's bounding box. |
protected float |
_changeThreshold
The timer will not invalidate itself until the completion level to render changes by at least this much from the previous time it was invalidated. |
protected float |
_complete
The percent of the duration time completed. |
protected boolean |
_completed
True if the completion has already been processed. |
protected long |
_duration
The total amount of time in the timer when it was 0% done. |
protected boolean |
_enabled
Whether to render the timer. |
protected ResultListener<TimerView> |
_finisher
A listener to be notified when the timer finishes. |
protected FrameManager |
_fmgr
The frame manager that manages our animated view. |
protected JComponent |
_host
The media panel containing the view. |
protected boolean |
_invalidated
True if the timer has been invalidated since its last repaint. |
protected long |
_lastUpdate
The last time the timer updated while running. |
protected float |
_paintComplete
The completion percent last time the timer was repainted. |
protected boolean |
_participating
Whether the timer is participating in media tick updates. |
protected boolean |
_processUnpause
True if the code should process everything required for an unpause on the next tick(). |
protected float |
_renderComplete
The completion percent at which to render the timer. |
protected float |
_renderOffset
The difference between the old rendered completion percent and the new completion percent the last time the completion percent had an unexpected change. |
protected long |
_renderOffsetTime
The timestamp of _renderOffset. |
protected boolean |
_running
Whether the timer is running. |
protected long |
_start
The timestamp when the timer effectively started. |
protected long |
_transitionTime
The amount of time it takes to fully interpolation a render transition from completion 0.0 to 1.0. |
protected boolean |
_warned
True if the warning has already been processed. |
protected ResultListener<TimerView> |
_warner
A listener to be notified when the warning time occurs. |
protected float |
_warnPercent
Trigger the warning when at least this much time has elapsed, or -1 for no warning. |
protected static long |
DEFAULT_RATE
The default update date. |
| Constructor Summary | |
|---|---|
TimerView(FrameManager fmgr,
JComponent host,
Rectangle bounds)
Constructs a timer view that fires at the default rate. |
|
| Method Summary | |
|---|---|
void |
changeComplete(float complete)
Generate an unexpected change in the timer's completion and set up the necessary details to render interpolation from the old to new states |
void |
checkFrameParticipation()
Check that the frame knows about the timer. |
Component |
getComponent()
If a frame participant wishes also to be actively rendered every frame rather than use passive rendering (which for Swing, at least, is hijacked when using the frame manager such that we take care of repainting dirty Swing components every frame into our off-screen buffer), it can return a component here which will have Component.paint(java.awt.Graphics) called on it once per frame with a translated but
unclipped graphics object. |
long |
getTransitionTime()
Get the amount of time it takes to render digital changes in the completion state. |
protected void |
handleCompleted()
Handle the trigger of the timer's completion. |
protected void |
handleWarning()
Handle the trigger of the warning. |
void |
hierarchyChanged(HierarchyEvent e)
|
protected void |
invalidate()
Invalidates this view's bounds via the host component. |
boolean |
needsPaint()
Called immediately prior to FrameParticipant.getComponent() and then Component.paint(java.awt.Graphics) on said component, to determine whether or not
this frame participant needs to be painted. |
void |
paint(Graphics2D gfx,
float complete)
Paint the timer into the given graphics context at the inputted percent complete (0f means just started, 1f means just finished). |
void |
pause()
Pause the timer from processing. |
void |
removeWarning()
Remove any warning this timer might have had. |
void |
render(Graphics2D gfx)
Renders the timer to the given graphics context if enabled. |
void |
reset()
Reset the timer. |
boolean |
running()
Test if the timer is running right now. |
void |
setEnabled(boolean enabled)
Sets whether this timer should be rendered. |
void |
setTransitionTime(long time)
Set the amount of time it takes to render digital changes in the completion state (probably due to a timer reset). |
void |
setWarning(float warnPercent,
ResultListener<TimerView> warner)
Setup a warning to trigger after the timer is "warnPercent" or more completed. |
void |
start(float startPercent,
long duration,
ResultListener<TimerView> finisher)
Start the timer running from the specified percentage complete, to expire at the specified time. |
void |
stop()
Stop the timer. |
void |
tick(long now)
This is called on all registered frame participants, one for every frame. |
protected boolean |
triggeredCompleted()
Test if the completion was triggered and needs to be processed. |
protected boolean |
triggeredWarning()
Test if the warning was triggered and needs to be processed. |
void |
unpause()
Unpause the timer. |
protected void |
update(long now)
Updates the timer for the current inputted time. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected FrameManager _fmgr
protected JComponent _host
protected Rectangle _bounds
protected boolean _enabled
protected boolean _running
protected boolean _participating
protected long _lastUpdate
protected long _duration
protected long _start
protected float _complete
protected float _renderOffset
protected long _renderOffsetTime
protected long _transitionTime
protected float _renderComplete
protected float _paintComplete
protected float _changeThreshold
protected boolean _invalidated
protected float _warnPercent
protected boolean _warned
protected boolean _completed
protected boolean _processUnpause
protected ResultListener<TimerView> _finisher
protected ResultListener<TimerView> _warner
protected static final long DEFAULT_RATE
| Constructor Detail |
|---|
public TimerView(FrameManager fmgr,
JComponent host,
Rectangle bounds)
| Method Detail |
|---|
public void setEnabled(boolean enabled)
public long getTransitionTime()
public void setTransitionTime(long time)
public void setWarning(float warnPercent,
ResultListener<TimerView> warner)
public void removeWarning()
public boolean running()
public void start(float startPercent,
long duration,
ResultListener<TimerView> finisher)
startPercent - a value in [0f, 1f) indicating how much
hourglass time has already elapsed when the timer starts.duration - The time interval over which the timer would
run if it started at 0%.finisher - a listener that will be notified when the timer
finishes, or null if nothing should be notified.public void reset()
public void stop()
public void pause()
public void unpause()
public void changeComplete(float complete)
protected void update(long now)
protected boolean triggeredWarning()
protected boolean triggeredCompleted()
protected void handleWarning()
protected void handleCompleted()
protected void invalidate()
public void render(Graphics2D gfx)
public void paint(Graphics2D gfx,
float complete)
public void tick(long now)
FrameParticipant
tick in interface FrameParticipantpublic boolean needsPaint()
FrameParticipantFrameParticipant.getComponent() and then Component.paint(java.awt.Graphics) on said component, to determine whether or not
this frame participant needs to be painted.
needsPaint in interface FrameParticipantpublic Component getComponent()
FrameParticipantComponent.paint(java.awt.Graphics) called on it once per frame with a translated but
unclipped graphics object.
Because clipping is expensive in terms of rectangle object allocation, frame participants are given the opportunity to do their own clipping because they are likely to want to clip to a more fine grained region than their entire bounds. If a participant does not wish to be actively rendered, it can safely return null.
getComponent in interface FrameParticipantpublic void hierarchyChanged(HierarchyEvent e)
hierarchyChanged in interface HierarchyListenerpublic void checkFrameParticipation()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||