KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > tools > admin > CreateDestinationDialog


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA.
18  *
19  * Initial developer(s): Alexander Fedorowicz
20  * Contributor(s):
21  */

22 package org.objectweb.joram.client.tools.admin;
23 import javax.swing.*;
24 import java.awt.*;
25 import java.awt.event.*;
26
27
28 public class CreateDestinationDialog extends JDialog {
29   private static CreateDestinationDialog dialog;
30
31   private Frame parent = null;
32   
33   private boolean actionCancelled = false;
34
35   private String JavaDoc destName;
36   private String JavaDoc destType;
37
38   private JTextField destNameField = null;
39   private ButtonGroup typeGroup = null;
40   private JRadioButton defaultType = null;
41
42
43   /**
44    * Set up the dialog. The first argument can be null,
45    * but it really should be a component in the dialog's
46    * controlling frame.
47    */

48   public static CreateDestinationDialog initialize(Frame parent) {
49     dialog = new CreateDestinationDialog(parent);
50     
51     return dialog;
52   }
53
54   /**
55    * Show the initialized dialog. The first argument should
56    * be null if you want the dialog to come up in the center
57    * of the screen. Otherwise, the argument should be the
58    * component on top of which the dialog should appear.
59    */

60   public static CreateDestinationDialog showDialog() throws Exception JavaDoc {
61     if (dialog != null) {
62       dialog.setActionCancelled(false);
63       dialog.setLocationRelativeTo(dialog.parent);
64       dialog.destNameField.setText("");
65       dialog.defaultType.setSelected(true);
66       dialog.setVisible(true);
67     }
68     else {
69       throw new Exception JavaDoc("CreateDestinationDialog not initialized");
70     }
71     
72     return dialog;
73   }
74
75
76   private CreateDestinationDialog(Frame frame)
77   {
78     super(frame, "Create a destination", true);
79
80     parent = frame;
81
82     // Buttons
83
final JButton createButton = new JButton("Create");
84     JButton cancelButton = new JButton("Cancel");
85     cancelButton.addActionListener(new ActionListener() {
86       public void actionPerformed(ActionEvent e) {
87         CreateDestinationDialog.dialog.setVisible(false);
88         CreateDestinationDialog.dialog.setActionCancelled(true);
89       }
90     });
91     createButton.addActionListener(new ActionListener() {
92       public void actionPerformed(ActionEvent e) {
93         CreateDestinationDialog.dialog.setVisible(false);
94         destName = destNameField.getText();
95         destType = typeGroup.getSelection().getActionCommand();
96       }
97     });
98     getRootPane().setDefaultButton(createButton);
99
100     // Name panel
101
JPanel namePanel = new JPanel();
102     namePanel.setLayout(new BoxLayout(namePanel, BoxLayout.X_AXIS));
103     namePanel.add(new JLabel("Name: "));
104     destNameField = new JTextField(destName, 30);
105     namePanel.add(destNameField);
106
107     // Type panel
108
JRadioButton qButton = new JRadioButton("Queue");
109     qButton.setActionCommand("Q");
110     qButton.setSelected(true);
111     defaultType = qButton;
112
113     JRadioButton tButton = new JRadioButton("Topic");
114     tButton.setActionCommand("T");
115     JRadioButton dmqButton = new JRadioButton("Dead Message Queue");
116     dmqButton.setActionCommand("DMQ");
117
118     // Group the radio buttons.
119
typeGroup = new ButtonGroup();
120     typeGroup.add(qButton);
121     typeGroup.add(tButton);
122     typeGroup.add(dmqButton);
123     JPanel typePanel = new JPanel();
124     typePanel.setLayout(new BoxLayout(typePanel, BoxLayout.Y_AXIS));
125     typePanel.setBorder(BorderFactory.createCompoundBorder(
126                           BorderFactory.createTitledBorder("Destination Type"),
127                           BorderFactory.createEmptyBorder(10, 10, 10, 10)));
128     typePanel.add(qButton);
129     typePanel.add(tButton);
130     typePanel.add(dmqButton);
131     
132     // Button panel
133
JPanel buttonPanel = new JPanel();
134     buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
135     buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
136     buttonPanel.add(Box.createHorizontalGlue());
137     buttonPanel.add(createButton);
138     buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
139     buttonPanel.add(cancelButton);
140
141     //Put everything together, using the content pane's BorderLayout.
142
Container contentPane = getContentPane();
143     contentPane.add(namePanel, BorderLayout.NORTH);
144     contentPane.add(typePanel, BorderLayout.CENTER);
145     contentPane.add(buttonPanel, BorderLayout.SOUTH);
146
147     pack();
148   }
149
150   public boolean getActionCancelled() { return actionCancelled; }
151     
152   public void setActionCancelled(boolean cancelled)
153   {
154     actionCancelled = cancelled;
155   }
156   
157   public String JavaDoc getDestinationName() { return destName; }
158   
159   public void setDestinationName(String JavaDoc name)
160   {
161     destName = name;
162   }
163
164   public String JavaDoc getDestinationType() { return destType; }
165 }
166
Popular Tags