KickJava   Java API By Example, From Geeks To Geeks.

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


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
24 import javax.swing.*;
25 import java.awt.*;
26 import java.awt.event.*;
27 import java.text.*;
28
29
30 public class CreateFactoryDialog extends JDialog {
31   private static CreateFactoryDialog dialog;
32
33   private Frame parent = null;
34   
35   private boolean actionCancelled = false;
36
37   private String JavaDoc host;
38   private int port;
39   private String JavaDoc factoryName;
40   private String JavaDoc factoryType;
41
42   private JTextField hostField = null;
43   private JFormattedTextField portField = null;
44   private JTextField factoryNameField = null;
45   private ButtonGroup typeGroup = null;
46   private JRadioButton defaultType = null;
47
48
49   /**
50    * Set up the dialog. The first argument can be null,
51    * but it really should be a component in the dialog's
52    * controlling frame.
53    */

54   public static CreateFactoryDialog initialize(Frame parent) {
55     dialog = new CreateFactoryDialog(parent);
56     
57     return dialog;
58   }
59
60   /**
61    * Show the initialized dialog. The first argument should
62    * be null if you want the dialog to come up in the center
63    * of the screen. Otherwise, the argument should be the
64    * component on top of which the dialog should appear.
65    */

66   public static CreateFactoryDialog showDialog() throws Exception JavaDoc {
67     if (dialog != null) {
68       dialog.setActionCancelled(false);
69       dialog.setLocationRelativeTo(dialog.parent);
70       dialog.hostField.setText("");
71       dialog.portField.setText("");
72       dialog.factoryNameField.setText("");
73       dialog.defaultType.setSelected(true);
74       dialog.setVisible(true);
75     }
76     else {
77       throw new Exception JavaDoc("CreateFactoryDialog not initialized");
78     }
79     
80     return dialog;
81   }
82
83
84   private CreateFactoryDialog(Frame frame)
85   {
86     super(frame, "Create a connection factory", true);
87
88     parent = frame;
89
90     // Buttons
91
final JButton createButton = new JButton("Create");
92     JButton cancelButton = new JButton("Cancel");
93     cancelButton.addActionListener(new ActionListener() {
94       public void actionPerformed(ActionEvent e) {
95         CreateFactoryDialog.dialog.setVisible(false);
96         CreateFactoryDialog.dialog.setActionCancelled(true);
97       }
98     });
99     createButton.addActionListener(new ActionListener() {
100       public void actionPerformed(ActionEvent e) {
101         CreateFactoryDialog.dialog.setVisible(false);
102         host = hostField.getText();
103         port = Integer.parseInt(portField.getText());
104         factoryName = factoryNameField.getText();
105         factoryType = typeGroup.getSelection().getActionCommand();
106       }
107     });
108     getRootPane().setDefaultButton(createButton);
109
110     // Form panel
111
hostField = new JTextField(host, 30);
112     NumberFormat portFormat = new DecimalFormat("####0");
113     portFormat.setMaximumIntegerDigits(5);
114     portField = new JFormattedTextField(portFormat);
115     portField.setValue(new Integer JavaDoc(port));
116     factoryNameField = new JTextField(factoryName, 30);
117     JLabel[] labels = {new JLabel("Host: "), new JLabel("Port: "), new JLabel("Name: ")};
118     JTextField[] textFields = {hostField, portField, factoryNameField};
119     JPanel formPanel = new InputFormPanel(labels, textFields);
120     formPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
121
122     // Type panel
123
JRadioButton cfButton = new JRadioButton("Connection Factory");
124     cfButton.setActionCommand("CF");
125     cfButton.setSelected(true);
126     defaultType = cfButton;
127
128     JRadioButton qcfButton = new JRadioButton("Queue Connection Factory");
129     qcfButton.setActionCommand("QCF");
130     JRadioButton tcfButton = new JRadioButton("Topic Connection Factory");
131     tcfButton.setActionCommand("TCF");
132     JRadioButton xcfButton = new JRadioButton("XA Connection Factory");
133     xcfButton.setActionCommand("XCF");
134     JRadioButton xqcfButton = new JRadioButton("XA Queue Connection Factory");
135     xqcfButton.setActionCommand("XQCF");
136     JRadioButton xtcfButton = new JRadioButton("XA Topic Connection Factory");
137     xtcfButton.setActionCommand("XTCF");
138
139     // Group the radio buttons.
140
typeGroup = new ButtonGroup();
141     typeGroup.add(cfButton);
142     typeGroup.add(qcfButton);
143     typeGroup.add(tcfButton);
144     typeGroup.add(xcfButton);
145     typeGroup.add(xqcfButton);
146     typeGroup.add(xtcfButton);
147     JPanel typePanel = new JPanel();
148     typePanel.setLayout(new BoxLayout(typePanel, BoxLayout.Y_AXIS));
149     typePanel.setBorder(BorderFactory.createCompoundBorder(
150                           BorderFactory.createTitledBorder("Factory Type"),
151                           BorderFactory.createEmptyBorder(10, 10, 10, 10)));
152     typePanel.add(cfButton);
153     typePanel.add(qcfButton);
154     typePanel.add(tcfButton);
155     typePanel.add(xcfButton);
156     typePanel.add(xqcfButton);
157     typePanel.add(xtcfButton);
158     
159     // Button panel
160
JPanel buttonPanel = new JPanel();
161     buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
162     buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
163     buttonPanel.add(Box.createHorizontalGlue());
164     buttonPanel.add(createButton);
165     buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
166     buttonPanel.add(cancelButton);
167
168     //Put everything together, using the content pane's BorderLayout.
169
Container contentPane = getContentPane();
170     contentPane.add(formPanel, BorderLayout.NORTH);
171     contentPane.add(typePanel, BorderLayout.CENTER);
172     contentPane.add(buttonPanel, BorderLayout.SOUTH);
173
174     pack();
175   }
176
177   public boolean getActionCancelled() { return actionCancelled; }
178     
179   public void setActionCancelled(boolean cancelled)
180   {
181     actionCancelled = cancelled;
182   }
183
184   public String JavaDoc getHost() { return host; }
185   
186   public void setHost(String JavaDoc host)
187   {
188     this.host = host;
189   }
190   
191   public int getPort() { return port; }
192
193   public void setPort(int port)
194   {
195     this.port = port;
196   }
197   
198   public String JavaDoc getFactoryName() { return factoryName; }
199   
200   public void setFactoryName(String JavaDoc name)
201   {
202     factoryName = name;
203   }
204
205   public String JavaDoc getFactoryType() { return factoryType; }
206 }
207
Popular Tags