001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package echo2example.chatclient;
031:
032: import java.util.EventListener;
033:
034: import nextapp.echo2.app.Button;
035: import nextapp.echo2.app.Extent;
036: import nextapp.echo2.app.Label;
037: import nextapp.echo2.app.Row;
038: import nextapp.echo2.app.SplitPane;
039: import nextapp.echo2.app.WindowPane;
040: import nextapp.echo2.app.event.ActionEvent;
041: import nextapp.echo2.app.event.ActionListener;
042:
043: /**
044: * A generic modal dialog that displays a message.
045: */
046: public class MessageDialog extends WindowPane {
047:
048: public static final int TYPE_ERROR = 1;
049: public static final int TYPE_CONFIRM = 1;
050:
051: public static final int CONTROLS_OK = 1;
052: public static final int CONTROLS_YES_NO = 2;
053:
054: public static final String COMMAND_OK = "ok";
055: public static final String COMMAND_CANCEL = "cancel";
056:
057: private ActionListener actionProcessor = new ActionListener() {
058:
059: /**
060: * @see nextapp.echo2.app.event.ActionListener#actionPerformed(nextapp.echo2.app.event.ActionEvent)
061: */
062: public void actionPerformed(ActionEvent e) {
063: getParent().remove(MessageDialog.this );
064: EventListener[] listeners = getEventListenerList()
065: .getListeners(ActionListener.class);
066: ActionEvent outgoingEvent = new ActionEvent(this , e
067: .getActionCommand());
068: for (int i = 0; i < listeners.length; ++i) {
069: ((ActionListener) listeners[i])
070: .actionPerformed(outgoingEvent);
071: }
072: }
073: };
074:
075: /**
076: * Creates a new <code>MessageDialog</code>.
077: *
078: * @param title the dialog title
079: * @param message the message to display
080: * @param type the type of dialog, one of the following values:
081: * <ul>
082: * <li><code>TYPE_ERROR</code></li>
083: * <li><code>TYPE_CONFIRM</code></li>
084: * </ul>
085: * @param controlConfiguration the control configuration, one of the
086: * following values:
087: * <ul>
088: * <li><code>CONTROLS_OK</code></li>
089: * <li><code>CONTROLS_YES_NO</code></li>
090: * </ul>
091: */
092: public MessageDialog(String title, String message, int type,
093: int controlConfiguration) {
094: super (title, new Extent(320), new Extent(240));
095: setStyleName("Default");
096: setClosable(false);
097: setModal(true);
098:
099: SplitPane splitPane = new SplitPane(
100: SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP, new Extent(
101: 32));
102: add(splitPane);
103:
104: Row controlsRow = new Row();
105: controlsRow.setStyleName("ControlPane");
106: splitPane.add(controlsRow);
107:
108: Button button;
109: switch (controlConfiguration) {
110: case CONTROLS_OK:
111: button = new Button(Messages.getString("Generic.Ok"),
112: Styles.ICON_24_YES);
113: button.setStyleName("ControlPane.Button");
114: button.setActionCommand(COMMAND_OK);
115: button.addActionListener(actionProcessor);
116: controlsRow.add(button);
117: break;
118: case CONTROLS_YES_NO:
119: button = new Button(Messages.getString("Generic.Yes"),
120: Styles.ICON_24_YES);
121: button.setStyleName("ControlPane.Button");
122: button.setActionCommand(COMMAND_OK);
123: button.addActionListener(actionProcessor);
124: controlsRow.add(button);
125: button = new Button(Messages.getString("Generic.No"),
126: Styles.ICON_24_NO);
127: button.setStyleName("ControlPane.Button");
128: button.setActionCommand(COMMAND_CANCEL);
129: button.addActionListener(actionProcessor);
130: controlsRow.add(button);
131: break;
132: }
133:
134: Label contentLabel = new Label(message);
135: contentLabel.setStyleName("MessageDialog.ContentLabel");
136: splitPane.add(contentLabel);
137:
138: setModal(true);
139: }
140:
141: /**
142: * Adds an <code>ActionListener</code> to receive notification when the
143: * user selects a choice. The fired <code>command</code> of the fired
144: * <code>ActionEvent</code> will contain be one of the
145: * <code>COMMAND_XXX</code> constants.
146: *
147: * @param l the <code>ActionListener</code> to add
148: */
149: public void addActionListener(ActionListener l) {
150: getEventListenerList().addListener(ActionListener.class, l);
151: }
152:
153: /**
154: * Removes an <code>ActionListener</code> from receiving notification
155: * when the user selects a choice.
156: *
157: * @param l the <code>ActionListener</code> to remove
158: */
159: public void removeActionListener(ActionListener l) {
160: getEventListenerList().removeListener(ActionListener.class, l);
161: }
162: }
|