Class TLcyUserInteractionBlocker

java.lang.Object
com.luciad.lucy.gui.status.TLcyUserInteractionBlocker
All Implemented Interfaces:
ILcdStatusListener, EventListener

public class TLcyUserInteractionBlocker extends Object implements ILcdStatusListener
Implementation of 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.

See Also:
  • Constructor Details

    • TLcyUserInteractionBlocker

      public TLcyUserInteractionBlocker(JFrame aTargetFrame)
      Constructs a new 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 TLcdStatusEvents, for example ILcyLucyEnv.
      Parameters:
      aTargetFrame - The frame to block the user input from.
      See Also:
    • TLcyUserInteractionBlocker

      public TLcyUserInteractionBlocker(JFrame aTargetFrame, Cursor aCursor)
      Constructs a new 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 TLcdStatusEvents.
      Parameters:
      aTargetFrame - The frame to block the user input from.
      aCursor - The mouse cursor to display while blocking the user interface.
    • TLcyUserInteractionBlocker

      public TLcyUserInteractionBlocker(JFrame aTargetFrame, Cursor aCursor, int aDelay)
      Constructs a new 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 TLcdStatusEvents.
      Parameters:
      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.
  • Method Details

    • getStopBlockingKeyStrokes

      public KeyStroke[] getStopBlockingKeyStrokes()
      Returns the keys strokes that, when pressed, stop blocking the user interface.
      Returns:
      the keys strokes that, when pressed, stop blocking the user interface.
      See Also:
    • setStopBlockingKeyStrokes

      public void setStopBlockingKeyStrokes(KeyStroke[] aStopBlockingKeyStrokes)
      Sets the key strokes that, when pressed, stop the user interface from blocking. This is mainly useful to allow the user to continue using the application in the event some 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().

      Parameters:
      aStopBlockingKeyStrokes - The key strokes that, when pressed, stop blocking the user interface. Typical values are control-c or escape.
      See Also:
    • stopBlocking

      public void stopBlocking()
      Stops blocking the user interface if it was being blocked. There is normally no need to call this method, but it can for example be useful to make sure the user interface does not remain blocked if some uncaught exception occurred.
      See Also:
    • statusChanged

      public void statusChanged(TLcdStatusEvent event)
      Handles the given status event by blocking the user interface if this condition holds:
      
         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.

      Specified by:
      statusChanged in interface ILcdStatusListener
      Parameters:
      event - The status event describing the status change.