Source code: com/ciphermod/cipherchat/ConnectDialog.java
1 /* $Id: ConnectDialog.java,v 1.1 2001/03/26 10:48:43 cvsbob Exp $ */
2
3 /*
4 * ConnectDialog.java, allows specifcation of chat server, username, etc.
5 * Copyright (C) 2001 Robert Bushman.
6 *
7 * I reserve the right to release this program under seperate license.
8 * If you require a special license grant contact Robert Bushman.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program 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
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 * 02111-1307, USA.
24 */
25
26 package com.ciphermod.cipherchat;
27
28 import java.awt.GridBagConstraints;
29 import java.awt.GridBagLayout;
30 import java.awt.event.ActionListener;
31 import javax.swing.JButton;
32 import javax.swing.JDialog;
33 import javax.swing.JFrame;
34 import javax.swing.JLabel;
35 import javax.swing.JTextField;
36 import javax.swing.SwingConstants;
37
38 class ConnectDialog extends JDialog {
39
40 // --------------------------------------------------
41 // CONSTRUCTORS
42 // --------------------------------------------------
43
44 public ConnectDialog( JFrame owner, ActionListener actionListener ) {
45 super( owner, "CipherChat Connect" );
46 initializeLabels();
47 initializeFields();
48 initializeActionCommands();
49 initializeSelf();
50 addActionListener( actionListener );
51 }
52
53 public void initializeLabels() {
54 _hostLabel.setHorizontalAlignment( SwingConstants.RIGHT );
55 _portLabel.setHorizontalAlignment( SwingConstants.RIGHT );
56 _nameLabel.setHorizontalAlignment( SwingConstants.RIGHT );
57 _passwordLabel.setHorizontalAlignment( SwingConstants.RIGHT );
58 _chatNameLabel.setHorizontalAlignment( SwingConstants.RIGHT );
59 }
60
61 public void initializeFields() {
62 }
63
64 public void initializeActionCommands() {
65 _cancel.setActionCommand( "Connect >> Cancel" );
66 _connect.setActionCommand( "Connect >> Connect" );
67 }
68
69 public void initializeSelf() {
70 getContentPane().setLayout( _gridBag );
71
72 _constraints.gridx = 0;
73 _constraints.gridy = 0;
74 _gridBag.setConstraints( _hostLabel, _constraints );
75 getContentPane().add( _hostLabel );
76
77 _constraints.gridy = 1;
78 _gridBag.setConstraints( _portLabel, _constraints );
79 getContentPane().add( _portLabel );
80
81 _constraints.gridy = 2;
82 _gridBag.setConstraints( _nameLabel, _constraints );
83 getContentPane().add( _nameLabel );
84
85 _constraints.gridy = 3;
86 _gridBag.setConstraints( _passwordLabel, _constraints );
87 getContentPane().add( _passwordLabel );
88
89 _constraints.gridy = 4;
90 _gridBag.setConstraints( _chatNameLabel, _constraints );
91 getContentPane().add( _chatNameLabel );
92
93 _constraints.gridx = 1;
94 _constraints.gridy = 0;
95 _constraints.gridwidth = 2;
96 _gridBag.setConstraints( _host, _constraints );
97 getContentPane().add( _host );
98
99 _constraints.gridy = 1;
100 _gridBag.setConstraints( _port, _constraints );
101 getContentPane().add( _port );
102
103 _constraints.gridy = 2;
104 _gridBag.setConstraints( _name, _constraints );
105 getContentPane().add( _name );
106
107 _constraints.gridy = 3;
108 _gridBag.setConstraints( _password, _constraints );
109 getContentPane().add( _password );
110
111 _constraints.gridy = 4;
112 _gridBag.setConstraints( _chatName, _constraints );
113 getContentPane().add( _chatName );
114
115 _constraints.gridx = 0;
116 _constraints.gridy = 5;
117 _gridBag.setConstraints( _cancel, _constraints );
118 getContentPane().add( _cancel );
119
120 _constraints.gridx = 2;
121 _constraints.gridwidth = 1;
122 _gridBag.setConstraints( _connect, _constraints );
123 getContentPane().add( _connect );
124 }
125
126 public void addActionListener( ActionListener listener ) {
127 _cancel.addActionListener( listener );
128 _connect.addActionListener( listener );
129 }
130
131 // --------------------------------------------------
132 // INSTANCE PARAMETERS AND ACCESSORS
133 // --------------------------------------------------
134
135 // PARAMETERS
136 private JLabel _hostLabel = new JLabel( "Host" );
137 private JTextField _host = new JTextField( "localhost", 20 );
138 private JLabel _portLabel = new JLabel( "Port" );
139 private JTextField _port = new JTextField( "5943", 20 );
140 private JLabel _nameLabel = new JLabel( "User Name" );
141 private JTextField _name = new JTextField( 20 );
142 private JLabel _passwordLabel = new JLabel( "Password" );
143 private JTextField _password = new JTextField( 20 );
144 private JLabel _chatNameLabel = new JLabel( "Chat Name" );
145 private JTextField _chatName = new JTextField( 20 );
146 private JButton _cancel = new JButton( "Cancel" );
147 private JButton _connect = new JButton( "Connect" );
148 private GridBagLayout _gridBag = new GridBagLayout();
149 private GridBagConstraints _constraints = new GridBagConstraints();
150
151 // SETTERS
152
153 // GETTERS
154 public String getHostName() { return( _host.getText() ); }
155 public int getPort() { return( Integer.parseInt( _port.getText() ) ); }
156 public String getUserName() { return( _name.getText() ); }
157 public String getPassword() { return( _password.getText() ); }
158 public String getChatName() { return( _chatName.getText() ); }
159 }
160