net.groboclown.gui.paintpipe.v1
Class RefreshPainter

java.lang.Object
  |
  +--net.groboclown.gui.paintpipe.v1.PainterThread
        |
        +--net.groboclown.gui.paintpipe.v1.RefreshPainter

public abstract class RefreshPainter
extends PainterThread

A RefreshPainter has some similarities to a PipePainter, in that it listens to input. However, it outputs directly to some on-screen component which implements RefreshComponent.

To prevent the case where the component is drawing one image, while that same image is being repainted in another thread, we swap between two images to paint to.

Again, like PipePainter, you have no need to override the functionality of the paint() method. Instead, you should implement its hooks, areMoreEvents() and processEvent(net.groboclown.gui.paintpipe.v1.PaintEvent). When areMoreEvents() returns false, all registered paint threads are finished up by a call to paintFinished(net.groboclown.gui.paintpipe.v1.PaintFinishedEvent).

Therefore, this class acts as the overal clock-master, keeping track of when the frames change.

Version:
1.0
Author:
Matt Albrecht
See Also:
PipePainter, PaintQueue

Inner classes inherited from class net.groboclown.gui.paintpipe.v1.PainterThread
PainterThread.PaintRunnable
 
Field Summary
private  PaintQueue inQ
           
private  Vector paintThreads
           
private  PaintFinishedEvent pfe
           
private  RefreshComponent rc
           
 
Fields inherited from class net.groboclown.gui.paintpipe.v1.PainterThread
frameNumber, group, isPainting, METRICS, metricsListeners, name, numberPaintAttempts, numberWaitForEvent, painter, priority, RUN_NEVER_STARTED, RUN_PAUSED, RUN_REQUESTED_PAUSE, RUN_REQUESTED_STOP, RUN_RUNNING, RUN_STOPPED, runState, sentPaintFinishedEvent, startTimeMillis, syncThis, totalPaintTimeMillis, totalWaitForEventTimeMillis
 
Constructor Summary
RefreshPainter(PaintQueue in, RefreshComponent rc)
          Creates a new PipePainter with the given input and output PaintQueues.
RefreshPainter(RefreshComponent rc)
          Creates a new RefreshPainter with a new input PaintQueue, and the given refresh component.
 
Method Summary
 void addPainterThread(PainterThread pt)
          Adds a PainterThread to the list of those known about.
protected abstract  boolean areMoreEvents()
          Checks if any more events need to be pulled from the queue.
 RefreshComponent getComponent()
           
protected abstract  Image getImage()
          Returns the current state of the image being generated.
 PaintQueue getInputQueue()
           
protected  void paint()
          The paint method is already implemented in this case.
 void paintFinished(PaintFinishedEvent pfe)
          Turn back on the queue at the end of the paint finished event to re-enable input checking.
protected abstract  void processEvent(PaintEvent pe)
          Processes the next PaintEvent from the input queue.
 void removePainterThread(PainterThread pt)
          Removes the given registered PainterThread from the list.
protected abstract  void setImage(Image img)
          Sets the image to use for the painting phaze.
 
Methods inherited from class net.groboclown.gui.paintpipe.v1.PainterThread
addMetricsListener, canPause, canStop, cleanup, fireMetricsPaint, fireMetricsWait, getFrameNumber, getNumberPaintCalls, getNumberWaitForEventTimes, getStartTimeMillis, getTotalPaintTimeMillis, getTotalWaitForEventTimeMillis, initialize, isAlive, isInterrupted, isRunning, isStopImpending, isStopping, isSuspended, isWaitingForEvent, join, killPainting, removeMetricsListener, resume, start, stop, stopInterrupt, stopInterruptJoin, stopJoin, suspend, suspendInterrupt
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

inQ

private PaintQueue inQ

rc

private RefreshComponent rc

paintThreads

private Vector paintThreads

pfe

private PaintFinishedEvent pfe
Constructor Detail

RefreshPainter

public RefreshPainter(RefreshComponent rc)
Creates a new RefreshPainter with a new input PaintQueue, and the given refresh component.
Parameters:
rc - the component to send refresh events to.

RefreshPainter

public RefreshPainter(PaintQueue in,
                      RefreshComponent rc)
Creates a new PipePainter with the given input and output PaintQueues.
Parameters:
in - the input queue, listened to by this thread.
rc - the component to send refresh events to.
Method Detail

getInputQueue

public PaintQueue getInputQueue()
Returns:
the current queue to listen to.

getComponent

public RefreshComponent getComponent()
Returns:
the current refresh component.

addPainterThread

public void addPainterThread(PainterThread pt)
Adds a PainterThread to the list of those known about.

removePainterThread

public void removePainterThread(PainterThread pt)
Removes the given registered PainterThread from the list.

paintFinished

public void paintFinished(PaintFinishedEvent pfe)
                   throws InterruptedException
Turn back on the queue at the end of the paint finished event to re-enable input checking. Also, all of the events stored in the queue up to this point are removed. ,p> And to boot, all registered painters are called.
Overrides:
paintFinished in class PainterThread

paint

protected final void paint()
                    throws InterruptedException
The paint method is already implemented in this case. Subclasses need not overload its functionality, so it has been made final to enforce this.

Instead, the paint method calls areMoreEvents() to check if any more events are needed to create the output image. The processEvent(net.groboclown.gui.paintpipe.v1.PaintEvent) method is called to process a new event which was read from the input queue.

If a FlushPaintingEvent is found in the queue, no more events are processed for the frame.

At the end of a paint, the component is refreshed, and the paintFinished(net.groboclown.gui.paintpipe.v1.PaintFinishedEvent) event is called to announce to everyone to start painting again.

Overrides:
paint in class PainterThread
See Also:
for more information on reasons to disable the queue.

processEvent

protected abstract void processEvent(PaintEvent pe)
Processes the next PaintEvent from the input queue. It doesn't have to post any output events, but it can.
Parameters:
pe - the event which is to be processed.

areMoreEvents

protected abstract boolean areMoreEvents()
Checks if any more events need to be pulled from the queue.
Returns:
true if it is believed that more PaintEvents are going to be used in the current frame creation.

getImage

protected abstract Image getImage()
Returns the current state of the image being generated.

setImage

protected abstract void setImage(Image img)
Sets the image to use for the painting phaze.


Written under the LGPL