JXTA

net.jxta.widget
Class OptionDialog

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Dialog
                          |
                          +--net.jxta.widget.OptionDialog

public class OptionDialog
extends java.awt.Dialog
implements java.awt.event.ActionListener

See Also:
Serialized Form

Field Summary
static int ABORT
          Return value if the ABORT button was pressed
static java.lang.String ABORT_TEXT
          Default text for the abort button
protected  boolean abortPressed
          Did the user press the abort button
static int ALERT
          Alert type message - only one okay button
protected  java.awt.Panel buttonPanel
          Panel that contains the buttons to be displayed
static int CANCEL
          Return value if the cancel button was pressed
static java.lang.String CANCEL_TEXT
          Default text for the cancel button
static int ERROR
          Return value if an ERROR occured
protected static java.awt.Frame frame
          The parent frame of this dialog
protected  java.awt.GridBagConstraints gbc
          The GridBagConstraint used to lay out the components
protected  java.awt.GridBagLayout gbl
          The GridBagLayout used to lay out the components
protected  ImageLabel imageLabel
          The ImageLabel displaying the alert image
static int INFO
          Info type message - only one okay button
static int OKAY
          Return value if the okay button was pressed
static java.lang.String OKAY_TEXT
          Default text for the okay button
protected  boolean okayPressed
          Did the user press the okay button
protected  ProgressBar progressBar
          The progress bar to display if any
static int QUESTION
          Alert type message - okay, cancel, abort button
protected  InfoLabel textLabel
          The InfoLabel displayed in this dialog
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
OptionDialog(java.awt.Frame frame)
          Creates a new dialog with a title of IP2P.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent evt)
          Called if any of the buttons was pressed or if the window was otherwise closed.
 OptionDialog getInstance()
          Gets an instance of an OptionDialog, if one was already created, i.e.
 void hideDialog()
          Hides this label.
 void prepareToShow()
          Call this method before calling any of the show methods if this dialog is to be shonw during a calculation and terminated by that calculation.
 void setText(java.lang.String[] strs)
          Sets the text displayed in this dialog, a new line is added after each element of str.
 void setText(java.lang.String[] strs, int imageType)
          Sets the text displayed in this dialog, a new line is added after each element of str.
 int showDialog(int dialogType, java.awt.Component panel)
          Shows a dialog with the indicated panel and the buttons as indicated by the type: one okay button (ALERT, INFO) or cancel, abort and okay button (QUESTION).
 int showDialog(int dialogType, java.awt.Component panel, java.lang.String okayText, java.lang.String cancelText, java.lang.String abortText)
          Shows a dialog with the indicated panel and the buttons as indicated by the type: one okay button (ALERT, INFO) or cancel, abort and okay button (QUESTION).
