qflib 0.98.1

de.qfs.lib.gui
Class EventQueueMark

java.lang.Object
  |
  +--de.qfs.lib.gui.EventQueueMark
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, java.lang.Runnable

public class EventQueueMark
extends java.lang.Object
implements java.lang.Runnable, java.awt.event.ActionListener

This little tool is useful to distinguish between artificial and user-generated events. Often it is necessary to decide, whether an event, e.g. a change in some component's selection, was generated by the application itself in responce to a certain action (in which case it should be ignored), or was caused explicitely by the user (so some response is required).

To determine whether an event is artificial, create an EventQueueMark and activate it right before and after the action that causes the event - before to ignore artificial events that are passed to listeners directly, bypassing the event queue, and after to ignore events collected on the queue during the action. In the corresponding listener, use isActive to determine whether the mark is still active on the event queue, meaning the event can be ignored.

If the artificial event is not generated immediately, but after some delay, use activate(int delay) with a similar, possibly slightly longer delay.

Since:
0.98.0
Version:
$Revision: 1.3 $
Author:
Gregor Schmid

Field Summary
protected  boolean active
          Flag to determine whether the mark is active.
protected  int toClear
          That many incantations need to be cleared.
protected  int toSkip
          That many clearances need to be skipped.
 
Constructor Summary
EventQueueMark()
          Create a new EventQueueMark.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Called when a timer fires.
 void activate()
          Activate the mark until the the events currently on the event queue are removed.
 void activate(int delay)
          Activate the mark until some time has passed.
 void deactivate()
          Deactivate the mark immediately.
 boolean isActive()
          Check whether the mark is active.
 void run()
          Zun method for SwingUtilities.invokeLater.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

active

protected boolean active
Flag to determine whether the mark is active.

toClear

protected int toClear
That many incantations need to be cleared.

toSkip

protected int toSkip
That many clearances need to be skipped.
Constructor Detail

EventQueueMark

public EventQueueMark()
Create a new EventQueueMark.
Method Detail

activate

public void activate()
Activate the mark until the the events currently on the event queue are removed.

activate

public void activate(int delay)
Activate the mark until some time has passed.
Parameters:
delay - The time to wait in ms.

deactivate

public void deactivate()
Deactivate the mark immediately.

isActive

public boolean isActive()
Check whether the mark is active.
Returns:
True if the mark is active.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Called when a timer fires. Decrement active count and deactivate the mark if it reaches 0.
Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - Ignored.

run

public void run()
Zun method for SwingUtilities.invokeLater. Decrement active count and deactivate the mark if it reaches 0.
Specified by:
run in interface java.lang.Runnable

qflib 0.98.1