KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exolab > jms > tools > admin > CreateConsumerDialog


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2000 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: CreateConsumerDialog.java,v 1.1 2004/11/26 01:51:15 tanderson Exp $
44  *
45  * Date Author Changes
46  * $Date jimm Created
47  */

48
49 package org.exolab.jms.tools.admin;
50
51 import java.awt.BorderLayout JavaDoc;
52 import java.awt.FlowLayout JavaDoc;
53 import java.awt.event.ActionEvent JavaDoc;
54 import java.awt.event.ActionListener JavaDoc;
55 import java.awt.event.KeyEvent JavaDoc;
56 import java.awt.event.WindowAdapter JavaDoc;
57 import java.awt.event.WindowEvent JavaDoc;
58
59 import javax.swing.BorderFactory JavaDoc;
60 import javax.swing.JButton JavaDoc;
61 import javax.swing.JDialog JavaDoc;
62 import javax.swing.JFrame JavaDoc;
63 import javax.swing.JLabel JavaDoc;
64 import javax.swing.JOptionPane JavaDoc;
65 import javax.swing.JPanel JavaDoc;
66 import javax.swing.JSeparator JavaDoc;
67 import javax.swing.JTextField JavaDoc;
68 import javax.swing.KeyStroke JavaDoc;
69 import javax.swing.SwingConstants JavaDoc;
70 import javax.swing.SwingUtilities JavaDoc;
71 import javax.swing.border.Border JavaDoc;
72 import javax.swing.text.Keymap JavaDoc;
73
74
75 /**
76  * A simple dialog to collect information for creating a durable consumer
77  *
78  * @version $Revision: 1.1 $ $Date: 2004/11/26 01:51:15 $
79  * @author <a HREF="mailto:jima@exolab.org">Jim Alateras</a>
80  * @see AdminMgr
81  */

