org.gerhardb.jibs.obsolete
Class WaitDialog

java.lang.Object
  extended by org.gerhardb.jibs.obsolete.WaitDialog
All Implemented Interfaces:
java.util.EventListener, javax.swing.event.ChangeListener

public class WaitDialog
extends java.lang.Object
implements javax.swing.event.ChangeListener

Displays a dialog while executing a task in the background. The dialog remains visible until either the task is complete, or the user cancels the operation (by pressing the dialog's Cancel button). In the case where the user cancels the operation, the executing task (which is a Thread) will be interrupted. It is up to the task thread to handle its interruption status and terminate itself at the earliest opportunity. (Java does not have the ability to abort an executing thread.)

Author:
Craig Pell (initial), $Author: gerhardb $ (latest)

Field Summary
static javax.swing.Icon WAIT_ICON
           
 
Constructor Summary
WaitDialog(long dialogThreshold, java.lang.String btnMsg)
          Constructs a WaitDialog with a specified timeout.
 
Method Summary
 void interrupt()
          Halts any executing task, and hides this object's dialog if it is displayed.
 void show(java.awt.Component parent, java.lang.Object message, java.lang.String title, java.lang.Thread task)
          Executes a task and displays a dialog indicating the task is in progress.
 void stateChanged(javax.swing.event.ChangeEvent e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WAIT_ICON

public static final javax.swing.Icon WAIT_ICON
Constructor Detail

WaitDialog

public WaitDialog(long dialogThreshold,
                  java.lang.String btnMsg)
Constructs a WaitDialog with a specified timeout.

Method Detail

show

public void show(java.awt.Component parent,
                 java.lang.Object message,
                 java.lang.String title,
                 java.lang.Thread task)
Executes a task and displays a dialog indicating the task is in progress. Actually, the dialog is not displayed immediately. The task begins executing immediately, but this method will launch a thread which waits for a specific amount of time (as specified in this WaitDialog's constructor) and then display the dialog, if and only if the task has not completed. This prevents a dialog from "flashing" on the screen and almost immediately disappearing again when a brief task executes.

This method returns immediately, in all cases. All work is done by launching new threads.

The executing task will be interrupted if the user activates the dialog's Cancel button. It is up to the task to respond to interruption and terminate itself cleanly and promptly.

Parameters:
parent - parent of the dialog which will be displayed
message - message to display in the dialog; it is displayed like a JOptionPane message
title - the title of the dialog which will be displayed
task - the task to execute in the background

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent e)
Specified by:
stateChanged in interface javax.swing.event.ChangeListener

interrupt

public void interrupt()
Halts any executing task, and hides this object's dialog if it is displayed. The executing task, if any, will be interrupted; it is up to that task to terminate itself based on its interruption status.



Copyright ? 2007 Gerhard Beck. All rights reserved. Subject to GPL.