KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ic2d > gui > dialog > NewGlobusHostDialog


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

31 package org.objectweb.proactive.ic2d.gui.dialog;
32
33 import java.awt.BorderLayout JavaDoc;
34 import java.awt.Container JavaDoc;
35 import java.awt.GridBagConstraints JavaDoc;
36 import java.awt.GridBagLayout JavaDoc;
37 import java.awt.Insets JavaDoc;
38 import java.awt.event.ActionEvent JavaDoc;
39 import java.awt.event.ActionListener JavaDoc;
40 import java.awt.event.MouseAdapter JavaDoc;
41 import java.awt.event.MouseEvent JavaDoc;
42 import java.net.InetAddress JavaDoc;
43
44 import javax.swing.JButton JavaDoc;
45 import javax.swing.JDialog JavaDoc;
46 import javax.swing.JLabel JavaDoc;
47 import javax.swing.JPanel JavaDoc;
48 import javax.swing.JTextField JavaDoc;
49
50 public class NewGlobusHostDialog extends JDialog JavaDoc implements ActionListener JavaDoc {
51
52   public boolean success = true;
53   public String JavaDoc host;
54   public int port;
55   private JButton JavaDoc btOk;
56   private JButton JavaDoc btCancel;
57   private JTextField JavaDoc tfHost;
58   private JTextField JavaDoc tfPort;
59
60
61   public void actionPerformed(ActionEvent JavaDoc e) {
62     if (tfHost.getText().length() != 0) {
63       host = tfHost.getText();
64       // System.out.println("PORT :::::::::::::::::::::::::::::::::::::::::" + tfPort.getText());
65
if (tfPort.getText() == null)
66         port = 754;
67       else
68         port = Integer.parseInt(tfPort.getText());
69     }
70     closeDialog(true);
71   }
72
73
74   /**
75    * Creates new form NewGlobusHostDialog
76    *
77    * @param parent The parent frame if any
78    * @param modal Lets you decide if you want this dialog to be modal or not
79    */

80   public NewGlobusHostDialog(java.awt.Frame JavaDoc parent, boolean modal) {
81     super(parent, modal);
82     initComponents();
83     pack();
84   }
85
86
87   /**
88    * Describe 'initComponents' method here.
89    *
90    * @param nil a value of type ''
91    */

92   private void initComponents() {
93     setTitle("GLOBUS host to ic2d");
94     setName("Acquire GLOBUS Host Dialog");
95
96     addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
97
98       public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
99         closeDialog(false);
100       }
101     });
102
103     Container JavaDoc content = getContentPane();
104     GridBagLayout JavaDoc gb = new GridBagLayout JavaDoc();
105     GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
106
107     content.setLayout(gb);
108
109     // The hostname
110
c.gridx = 0;
111     c.gridy = 0;
112     c.insets = new Insets JavaDoc(5, 10, 5, 10);
113     JLabel JavaDoc label = new JLabel JavaDoc("Url");
114     gb.setConstraints(label, c);
115     content.add(label);
116     
117     // Textfields
118
// tfHost=new JTextField("localhost");
119
try {
120       tfHost = new JTextField JavaDoc(InetAddress.getLocalHost().getCanonicalHostName());
121     } catch (Exception JavaDoc e) {
122       tfHost = new JTextField JavaDoc("localhost");
123     }
124     tfHost.addActionListener(this);
125     c.gridx = 1;
126     c.fill = GridBagConstraints.HORIZONTAL;
127     gb.setConstraints(tfHost, c);
128     content.add(tfHost);
129
130     tfPort = new JTextField JavaDoc("754");
131     tfPort.addActionListener(this);
132     c.gridx = 2;
133     c.fill = GridBagConstraints.HORIZONTAL;
134     gb.setConstraints(tfPort, c);
135     content.add(tfPort);
136
137
138     // The buttons
139
JPanel JavaDoc p = new JPanel JavaDoc();
140     p.setLayout(new BorderLayout JavaDoc());
141     // Ok button
142
btOk = new JButton JavaDoc("OK");
143     btOk.addMouseListener(new MouseAdapter JavaDoc() {
144
145       public void mouseReleased(MouseEvent JavaDoc evt) {
146         if (tfHost.getText().length() != 0) {
147           host = tfHost.getText();
148         }
149         closeDialog(true);
150       }
151     });
152     p.add(btOk, BorderLayout.EAST);
153     
154     // Cancel button
155
btCancel = new JButton JavaDoc("Cancel");
156     btCancel.addMouseListener(new MouseAdapter JavaDoc() {
157
158       public void mouseReleased(MouseEvent JavaDoc e) {
159         closeDialog(false);
160       }
161     });
162     p.add(btCancel, BorderLayout.WEST);
163
164     c.gridx = 0;
165     c.gridy = 1;
166     c.gridwidth = 2;
167     gb.setConstraints(p, c);
168     content.add(p);
169     p = null;
170   }
171
172
173   private void closeDialog(boolean val) {
174     success = val;
175     setVisible(false);
176     dispose();
177   }
178 }
179
Popular Tags