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.JComponent;
023: import javax.swing.JLabel;
024: import javax.swing.JPanel;
025: import javax.swing.JTextField;
026: import javax.swing.SwingUtilities;
027: import javax.swing.event.DocumentEvent;
028: import javax.swing.event.DocumentListener;
029:
030: import net.javaprog.ui.wizard.AbstractStep;
031: import net.javaprog.ui.wizard.DataModel;
032: import net.javaprog.ui.wizard.DefaultDataLookup;
033:
034: import org.columba.core.gui.base.LabelWithMnemonic;
035: import org.columba.core.gui.base.MultiLineLabel;
036: import org.columba.core.gui.base.WizardTextField;
037: import org.columba.mail.util.MailResourceLoader;
038:
039: class OutgoingServerStep extends AbstractStep {
040: protected DataModel data;
041: protected boolean isLastStep;
042: private JTextField hostTextField;
043:
044: public OutgoingServerStep(DataModel data, boolean isLastStep) {
045: super (MailResourceLoader.getString("dialog", "accountwizard",
046: "outgoingserver"), MailResourceLoader
047: .getString("dialog", "accountwizard",
048: "outgoingserver_description"));
049: this .data = data;
050: this .isLastStep = isLastStep;
051: setCanGoNext(false);
052: }
053:
054: protected JComponent createComponent() {
055: JComponent component = new JPanel();
056: component.setLayout(new BoxLayout(component, BoxLayout.Y_AXIS));
057: component.add(new MultiLineLabel(MailResourceLoader.getString(
058: "dialog", "accountwizard", "outgoingserver_text")));
059: component.add(Box.createVerticalStrut(40));
060:
061: WizardTextField middlePanel = new WizardTextField();
062:
063: LabelWithMnemonic addressLabel = new LabelWithMnemonic(
064: MailResourceLoader.getString("dialog", "accountwizard",
065: "host"));
066: middlePanel.addLabel(addressLabel);
067: hostTextField = new JTextField();
068:
069: Method method = null;
070:
071: try {
072: method = hostTextField.getClass()
073: .getMethod("getText", null);
074: } catch (NoSuchMethodException nsme) {
075: }
076:
077: data.registerDataLookup("OutgoingServer.host",
078: new DefaultDataLookup(hostTextField, method, null));
079: hostTextField.getDocument().addDocumentListener(
080: new DocumentListener() {
081: public void removeUpdate(DocumentEvent e) {
082: setCanProceed(e.getDocument().getLength() > 0);
083: }
084:
085: public void insertUpdate(DocumentEvent e) {
086: setCanProceed(e.getDocument().getLength() > 0);
087: }
088:
089: protected void setCanProceed(boolean b) {
090: if (isLastStep) {
091: setCanFinish(b);
092: } else {
093: setCanGoNext(b);
094: }
095: }
096:
097: public void changedUpdate(DocumentEvent e) {
098: }
099: });
100: addressLabel.setLabelFor(hostTextField);
101: middlePanel.addTextField(hostTextField);
102:
103: JLabel addressExampleLabel = new JLabel(MailResourceLoader
104: .getString("dialog", "accountwizard", "example")
105: + "mail.microsoft.com");
106: middlePanel.addExample(addressExampleLabel);
107: component.add(middlePanel);
108:
109: return component;
110: }
111:
112: public void prepareRendering() {
113: SwingUtilities.invokeLater(new Runnable() {
114: public void run() {
115: hostTextField.requestFocus();
116: }
117: });
118: }
119: }
|