|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.visuals.MessageBox
public class MessageBox
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 :
MessageBoxEvent
,
MessageBoxListener
,
MessageBoxSource
,
MessageBoxListenerList
,
Serialized FormField 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 interface com.sas.awt.ContainerInterface |
---|
getComponents, getLayout, invalidate, setLayout, validate |
Field Detail |
---|
public static final java.lang.String RB_KEY
public static final int BUTTON_OK
public static final int BUTTON_YES
public static final int BUTTON_NO
public static final int BUTTON_ABORT
public static final int BUTTON_RETRY
public static final int BUTTON_IGNORE
public static final int BUTTON_CANCEL
public static final int BUTTON_HELP
public static final int BUTTON_STOP
public static final int BUTTON_CONTINUE
public static final int BUTTON_SKIP
public static final int BUTTONS_NONE
public static final int BUTTONS_OK_CANCEL
public static final int BUTTONS_YES_NO
public static final int BUTTONS_YES_NO_CANCEL
public static final int BUTTONS_ABORT_RETRY_IGNORE
public static final int BUTTONS_RETRY_CANCEL
public static final int BUTTONS_STOP_CONTINUE
public static final int BUTTONS_STOP_SKIP
public static final int ICON_NONE
public static final int ICON_INFO
public static final int ICON_ERROR
public static final int ICON_WARNING
public static final int ICON_QUERY
protected com.sas.collection.AssociationList buttonControls
protected ImageView image
protected PushButton lastButtonWithFocus
protected com.sas.visuals.MessageBoxEscapeKeyAdapter escKeyAdapter
protected java.lang.String message
protected int buttons
protected int focusButton
protected int icon
protected int selectedButton
protected java.awt.Panel main
protected java.awt.Panel panelBottom
protected java.awt.Panel panelMiddle
protected ButtonPanel buttonPanel
protected boolean customButtonsFlag
protected java.awt.Panel panelButtons
protected java.lang.String[][] customButtons
protected java.awt.Panel mainTop
protected java.lang.String selectedActionCommand
protected MessageBoxListenerList messageBoxListenerList
Constructor Detail |
---|
public MessageBox(java.awt.Frame frame, java.lang.String message)
frame
- The frame to own the MessageBox.message
- The message to display in the MessageBox.public MessageBox(java.awt.Frame frame, java.lang.String title, boolean modal, java.lang.String message, int buttons, int defaultButton, int icon)
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, ICONpublic MessageBox(java.awt.Frame frame, java.lang.String title, boolean modal, java.lang.String message, java.lang.String[][] customButtons, int icon)
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, ICONMethod Detail |
---|
public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
com.sas.beans.Introspector
to
augment the automatically introspected information about this MessageBox.
public static int showModalMessageBox(java.lang.String message)
message
- text to be displayed on the message boxpublic static int showModalMessageBox(java.awt.Component frame, java.lang.String message)
frame
.
frame
- the frame to own the MessageBox.message
- text to be displayed on the message boxpublic static int showModalMessageBox(java.lang.String title, java.lang.String message, int buttons, int defaultButton, int icon)
title
- text to be displayed as the title of the message boxmessage
- text to be displayed on the message boxbuttons
- the int value representing which buttons are to appear on the message boxdefaultButton
- 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 boxpublic static java.lang.String showModalMessageBox(java.lang.String title, java.lang.String message, java.lang.String[][] customButtons, int icon)
title
- text to be displayed as the title of the message boxmessage
- text to be displayed on the message boxcustomButtons
- 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 boxpublic static int showModalMessageBox(java.awt.Component frame, java.lang.String title, java.lang.String message, int buttons, int defaultButton, int icon)
frame
.
frame
- the frame to own the MessageBox.title
- text to be displayed as the title of the message boxmessage
- text to be displayed on the message boxbuttons
- the int value representing which buttons are to appear on the message boxdefaultButton
- 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 boxpublic static java.lang.String showModalMessageBox(java.awt.Component frame, java.lang.String title, java.lang.String message, java.lang.String[][] customButtons, int icon)
frame
.
frame
- the frame to own the MessageBox.title
- text to be displayed as the title of the message boxmessage
- text to be displayed on the message boxcustomButtons
- 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-with customButtons param
public void setDefaultValues()
setDefaultValues
in interface ContainerInterface
setDefaultValues
in interface VisualInterface
setDefaultValues
in interface com.sas.ComponentInterface
setDefaultValues
in class DialogContainerComponent
ContainerInterface.setDefaultValues()
protected void commonInit()
public void addBottomPanel(java.awt.Container cont)
cont
- a container which contains whatever components added to it.addMiddlePanel(java.awt.Container)
public void addMiddlePanel(java.awt.Container cont)
cont
- a container which contains whatever components added to it.addBottomPanel(java.awt.Container)
public java.lang.String getSelectedActionCommand()
public void addButton(java.lang.String buttonText, java.lang.String actionCommand)
buttonText
- desired text label on the buttonactionCommand
- desired actionCommand to be associated with this button.getButton(java.lang.String)
,
getSelectedActionCommand()
,
MessageBox(java.awt.Frame, java.lang.String, boolean, java.lang.String, java.lang.String[][], int)
public PushButton getButton(java.lang.String buttonText)
buttonText
- name of the button added in the constructor or in addButton
addButton(java.lang.String, java.lang.String)
,
MessageBox(java.awt.Frame, java.lang.String, boolean, java.lang.String, java.lang.String[][], int)
public LabelView getLabel()
public com.sas.visuals.IconInterface getIcon()
setIcon(com.sas.visuals.IconInterface)
public void setIcon(com.sas.visuals.IconInterface image)
image
- and object implementing IconInterfacegetIcon()
public void setVisible(boolean visible)
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.
setVisible
in interface VisualInterface
setVisible
in class Dialog
visible
- boolean valueDialog.setVisible(boolean)
protected java.lang.String paramString()
paramString
in class java.awt.Dialog
public void setLabelHorizontalAlignment(int align)
align
- int representation of com.sas.geometry.Orientations.
values can be either LEFT, RIGHT, or CENTER.public int getLabelHorizontalAlignment()
public void setLabelVerticalAlignment(int align)
align
- int representation of com.sas.geometry.Orientations.
values can be either TOP, BOTTOM, or CENTER.public int getLabelVerticalAlignment()
protected java.lang.String getImageName()
public int getSelectedButton()
public void windowOpened(java.awt.event.WindowEvent e)
windowOpened
in interface java.awt.event.WindowListener
windowOpened
in class Dialog
e
- the window event that is occurringpublic void windowClosing(java.awt.event.WindowEvent e)
When the window close button is clicked, a MessageBoxEvent is sent with the button field as CANCEL and the window is hidden using dipose().
windowClosing
in interface java.awt.event.WindowListener
windowClosing
in class Dialog
e
- the window event that is occurringpublic void windowClosed(java.awt.event.WindowEvent e)
windowClosed
in interface java.awt.event.WindowListener
windowClosed
in class Dialog
e
- the window event that is occurringpublic void windowIconified(java.awt.event.WindowEvent e)
windowIconified
in interface java.awt.event.WindowListener
windowIconified
in class Dialog
e
- the window event that is occurringpublic void windowDeiconified(java.awt.event.WindowEvent e)
windowDeiconified
in interface java.awt.event.WindowListener
windowDeiconified
in class Dialog
e
- the window event that is occurringpublic void windowActivated(java.awt.event.WindowEvent e)
windowActivated
in interface java.awt.event.WindowListener
windowActivated
in class Dialog
e
- the window event that is occurringpublic void windowDeactivated(java.awt.event.WindowEvent e)
windowDeactivated
in interface java.awt.event.WindowListener
windowDeactivated
in class Dialog
e
- the window event that is occurringpublic void actionPerformed(java.awt.event.ActionEvent evt)
actionPerformed
in interface java.awt.event.ActionListener
evt
- the action event that is occurringpublic void focusGained(java.awt.event.FocusEvent event)
focusGained
in interface java.awt.event.FocusListener
event
- the focus event that is occurringpublic void focusLost(java.awt.event.FocusEvent event)
focusLost
in interface java.awt.event.FocusListener
event
- the focus event that is occurringpublic void addMessageBoxListener(MessageBoxListener listener)
addMessageBoxListener
in interface MessageBoxSource
listener
- the message box listener to be addedremoveMessageBoxListener(com.sas.visuals.MessageBoxListener)
,
fireMessageBoxEvent(int)
public void removeMessageBoxListener(MessageBoxListener listener)
removeMessageBoxListener
in interface MessageBoxSource
listener
- the message box listener to be removedaddMessageBoxListener(com.sas.visuals.MessageBoxListener)
,
fireMessageBoxEvent(int)
public void fireMessageBoxEvent(int button)
int
- int value representing the type of button the event is firedaddMessageBoxListener(com.sas.visuals.MessageBoxListener)
,
removeMessageBoxListener(com.sas.visuals.MessageBoxListener)
public void fireMessageBoxEvent(java.lang.String command)
command
- string value representing the actionCommand of button the event is firedaddMessageBoxListener(com.sas.visuals.MessageBoxListener)
,
removeMessageBoxListener(com.sas.visuals.MessageBoxListener)
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |