com.sas.visuals
Class MessageBox

com.sas.visuals.MessageBox
All Implemented Interfaces:
ContainerInterface, VisualInterface, com.sas.beans.PropertyChangeSource, com.sas.beans.VetoableChangeSource, com.sas.ComponentInterface, com.sas.DesignTimeDropTargetInterface, com.sas.lang.StringDataInterface, com.sas.LinkPropertiesInterface, com.sas.ModelInterface, ValidatorInterface, com.sas.ViewInterface, MessageBoxSource, MultipleValueEventSourceInterface, java.awt.event.ActionListener, java.awt.event.FocusListener, java.awt.event.WindowListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.beans.PropertyChangeListener, java.io.ObjectInputValidation, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class MessageBox
implements java.awt.event.WindowListener, java.awt.event.ActionListener, java.awt.event.FocusListener, MessageBoxSource

MessageBox is a subclass of Dialog which displays a text message, an icon, and a set of buttons to allow a user response. The dialog uses a multiline capable LabelView, adds \n in the text for carriage returns in the text. The dialog can be modal or non-modal. When a button is selected by the user, a MessageBoxEvent is sent to all registered MessageBoxListeners. Listening for this event is necessary to use the MessageBox non-modally. When the MessageBox is modal, the selection of a button causes the SelectedButton property to be set on the MessageBox. After the call to show() on a modal MessageBox, SelectedButton indicates which button was pressed.

There is also another option to define your own buttons and their associated action command by using an alternate constructor. In this case, there is a selectedActionCommand that is set whenever a button is pressed, this can be accessed as well after the call to show() on a modal MessageBox. SelectedActionCommand returns the string command associated with the pressed button and MessageBoxEvent is sent to all registered MessageBoxListeners.

Another ability of MessageBox is customization of panels within the dialog. There are two methods, addMiddlePanel() and addBottomPanel(), both of which take a container as a parameter. Users can create their own container with whatever components and listeners and add it to the MessageBox. There are two invisible panels that can be replace using these methods, the middle panel lies between the text and the buttons and the bottom panel lies under the buttons.

On Windows NT (at least), there is a button in the upper right hand corner of the MessageBox with an "x". When this button is pressed, it is as if the user pressed "Cancel". So, users of the MessageBox should properly handle the "Cancel" button even if there is not one in the MessageBox.

WARNING: At least until JDK version 1.1.2 there are bugs in AWT modal dialog handling. An application using a modal dialog may hang, partially hang, or improperly display the modal dialog.

A sample use of the MessageBox (non-modally) might look like :

     MessageBox messageBox = new MessageBox( frame,
         "A Title", false, "Would you like to continue?",
         MessageBox.BUTTONS_YES_NO | MessageBox.BUTTON_HELP,
         MessageBox.BUTTON_YES, MessageBox.ICON_QUERY );
     messageBox.initialize();
     messageBox.addMessageBoxListener(this);
     messageBox.setVisible(true);
 

The user of the MessageBox would then need to listen for MessageBoxEvents. The MessageBoxEvent contains an integer indicating which button was selected.

A sample use of the MessageBox (modally) might look like :

     MessageBox messageBox = new MessageBox( frame,
         "A Title", true, "Would you like to continue?",
         MessageBox.BUTTONS_YES_NO | MessageBox.BUTTON_HELP,
         MessageBox.BUTTON_YES, MessageBox.ICON_QUERY );
     messageBox.initialize();
     messageBox.setVisible(true);
     switch (messageBox.getSelectedButton() )
     {
         case MessageBox.BUTTON_YES:
             break;
         case MessageBox.BUTTON_NO:
             break;
         case MessageBox.BUTTON_CANCEL:
             break;
     } // switch
 

Note that the order of the buttons in the MessageBox is predefined. They will always appear in the order of : OK, Yes, No, Abort, Retry, Ignore, Cancel, Help Stop, Continue. This is because the button specifier is a bitfield where order is insignificant.

The other case is to define you own buttons. A sample of the MessageBox (modally) where custom buttons are added may look like:

     MessageBox messageBox = new MessageBox( frame,
         "A Title", true, "Would you like to continue?",
                        new String[][]{ {"Ok", "Close"}, {"Cancel", "Cancel"}, {"Help", "Help"}},
                         MessageBox.ICON_INFO );
                messageBox.initialize();
                messageBox.pack();
                messageBox.show();
                if ( messageBox.getSelectedActionCommand().equals("Close") )
                        break;
                else if (  messageBox.getSelectedActionCommand().equals("Cancel") )
                        break;
                else if (  messageBox.getSelectedActionCommand().equals("Help") )
                        break;
 

