KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > jmailaccount > AccountFrame


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.jmailaccount;
20
21 import javax.swing.*;
22 import java.awt.*;
23 import java.awt.event.*;
24
25 import org.lucane.client.Client;
26 import org.lucane.client.widgets.ManagedWindow;
27
28
29
30 public class AccountFrame extends ManagedWindow
31 implements ActionListener
32 {
33     private JMailAccountPlugin plugin;
34     
35     private JTextField address;
36     private JComboBox type;
37     private JTextField inHost;
38     private JTextField inPort;
39     private JTextField outHost;
40     private JTextField outPort;
41     private JTextField login;
42     private JPasswordField password;
43     private JTextField refreshInterval;
44
45     private JButton btnOk;
46     private JButton btnCancel;
47     
48     public AccountFrame(JMailAccountPlugin plugin)
49     {
50         super(plugin, plugin.getTitle());
51         this.plugin = plugin;
52         
53         getContentPane().setLayout(new BorderLayout());
54         setExitPluginOnClose(true);
55         this.address = new JTextField();
56         this.type = new JComboBox();
57         this.type.addItem("imap");
58         
59         //-- we don't want pop
60
//this.type.addItem("pop3");
61

62         this.type.addActionListener(this);
63         this.inHost = new JTextField();
64         this.inPort = new JTextField("143");
65         this.outHost = new JTextField();
66         this.outPort = new JTextField("25");
67         this.login = new JTextField();
68         this.password = new JPasswordField();
69         this.refreshInterval = new JTextField("5");
70
71         this.btnOk = new JButton(tr("ok"), Client.getImageIcon("ok.png"));
72         this.btnOk.addActionListener(this);
73         this.btnCancel = new JButton(tr("cancel"), Client.getImageIcon("cancel.png"));
74         this.btnCancel.addActionListener(this);
75         
76         JPanel labels = new JPanel(new GridLayout(9, 1));
77         labels.add(new JLabel(tr("address")));
78         labels.add(new JLabel(tr("type")));
79         labels.add(new JLabel(tr("inHost")));
80         labels.add(new JLabel(tr("inPort")));
81         labels.add(new JLabel(tr("outHost")));
82         labels.add(new JLabel(tr("outPort")));
83         labels.add(new JLabel(tr("login")));
84         labels.add(new JLabel(tr("password")));
85         labels.add(new JLabel(tr("refreshInterval")));
86
87         JPanel fields = new JPanel(new GridLayout(9, 1));
88         fields.add(this.address);
89         fields.add(this.type);
90         fields.add(this.inHost);
91         fields.add(this.inPort);
92         fields.add(this.outHost);
93         fields.add(this.outPort);
94         fields.add(this.login);
95         fields.add(this.password);
96         fields.add(this.refreshInterval);
97
98         JPanel buttons = new JPanel(new BorderLayout());
99         JPanel buttons2 = new JPanel(new GridLayout(1, 2));
100         buttons2.add(this.btnCancel);
101         buttons2.add(this.btnOk);
102         buttons.add(buttons2, BorderLayout.EAST);
103
104         getContentPane().add(labels, BorderLayout.WEST);
105         getContentPane().add(fields, BorderLayout.CENTER);
106         getContentPane().add(buttons, BorderLayout.SOUTH);
107     }
108     
109     public void setAccount(Account a)
110     {
111         if(a == null)
112             return;
113
114         this.address.setText(a.address);
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.login.setText(a.login);
121         this.password.setText(a.password);
122         this.refreshInterval.setText("" + a.refreshInterval);
123     }
124
125     public Account getAccount()
126     {
127         int inPort = Integer.parseInt(this.inPort.getText());
128         int outPort = Integer.parseInt(this.outPort.getText());
129         int refreshInterval = Integer.parseInt(this.refreshInterval.getText());
130
131         return new Account(
132             address.getText(),
133             (String JavaDoc)type.getSelectedItem(),
134             inHost.getText(),
135             inPort,
136             outHost.getText(),
137             outPort,
138             login.getText(),
139             new String JavaDoc(password.getPassword()),
140             refreshInterval);
141     }
142
143     public void actionPerformed(ActionEvent ae)
144     {
145         if(ae.getSource() == btnCancel)
146         {
147             plugin.exit();
148             dispose();
149         }
150         else if(ae.getSource() == btnOk)
151         {
152             if(plugin.storeAccount(getAccount()))
153             {
154                 plugin.exit();
155                 dispose();
156             }
157         }
158         else if(ae.getSource() == type)
159         {
160             if(type.getSelectedItem().equals("imap"))
161                 inPort.setText("143");
162             else if(type.getSelectedItem().equals("pop3"))
163                 inPort.setText("110");
164         }
165     }
166     
167     private String JavaDoc tr(String JavaDoc s)
168     {
169         return plugin.tr(s);
170     }
171 }
Popular Tags