net.groboclown.gui.paintpipe.v1
Class PaintQueue

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

public class PaintQueue
extends Object

A Queue designed for a multi-threaded painting environment. It only allows paint events to pass through.

A problem may occur when a painting thread has just finished recieving all the incoming events it needs to draw the given image. A situation could arise where the posting thread(s) continue to send events to the queue. Then when the new frame is triggered, the listening thread would read the past frame's events in before the events for the current frame.

To prevent this from happening, we have a current frame number variable. This way, if events are posted from an earlier frame, they are ignored. This means that we want to keep track of future frame events as well in another list, and move them over when the frame number changes. Also, when the frame updates, we need to clear out all the old events relating to previous frames.

In the current architecture, the frame number is updated in the PainterThread.paintFinished(net.groboclown.gui.paintpipe.v1.PaintFinishedEvent) routine. All other events posted need to have their frame number stamped to the current painter's frame number.

Since:
1.0
Author:
Matt Albrecht

Field Summary
private  int frameNumber
           
private  Vector futureEvents
           
private  SynchQueue tq
           
 
Constructor Summary
PaintQueue()
          Creates a new thread queue.
PaintQueue(SynchQueue queue)
          Uses the given queue as the internal representation of a queue.
 
Method Summary
 PaintEvent dequeue()
          Removes a paint event from the queue, and waits if the queue is empty.
 void enqueue(PaintEvent pe)
          Puts a paint event at the tail of the queue.
 int getFrame()
          Returns the state of the queue to allow input or not.
 boolean isEmpty()
          Checks if the queue is empty.
 void removeAll()
          Empties the queue, and the future list.
 void setFrame(int f)
          Sets the current frame number, and adjusts the queues accordingly.
 int size()
          Returns the number of events waiting in the queue with the same frame number as the queue.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

tq

private SynchQueue tq

frameNumber

private int frameNumber

futureEvents

private Vector futureEvents
Constructor Detail

PaintQueue

public PaintQueue()
Creates a new thread queue.

PaintQueue

public PaintQueue(SynchQueue queue)
Uses the given queue as the internal representation of a queue.
Parameters:
queue - Description of Parameter
Method Detail

isEmpty

public boolean isEmpty()
Checks if the queue is empty.
Returns:
The Empty value

getFrame

public int getFrame()
Returns the state of the queue to allow input or not.
Returns:
The Frame value

enqueue

public void enqueue(PaintEvent pe)
Puts a paint event at the tail of the queue.
Parameters:
pe - Description of Parameter

dequeue

public PaintEvent dequeue()
                   throws InterruptedException
Removes a paint event from the queue, and waits if the queue is empty. If a non-paint event is the next on the list, we return null.
Returns:
Description of the Returned Value
Throws:
InterruptedException - thrown when the thread was interrupted by another thread.

removeAll

public void removeAll()
Empties the queue, and the future list.

size

public int size()
Returns the number of events waiting in the queue with the same frame number as the queue.
Returns:
Description of the Returned Value

setFrame

public void setFrame(int f)
              throws InterruptedException
Sets the current frame number, and adjusts the queues accordingly.
Parameters:
f - The new Frame value
Throws:
InterruptedException - thrown when the thread was interrupted by another thread.


Written under the LGPL