Known problems :

See Also:
MessageBoxEvent, MessageBoxListener, MessageBoxSource, MessageBoxListenerList, Serialized Form

Field Summary
static int BUTTON_ABORT
          int value representing the ABORT button
static int BUTTON_CANCEL
          int value representing the CANCEL button
static int BUTTON_CONTINUE
           
static int BUTTON_HELP
          int value representing the HELP button
static int BUTTON_IGNORE
          int value representing the IGNORE button
static int BUTTON_NO
          int value representing the NO button
static int BUTTON_OK
          int value representing the OK button
static int BUTTON_RETRY
          int value representing the RETRY button
static int BUTTON_SKIP
           
static int BUTTON_STOP
           
static int BUTTON_YES
          int value representing the YES button
protected  com.sas.collection.AssociationList buttonControls
           
protected  ButtonPanel buttonPanel
           
protected  int buttons
          int value representing which button is displayed on the message box
static int BUTTONS_ABORT_RETRY_IGNORE
          int value representing the combination of the ABORT, RETRY, and IGNORE buttons
static int BUTTONS_NONE
          int value representing not to have any buttons
static int BUTTONS_OK_CANCEL
          int value representing the combination of the OK, CANCEL buttons
static int BUTTONS_RETRY_CANCEL
          int value representing the combination of the RETRY and CANCEL buttons
static int BUTTONS_STOP_CONTINUE
           
static int BUTTONS_STOP_SKIP
           
static int BUTTONS_YES_NO
          int value representing the combination of the YES, NO buttons
static int BUTTONS_YES_NO_CANCEL
          int value representing the combination of the YES, NO, and CANCEL buttons
protected  java.lang.String[][] customButtons
           
protected  boolean customButtonsFlag
           
protected  com.sas.visuals.MessageBoxEscapeKeyAdapter escKeyAdapter
          escape key adapter to handle escape keypress
protected  int focusButton
          int value representing which button should have the focus
protected  int icon
          int value represent which icon to place on the message box
static int ICON_ERROR
          int value representing the ERROR icon to be displayed on the message box
static int ICON_INFO
          int value representing the INFO icon to be displayed on the message box
static int ICON_NONE
          int value representing to have no icons on the message box
static int ICON_QUERY
          int value representing the QUERY icon to be displayed on the message box
static int ICON_WARNING
          int value representing the WARNING icon to be displayed on the message box
protected  ImageView image
          ImageView object that is displayed on the message box
protected  PushButton lastButtonWithFocus
          button that keep track of the last button the focus rectangle should was on
protected  java.awt.Panel main
           
protected  java.awt.Panel mainTop
           
protected  java.lang.String message
          text string that appears in the message box
protected  MessageBoxListenerList messageBoxListenerList
           
protected  java.awt.Panel panelBottom
           
protected  java.awt.Panel panelButtons
           
protected  java.awt.Panel panelMiddle
           
static java.lang.String RB_KEY
           
protected  java.lang.String selectedActionCommand
          string value representing the action command associated with button selected
protected  int selectedButton
          int value representing which button is selected
 
Fields inherited from class com.sas.awt.Dialog
_cantUseSASModal, _inApplet, _modal, autoDispose, READY, setVisibleCalled, t
 
Constructor Summary
MessageBox(java.awt.Frame frame, java.lang.String message)
          Construct a MessageBox owned by a given Frame and containing the given message.
MessageBox(java.awt.Frame frame, java.lang.String title, boolean modal, java.lang.String message, int buttons, int defaultButton, int icon)
          Construct a MessageBox owned by a given Frame.
MessageBox(java.awt.Frame frame, java.lang.String title, boolean modal, java.lang.String message, java.lang.String[][] customButtons, int icon)
          Construct a MessageBox owned by a given Frame, and with custom buttons.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent evt)
          Handles ActionEvents from the buttons in the MessageBox.
 void addBottomPanel(java.awt.Container cont)
          Adds a container to below the buttons.
 void addButton(java.lang.String buttonText, java.lang.String actionCommand)
          Adds a button with specified text and action command to the MessageBox.
 void addMessageBoxListener(MessageBoxListener listener)
          This is part of the MessageBoxSource interface implementation.
 void addMiddlePanel(java.awt.Container cont)
          Adds a container to below the MessageBox label and above the buttons.
