001: /*
002: * @(#) $Id: ConnectDialog.java 555855 2007-07-13 03:19:00Z trustin $
003: *
004: * Copyright 2006 The Apache Software Foundation
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: */
019: package org.apache.mina.example.chat.client;
020:
021: import java.awt.BorderLayout;
022: import java.awt.Frame;
023: import java.awt.HeadlessException;
024: import java.awt.event.ActionEvent;
025:
026: import javax.swing.AbstractAction;
027: import javax.swing.BoxLayout;
028: import javax.swing.JButton;
029: import javax.swing.JCheckBox;
030: import javax.swing.JDialog;
031: import javax.swing.JLabel;
032: import javax.swing.JPanel;
033: import javax.swing.JTextField;
034:
035: /**
036: *
037: * @author The Apache MINA Project (dev@mina.apache.org)
038: * @version $Rev$, $Date$
039: *
040: */
041: public class ConnectDialog extends JDialog {
042: private static final long serialVersionUID = 2009384520250666216L;
043:
044: private String serverAddress;
045:
046: private String username;
047:
048: private boolean useSsl;
049:
050: private boolean cancelled = false;
051:
052: public ConnectDialog(Frame owner) throws HeadlessException {
053: super (owner, "Connect", true);
054:
055: serverAddress = "localhost:1234";
056: username = "user" + Math.round(Math.random() * 10);
057:
058: final JTextField serverAddressField = new JTextField(
059: serverAddress);
060: final JTextField usernameField = new JTextField(username);
061: final JCheckBox useSslCheckBox = new JCheckBox("Use SSL", false);
062:
063: JPanel content = new JPanel();
064: content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));
065: content.add(new JLabel("Server address"));
066: content.add(serverAddressField);
067: content.add(new JLabel("Username"));
068: content.add(usernameField);
069: content.add(useSslCheckBox);
070:
071: JButton okButton = new JButton();
072: okButton.setAction(new AbstractAction("OK") {
073: private static final long serialVersionUID = -2292183622613960604L;
074:
075: public void actionPerformed(ActionEvent e) {
076: serverAddress = serverAddressField.getText();
077: username = usernameField.getText();
078: useSsl = useSslCheckBox.isSelected();
079: ConnectDialog.this .dispose();
080: }
081: });
082:
083: JButton cancelButton = new JButton();
084: cancelButton.setAction(new AbstractAction("Cancel") {
085: private static final long serialVersionUID = 6122393546173723305L;
086:
087: public void actionPerformed(ActionEvent e) {
088: cancelled = true;
089: ConnectDialog.this .dispose();
090: }
091: });
092:
093: JPanel buttons = new JPanel();
094: buttons.add(okButton);
095: buttons.add(cancelButton);
096:
097: getContentPane().add(content, BorderLayout.CENTER);
098: getContentPane().add(buttons, BorderLayout.SOUTH);
099: }
100:
101: public boolean isCancelled() {
102: return cancelled;
103: }
104:
105: public String getServerAddress() {
106: return serverAddress;
107: }
108:
109: public String getUsername() {
110: return username;
111: }
112:
113: public boolean isUseSsl() {
114: return useSsl;
115: }
116: }
|