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.email;
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: setModal(true);
097:
098: SplitPane splitPane = new SplitPane(
099: SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP, new Extent(
100: 32));
101: add(splitPane);
102:
103: Row controlsRow = new Row();
104: controlsRow.setStyleName("ControlPane");
105: splitPane.add(controlsRow);
106:
107: Button button;
108: switch (controlConfiguration) {
109: case CONTROLS_OK:
110: button = new Button(Messages.getString("Generic.Ok"),
111: Styles.ICON_24_YES);
112: button.setStyleName("ControlPane.Button");
113: button.setActionCommand(COMMAND_OK);
114: button.addActionListener(actionProcessor);
115: controlsRow.add(button);
116: break;
117: case CONTROLS_YES_NO:
118: button = new Button(Messages.getString("Generic.Yes"),
119: Styles.ICON_24_YES);
120: button.setStyleName("ControlPane.Button");
121: button.setActionCommand(COMMAND_OK);
122: button.addActionListener(actionProcessor);
123: controlsRow.add(button);
124: button = new Button(Messages.getString("Generic.No"),
125: Styles.ICON_24_NO);
126: button.setStyleName("ControlPane.Button");
127: button.setActionCommand(COMMAND_CANCEL);
128: button.addActionListener(actionProcessor);
129: controlsRow.add(button);
130: break;
131: }
132:
133: Label contentLabel = new Label(message);
134: contentLabel.setStyleName("MessageDialog.ContentLabel");
135: splitPane.add(contentLabel);
136:
137: setModal(true);
138: }
139:
140: /**
141: * Adds an <code>ActionListener</code> to receive notification when the
142: * user selects a choice. The fired <code>command</code> of the fired
143: * <code>ActionEvent</code> will contain be one of the
144: * <code>COMMAND_XXX</code> constants.
145: *
146: * @param l the <code>ActionListener</code> to add
147: */
148: public void addActionListener(ActionListener l) {
149: getEventListenerList().addListener(ActionListener.class, l);
150: }
151:
152: /**
153: * Removes an <code>ActionListener</code> from receiving notification
154: * when the user selects a choice.
155: *
156: * @param l the <code>ActionListener</code> to remove
157: */
158: public void removeActionListener(ActionListener l) {
159: getEventListenerList().removeListener(ActionListener.class, l);
160: }
161: }
|