protected  void commonInit()
          Performs all the common functionality between the constructors of the MessageBox.
 void fireMessageBoxEvent(int button)
          Sends a MessageBoxEvent to all of the registered listeners.
 void fireMessageBoxEvent(java.lang.String command)
          Sends a MessageBoxEvent to all of the registered listeners.
 void focusGained(java.awt.event.FocusEvent event)
          Handles the focus rectangle and which button gains the focus
 void focusLost(java.awt.event.FocusEvent event)
          Handles the focus rectangle and which button loses the focus
 PushButton getButton(java.lang.String buttonText)
          Returns a PushButton from the ButtonPanel in the MessageBox.
static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
          Returns information used by the com.sas.beans.Introspector to augment the automatically introspected information about this MessageBox.
 com.sas.visuals.IconInterface getIcon()
          Return a reference to IconInterface that displays the image in the MessageBox.
protected  java.lang.String getImageName()
          Helper function that converts the icon type into a string.
 LabelView getLabel()
          Returns a reference to the MessageBox labelView.
 int getLabelHorizontalAlignment()
          Return the LabelView Horizontal alignment in the MessageBox.
 int getLabelVerticalAlignment()
          Return the LabelView Vertical alignment in the MessageBox.
 java.lang.String getSelectedActionCommand()
          Called on the MessageBox to return the selectedActionCommand.
 int getSelectedButton()
          Called on the MessageBox to return the selected button .
protected  java.lang.String paramString()
          Returns information about the MessageBox in String format.
 void removeMessageBoxListener(MessageBoxListener listener)
          This is part of the MessageBoxSource interface implementation.
 void setDefaultValues()
          Sets the initial values of the MessageBox's fields.
 void setIcon(com.sas.visuals.IconInterface image)
          Set an IconInterface object in the MessageBox.
 void setLabelHorizontalAlignment(int align)
          Sets the LabelView Horizontal alignment in the MessageBox.
 void setLabelVerticalAlignment(int align)
          Sets the LabelView Vertical alignment in the MessageBox.
 void setVisible(boolean visible)
          If true, sets the selectedButton property to zero to indicate that no button has been selected.
static int showModalMessageBox(java.awt.Component frame, java.lang.String message)
          Display a MessageBox with the specified message.
static int showModalMessageBox(java.awt.Component frame, java.lang.String title, java.lang.String message, int buttons, int defaultButton, int icon)
          Display a MessageBox with the specified message.
static java.lang.String showModalMessageBox(java.awt.Component frame, java.lang.String title, java.lang.String message, java.lang.String[][] customButtons, int icon)
          Display a MessageBox with the specified message.
static int showModalMessageBox(java.lang.String message)
          Display a MessageBox with the specified message.
static int showModalMessageBox(java.lang.String title, java.lang.String message, int buttons, int defaultButton, int icon)
          Display a MessageBox with the specified message.
static java.lang.String showModalMessageBox(java.lang.String title, java.lang.String message, java.lang.String[][] customButtons, int icon)
          Display a MessageBox with the specified message and custom buttons.
 void windowActivated(java.awt.event.WindowEvent e)
          Part of the implementation of the WindowListener interface.
 void windowClosed(java.awt.event.WindowEvent e)
          Part of the implementation of the WindowListener interface.
 void windowClosing(java.awt.event.WindowEvent e)
          Part of the implementation of the WindowListener interface.
 void windowDeactivated(java.awt.event.WindowEvent e)
          Part of the implementation of the WindowListener interface.
 void windowDeiconified(java.awt.event.WindowEvent e)
          Part of the implementation of the WindowListener interface.
 void windowIconified(java.awt.event.WindowEvent e)
          Part of the implementation of the WindowListener interface.
 void windowOpened(java.awt.event.WindowEvent e)
          Part of the implementation of the WindowListener interface.
 
Methods inherited from class com.sas.awt.Dialog
center, centerOver, centerOverWindow, dispose, fireReadySignal, getAutoDispose, getDefaultHeight, getDefaultWidth, getText, hide, isSASModalEnabled, newDispatchThread, processWindowEvent, setAutoDispose, setDefaultHeight, setDefaultWidth, setModal, setResizable, setSASModalEnabled, setText, setTitle, setVisible, show, stopDispatchThread, waitForReadySignal, waitTilReady
 
Methods inherited from class com.sas.awt.DialogContainerComponent
addNotify, clone, dragEnter, dragLeave, dragOver, drop, getContainerInterfaceSupportInfo, getErrorHandler, getInsets, getValidator, isIDEDnDDropBarrier, isIDEDnDDropTarget, isValid, removeNotify, setContainerInterfaceSupportInfo, setErrorHandler, setIDEDnDDropBarrier, setIDEDnDDropTarget, setInsets, setInsets, setValidator, superAddNotify, superGetInsets, superRemoveNotify, superSetDefaultValues
 
