001: /*
002: * Lucane - a collaborative platform
003: * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019: package org.lucane.applications.jmailadmin.gui;
020:
021: import javax.swing.*;
022:
023: import org.lucane.applications.jmailadmin.Account;
024: import org.lucane.applications.jmailadmin.JMailAdminPlugin;
025:
026: import java.awt.*;
027:
028: public class AccountPanel extends JPanel {
029: private JMailAdminPlugin plugin;
030:
031: private Account account;
032:
033: private JTextField address;
034: private JComboBox type;
035: private JTextField inHost;
036: private JTextField inPort;
037: private JTextField outHost;
038: private JTextField outPort;
039: private JTextField login;
040: private JPasswordField password;
041: private JTextField refreshInterval;
042:
043: public AccountPanel(JMailAdminPlugin plugin) {
044: super (new BorderLayout());
045: this .plugin = plugin;
046:
047: this .address = new JTextField();
048: this .type = new JComboBox();
049: this .type.addItem("imap");
050:
051: //-- we don't want pop
052: //this.type.addItem("pop3");
053:
054: // this.type.addActionListener(this);
055: this .inHost = new JTextField();
056: this .inPort = new JTextField("143");
057: this .outHost = new JTextField();
058: this .outPort = new JTextField("25");
059: this .login = new JTextField();
060: this .password = new JPasswordField();
061: this .refreshInterval = new JTextField("5");
062:
063: JPanel labels = new JPanel(new GridLayout(9, 1));
064: labels.add(new JLabel(tr("address")));
065: labels.add(new JLabel(tr("type")));
066: labels.add(new JLabel(tr("inHost")));
067: labels.add(new JLabel(tr("inPort")));
068: labels.add(new JLabel(tr("outHost")));
069: labels.add(new JLabel(tr("outPort")));
070: labels.add(new JLabel(tr("login")));
071: labels.add(new JLabel(tr("password")));
072: labels.add(new JLabel(tr("refreshInterval")));
073:
074: JPanel fields = new JPanel(new GridLayout(9, 1));
075: fields.add(this .address);
076: fields.add(this .type);
077: fields.add(this .inHost);
078: fields.add(this .inPort);
079: fields.add(this .outHost);
080: fields.add(this .outPort);
081: fields.add(this .login);
082: fields.add(this .password);
083: fields.add(this .refreshInterval);
084:
085: this .add(labels, BorderLayout.WEST);
086: this .add(fields, BorderLayout.CENTER);
087: }
088:
089: public void setAccount(Account a) {
090: if (a == null)
091: return;
092:
093: this .account = a;
094:
095: this .address.setText(a.address);
096: this .type.setSelectedItem(a.type);
097: this .inHost.setText(a.inHost);
098: this .inPort.setText("" + a.inPort);
099: this .outHost.setText(a.outHost);
100: this .outPort.setText("" + a.outPort);
101: this .login.setText(a.login);
102: this .password.setText(a.password);
103: this .refreshInterval.setText("" + a.refreshInterval);
104: }
105:
106: public void applyTemplate(Account a) {
107: if (a == null)
108: return;
109:
110: //always copy
111: this .type.setSelectedItem(a.type);
112: this .inHost.setText(a.inHost);
113: this .inPort.setText("" + a.inPort);
114: this .outHost.setText(a.outHost);
115: this .outPort.setText("" + a.outPort);
116: this .refreshInterval.setText("" + a.refreshInterval);
117:
118: //copy if user matches login
119: if (a.user.equals(a.login))
120: this .login.setText(this .account.user);
121:
122: //copy if user matches email
123: if (a.address.startsWith(a.user + "@")) {
124: this .address.setText(this .account.user
125: + a.address.substring(a.address.indexOf('@')));
126: }
127: }
128:
129: public Account getAccount() {
130: int inPort = Integer.parseInt(this .inPort.getText());
131: int outPort = Integer.parseInt(this .outPort.getText());
132: int refreshInterval = Integer.parseInt(this .refreshInterval
133: .getText());
134:
135: return new Account(account.user, address.getText(),
136: (String) type.getSelectedItem(), inHost.getText(),
137: inPort, outHost.getText(), outPort, login.getText(),
138: new String(password.getPassword()), refreshInterval);
139: }
140:
141: private String tr(String s) {
142: return plugin.tr(s);
143: }
144: }
|