KickJava   Java API By Example, From Geeks To Geeks.

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


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 CreateDomainDialog extends JDialog {
29   private static CreateDomainDialog dialog;
30   private static JLabel nameLabel;
31   private static JLabel portLabel;
32
33   private Frame parent = null;
34   private String JavaDoc name = "";
35   private int port;
36
37   private JTextField nameField;
38   private JTextField portField;
39   private JButton submitButton;
40   private boolean actionCancelled = false;
41
42   /**
43    * Set up the dialog. The first argument can be null,
44    * but it really should be a component in the dialog's
45    * controlling frame.
46    */

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

63   public static CreateDomainDialog showDialog() {
64     dialog.nameField.setText("");
65     
66     dialog.setTitle("Create domain");
67     dialog.submitButton.setText("Apply");
68     
69     dialog.setActionCancelled(false);
70     dialog.setLocationRelativeTo(dialog.parent);
71     dialog.setVisible(true);
72     
73     return dialog;
74   }
75
76
77   private CreateDomainDialog(Frame frame) {
78     super(frame, true);
79
80     parent = frame;
81
82     // Buttons
83
submitButton = new JButton("Create");
84     JButton cancelButton = new JButton("Cancel");
85     cancelButton.addActionListener(new ActionListener() {
86       public void actionPerformed(ActionEvent e) {
87         CreateDomainDialog.dialog.setVisible(false);
88         CreateDomainDialog.dialog.setActionCancelled(true);
89       }
90     });
91
92     submitButton.addActionListener(new ActionListener() {
93       public void actionPerformed(ActionEvent e) {
94         CreateDomainDialog.dialog.setVisible(false);
95         name = nameField.getText();
96         port = Integer.parseInt(
97           portField.getText());
98       }
99     });
100     getRootPane().setDefaultButton(submitButton);
101
102     // Main part of the dialog
103
nameField = new JTextField(name, 20);
104     portField = new JTextField("" + port, 20);
105     JLabel[] labels = {nameLabel,
106                        portLabel};
107     JTextField[] textFields = {nameField,
108                                portField};
109     JPanel form = new InputFormPanel(labels, textFields);
110     form.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
111     
112     //Lay out the buttons from left to right.
113
JPanel buttonPane = new JPanel();
114     buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
115     buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
116     buttonPane.add(Box.createHorizontalGlue());
117     buttonPane.add(submitButton);
118     buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
119     buttonPane.add(cancelButton);
120
121     //Put everything together, using the content pane's BorderLayout.
122
Container contentPane = getContentPane();
123     contentPane.add(form, BorderLayout.CENTER);
124     contentPane.add(buttonPane, BorderLayout.SOUTH);
125
126     pack();
127   }
128
129   public boolean getActionCancelled() { return actionCancelled; }
130     
131   public void setActionCancelled(boolean cancelled)
132   {
133     actionCancelled = cancelled;
134   }
135   
136   public String JavaDoc getName() { return name; }
137   
138   public void setName(String JavaDoc name)
139   {
140     this.name = name;
141   }
142
143   public int getPort() { return port; }
144   
145   public void setPort(int port)
146   {
147     this.port = port;
148   }
149 }
150
Popular Tags