net.groboclown.gui.paintpipe.v1
Class PipePainter

java.lang.Object
  |
  +--net.groboclown.gui.paintpipe.v1.PainterThread
        |
        +--net.groboclown.gui.paintpipe.v1.OutputPainter
              |
              +--net.groboclown.gui.paintpipe.v1.PipePainter
Direct Known Subclasses:
SortingPainter

public abstract class PipePainter
extends OutputPainter

PipePainter waits for a set of PaintEvents on a PaintQueue. It assembles the events to create a composite image (or multiple images) to send to another PaintQueue.

This class relies on OutputPainter to handle the firing of paint events. See that class to get ideas on event pooling.

The Queue references a frame number in the events to check if the event should be placed in the input queue or not. This prevents out-of-date events from being inserted into our input queue, thus probably throwing off the image creation.

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

Inner classes inherited from class net.groboclown.gui.paintpipe.v1.PainterThread
PainterThread.PaintRunnable
 
Field Summary
private  PaintQueue inQ
           
 
Fields inherited from class net.groboclown.gui.paintpipe.v1.OutputPainter
outq
 
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
PipePainter()
          Creates a new PipePainter with a new input and output PaintQueue.
PipePainter(PaintQueue in, PaintQueue out)
          Creates a new PipePainter with the given input and output PaintQueues.
 
Method Summary
protected abstract  boolean areMoreEvents()
          Checks if any more events need to be pulled from the queue.
protected  void flushEvents()
          If any events or images are in a good enough position to send, fire them all in this event.
 PaintQueue getInputQueue()
           
protected  void paint()
          The paint method is already implemented in this case.
 void paintFinished(PaintFinishedEvent pfe)
          Update the frame number to accept.
protected abstract  void processEvent(PaintEvent pe)
          Processes the next PaintEvent from the input queue.
 
Methods inherited from class net.groboclown.gui.paintpipe.v1.OutputPainter
firePaintEvent, getOutputQueue
 
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
Constructor Detail

PipePainter

public PipePainter()
Creates a new PipePainter with a new input and output PaintQueue.

PipePainter

public PipePainter(PaintQueue in,
                   PaintQueue out)
Creates a new PipePainter with the given input and output PaintQueues.
Parameters:
in - the input queue, listened to by this thread.
out - the output queue, in which events are fired to.
Method Detail

getInputQueue

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

paintFinished

public void paintFinished(PaintFinishedEvent pfe)
                   throws InterruptedException
Update the frame number to accept. This prevents old events from a previous frame from interfering with our event processing.
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, flushEvents() is called to announce this event. Then the flush event is sent down to the output queue, and no more events are processed for the frame.

Due to the way the paint queue is implemented, older events from older frames are not recieved in the input.

Overrides:
paint in class PainterThread
Following copied from class: net.groboclown.gui.paintpipe.v1.PainterThread
Throws:
InterruptedException - must be allowed to propigate without being caught. It is thrown when the thread has been interrupted during some kind of Thread.sleep(long) or Object.wait() call.

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.

flushEvents

protected void flushEvents()
If any events or images are in a good enough position to send, fire them all in this event. You should not fire a FlushPaintingEvent here, since it is done for you in the paint() method above. This is called as the last method of the frame in all circumstances, except for an InterruptedException, which shouldn't be caught.

This method must not perform any method which can be Interrupted.

The default functionality is to do nothing. This is not made abstract, since most painters won't output half-complete images or data processing anyway.



Written under the LGPL