KickJava   Java API By Example, From Geeks To Geeks.

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


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 ConnectAdminDialog extends JDialog {
31   private static ConnectAdminDialog dialog;
32   private static JLabel hostLabel;
33   private static JLabel portLabel;
34   private static JLabel userLabel;
35   private static JLabel passwdLabel;
36
37   private Frame parent = null;
38   private String JavaDoc adminHost;
39   private int adminPort;
40   private String JavaDoc adminUser;
41   private String JavaDoc adminPasswd;
42
43   private JTextField hostField = null;
44   private JFormattedTextField portField = null;
45   private JTextField userField = null;
46   private JPasswordField passwdField = null;
47   private boolean actionCancelled = false;
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 ConnectAdminDialog initialize(Frame parent) {
55     // These JLabel objects are required by the constructor
56
hostLabel = new JLabel("Host: ");
57     portLabel = new JLabel("Port: ");
58     userLabel = new JLabel("User: ");
59     passwdLabel = new JLabel("Password: ");
60
61     dialog = new ConnectAdminDialog(parent);
62     
63     return dialog;
64   }
65
66   /**
67    * Show the initialized dialog. The first argument should
68    * be null if you want the dialog to come up in the center
69    * of the screen. Otherwise, the argument should be the
70    * component on top of which the dialog should appear.
71    */

72   public static ConnectAdminDialog showDialog() throws Exception JavaDoc {
73     if (dialog != null) {
74       dialog.setActionCancelled(false);
75       dialog.setLocationRelativeTo(dialog.parent);
76       dialog.setVisible(true);
77     }
78     else {
79       throw new Exception JavaDoc("ConnectDialog not initialized");
80     }
81     
82     return dialog;
83   }
84
85
86   private ConnectAdminDialog(Frame frame)
87   {
88     super(frame, "Connect to Admin server", true);
89
90     parent = frame;
91
92     adminHost = AdminController.DEFAULT_ADMIN_HOST;
93     String JavaDoc portStr = AdminController.DEFAULT_ADMIN_PORT;
94     adminPort = Integer.parseInt(portStr);
95
96     // Buttons
97
JButton cancelButton = new JButton("Cancel");
98     final JButton connectButton = new JButton("Connect");
99     cancelButton.addActionListener(new ActionListener() {
100       public void actionPerformed(ActionEvent e) {
101         ConnectAdminDialog.dialog.setVisible(false);
102         ConnectAdminDialog.dialog.setActionCancelled(true);
103       }
104     });
105     connectButton.addActionListener(new ActionListener() {
106       public void actionPerformed(ActionEvent e) {
107         ConnectAdminDialog.dialog.setVisible(false);
108         adminHost = hostField.getText();
109         adminPort = Integer.parseInt(portField.getText());
110         adminUser = userField.getText();
111         adminPasswd = new String JavaDoc(passwdField.getPassword());
112       }
113     });
114     getRootPane().setDefaultButton(connectButton);
115
116     // Main part of the dialog
117
hostField = new JTextField(adminHost, 30);
118     NumberFormat portFormat = new DecimalFormat("####0");
119     portFormat.setMaximumIntegerDigits(5);
120     portField = new JFormattedTextField(portFormat);
121     portField.setValue(new Integer JavaDoc(adminPort));
122     userField = new JTextField(adminUser, 30);
123     passwdField = new JPasswordField(adminPasswd, 30);
124     JLabel[] labels = {hostLabel, portLabel, userLabel, passwdLabel};
125     JTextField[] textFields = {hostField, portField, userField, passwdField};
126     JPanel form = new InputFormPanel(labels, textFields);
127     form.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
128     
129     //Lay out the buttons from left to right.
130
JPanel buttonPane = new JPanel();
131     buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
132     buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
133     buttonPane.add(Box.createHorizontalGlue());
134     buttonPane.add(connectButton);
135     buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
136     buttonPane.add(cancelButton);
137
138     //Put everything together, using the content pane's BorderLayout.
139
Container contentPane = getContentPane();
140     contentPane.add(form, BorderLayout.CENTER);
141     contentPane.add(buttonPane, BorderLayout.SOUTH);
142
143     pack();
144   }
145
146   public boolean getActionCancelled() { return actionCancelled; }
147     
148   public void setActionCancelled(boolean cancelled)
149   {
150     actionCancelled = cancelled;
151   }
152   
153   public String JavaDoc getAdminHost() { return adminHost; }
154   
155   public void setAdminHost(String JavaDoc host)
156   {
157     adminHost = host;
158   }
159   
160   public int getAdminPort() { return adminPort; }
161   
162   public void setAdminPort(int port)
163   {
164     adminPort = port;
165   }
166   
167   public String JavaDoc getAdminUser() { return adminUser; }
168   
169   public void setAdminUser(String JavaDoc user)
170   {
171     adminUser = user;
172   }
173   
174   public String JavaDoc getAdminPassword() { return adminPasswd; }
175   
176   public void setAdminPassword(String JavaDoc passwd)
177   {
178     adminPasswd = passwd;
179   }
180 }
181
Popular Tags