public class TLcyUserInteractionBlocker extends Object implements ILcdStatusListener
ILcdStatusListener
that blocks user interaction with a given frame
between receiving a START_BUSY
and an END_BUSY
status event, provided
the blocking hint of those events is set to true
. It displays a mouse cursor of choice,
typically a wait cursor, while the user interface is blocked.
As this listener blocks the user interface when a START_BUSY
event is received, it
is very important that an END_BUSY
event is received as well. Implementations firing
a START_BUSY
event (with blocking hint set to true
) should therefore be
carefully implemented to make sure an END_BUSY
is fired as well, even if for example
an exception has occurred. If required, the method stopBlocking()
can be used to make
sure the user interface is not blocked.TLcdStatusEvent.isBlockingHint()
Constructor and Description |
---|
TLcyUserInteractionBlocker(JFrame aTargetFrame)
Constructs a new
TLcyUserInteractionBlocker , without a delay and with a
Cursor.WAIT_CURSOR . |
TLcyUserInteractionBlocker(JFrame aTargetFrame,
Cursor aCursor)
Constructs a new
TLcyUserInteractionBlocker , without a delay, and with the given mouse cursor. |
TLcyUserInteractionBlocker(JFrame aTargetFrame,
Cursor aCursor,
int aDelay)
Constructs a new
TLcyUserInteractionBlocker , with the given delay and given mouse cursor. |
Modifier and Type | Method and Description |
---|---|
KeyStroke[] |
getStopBlockingKeyStrokes()
Returns the keys strokes that, when pressed, stop blocking the user interface.
|
void |
setStopBlockingKeyStrokes(KeyStroke[] aStopBlockingKeyStrokes)
Sets the key strokes that, when pressed, stop the user interface from blocking.
|
void |
statusChanged(TLcdStatusEvent event)
Handles the given status event by blocking the user interface if this condition holds:
|
void |
stopBlocking()
Stops blocking the user interface if it was being blocked.
|
public TLcyUserInteractionBlocker(JFrame aTargetFrame)
TLcyUserInteractionBlocker
, without a delay and with a
Cursor.WAIT_CURSOR
. It is up to the user of this method to add it to a
source of TLcdStatusEvent
s, for example ILcyLucyEnv
.aTargetFrame
- The frame to block the user input from.( javax.swing.JFrame, java.awt.Cursor, int )
public TLcyUserInteractionBlocker(JFrame aTargetFrame, Cursor aCursor)
TLcyUserInteractionBlocker
, without a delay, and with the given mouse cursor.
It is up to the user of this method to add it to a source of TLcdStatusEvent
s.aTargetFrame
- The frame to block the user input from.aCursor
- The mouse cursor to display while blocking the user interface.public TLcyUserInteractionBlocker(JFrame aTargetFrame, Cursor aCursor, int aDelay)
TLcyUserInteractionBlocker
, with the given delay and given mouse cursor.
It is up to the user of this method to add it to a source of TLcdStatusEvent
s.aTargetFrame
- The frame to block the user input from.aCursor
- The mouse cursor to display while blocking the user interface.aDelay
- The delay, in milliseconds, before blocking the UI. When a START_BUSY
event is received, the user interface is only blocked after the given time delay. This can help avoid
flickering caused by bursts of short tasks.public KeyStroke[] getStopBlockingKeyStrokes()
setStopBlockingKeyStrokes(javax.swing.KeyStroke[])
public void setStopBlockingKeyStrokes(KeyStroke[] aStopBlockingKeyStrokes)
ILcdStatusListener
,
for some exceptional reason, only fired a START_BUSY
event and no STOP_BUSY
event.
Note that pressing any of the given key strokes has the same effect as a call to stopBlocking()
.aStopBlockingKeyStrokes
- The key strokes that, when pressed, stop blocking the user interface.
Typical values are control-c or escape.getStopBlockingKeyStrokes()
,
stopBlocking()
public void stopBlocking()
public void statusChanged(TLcdStatusEvent event)
event.getID() == TLcdStatusEvent.START_BUSY && event.isBlockingHint()
Unblocks the user interface if this condition holds:
event.getID() == TLcdStatusEvent.END_BUSY && event.isBlockingHint()
Nested busy events are supported as well, causing the user interface to unblock only
after all nested tasks are ended.statusChanged
in interface ILcdStatusListener
event
- The status event describing the status change.