Methods inherited from class com.sas.awt.DialogVisualComponent
addLink, addPropertyChangeListener, addVetoableChangeListener, anyPropertyChangeListeners, attachModel, attachView, computePreferredSize, detachModel, detachView, dumpComponent, firePropertyChange, firePropertyChange, fireVetoableChange, getBackgroundColor, getBorder, getComponentDescription, getComponentSupportInfo, getEventMethod, getEventValues, getFont, getForegroundColor, getHeight, getHorizontalPosition, getLinkInfo, getMinimumSize, getModelInterface, getPreferredSize, getPrePainter, getRequiredInterfaces, getVerticalPosition, getViewInterfaceSupportInfo, getVisualInterfaceSupportInfo, getWidth, initialize, initializeComponent, isDesignTime, isEnabled, isFocus, isLinked, isTransparent, isVisible, paint, propertyChange, queryLinks, queryLinks, refresh, removeAllLinks, removeInterfaceTraps, removeLink, removePropertyChangeListener, removeVetoableChangeListener, setBackgroundColor, setBorder, setBounds, setComponentDescription, setComponentSupportInfo, setEnabled, setFocus, setFont, setForegroundColor, setHeight, setHorizontalPosition, setLinkInfo, setModelInterface, setPreferredSize, setPrePainter, setRequiredInterfaces, setTransparent, setVerticalPosition, setViewInterfaceSupportInfo, setVisualInterfaceSupportInfo, setWidth, superGetFont, superGetMinimumSize, superGetPreferredSize, superIsEnabled, superIsVisible, superPaint, superSetBounds, superSetEnabled, superSetFont, superSetVisible, superUpdate, supportsListenerInterface, supportsRequiredInterfaces, trapInterfaceEvents, update, validateObject
 
Methods inherited from interface com.sas.awt.ContainerInterface
getComponents, getLayout, invalidate, setLayout, validate
 
Methods inherited from interface com.sas.awt.VisualInterface
computePreferredSize, getBackgroundColor, getBorder, getFont, getForegroundColor, getHeight, getHorizontalPosition, getMinimumSize, getPreferredSize, getPrePainter, getVerticalPosition, getVisualInterfaceSupportInfo, getWidth, isEnabled, isFocus, isTransparent, isVisible, setBackgroundColor, setBorder, setBounds, setEnabled, setFocus, setFont, setForegroundColor, setHeight, setHorizontalPosition, setPreferredSize, setPrePainter, setTransparent, setVerticalPosition, setVisualInterfaceSupportInfo, setWidth, superGetFont, superGetMinimumSize, superGetPreferredSize, superIsEnabled, superIsVisible, superPaint, superSetBounds, superSetEnabled, superSetFont, superSetVisible, superUpdate
 

Field Detail

RB_KEY

public static final java.lang.String RB_KEY
See Also:
Constant Field Values

BUTTON_OK

public static final int BUTTON_OK
int value representing the OK button

See Also:
Constant Field Values

BUTTON_YES

public static final int BUTTON_YES
int value representing the YES button

See Also:
Constant Field Values

BUTTON_NO

public static final int BUTTON_NO
int value representing the NO button

See Also:
Constant Field Values

BUTTON_ABORT

public static final int BUTTON_ABORT
int value representing the ABORT button

See Also:
Constant Field Values

BUTTON_RETRY

public static final int BUTTON_RETRY
int value representing the RETRY button

See Also:
Constant Field Values

BUTTON_IGNORE

public static final int BUTTON_IGNORE
int value representing the IGNORE button

See Also:
Constant Field Values

BUTTON_CANCEL

public static final int BUTTON_CANCEL
int value representing the CANCEL button

See Also:
Constant Field Values

BUTTON_HELP

public static final int BUTTON_HELP
int value representing the HELP button

See Also:
Constant Field Values

BUTTON_STOP

public static final int BUTTON_STOP
See Also:
Constant Field Values

BUTTON_CONTINUE

public static final int BUTTON_CONTINUE
See Also:
Constant Field Values

BUTTON_SKIP

public static final int BUTTON_SKIP
See Also:
Constant Field Values

BUTTONS_NONE

public static final int BUTTONS_NONE
int value representing not to have any buttons

See Also:
Constant Field Values

BUTTONS_OK_CANCEL

public static final int BUTTONS_OK_CANCEL
int value representing the combination of the OK, CANCEL buttons

See Also:
Constant Field Values

BUTTONS_YES_NO

public static final int BUTTONS_YES_NO
int value representing the combination of the YES, NO buttons

See Also:
Constant Field Values

BUTTONS_YES_NO_CANCEL

