KickJava   Java API By Example, From Geeks To Geeks.

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


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): ScalAgent DT
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
28 public class CreateServerDialog extends JDialog {
29   private static CreateServerDialog dialog;
30   private static JLabel nameLabel;
31   private static JLabel hostNameLabel;
32   private static JLabel serverIdLabel;
33   private static JLabel portLabel;
34
35   private Frame parent = null;
36   private String JavaDoc name = "";
37   private String JavaDoc hostName = "";
38   private short serverId;
39   private int port;
40
41   private JTextField nameField;
42   private JTextField hostNameField;
43   private JTextField serverIdField;
44   private JTextField portField;
45   private JButton submitButton;
46   private boolean actionCancelled = false;
47
48   /**
49    * Set up the dialog. The first argument can be null,
50    * but it really should be a component in the dialog's
51    * controlling frame.
52    */

53   public static CreateServerDialog initialize(Frame parent) {
54     // These JLabel objects are required by the constructor
55
nameLabel = new JLabel("Server name: ");
56     hostNameLabel = new JLabel("Host name (address): ");
57     serverIdLabel = new JLabel("Server id: ");
58     portLabel = new JLabel("Port: ");
59
60     dialog = new CreateServerDialog(parent);
61     
62     return dialog;
63   }
64
65   /**
66    * Show the initialized dialog. The first argument should
67    * be null if you want the dialog to come up in the center
68    * of the screen. Otherwise, the argument should be the
69    * component on top of which the dialog should appear.
70    */

71   public static CreateServerDialog showDialog() {
72     dialog.nameField.setText("");
73     dialog.hostNameField.setText("");
74     
75     dialog.setTitle("Create server");
76     dialog.submitButton.setText("Apply");
77     
78     dialog.setActionCancelled(false);
79     dialog.setLocationRelativeTo(dialog.parent);
80     dialog.setVisible(true);
81     
82     return dialog;
83   }
84
85
86   private CreateServerDialog(Frame frame)
87   {
88     super(frame, true);
89
90     parent = frame;
91
92     // Buttons
93
submitButton = new JButton("Create");
94     JButton cancelButton = new JButton("Cancel");
95     cancelButton.addActionListener(new ActionListener() {
96       public void actionPerformed(ActionEvent e) {
97         CreateServerDialog.dialog.setVisible(false);
98         CreateServerDialog.dialog.setActionCancelled(true);
99       }
100     });
101
102     submitButton.addActionListener(new ActionListener() {
103       public void actionPerformed(ActionEvent e) {
104         CreateServerDialog.dialog.setVisible(false);
105         name = nameField.getText();
106         serverId = Short.parseShort(
107           serverIdField.getText());
108         hostName = hostNameField.getText();
109         port = Integer.parseInt(
110           portField.getText());
111       }
112     });
113     getRootPane().setDefaultButton(submitButton);
114
115     // Main part of the dialog
116
nameField = new JTextField(name, 20);
117     hostNameField = new JTextField(hostName, 20);
118     serverIdField = new JTextField("" + serverId, 20);
119     portField = new JTextField("" + port, 20);
120     JLabel[] labels = {nameLabel,
121                        hostNameLabel,
122                        serverIdLabel,
123                        portLabel};
124     JTextField[] textFields = {nameField,
125                                hostNameField,
126                                serverIdField,
127                                portField};
128     JPanel form = new InputFormPanel(labels, textFields);
129     form.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
130     
131     //Lay out the buttons from left to right.
132
JPanel buttonPane = new JPanel();
133     buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
134     buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
135     buttonPane.add(Box.createHorizontalGlue());
136     buttonPane.add(submitButton);
137     buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
138     buttonPane.add(cancelButton);
139
140     //Put everything together, using the content pane's BorderLayout.
141
Container contentPane = getContentPane();
142     contentPane.add(form, BorderLayout.CENTER);
143     contentPane.add(buttonPane, BorderLayout.SOUTH);
144
145     pack();
146   }
147
148   public boolean getActionCancelled() { return actionCancelled; }
149     
150   public void setActionCancelled(boolean cancelled)
151   {
152     actionCancelled = cancelled;
153   }
154   
155   public String JavaDoc getName() { return name; }
156   
157   public void setName(String JavaDoc name)
158   {
159     this.name = name;
160   }
161
162   public String JavaDoc getHostName() { return hostName; }
163   
164   public void setHostName(String JavaDoc hostName)
165   {
166     this.hostName = hostName;
167   }
168   
169   public short getServerId() { return serverId; }
170   
171   public void setServerId(short serverId)
172   {
173     this.serverId = serverId;
174   }
175
176   public int getPort() { return port; }
177   
178   public void setPort(int port)
179   {
180     this.port = port;
181   }
182 }
183
Popular Tags