KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > echo2example > email > MessageDialog


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package echo2example.email;
31
32 import java.util.EventListener JavaDoc;
33
34 import nextapp.echo2.app.Button;
35 import nextapp.echo2.app.Extent;
36 import nextapp.echo2.app.Label;
37 import nextapp.echo2.app.Row;
38 import nextapp.echo2.app.SplitPane;
39 import nextapp.echo2.app.WindowPane;
40 import nextapp.echo2.app.event.ActionEvent;
41 import nextapp.echo2.app.event.ActionListener;
42
43 /**
44  * A generic modal dialog that displays a message.
45  */

46 public class MessageDialog extends WindowPane {
47
48     public static final int TYPE_ERROR = 1;
49     public static final int TYPE_CONFIRM = 1;
50     
51     public static final int CONTROLS_OK = 1;
52     public static final int CONTROLS_YES_NO = 2;
53     
54     public static final String JavaDoc COMMAND_OK = "ok";
55     public static final String JavaDoc COMMAND_CANCEL = "cancel";
56     
57     private ActionListener actionProcessor = new ActionListener() {
58
59         /**
60          * @see nextapp.echo2.app.event.ActionListener#actionPerformed(nextapp.echo2.app.event.ActionEvent)
61          */

62         public void actionPerformed(ActionEvent e) {
63             getParent().remove(MessageDialog.this);
64             EventListener JavaDoc[] listeners = getEventListenerList().getListeners(ActionListener.class);
65             ActionEvent outgoingEvent = new ActionEvent(this, e.getActionCommand());
66             for (int i = 0; i < listeners.length; ++i) {
67                 ((ActionListener) listeners[i]).actionPerformed(outgoingEvent);
68             }
69         }
70     };
71     
72     /**
73      * Creates a new <code>MessageDialog</code>.
74      *
75      * @param title the dialog title
76      * @param message the message to display
77      * @param type the type of dialog, one of the following values:
78      * <ul>
79      * <li><code>TYPE_ERROR</code></li>
80      * <li><code>TYPE_CONFIRM</code></li>
81      * </ul>
82      * @param controlConfiguration the control configuration, one of the
83      * following values:
84      * <ul>
85      * <li><code>CONTROLS_OK</code></li>
86      * <li><code>CONTROLS_YES_NO</code></li>
87      * </ul>
88      */

89     public MessageDialog(String JavaDoc title, String JavaDoc message, int type, int controlConfiguration) {
90         super(title, new Extent(320), new Extent(240));
91         setStyleName("Default");
92         setModal(true);
93
94         SplitPane splitPane = new SplitPane(SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP, new Extent(32));
95         add(splitPane);
96         
97         Row controlsRow = new Row();
98         controlsRow.setStyleName("ControlPane");
99         splitPane.add(controlsRow);
100
101         Button button;
102         switch (controlConfiguration) {
103         case CONTROLS_OK:
104             button = new Button(Messages.getString("Generic.Ok"), Styles.ICON_24_YES);
105             button.setStyleName("ControlPane.Button");
106             button.setActionCommand(COMMAND_OK);
107             button.addActionListener(actionProcessor);
108             controlsRow.add(button);
109             break;
110         case CONTROLS_YES_NO:
111             button = new Button(Messages.getString("Generic.Yes"), Styles.ICON_24_YES);
112             button.setStyleName("ControlPane.Button");
113             button.setActionCommand(COMMAND_OK);
114             button.addActionListener(actionProcessor);
115             controlsRow.add(button);
116             button = new Button(Messages.getString("Generic.No"), Styles.ICON_24_NO);
117             button.setStyleName("ControlPane.Button");
118             button.setActionCommand(COMMAND_CANCEL);
119             button.addActionListener(actionProcessor);
120             controlsRow.add(button);
121             break;
122         }
123         
124         Label contentLabel = new Label(message);
125         contentLabel.setStyleName("MessageDialog.ContentLabel");
126         splitPane.add(contentLabel);
127         
128         setModal(true);
129     }
130     
131     /**
132      * Adds an <code>ActionListener</code> to receive notification when the
133      * user selects a choice. The fired <code>command</code> of the fired
134      * <code>ActionEvent</code> will contain be one of the
135      * <code>COMMAND_XXX</code> constants.
136      *
137      * @param l the <code>ActionListener</code> to add
138      */

139     public void addActionListener(ActionListener l) {
140         getEventListenerList().addListener(ActionListener.class, l);
141     }
142     
143     /**
144      * Removes an <code>ActionListener</code> from receiving notification
145      * when the user selects a choice.
146      *
147      * @param l the <code>ActionListener</code> to remove
148      */

149     public void removeActionListener(ActionListener l) {
150         getEventListenerList().removeListener(ActionListener.class, l);
151     }
152 }
153
Popular Tags