public static final int BUTTONS_YES_NO_CANCEL
int value representing the combination of the YES, NO, and CANCEL buttons

See Also:
Constant Field Values

BUTTONS_ABORT_RETRY_IGNORE

public static final int BUTTONS_ABORT_RETRY_IGNORE
int value representing the combination of the ABORT, RETRY, and IGNORE buttons

See Also:
Constant Field Values

BUTTONS_RETRY_CANCEL

public static final int BUTTONS_RETRY_CANCEL
int value representing the combination of the RETRY and CANCEL buttons

See Also:
Constant Field Values

BUTTONS_STOP_CONTINUE

public static final int BUTTONS_STOP_CONTINUE
See Also:
Constant Field Values

BUTTONS_STOP_SKIP

public static final int BUTTONS_STOP_SKIP
See Also:
Constant Field Values

ICON_NONE

public static final int ICON_NONE
int value representing to have no icons on the message box

See Also:
Constant Field Values

ICON_INFO

public static final int ICON_INFO
int value representing the INFO icon to be displayed on the message box

See Also:
Constant Field Values

ICON_ERROR

public static final int ICON_ERROR
int value representing the ERROR icon to be displayed on the message box

See Also:
Constant Field Values

ICON_WARNING

public static final int ICON_WARNING
int value representing the WARNING icon to be displayed on the message box

See Also:
Constant Field Values

ICON_QUERY

public static final int ICON_QUERY
int value representing the QUERY icon to be displayed on the message box

See Also:
Constant Field Values

buttonControls

protected com.sas.collection.AssociationList buttonControls

image

protected ImageView image
ImageView object that is displayed on the message box


lastButtonWithFocus

protected PushButton lastButtonWithFocus
button that keep track of the last button the focus rectangle should was on


escKeyAdapter

protected com.sas.visuals.MessageBoxEscapeKeyAdapter escKeyAdapter
escape key adapter to handle escape keypress


message

protected java.lang.String message
text string that appears in the message box


buttons

protected int buttons
int value representing which button is displayed on the message box


focusButton

protected int focusButton
int value representing which button should have the focus


icon

protected int icon
int value represent which icon to place on the message box


selectedButton

protected int selectedButton
int value representing which button is selected


main

protected java.awt.Panel main

panelBottom

protected java.awt.Panel panelBottom

panelMiddle

protected java.awt.Panel panelMiddle

buttonPanel

protected ButtonPanel buttonPanel

customButtonsFlag

protected boolean customButtonsFlag

panelButtons

protected java.awt.Panel panelButtons

customButtons

protected java.lang.String[][] customButtons

mainTop

protected java.awt.Panel mainTop

selectedActionCommand

protected java.lang.String selectedActionCommand
string value representing the action command associated with button selected


messageBoxListenerList

protected MessageBoxListenerList messageBoxListenerList
Constructor Detail

MessageBox

public MessageBox(java.awt.Frame frame,
                  java.lang.String message)
Construct a MessageBox owned by a given Frame and containing the given message. The MessageBox will have a title of "Note", be modal, only have an OK button, and the icon will be ICON_INFO.

Parameters:
frame - The frame to own the MessageBox.
message - The message to display in the MessageBox.

MessageBox

public MessageBox(java.awt.Frame frame,
                  java.lang.String title,
                  boolean modal,
                  java.lang.String message,
                  int buttons,
                  int defaultButton,
                  int icon)
Construct a MessageBox owned by a given Frame.

Parameters:
frame - The frame to own the MessageBox.
title - The title to display in the title bar of the MessageBox.
modal - Whether the MessageBox is modal.
message - The message to display in the MessageBox.
buttons - The buttons to display. This is the union of any of BUTTON_* values in the MessageBox class. Examples would be BUTTON_OK | BUTTON_HELP, or BUTTONS_OK.
defaultButton - This is the union of any of BUTTON_* values in the MessageBox class, and will hold the focus rectangle when the message box appears.
icon - One of ICON_NONE, ICON_ERROR, ICON_INFO, ICON

MessageBox

public MessageBox(java.awt.Frame frame,
                  java.lang.String title,
                  boolean modal,
                  java.lang.String message,
                  java.lang.String[][] customButtons,
                  int icon)
Construct a MessageBox owned by a given Frame, and with custom buttons.

Parameters:
frame - The frame to own the MessageBox.
title - The title to display in the title bar of the MessageBox.
modal - Whether the MessageBox is modal.
message - The message to display in the MessageBox.
customButtons - Multidimensional array containing the button name and associated actionCommand. ie. new String[][]{ {"Ok", "Close"}, {"Cancel", "Cancel"}, {"Help", "Help"}} - creates three buttons, Ok, Cancel, and Help. Each button has an associated actionCommand which is fired when the button is selected.
icon - One of ICON_NONE, ICON_ERROR, ICON_INFO, ICON
Method Detail

