001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.chat.ui.dialog;
019:
020: import java.awt.BorderLayout;
021: import java.awt.Frame;
022: import java.awt.GridLayout;
023: import java.awt.HeadlessException;
024: import java.awt.event.ActionEvent;
025: import java.awt.event.ActionListener;
026:
027: import javax.swing.BorderFactory;
028: import javax.swing.JButton;
029: import javax.swing.JCheckBox;
030: import javax.swing.JDialog;
031: import javax.swing.JPanel;
032: import javax.swing.JSpinner;
033: import javax.swing.JTextField;
034: import javax.swing.SpinnerNumberModel;
035: import javax.swing.SwingConstants;
036:
037: import org.columba.addressbook.util.AddressbookResourceLoader;
038: import org.columba.chat.config.api.IAccount;
039: import org.columba.core.gui.base.ButtonWithMnemonic;
040: import org.columba.core.gui.base.SingleSideEtchedBorder;
041:
042: import com.jgoodies.forms.builder.DefaultFormBuilder;
043: import com.jgoodies.forms.layout.FormLayout;
044:
045: /**
046: *
047: * @author fdietz
048: */
049:
050: public class AccountDialog extends JDialog implements ActionListener {
051:
052: private JTextField serverTextField;
053:
054: private JTextField idTextField;
055:
056: // private JPasswordField passwordTextField;
057:
058: private JTextField resourceTextField;
059:
060: private JSpinner portSpinner;
061:
062: private JCheckBox enableSSLCheckBox;
063:
064: private JButton okButton;
065:
066: private JButton registerButton;
067:
068: private IAccount account;
069:
070: /**
071: * @throws java.awt.HeadlessException
072: */
073: public AccountDialog(IAccount account) throws HeadlessException {
074: super (new Frame(), true);
075:
076: this .account = account;
077:
078: initComponents();
079:
080: layoutComponents();
081:
082: updateComponents(true);
083:
084: pack();
085:
086: setLocationRelativeTo(null);
087:
088: setVisible(true);
089: }
090:
091: private void updateComponents(boolean b) {
092: if (b) {
093: idTextField.setText(account.getId());
094: serverTextField.setText(account.getHost());
095: // passwordTextField.setText(account.getPassword());
096: enableSSLCheckBox.setSelected(account.isEnableSSL());
097: resourceTextField.setText(account.getResource());
098:
099: } else {
100: account.setHost(getServer());
101: account.setEnableSSL(new Boolean(enableSSLCheckBox
102: .isSelected()).booleanValue());
103: account.setResource(resourceTextField.getText());
104: account.setId(idTextField.getText());
105:
106: }
107: }
108:
109: /**
110: *
111: */
112: private void layoutComponents() {
113:
114: JPanel panel = new JPanel();
115: panel.setLayout(new BorderLayout());
116:
117: getContentPane().add(panel);
118:
119: JPanel center = new JPanel();
120: center.setBorder(BorderFactory
121: .createEmptyBorder(12, 12, 12, 12));
122:
123: panel.add(center, BorderLayout.CENTER);
124:
125: FormLayout layout = new FormLayout(
126: "right:default, 3dlu, default:grow", "");
127:
128: DefaultFormBuilder b = new DefaultFormBuilder(layout, center);
129: b.setRowGroupingEnabled(true);
130:
131: // b.addSeparator("Account Options");
132:
133: b.append("&Server:", serverTextField);
134:
135: b.append("&User:", idTextField);
136: // b.append("Pass&word:", passwordTextField);
137: b.append("&Resource:", resourceTextField);
138: b.append("&Port:", portSpinner);
139:
140: b.append(enableSSLCheckBox, 3);
141:
142: JPanel bottomPanel = new JPanel(new BorderLayout());
143: bottomPanel.setBorder(new SingleSideEtchedBorder(
144: SwingConstants.TOP));
145:
146: JPanel buttonPanel = new JPanel(new GridLayout(1, 2, 5, 0));
147: buttonPanel.setBorder(BorderFactory.createEmptyBorder(12, 12,
148: 12, 12));
149: okButton = new ButtonWithMnemonic(AddressbookResourceLoader
150: .getString("global", "ok"));
151: okButton.setActionCommand("OK");
152: okButton.addActionListener(this );
153:
154: registerButton = new JButton("Register...");
155: registerButton.setActionCommand("REGISTER");
156: registerButton.addActionListener(this );
157:
158: buttonPanel.add(registerButton);
159: buttonPanel.add(okButton);
160:
161: bottomPanel.add(buttonPanel, BorderLayout.EAST);
162: panel.add(bottomPanel, BorderLayout.SOUTH);
163:
164: getRootPane().setDefaultButton(okButton);
165:
166: }
167:
168: /**
169: *
170: */
171: private void initComponents() {
172:
173: enableSSLCheckBox = new JCheckBox("Use Secure Connection (SSL)");
174: enableSSLCheckBox.setMnemonic('s');
175:
176: serverTextField = new JTextField(10);
177: idTextField = new JTextField(10);
178: // passwordTextField = new JPasswordField(10);
179: resourceTextField = new JTextField(10);
180: portSpinner = new JSpinner(new SpinnerNumberModel(5222, 1,
181: 65535, 1));
182: portSpinner.setEditor(new JSpinner.NumberEditor(portSpinner,
183: "#####"));
184:
185: }
186:
187: public String getServer() {
188: return serverTextField.getText();
189: }
190:
191: public String getUser() {
192: return idTextField.getText();
193: }
194:
195: public String getResource() {
196: return resourceTextField.getText();
197: }
198:
199: /*
200: * public String getPassword() { return passwordTextField.getText(); }
201: */
202:
203: public boolean enableSSL() {
204: return enableSSLCheckBox.isSelected();
205: }
206:
207: /**
208: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
209: */
210: public void actionPerformed(ActionEvent arg0) {
211:
212: String action = arg0.getActionCommand();
213:
214: if (action.equals("OK")) {
215: updateComponents(false);
216:
217: setVisible(false);
218: }
219:
220: }
221:
222: }
|