001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.mail.gui.config.accountwizard;
017:
018: import java.lang.reflect.Method;
019:
020: import javax.swing.Box;
021: import javax.swing.BoxLayout;
022: import javax.swing.JComboBox;
023: import javax.swing.JComponent;
024: import javax.swing.JLabel;
025: import javax.swing.JPanel;
026: import javax.swing.JTextField;
027: import javax.swing.SwingUtilities;
028: import javax.swing.event.DocumentEvent;
029: import javax.swing.event.DocumentListener;
030:
031: import net.javaprog.ui.wizard.AbstractStep;
032: import net.javaprog.ui.wizard.DataModel;
033: import net.javaprog.ui.wizard.DefaultDataLookup;
034:
035: import org.columba.core.gui.base.LabelWithMnemonic;
036: import org.columba.core.gui.base.MultiLineLabel;
037: import org.columba.core.gui.base.WizardTextField;
038: import org.columba.mail.util.MailResourceLoader;
039:
040: class IncomingServerStep extends AbstractStep {
041: protected DataModel data;
042: protected JTextField loginTextField;
043: protected JTextField hostTextField;
044: protected JLabel addressLabel;
045: protected JComboBox typeComboBox;
046:
047: public IncomingServerStep(DataModel data) {
048: super (MailResourceLoader.getString("dialog", "accountwizard",
049: "incomingserver"), MailResourceLoader
050: .getString("dialog", "accountwizard",
051: "incomingserver_description"));
052: this .data = data;
053: setCanGoNext(false);
054: }
055:
056: protected JComponent createComponent() {
057: JComponent component = new JPanel();
058: component.setLayout(new BoxLayout(component, BoxLayout.Y_AXIS));
059: component.add(new MultiLineLabel(MailResourceLoader.getString(
060: "dialog", "accountwizard", "incomingserver_text")));
061: component.add(Box.createVerticalStrut(40));
062:
063: WizardTextField middlePanel = new WizardTextField();
064: LabelWithMnemonic nameLabel = new LabelWithMnemonic(
065: MailResourceLoader.getString("dialog", "accountwizard",
066: "login"));
067: middlePanel.addLabel(nameLabel);
068: loginTextField = new JTextField();
069:
070: Method method = null;
071:
072: try {
073: method = loginTextField.getClass().getMethod("getText",
074: null);
075: } catch (NoSuchMethodException nsme) {
076: }
077:
078: data.registerDataLookup("IncomingServer.login",
079: new DefaultDataLookup(loginTextField, method, null));
080:
081: DocumentListener fieldListener = new DocumentListener() {
082: public void removeUpdate(DocumentEvent e) {
083: checkFields();
084: }
085:
086: public void insertUpdate(DocumentEvent e) {
087: checkFields();
088: }
089:
090: protected void checkFields() {
091: setCanGoNext((loginTextField.getDocument().getLength() > 0)
092: && (hostTextField.getDocument().getLength() > 0));
093: }
094:
095: public void changedUpdate(DocumentEvent e) {
096: }
097: };
098:
099: loginTextField.getDocument().addDocumentListener(fieldListener);
100: nameLabel.setLabelFor(loginTextField);
101: middlePanel.addTextField(loginTextField);
102:
103: JLabel exampleLabel = new JLabel(MailResourceLoader.getString(
104: "dialog", "accountwizard", "example")
105: + "billgates");
106: middlePanel.addExample(exampleLabel);
107: addressLabel = new LabelWithMnemonic(MailResourceLoader
108: .getString("dialog", "accountwizard", "host"));
109: middlePanel.addLabel(addressLabel);
110: hostTextField = new JTextField();
111: data.registerDataLookup("IncomingServer.host",
112: new DefaultDataLookup(hostTextField, method, null));
113: hostTextField.getDocument().addDocumentListener(fieldListener);
114: addressLabel.setLabelFor(hostTextField);
115: middlePanel.addTextField(hostTextField);
116:
117: JLabel addressExampleLabel = new JLabel(MailResourceLoader
118: .getString("dialog", "accountwizard", "example")
119: + "mail.microsoft.com");
120: middlePanel.addExample(addressExampleLabel);
121:
122: LabelWithMnemonic typeLabel = new LabelWithMnemonic(
123: MailResourceLoader.getString("dialog", "accountwizard",
124: "type"));
125: middlePanel.addLabel(typeLabel);
126: typeComboBox = new JComboBox();
127: typeLabel.setLabelFor(typeComboBox);
128: typeComboBox.addItem("POP3");
129: typeComboBox.addItem("IMAP");
130:
131: try {
132: method = typeComboBox.getClass().getMethod(
133: "getSelectedItem", null);
134: } catch (NoSuchMethodException nsme) {
135: }
136:
137: data.registerDataLookup("IncomingServer.type",
138: new DefaultDataLookup(typeComboBox, method, null));
139: middlePanel.addTextField(typeComboBox);
140: middlePanel.addEmptyExample();
141: component.add(middlePanel);
142:
143: return component;
144: }
145:
146: public void prepareRendering() {
147: SwingUtilities.invokeLater(new Runnable() {
148: public void run() {
149: loginTextField.requestFocus();
150: }
151: });
152: }
153: }
|