getExtendedBeanInfo

public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
Returns information used by the com.sas.beans.Introspector to augment the automatically introspected information about this MessageBox.

Returns:
the ExtendedBeanInfo for this class

showModalMessageBox

public static int showModalMessageBox(java.lang.String message)
Display a MessageBox with the specified message. The MessageBox will be centered on the screen.

Parameters:
message - text to be displayed on the message box

showModalMessageBox

public static int showModalMessageBox(java.awt.Component frame,
                                      java.lang.String message)
Display a MessageBox with the specified message. The MessageBox will be centered over the specified frame.

Parameters:
frame - the frame to own the MessageBox.
message - text to be displayed on the message box

showModalMessageBox

public static int showModalMessageBox(java.lang.String title,
                                      java.lang.String message,
                                      int buttons,
                                      int defaultButton,
                                      int icon)
Display a MessageBox with the specified message. The MessageBox will be centered on the screen.

Parameters:
title - text to be displayed as the title of the message box
message - text to be displayed on the message box
buttons - the int value representing which buttons are to appear on the message box
defaultButton - the int value representing which button is to appear with the focus rectangle already painted on it, hence the default button.
icon - the int value representing which icon is to be displayed on the message box

showModalMessageBox

public static java.lang.String showModalMessageBox(java.lang.String title,
                                                   java.lang.String message,
                                                   java.lang.String[][] customButtons,
                                                   int icon)
Display a MessageBox with the specified message and custom buttons. The MessageBox will be centered on the screen.

Parameters:
title - text to be displayed as the title of the message box
message - text to be displayed on the message box
customButtons - multidimensional array, with two strings per index, the first is the name of the button and the second will be the associated actionCommand the button fires.
icon - the int value representing which icon is to be displayed on the message box

showModalMessageBox

public static int showModalMessageBox(java.awt.Component frame,
                                      java.lang.String title,
                                      java.lang.String message,
                                      int buttons,
                                      int defaultButton,
                                      int icon)
Display a MessageBox with the specified message. The MessageBox will be centered over the specified frame.

Parameters:
frame - the frame to own the MessageBox.
title - text to be displayed as the title of the message box
message - text to be displayed on the message box
buttons - the int value representing which buttons are to appear on the message box
defaultButton - the int value representing which button is to appear with the focus rectangle already painted on it, hence the default button.
icon - the int value representing which icon is to be displayed on the message box

showModalMessageBox

public static java.lang.String showModalMessageBox(java.awt.Component frame,
                                                   java.lang.String title,
                                                   java.lang.String message,
                                                   java.lang.String[][] customButtons,
                                                   int icon)
Display a MessageBox with the specified message. The MessageBox will be centered over the specified frame.

Parameters:
frame - the frame to own the MessageBox.
title - text to be displayed as the title of the message box
message - text to be displayed on the message box
customButtons - multidimensional array, with two strings per index, the first is the name of the button and the second will be the associated actionCommand the button fires.
icon - the int value representing which icon is to be displayed on the message box
See Also:
-with customButtons param

setDefaultValues

public void setDefaultValues()
Sets the initial values of the MessageBox's fields.

Specified by:
setDefaultValues in interface ContainerInterface
Specified by:
setDefaultValues in interface VisualInterface
Specified by:
setDefaultValues in interface com.sas.ComponentInterface
Overrides:
setDefaultValues in class DialogContainerComponent
See Also:
ContainerInterface.setDefaultValues()

commonInit

protected void commonInit()
Performs all the common functionality between the constructors of the MessageBox. It creates all the controls in the MessageBox.


addBottomPanel

public void addBottomPanel(java.awt.Container cont)
Adds a container to below the buttons. Useful when one desires extra components in the MessageBox and allows more customization of the MessageBox.

Parameters:
cont - a container which contains whatever components added to it.
See Also:
addMiddlePanel(java.awt.Container)

addMiddlePanel

public void addMiddlePanel(java.awt.Container cont)
Adds a container to below the MessageBox label and above the buttons. Useful when one desires extra components in the MessageBox and allows more customization in the MessageBox.

Parameters:
cont - a container which contains whatever components added to it.
See Also:
addBottomPanel(java.awt.Container)

getSelectedActionCommand

