001: /*
002: * Copyright (c) 2001 Silvere Martin-Michiellot All Rights Reserved.
003: *
004: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
005: * royalty free, license to use, modify and redistribute this
006: * software in source and binary code form,
007: * provided that i) this copyright notice and license appear on all copies of
008: * the software; and ii) Licensee does not utilize the software in a manner
009: * which is disparaging to Silvere Martin-Michiellot.
010: *
011: * This software is provided "AS IS," without a warranty of any kind. ALL
012: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
013: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
014: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
015: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
016: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
017: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
018: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
019: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
020: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
021: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
022: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
023: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
024: *
025: * This software is not designed or intended for use in on-line control of
026: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
027: * the design, construction, operation or maintenance of any nuclear
028: * facility. Licensee represents and warrants that it will not use or
029: * redistribute the Software for such purposes.
030: *
031: * @Author: Silvere Martin-Michiellot
032: *
033: */
034:
035: package com.db.client;
036:
037: import java.awt.*;
038: import java.awt.event.*;
039: import java.net.InetAddress;
040: import java.net.UnknownHostException;
041: import java.util.*;
042: import javax.swing.*;
043:
044: import com.db.server.LoginInformation;
045:
046: public class ConnectionJDialog extends JDialog implements
047: ActionListener {
048:
049: private DigitalBiosphereClient parent;
050:
051: private JPanel jPanel3;
052: private JLabel jLabel2;
053: private JPanel jPanel4;
054: private JLabel jLabel3;
055: private JTextField jTextField1;
056: private JLabel jLabel4;
057: private JTextField jTextField2;
058: private JLabel jLabel5;
059: private JTextField jTextField3;
060: private JLabel jLabel6;
061: private JTextField jTextField4;
062: private JPanel jPanel6;
063: private JButton jButton3;
064: private JButton jButton4;
065:
066: public ConnectionJDialog(DigitalBiosphereClient parent,
067: ResourceBundle resourceBundle) {
068:
069: this .parent = parent;
070: jPanel3 = new JPanel();
071: jLabel2 = new JLabel();
072: jPanel4 = new JPanel();
073: jLabel3 = new JLabel();
074: jTextField1 = new JTextField();
075: jLabel4 = new JLabel();
076: jTextField2 = new JTextField();
077: jLabel5 = new JLabel();
078: jTextField3 = new JTextField();
079: jLabel6 = new JLabel();
080: jTextField4 = new JTextField();
081: jPanel6 = new JPanel();
082: jButton3 = new JButton();
083: jButton4 = new JButton();
084:
085: this .getContentPane().setLayout(new FlowLayout());
086: this .setName(resourceBundle
087: .getString("Set IP, Port, Login and Password"));
088: this .setModal(true);
089: this .setTitle(resourceBundle
090: .getString("Set IP, Port, Login and Password"));
091: this .setResizable(false);
092:
093: /* The following code is to close the windows. */
094:
095: this .addWindowListener(new WindowAdapter() {
096:
097: public void windowClosing(WindowEvent e) {
098:
099: setVisible(false);
100: dispose();
101:
102: }
103:
104: });
105:
106: this .addWindowListener(new WindowAdapter() {
107:
108: public void windowIconified(WindowEvent e) {
109:
110: setVisible(false);
111: dispose();
112:
113: }
114:
115: });
116:
117: jPanel3.setPreferredSize(new Dimension(250, 30));
118: jPanel3.setMinimumSize(new Dimension(250, 30));
119: jPanel3.setMaximumSize(new Dimension(250, 30));
120:
121: jLabel2
122: .setText(resourceBundle
123: .getString("Please select an IP, a port, a login and a password:"));
124: jPanel3.add(jLabel2);
125:
126: this .getContentPane().add(jPanel3);
127:
128: jPanel4.setLayout(new GridLayout(5, 2));
129: jPanel4.setPreferredSize(new Dimension(300, 200));
130: jPanel4.setMinimumSize(new Dimension(300, 200));
131: jPanel4.setMaximumSize(new Dimension(300, 200));
132:
133: jLabel3.setText(resourceBundle.getString("Server IP:"));
134: jPanel4.add(jLabel3);
135:
136: jTextField1.setColumns(40);
137: jTextField1.setToolTipText(resourceBundle
138: .getString("ServerIPToolTipText"));
139: jTextField1.getAccessibleContext().setAccessibleDescription(
140: resourceBundle
141: .getString("ServerIPAccessibleDescription"));
142: jPanel4.add(jTextField1);
143:
144: jLabel4.setText(resourceBundle.getString("Server Port:"));
145: jPanel4.add(jLabel4);
146:
147: jTextField2.setColumns(40);
148: jTextField2.setToolTipText(resourceBundle
149: .getString("ServerPortToolTipText"));
150: jTextField2.getAccessibleContext().setAccessibleDescription(
151: resourceBundle
152: .getString("ServerPortAccessibleDescription"));
153: jPanel4.add(jTextField2);
154:
155: jLabel5.setText(resourceBundle.getString("Login:"));
156: jPanel4.add(jLabel5);
157:
158: jTextField3.setColumns(40);
159: jTextField3.setText("anonymous");
160: jTextField3.setToolTipText(resourceBundle
161: .getString("LoginToolTipText"));
162: jTextField3.getAccessibleContext().setAccessibleDescription(
163: resourceBundle.getString("LoginAccessibleDescription"));
164: jPanel4.add(jTextField3);
165:
166: jLabel4.setText(resourceBundle.getString("Password:"));
167: jPanel4.add(jLabel4);
168:
169: //not a password field
170: jTextField4.setColumns(40);
171: jTextField4.setText("anonymous");
172: jTextField4.setToolTipText(resourceBundle
173: .getString("PasswordToolTipText"));
174: jTextField4.getAccessibleContext().setAccessibleDescription(
175: resourceBundle
176: .getString("PasswordAccessibleDescription"));
177: jPanel4.add(jTextField4);
178:
179: this .getContentPane().add(jPanel4);
180:
181: jPanel6.setPreferredSize(new Dimension(250, 40));
182: jPanel6.setMinimumSize(new Dimension(250, 40));
183: jPanel6.setMaximumSize(new Dimension(250, 40));
184:
185: jButton3.setText("OK");
186: jButton3.addActionListener(this );
187: jButton3.setToolTipText(resourceBundle
188: .getString("OKToolTipText"));
189: jButton3.getAccessibleContext().setAccessibleDescription(
190: resourceBundle.getString("OKAccessibleDescription"));
191: jPanel6.add(jButton3);
192:
193: jButton4.setText("Cancel");
194: jButton4.addActionListener(this );
195: jButton4.setToolTipText(resourceBundle
196: .getString("CancelToolTipText"));
197: jButton4
198: .getAccessibleContext()
199: .setAccessibleDescription(
200: resourceBundle
201: .getString("CancelAccessibleDescription"));
202: jPanel6.add(jButton4);
203:
204: this .getContentPane().add(jPanel6);
205:
206: this .pack();
207: }
208:
209: public void actionPerformed(ActionEvent TheActionEvent) {
210:
211: InetAddress inetAddress;
212: Object TheObject;
213: LoginInformation loginInformation;
214:
215: TheObject = TheActionEvent.getSource();
216:
217: if (TheObject instanceof JButton) {
218: if (TheObject == jButton3) {
219: try {
220: inetAddress = InetAddress.getByName(jTextField1
221: .getText());
222: loginInformation = new LoginInformation(jTextField3
223: .getText(), jTextField4.getText());
224: this .TheSetCommand(inetAddress, new Integer(
225: jTextField2.getText()).intValue(),
226: loginInformation);
227: this .TheCloseCommand();
228: } catch (UnknownHostException unknownHostException) {
229: jTextField1.setText(new String(""));
230: }
231: }
232: if (TheObject == jButton4) {
233: this .TheCloseCommand();
234: }
235: }
236:
237: }
238:
239: private void TheSetCommand(InetAddress inetAddress, int port,
240: LoginInformation loginInformation) {
241:
242: this .parent.setConnectionJDialogResult(inetAddress, port,
243: loginInformation);
244:
245: }
246:
247: private void TheCloseCommand() {
248:
249: this .setVisible(false);
250: this.dispose();
251:
252: }
253:
254: }
|