KickJava   Java API By Example, From Geeks To Geeks.

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


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 ConnectJndiDialog extends JDialog {
31   private static ConnectJndiDialog dialog;
32   private static JLabel hostLabel;
33   private static JLabel portLabel;
34   private static JLabel ctxLabel;
35
36   private Frame parent = null;
37   private String JavaDoc jndiHost;
38   private int jndiPort;
39   private String JavaDoc namedCtx = "";
40   private JTextField hostField = null;
41   private JFormattedTextField portField = null;
42   private JTextField ctxField = null;
43   private boolean actionCancelled = false;
44
45   /**
46    * Set up the dialog. The first argument can be null,
47    * but it really should be a component in the dialog's
48    * controlling frame.
49    */

50   public static ConnectJndiDialog initialize(Frame parent) {
51     // These JLabel objects are required by the constructor
52
hostLabel = new JLabel("Host: ");
53     portLabel = new JLabel("Port: ");
54     ctxLabel = new JLabel("Context: ");
55
56     dialog = new ConnectJndiDialog(parent);
57     
58     return dialog;
59   }
60
61   /**
62    * Show the initialized dialog. The first argument should
63    * be null if you want the dialog to come up in the center
64    * of the screen. Otherwise, the argument should be the
65    * component on top of which the dialog should appear.
66    */

67   public static ConnectJndiDialog showDialog() throws Exception JavaDoc {
68     if (dialog != null) {
69       dialog.setActionCancelled(false);
70       dialog.setLocationRelativeTo(dialog.parent);
71       dialog.setVisible(true);
72     }
73     else {
74       throw new Exception JavaDoc("ConnectDialog not initialized");
75     }
76     
77     return dialog;
78   }
79
80
81   private ConnectJndiDialog(Frame frame)
82   {
83     super(frame, "Connect to JNDI directory", true);
84
85     parent = frame;
86
87     jndiHost = System.getProperty(AdminController.PROP_JNDI_HOST) != null ? System.getProperty(AdminController.PROP_JNDI_HOST) : AdminController.DEFAULT_JNDI_HOST;
88     String JavaDoc portStr = System.getProperty(AdminController.PROP_JNDI_PORT) != null ? System.getProperty(AdminController.PROP_JNDI_PORT) : AdminController.DEFAULT_JNDI_PORT;
89     jndiPort = Integer.parseInt(portStr);
90
91     // Buttons
92
JButton cancelButton = new JButton("Cancel");
93     final JButton connectButton = new JButton("Connect");
94     cancelButton.addActionListener(new ActionListener() {
95       public void actionPerformed(ActionEvent e) {
96         ConnectJndiDialog.dialog.setVisible(false);
97         ConnectJndiDialog.dialog.setActionCancelled(true);
98       }
99     });
100     connectButton.addActionListener(new ActionListener() {
101       public void actionPerformed(ActionEvent e) {
102         ConnectJndiDialog.dialog.setVisible(false);
103         jndiHost = hostField.getText();
104         jndiPort = Integer.parseInt(portField.getText());
105         namedCtx = ctxField.getText();
106       }
107     });
108     getRootPane().setDefaultButton(connectButton);
109
110     // Main part of the dialog
111
hostField = new JTextField(jndiHost, 30);
112     NumberFormat portFormat = new DecimalFormat("####0");
113     portFormat.setMaximumIntegerDigits(5);
114     portField = new JFormattedTextField(portFormat);
115     portField.setValue(new Integer JavaDoc(jndiPort));
116     ctxField = new JTextField(namedCtx, 30);
117     JLabel[] labels = {hostLabel, portLabel, ctxLabel};
118     JTextField[] textFields = {hostField, portField, ctxField};
119     JPanel form = new InputFormPanel(labels, textFields);
120     form.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
121     
122     //Lay out the buttons from left to right.
123
JPanel buttonPane = new JPanel();
124     buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
125     buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
126     buttonPane.add(Box.createHorizontalGlue());
127     buttonPane.add(connectButton);
128     buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
129     buttonPane.add(cancelButton);
130
131     //Put everything together, using the content pane's BorderLayout.
132
Container contentPane = getContentPane();
133     contentPane.add(form, BorderLayout.CENTER);
134     contentPane.add(buttonPane, BorderLayout.SOUTH);
135
136     pack();
137   }
138
139   public boolean getActionCancelled() { return actionCancelled; }
140     
141   public void setActionCancelled(boolean cancelled)
142   {
143     actionCancelled = cancelled;
144   }
145   
146   public String JavaDoc getJndiHost() { return jndiHost; }
147   
148   public void setJndiHost(String JavaDoc host)
149   {
150     jndiHost = host;
151   }
152   
153   public int getJndiPort() { return jndiPort; }
154   
155   public void setJndiPort(int port)
156   {
157     jndiPort = port;
158   }
159   
160   public String JavaDoc getNamedContext() { return namedCtx; }
161   
162   public void setNamedContext(String JavaDoc ctx)
163   {
164     namedCtx = ctx;
165   }
166 }
167
Popular Tags