static void showError(java.lang.String[] strs)
          Shows an error dialog if the dialog was already initialized otherwise, we write the text to the screen
 int showImageDialog(int dialogType, java.lang.String text)
          Shows a dialog with no image.
 int showImageDialog(int dialogType, java.lang.String text, int imageType)
          Shows a dialog with a image, depending on the type (no image if imageType is -1.
 int showImageDialog(int dialogType, java.lang.String text, int imageType, java.lang.String okayText, java.lang.String cancelText, java.lang.String abortText)
          Shows a dialog with a image, depending on the type (no image if imageType is -1.
 int showImageDialog(int dialogType, java.lang.String text, int imageType, java.lang.String okayText, java.lang.String cancelText, java.lang.String abortText, boolean showProgress)
          Shows a dialog with a image, depending on the type (no image if imageType is -1.
 int showImageDialog(int dialogType, java.lang.String text, java.lang.String okayText, java.lang.String cancelText, java.lang.String abortText)
          Shows a dialog with no image.
 void updateProgress(double percentage)
          Updates the progress bar This method is thread safe - the current thread will block if other threads are currrently changing the text
 void updateText(java.lang.String text)
          Updates the text shown in the label.
 
Methods inherited from class java.awt.Dialog
addNotify, dispose, getTitle, hide, isModal, isResizable, paramString, setModal, setResizable, setTitle, show
 
Methods inherited from class java.awt.Window
addWindowListener, applyResourceBundle, applyResourceBundle, finalize, getFocusOwner, getInputContext, getLocale, getOwnedWindows, getOwner, getToolkit, getWarningString, isShowing, pack, postEvent, processEvent, processWindowEvent, removeWindowListener, setCursor, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CANCEL

public static final int CANCEL
Return value if the cancel button was pressed

OKAY

public static final int OKAY
Return value if the okay button was pressed

ABORT

public static final int ABORT
Return value if the ABORT button was pressed

ERROR

public static final int ERROR
Return value if an ERROR occured

ALERT

public static final int ALERT
Alert type message - only one okay button

INFO

public static final int INFO
Info type message - only one okay button

QUESTION

public static final int QUESTION
Alert type message - okay, cancel, abort button

OKAY_TEXT

public static final java.lang.String OKAY_TEXT
Default text for the okay button

ABORT_TEXT

public static final java.lang.String ABORT_TEXT
Default text for the abort button

CANCEL_TEXT

public static final java.lang.String CANCEL_TEXT
Default text for the cancel button

okayPressed

protected boolean okayPressed
Did the user press the okay button

abortPressed

protected boolean abortPressed
Did the user press the abort button

frame

protected static java.awt.Frame frame
The parent frame of this dialog

textLabel

protected InfoLabel textLabel
The InfoLabel displayed in this dialog

imageLabel

protected ImageLabel imageLabel
The ImageLabel displaying the alert image

progressBar

protected ProgressBar progressBar
The progress bar to display if any

buttonPanel

protected java.awt.Panel buttonPanel
Panel that contains the buttons to be displayed

gbl

protected java.awt.GridBagLayout gbl
The GridBagLayout used to lay out the components

gbc

protected java.awt.GridBagConstraints gbc
The GridBagConstraint used to lay out the components
Constructor Detail

OptionDialog

public OptionDialog(java.awt.Frame frame)
Creates a new dialog with a title of IP2P. All member variables are created but showing is defered until one of the showDialog methods is called.
Parameters:
frame - the parent frame of this dialog
Method Detail

getInstance

public OptionDialog getInstance()
Gets an instance of an OptionDialog, if one was already created, i.e. we know what the parent frame is. Otherwise, null is returned
Returns:
instance of an OptionDialog or null, if none was created by the parent frame

showError

public static void showError(java.lang.String[] strs)
Shows an error dialog if the dialog was already initialized otherwise, we write the text to the screen

showImageDialog

public int showImageDialog(int dialogType,
                           java.lang.String text)
Shows a dialog with no image. Depending on the value of dialogType, we show one okay button (ALERT, INFO) or cancel, abort and okay button (QUESTION).
Parameters:
dialogType - what type of dialog is to be shown - ALERT, INFO one okay button. QUESTION cancel, abort and okay button
text - String array of the text to display
Returns:
the value of the button that was pressed or ERROR

showImageDialog

public int showImageDialog(int dialogType,
                           java.lang.String text,
                           java.lang.String okayText,
                           java.lang.String cancelText,
                           java.lang.String abortText)
Shows a dialog with no image. Depending on the value of dialogType, we show one okay button (ALERT, INFO) or cancel, abort and okay button (QUESTION).
Parameters:
dialogType - what type of dialog is to be shown - ALERT, INFO one okay button. QUESTION cancel, abort and okay button
text - String array of the text to display
okayText - the name to appear on okay button (if null, button is not displayed)
cancelText - the name to appear on cancel button (if null, button is not displayed)
abortText - the name to appear on okay abort (if null, button is not displayed)
Returns:
the value of the button that was pressed or ERROR

showImageDialog

public int showImageDialog(int dialogType,
                           java.lang.String text,
                           int imageType)
Shows a dialog with a image, depending on the type (no image if imageType is -1. Depending on the value of dialogType, we show one okay button (ALERT, INFO) or cancel, abort and okay button (QUESTION).
Parameters:
dialogType - what type of dialog is to be shown - ALERT, INFO one okay button. QUESTION cancel, abort and okay button
text - String array of the text to display
imageType - determines the image to be shown. If it is -1, no image is shown
Returns:
the value of the button that was pressed or ERROR

showImageDialog

public int showImageDialog(int dialogType,
                           java.lang.String text,
                           int imageType,
                           java.lang.String okayText,
                           java.lang.String cancelText,
                           java.lang.String abortText)
Shows a dialog with a image, depending on the type (no image if imageType is -1. Depending on the value of dialogType, we show one okay button (ALERT, INFO) or cancel, abort and okay button (QUESTION).
Parameters:
dialogType - what type of dialog is to be shown - ALERT, INFO one okay button. QUESTION cancel, abort and okay button
text - String array of the text to display
imageType - determines the image to be shown. If it is -1, no image is shown
okayText - the name to appear on okay button (if null, button is not displayed)
cancelText - the name to appear on cancel button (if null, button is not displayed)
abortText - the name to appear on okay abort (if null, button is not displayed)
Returns:
the value of the button that was pressed or ERROR

prepareToShow

public void prepareToShow()
Call this method before calling any of the show methods if this dialog is to be shonw during a calculation and terminated by that calculation.
Since the show methods block, they have to be called after the calculation thread was started. However, we may then get the hide before the show and thus get a deadlock. This method will instruct the hide method to wait until the dialog was actually made visible.

showImageDialog

public int showImageDialog(int dialogType,
                           java.lang.String text,
                           int imageType,
                           java.lang.String okayText,
                           java.lang.String cancelText,
                           java.lang.String abortText,
                           boolean showProgress)
Shows a dialog with a image, depending on the type (no image if imageType is -1. Depending on the value of dialogType, we show one okay button (ALERT, INFO) or cancel, abort and okay button (QUESTION).
Parameters:
dialogType - what type of dialog is to be shown - ALERT, INFO one okay button. QUESTION cancel, abort and okay button
text - String array of the text to display
imageType - determines the image to be shown. If it is -1, no image is shown
okayText - the name to appear on okay button (if null, button is not displayed)
cancelText - the name to appear on cancel button (if null, button is not displayed)
abortText - the name to appear on okay abort (if null, button is not displayed)
showProgress - if true, a progress bar is displayed
Returns:
the value of the button that was pressed or ERROR

showDialog

public int showDialog(int dialogType,
                      java.awt.Component panel)
Shows a dialog with the indicated panel and the buttons as indicated by the type: one okay button (ALERT, INFO) or cancel, abort and okay button (QUESTION).
Parameters:
dialogType - what type of dialog is to be shown - ALERT, INFO one okay button. QUESTION cancel, abort and okay button
panel - the panel to show
Returns:
the value of the button that was pressed or ERROR

showDialog

public int showDialog(int dialogType,
                      java.awt.Component panel,
                      java.lang.String okayText,
                      java.lang.String cancelText,
                      java.lang.String abortText)
Shows a dialog with the indicated panel and the buttons as indicated by the type: one okay button (ALERT, INFO) or cancel, abort and okay button (QUESTION).
Parameters:
dialogType - what type of dialog is to be shown - ALERT, INFO one okay button. QUESTION cancel, abort and okay button
panel - the panel to show
okayText - the name to appear on okay button (if null, button is not displayed)
cancelText - the name to appear on cancel button (if null, button is not displayed)
abortText - the name to appear on okay abort (if null, button is not displayed)
Returns:
the value of the button that was pressed or ERROR

setText

public void setText(java.lang.String[] strs)
Sets the text displayed in this dialog, a new line is added after each element of str. The dialog is centered on the screen
Parameters:
strs - String array of the text to display

setText

public void setText(java.lang.String[] strs,
                    int imageType)
Sets the text displayed in this dialog, a new line is added after each element of str. The dialog is centered on the screen. The image indicated by imageType is shown, or no image, if imageType is -1
Parameters:
strs - String array of the text to display
imageType - the image type to display

updateText

public void updateText(java.lang.String text)
Updates the text shown in the label. This method is thread safe - the current thread will block if other threads are currrently changing the text
Parameters:
text - the new text to display

updateProgress

public void updateProgress(double percentage)
Updates the progress bar This method is thread safe - the current thread will block if other threads are currrently changing the text
Parameters:
percentage - new progress to show

hideDialog

public void hideDialog()
Hides this label. This method is thread safe - the current thread will block if other threads are currrently changing the text or hidding the label

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent evt)
Called if any of the buttons was pressed or if the window was otherwise closed. In the latter case, cancel is assumed. The dialog is hidden.
Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
evt - the triggering ActionEvent if any. If it is null, we assume. cancel was pressed

JXTA