KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > jmailadmin > gui > AccountPanel


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.jmailadmin.gui;
20
21 import javax.swing.*;
22
23 import org.lucane.applications.jmailadmin.Account;
24 import org.lucane.applications.jmailadmin.JMailAdminPlugin;
25
26 import java.awt.*;
27
28 public class AccountPanel extends JPanel
29 {
30     private JMailAdminPlugin plugin;
31     
32     private Account account;
33
34     private JTextField address;
35     private JComboBox type;
36     private JTextField inHost;
37     private JTextField inPort;
38     private JTextField outHost;
39     private JTextField outPort;
40     private JTextField login;
41     private JPasswordField password;
42     private JTextField refreshInterval;
43
44     public AccountPanel(JMailAdminPlugin plugin)
45     {
46         super(new BorderLayout());
47         this.plugin = plugin;
48         
49         this.address = new JTextField();
50         this.type = new JComboBox();
51         this.type.addItem("imap");
52         
53         //-- we don't want pop
54
//this.type.addItem("pop3");
55

56 // this.type.addActionListener(this);
57
this.inHost = new JTextField();
58         this.inPort = new JTextField("143");
59         this.outHost = new JTextField();
60         this.outPort = new JTextField("25");
61         this.login = new JTextField();
62         this.password = new JPasswordField();
63         this.refreshInterval = new JTextField("5");
64         
65         JPanel labels = new JPanel(new GridLayout(9, 1));
66         labels.add(new JLabel(tr("address")));
67         labels.add(new JLabel(tr("type")));
68         labels.add(new JLabel(tr("inHost")));
69         labels.add(new JLabel(tr("inPort")));
70         labels.add(new JLabel(tr("outHost")));
71         labels.add(new JLabel(tr("outPort")));
72         labels.add(new JLabel(tr("login")));
73         labels.add(new JLabel(tr("password")));
74         labels.add(new JLabel(tr("refreshInterval")));
75
76         JPanel fields = new JPanel(new GridLayout(9, 1));
77         fields.add(this.address);
78         fields.add(this.type);
79         fields.add(this.inHost);
80         fields.add(this.inPort);
81         fields.add(this.outHost);
82         fields.add(this.outPort);
83         fields.add(this.login);
84         fields.add(this.password);
85         fields.add(this.refreshInterval);
86     
87         this.add(labels, BorderLayout.WEST);
88         this.add(fields, BorderLayout.CENTER);
89     }
90     
91     public void setAccount(Account a)
92     {
93         if(a == null)
94             return;
95
96         this.account = a;
97         
98         this.address.setText(a.address);
99         this.type.setSelectedItem(a.type);
100         this.inHost.setText(a.inHost);
101         this.inPort.setText(""+a.inPort);
102         this.outHost.setText(a.outHost);
103         this.outPort.setText(""+a.outPort);
104         this.login.setText(a.login);
105         this.password.setText(a.password);
106         this.refreshInterval.setText(""+a.refreshInterval);
107     }
108     
109     public void applyTemplate(Account a)
110     {
111         if(a == null)
112             return;
113         
114         //always copy
115
this.type.setSelectedItem(a.type);
116         this.inHost.setText(a.inHost);
117         this.inPort.setText(""+a.inPort);
118         this.outHost.setText(a.outHost);
119         this.outPort.setText(""+a.outPort);
120         this.refreshInterval.setText("" + a.refreshInterval);
121         
122         //copy if user matches login
123
if(a.user.equals(a.login))
124             this.login.setText(this.account.user);
125         
126         //copy if user matches email
127
if(a.address.startsWith(a.user +"@"))
128         {
129             this.address.setText(this.account.user
130                     + a.address.substring(a.address.indexOf('@')));
131         }
132     }
133
134     public Account getAccount()
135     {
136         int inPort = Integer.parseInt(this.inPort.getText());
137         int outPort = Integer.parseInt(this.outPort.getText());
138         int refreshInterval = Integer.parseInt(this.refreshInterval.getText());
139
140         return new Account(
141             account.user,
142             address.getText(),
143             (String JavaDoc)type.getSelectedItem(),
144             inHost.getText(),
145             inPort,
146             outHost.getText(),
147             outPort,
148             login.getText(),
149             new String JavaDoc(password.getPassword()),
150             refreshInterval);
151     }
152
153     private String JavaDoc tr(String JavaDoc s)
154     {
155         return plugin.tr(s);
156     }
157 }
Popular Tags