82 public class CreateConsumerDialog extends JDialog JavaDoc {
83
84     // The name chosen for this object
85
protected String JavaDoc consumerName_;
86     protected String JavaDoc topicSubscription_;
87
88     // shared gui fields
89
protected JTextField JavaDoc displayText;
90
91     // The two possible states of theis dialog.
92
final static public int CANCELED = 1;
93     final static public int CONFIRMED = 2;
94
95     // The command status used to shutdown this window.
96
protected int status_;
97
98     // All the gui objects for this dialog
99
private JPanel JavaDoc jPanel1;
100     private JButton JavaDoc okButton;
101     private JButton JavaDoc cancelButton;
102     private JPanel JavaDoc jPanel2;
103     private JPanel JavaDoc jPanel3;
104     private JPanel JavaDoc jPanel4;
105     private JSeparator JavaDoc jSeparator2;
106     private JLabel JavaDoc jLabel1;
107     private JTextField JavaDoc jTextField1;
108     private JLabel JavaDoc jLabel2;
109     private JTextField JavaDoc jTextField2;
110
111     // The one and only instance of this object.
112
static private CreateConsumerDialog instance_;
113
114     /**
115      * Creates new form TopicDialog
116      *
117      * @param parent The parent form.
118      */

119     public CreateConsumerDialog(JFrame JavaDoc parent) {
120         super(parent, true);
121         initComponents();
122         pack();
123     }
124
125     /**
126      * Create all the gui components that comprise this form, and setup all
127      * action handlers.
128      *
129      */

130     protected void initComponents() {
131         jPanel1 = new JPanel JavaDoc();
132         okButton = new JButton JavaDoc();
133         cancelButton = new JButton JavaDoc();
134         jPanel2 = new JPanel JavaDoc();
135         jPanel3 = new JPanel JavaDoc();
136         jPanel4 = new JPanel JavaDoc();
137         jLabel1 = new JLabel JavaDoc();
138         jLabel1.setText("Enter the consumer name");
139         jLabel2 = new JLabel JavaDoc();
140         jLabel2.setText("Enter the topic");
141         jTextField1 = new JTextField JavaDoc();
142         jTextField2 = new JTextField JavaDoc();
143         jSeparator2 = new JSeparator JavaDoc();
144         setTitle("Create Durable Consumer");
145         setModal(true);
146         setResizable(true);
147         addWindowListener(new WindowAdapter JavaDoc() {
148
149             public void windowClosing(WindowEvent JavaDoc evt) {
150                 closeDialog(evt);
151             }
152         }
153         );
154
155         jPanel1.setLayout(new FlowLayout JavaDoc(1, 50, 10));
156         okButton.setToolTipText("Press to confirm Action");
157         okButton.setText("OK");
158         getRootPane().setDefaultButton(okButton);
159         jPanel1.add(okButton);
160         cancelButton.setToolTipText("Press to abort Action");
161         cancelButton.setText("Cancel");
162         jPanel1.add(cancelButton);
163         getContentPane().add(jPanel1, BorderLayout.SOUTH);
164         jPanel2.setLayout(new BorderLayout JavaDoc(0, 15));
165         jPanel3.setLayout(new BorderLayout JavaDoc(0, 15));
166         jPanel4.setLayout(new BorderLayout JavaDoc(0, 15));
167         jTextField1.setToolTipText
168             ("Enter the unique consumer name");
169         jTextField2.setToolTipText
170             ("Enter the topic or wildcard subscription");
171
172         Border JavaDoc loweredbevel = BorderFactory.createLoweredBevelBorder();
173
174         jTextField1.setBorder(loweredbevel);
175         jTextField1.setEditable(true);
176         jTextField1.setText("");
177         jTextField1.setHorizontalAlignment(SwingConstants.LEFT);
178
179         jTextField2.setBorder(loweredbevel);
180         jTextField2.setEditable(true);
181         jTextField2.setText("");
182         jTextField2.setHorizontalAlignment(SwingConstants.LEFT);
183
184         jPanel2.add(jLabel1, BorderLayout.NORTH);
185         jPanel2.add(jTextField1, BorderLayout.CENTER);
186         jPanel2.add(jSeparator2, BorderLayout.SOUTH);
187
188         jPanel3.add(jLabel2, BorderLayout.NORTH);
189         jPanel3.add(jTextField2, BorderLayout.CENTER);
190         jPanel3.add(jSeparator2, BorderLayout.SOUTH);
191
192         jPanel4.add(jPanel2, BorderLayout.NORTH);
193         jPanel4.add(jPanel2, BorderLayout.CENTER);
194         jPanel4.add(jSeparator2, BorderLayout.SOUTH);
195
196         getContentPane().add(jPanel4, BorderLayout.CENTER);
197
198         okButton.addActionListener(new ActionListener JavaDoc() {
199
200             public void actionPerformed(ActionEvent JavaDoc evt) {
201                 confirm();
202             }
203         }
204         );
205
206         cancelButton.addActionListener(new ActionListener JavaDoc() {
207
208             public void actionPerformed(ActionEvent JavaDoc evt) {
209                 cancel();
210             }
211         }
212         );
213
214         // Have default button get the keypress event.
215
// This is broken with jdk1.3rc1
216
KeyStroke JavaDoc enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
217         Keymap JavaDoc km = displayText.getKeymap();
218         km.removeKeyStrokeBinding(enter);
219     }
220
221     /**
222      * Display the create consumer dialog box
223      */

224     public void displayCreateConsumer() {
225         jTextField1.setText("");
226         jTextField2.setText("");
227         setLocationRelativeTo(getParent());
228         status_ = CANCELED;
229         setVisible(true);
230
231         SwingUtilities.invokeLater(new Runnable JavaDoc() {
232
233             public void run() {
234                 cancelButton.requestFocus();
235             }
236         }
237         );
238     }
239
240     /**
241      * Get the consumer name
242      *
243      * @return String
244      */

245     public String JavaDoc getConsumerName() {
246         return consumerName_;
247     }
248
249     /**
250      * Get the topic subscription
251      *
252      * @return String
253      */

254     public String JavaDoc getTopicSubscription() {
255         return topicSubscription_;
256     }
257
258     /**
259      * Closes the dialog
260      *
261      * @param evt the window event that triggered this call.
262      *
263      */

264     protected void closeDialog(WindowEvent JavaDoc evt) {
265         setVisible(false);
266         dispose();
267     }
268
269     /**
270      * Whether this dialog was confirmed or canceled.
271      *
272      * @return boolena true if the OK button was pressed.
273      *
274      */

275     public boolean isConfirmed() {
276         return status_ == CONFIRMED;
277     }
278
279     /**
280      * The cancel button was pressed. Close the GUI, and recored that cancel
281      * was pressed.
282      *
283      */

284     protected void cancel() {
285         status_ = CANCELED;
286         setVisible(false);
287         dispose();
288     }
289
290     /**
291      * The OK button was pressed. Get the name and confirm its not null.
292      * if it is null or empty display an error dialog.
293      *
294      * if a consumer name and a topic sub have been entered then close the
295      * dialog box otherwise display an error.
296      */

297     protected void confirm() {
298         consumerName_ = jTextField1.getText();
299         topicSubscription_ = jTextField2.getText();
300
301         if ((consumerName_ == null) ||
302             (consumerName_.length() == 0) ||
303             (topicSubscription_ == null) ||
304             (topicSubscription_.length() == 0)) {
305             JOptionPane.showMessageDialog
306                 (this, "A consumer name and topic subscription must be suplied",
307                     "Create Error", JOptionPane.ERROR_MESSAGE);
308         } else {
309             status_ = CONFIRMED;
310             setVisible(false);
311             dispose();
312         }
313     }
314
315     /**
316      * Get the one and only instance of this dialog. The dialog must first
317      * have been created with the create call below.
318      *
319      * @return TopicDialog the one and only instance
320      *
321      */

322     public static CreateConsumerDialog instance() {
323         return instance_;
324     }
325
326     /**
327      * Create the one and only instance of the Consumer Dialog.
328      *
329      * @param parent the parent of this dialog
330      * @return TopicDialog the one and only instance
331      *
332      */

333     public static CreateConsumerDialog create(JFrame JavaDoc parent) {
334         if (instance_ == null) {
335             instance_ = new CreateConsumerDialog(parent);
336         }
337         return instance_;
338     }
339
340     /**
341      * Display the consumer dialog box
342      */

343     public void display() {
344         JOptionPane.showInputDialog
345             (getParent(), "Enter a unique consumer name",
346                 "Create Durable Consumer", JOptionPane.PLAIN_MESSAGE);
347     }
348 }
349
Popular Tags