public java.lang.String getSelectedActionCommand()
Called on the MessageBox to return the selectedActionCommand. If there has not been a button selected, "Cancel" will be returned. Otherwise, the string indicating the button's actionCommand will be returned. This is the same string that is delivered in the MessageBoxEvent when a button is selected. This method is useful when you have a modal MessageBox and do not want to listen for MessageBoxEvents. When using this method with a modal MessageBox, you can call it after the show() method. This method is only useful if the instance of the MessageBox was added using custom buttons, if not it will always return "Cancel".

Returns:
string corresponding to the action command associated with the button entered in the constructor or in the addButton method.

addButton

public void addButton(java.lang.String buttonText,
                      java.lang.String actionCommand)
Adds a button with specified text and action command to the MessageBox. Also adds ActionListener and FocusListener to the new PushButton created. Can acces the button, using the getButton method. Can only be added if custom buttons constructor is used.

Parameters:
buttonText - desired text label on the button
actionCommand - desired actionCommand to be associated with this button.
See Also:
getButton(java.lang.String), getSelectedActionCommand(), MessageBox(java.awt.Frame, java.lang.String, boolean, java.lang.String, java.lang.String[][], int)

getButton

public PushButton getButton(java.lang.String buttonText)
Returns a PushButton from the ButtonPanel in the MessageBox. The method can only be used if the MessageBox constructor where your own buttons are added, if not, the method will return null.

Parameters:
buttonText - name of the button added in the constructor or in addButton
Returns:
reference to the PushButton with buttonText, if custom buttons not added, returns null
See Also:
addButton(java.lang.String, java.lang.String), MessageBox(java.awt.Frame, java.lang.String, boolean, java.lang.String, java.lang.String[][], int)

getLabel

public LabelView getLabel()
Returns a reference to the MessageBox labelView. Any changes made to the label will be reflected in the MessageBox.

Returns:
LabelView reference to the LabelView in the MessageBox

getIcon

public com.sas.visuals.IconInterface getIcon()
Return a reference to IconInterface that displays the image in the MessageBox. It can be cast as an ImageView or IconView and its source can be changed to set a new image in the MessageBox.

Returns:
reference to the IconInterface in the MessageBox
See Also:
setIcon(com.sas.visuals.IconInterface)

setIcon

public void setIcon(com.sas.visuals.IconInterface image)
Set an IconInterface object in the MessageBox.

Parameters:
image - and object implementing IconInterface
See Also:
getIcon()

setVisible

public void setVisible(boolean visible)
If true, sets the selectedButton property to zero to indicate that no button has been selected. This is useful when the same MessageBox is shown multiple times.

setVisible also sets the focus on the default button.

Specified by:
setVisible in interface VisualInterface
Overrides:
setVisible in class Dialog
Parameters:
visible - boolean value
See Also:
Dialog.setVisible(boolean)

paramString

protected java.lang.String paramString()
Returns information about the MessageBox in String format. This is use by toString() on java.awt.Component subclasses.

Overrides:
paramString in class java.awt.Dialog
Returns:
string information about the MessageBox

setLabelHorizontalAlignment

public void setLabelHorizontalAlignment(int align)
Sets the LabelView Horizontal alignment in the MessageBox. The default is set to LEFT.

Parameters:
align - int representation of com.sas.geometry.Orientations. values can be either LEFT, RIGHT, or CENTER.

getLabelHorizontalAlignment

public int getLabelHorizontalAlignment()
Return the LabelView Horizontal alignment in the MessageBox. The default is set to LEFT.

Returns:
int representation of com.sas.geometry.Orientations. values will be either LEFT, RIGHT, or CENTER.

setLabelVerticalAlignment

public void setLabelVerticalAlignment(int align)
Sets the LabelView Vertical alignment in the MessageBox. The default is set to CENTER.

Parameters:
align - int representation of com.sas.geometry.Orientations. values can be either TOP, BOTTOM, or CENTER.

getLabelVerticalAlignment

public int getLabelVerticalAlignment()
Return the LabelView Vertical alignment in the MessageBox. The default is set to CENTER.

Returns:
int representation of com.sas.geometry.Orientations. values will be either TOP, BOTTOM, or CENTER.

getImageName

protected java.lang.String getImageName()
Helper function that converts the icon type into a string.

Returns:
string name of the icon used in the message box

getSelectedButton

public int getSelectedButton()
Called on the MessageBox to return the selected button . If there has not been a button selected, zero will be returned. Otherwise, the number indicating the button will be returned. This is the same number that is delivered in the MessageBoxEvent when a button is selected. This method is useful when you have a modal MessageBox and do not want to listen for MessageBoxEvents. When using this method with a modal MessageBox, you can call it after the show() method.


windowOpened

public void windowOpened(java.awt.event.WindowEvent e)
Part of the implementation of the WindowListener interface. This interface is used to listen for the close event on the window.

