public class ThreadMonitorDialog extends JDialog implements ActionListener
This dialog box generally has a progress bar and always has a Cancel button which allows to interrupt the monitored thread at any time.
JDialog.AccessibleJDialog
Dialog.AccessibleAWTDialog, Dialog.ModalExclusionType, Dialog.ModalityType
Window.AccessibleAWTWindow, Window.Type
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected JButton |
cancelButton |
protected long |
cancelDate |
protected boolean |
canceled |
protected int |
cancelMaxDuration |
protected static int |
DEFAULT_CANCEL_MAX_DURATION |
protected Component |
dialogAnchor |
protected JLabel |
iconLabel |
protected String |
messageLog |
protected JTextComponent |
messages |
protected StoppableThread |
monitoredThread |
protected Timer |
monitorTimer |
protected Component |
parentComponent |
protected JProgressBar |
progressBar |
protected MultiLineJLabel |
subTitleLabel |
accessibleContext, rootPane, rootPaneCheckingEnabled
DEFAULT_MODALITY_TYPE
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
ThreadMonitorDialog(Component parentComponent,
String title,
String subTitle,
int rows,
int columns,
boolean hasProgressBar)
Constructs a ThreadMonitorDialog.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(ActionEvent e) |
void |
animateLastLine(String line,
boolean firstFrame)
To be invoked by the thread being monitored: replace last line
displayed in the message area (if any) by specified line.
|
void |
appendMessage(String message)
Equivalent to
appendMessage(message, Log.Level.INFO) . |
void |
appendMessage(String message,
Log.Level level)
To be invoked by the thread being monitored: append specified message
to the messages displayed in the message area (if any).
|
boolean |
attachThread(StoppableThread thread)
Attach to specified, already started, thread.
|
protected void |
cancel() |
protected JTextComponent |
createMessages(int rows,
int columns)
Returns a
JTextArea having specified number of rows and number
of columns. |
protected JScrollPane |
createMessagesScroller(JTextComponent messages,
int rows,
int columns)
Returns a
JScrollPane containing specified text component. |
protected void |
doAnimateLastLine(String line,
boolean firstFrame) |
protected void |
doAppendMessage(String message,
Log.Level level) |
protected boolean |
doAttachThread(StoppableThread thread,
boolean start) |
protected void |
doClearMessages() |
protected void |
doSetMessage(String message,
Log.Level level) |
protected void |
doSetProgress(int step,
int stepCount) |
int |
getCancelMaxDuration()
Returns the grace time of a canceled thread.
|
protected static Icon |
getDefaultIcon() |
Icon |
getIcon()
Returns the icon of this dialog box.
|
String |
getMessageLog()
Returns the the name of the log where progress messages are logged.
|
protected void |
initialize(Component parentComponent,
String subTitle,
int rows,
int columns,
boolean hasProgressBar) |
protected static void |
invokeAndWait(Runnable runnable) |
boolean |
isCanceled()
To be invoked by the thread being monitored: Returns
true
if the user has canceled the task implemented by the thread being
monitored; false otherwise. |
boolean |
isIndeterminateProgressBar()
Returns the indeterminate mode of the progress bar.
|
protected JTextArea |
messageArea() |
protected void |
monitor() |
void |
setCancelMaxDuration(int duration)
Specifies the grace time of a canceled thread.
|
void |
setIcon(Icon icon)
Changes the icon of this dialog box.
|
void |
setIndeterminateProgressBar(boolean indeterminate)
Sets the progress bar to specified indeterminate mode.
|
void |
setMessage(String message)
Equivalent to
setMessage(message, Log.Level.INFO) . |
void |
setMessage(String message,
Log.Level level)
To be invoked by the thread being monitored: replace the messages
displayed in the message area (if any) by specified message.
|
void |
setMessageLog(String logName)
Specifies the name of the log where progress messages are to be logged.
|
void |
setProgress(int step,
int stepCount)
To be invoked by the thread being monitored: update the progress bar
(if any).
|
boolean |
startThread(StoppableThread thread)
Attach to specified thread and start it.
|
static Log.Level |
toLogLevel(Console.MessageType messageType)
Converts specified Console message type to the corresponding log level.
|
addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
addNotify, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, setBackground, setModal, setModalityType, setOpacity, setResizable, setShape, setTitle, setUndecorated, setVisible, show, toBack
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, toFront
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
protected Component parentComponent
protected Component dialogAnchor
protected JLabel iconLabel
protected MultiLineJLabel subTitleLabel
protected JTextComponent messages
protected JProgressBar progressBar
protected JButton cancelButton
protected String messageLog
protected int cancelMaxDuration
protected StoppableThread monitoredThread
protected Timer monitorTimer
protected boolean canceled
protected long cancelDate
protected static final int DEFAULT_CANCEL_MAX_DURATION
public ThreadMonitorDialog(Component parentComponent, String title, String subTitle, int rows, int columns, boolean hasProgressBar)
parentComponent
- the parent of the dialog boxtitle
- the title of the dialog boxsubTitle
- a message displayed at the top of the dialog boxrows
- the number of rows of the text area displaying the progress
messages. Specify a negative or null number to suppress this text area.columns
- the number of rows of the text area displaying the
progress messages. Specify a negative or null number to suppress this
text area.hasProgressBar
- if true
, the dialog box will have a
progress barprotected void initialize(Component parentComponent, String subTitle, int rows, int columns, boolean hasProgressBar)
protected JTextComponent createMessages(int rows, int columns)
JTextArea
having specified number of rows and number
of columns.protected JScrollPane createMessagesScroller(JTextComponent messages, int rows, int columns)
JScrollPane
containing specified text component.public void setIcon(Icon icon)
icon
- the new icon. Specify null
to
use the default icon.protected static Icon getDefaultIcon()
public Icon getIcon()
public void setIndeterminateProgressBar(boolean indeterminate)
public boolean isIndeterminateProgressBar()
false
if this dialog box has no progress bar.public void setMessageLog(String logName)
null
. Default value: null
(progress
messages are not logged).public String getMessageLog()
setMessageLog(java.lang.String)
public void setCancelMaxDuration(int duration)
public int getCancelMaxDuration()
setCancelMaxDuration(int)
public boolean startThread(StoppableThread thread)
public boolean attachThread(StoppableThread thread)
protected boolean doAttachThread(StoppableThread thread, boolean start)
public void actionPerformed(ActionEvent e)
actionPerformed
in interface ActionListener
protected void monitor()
protected void cancel()
public boolean isCanceled()
true
if the user has canceled the task implemented by the thread being
monitored; false
otherwise.public void setProgress(int step, int stepCount)
public void setMessage(String message)
setMessage(message, Log.Level.INFO)
.public void setMessage(String message, Log.Level level)
public static Log.Level toLogLevel(Console.MessageType messageType)
public void appendMessage(String message)
appendMessage(message, Log.Level.INFO)
.public void appendMessage(String message, Log.Level level)
public void animateLastLine(String line, boolean firstFrame)
line
- initial text line or replacement text line. Must not
include newline characters.firstFrame
- if true
, line is the initial
text line. if false
, line is a replacement text
line.protected static final void invokeAndWait(Runnable runnable)
protected void doSetProgress(int step, int stepCount)
protected void doClearMessages()
protected void doAnimateLastLine(String line, boolean firstFrame)
protected JTextArea messageArea()