Specified by:
windowOpened in interface java.awt.event.WindowListener
Overrides:
windowOpened in class Dialog
Parameters:
e - the window event that is occurring

windowClosing

public void windowClosing(java.awt.event.WindowEvent e)
Part of the implementation of the WindowListener interface. This interface is used to listen for the close event on the window.

When the window close button is clicked, a MessageBoxEvent is sent with the button field as CANCEL and the window is hidden using dipose().

Specified by:
windowClosing in interface java.awt.event.WindowListener
Overrides:
windowClosing in class Dialog
Parameters:
e - the window event that is occurring

windowClosed

public void windowClosed(java.awt.event.WindowEvent e)
Part of the implementation of the WindowListener interface. This interface is used to listen for the close event on the window.

Specified by:
windowClosed in interface java.awt.event.WindowListener
Overrides:
windowClosed in class Dialog
Parameters:
e - the window event that is occurring

windowIconified

public void windowIconified(java.awt.event.WindowEvent e)
Part of the implementation of the WindowListener interface. This interface is used to listen for the close event on the window.

Specified by:
windowIconified in interface java.awt.event.WindowListener
Overrides:
windowIconified in class Dialog
Parameters:
e - the window event that is occurring

windowDeiconified

public void windowDeiconified(java.awt.event.WindowEvent e)
Part of the implementation of the WindowListener interface. This interface is used to listen for the close event on the window.

Specified by:
windowDeiconified in interface java.awt.event.WindowListener
Overrides:
windowDeiconified in class Dialog
Parameters:
e - the window event that is occurring

windowActivated

public void windowActivated(java.awt.event.WindowEvent e)
Part of the implementation of the WindowListener interface. This interface is used to listen for the close event on the window.

Specified by:
windowActivated in interface java.awt.event.WindowListener
Overrides:
windowActivated in class Dialog
Parameters:
e - the window event that is occurring

windowDeactivated

public void windowDeactivated(java.awt.event.WindowEvent e)
Part of the implementation of the WindowListener interface. This interface is used to listen for the close event on the window.

Specified by:
windowDeactivated in interface java.awt.event.WindowListener
Overrides:
windowDeactivated in class Dialog
Parameters:
e - the window event that is occurring

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent evt)
Handles ActionEvents from the buttons in the MessageBox. When a button is selected, the button number corresponding to the button component is determined. Then, a MessageBoxEvent is sent.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
evt - the action event that is occurring

focusGained

public void focusGained(java.awt.event.FocusEvent event)
Handles the focus rectangle and which button gains the focus

Specified by:
focusGained in interface java.awt.event.FocusListener
Parameters:
event - the focus event that is occurring

focusLost

public void focusLost(java.awt.event.FocusEvent event)
Handles the focus rectangle and which button loses the focus

Specified by:
focusLost in interface java.awt.event.FocusListener
Parameters:
event - the focus event that is occurring

addMessageBoxListener

public void addMessageBoxListener(MessageBoxListener listener)
This is part of the MessageBoxSource interface implementation. Components which want to listen for MessageBoxEvents should call this method to register themselves.

Specified by:
addMessageBoxListener in interface MessageBoxSource
Parameters:
listener - the message box listener to be added
See Also:
removeMessageBoxListener(com.sas.visuals.MessageBoxListener), fireMessageBoxEvent(int)

removeMessageBoxListener

public void removeMessageBoxListener(MessageBoxListener listener)
This is part of the MessageBoxSource interface implementation. Components which want to stop listening for MessageBoxEvents should call this method to unregister themselves.

Specified by:
removeMessageBoxListener in interface MessageBoxSource
Parameters:
listener - the message box listener to be removed
See Also:
addMessageBoxListener(com.sas.visuals.MessageBoxListener), fireMessageBoxEvent(int)

fireMessageBoxEvent

public void fireMessageBoxEvent(int button)
Sends a MessageBoxEvent to all of the registered listeners.

Parameters:
int - int value representing the type of button the event is fired
See Also:
addMessageBoxListener(com.sas.visuals.MessageBoxListener), removeMessageBoxListener(com.sas.visuals.MessageBoxListener)

fireMessageBoxEvent

public void fireMessageBoxEvent(java.lang.String command)
Sends a MessageBoxEvent to all of the registered listeners.

Parameters:
command - string value representing the actionCommand of button the event is fired
See Also:
addMessageBoxListener(com.sas.visuals.MessageBoxListener), removeMessageBoxListener(com.sas.visuals.MessageBoxListener)



Copyright © 2009 SAS Institute Inc. All Rights Reserved.