KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > composer > AccountView


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16

17 package org.columba.mail.gui.composer;
18
19 import java.awt.Component JavaDoc;
20
21 import javax.swing.ImageIcon JavaDoc;
22 import javax.swing.JComboBox JavaDoc;
23 import javax.swing.JLabel JavaDoc;
24 import javax.swing.JList JavaDoc;
25 import javax.swing.ListCellRenderer JavaDoc;
26
27 import org.columba.core.resourceloader.IconKeys;
28 import org.columba.core.resourceloader.ImageLoader;
29 import org.columba.mail.config.AccountItem;
30 import org.columba.ristretto.message.Address;
31
32 /**
33  * @author frd
34  *
35  * To change this generated comment edit the template variable "typecomment":
36  * Window>Preferences>Java>Templates.
37  * To enable and disable the creation of type comments go to
38  * Window>Preferences>Java>Code Generation.
39  */

40
41 public class AccountView extends JComboBox JavaDoc {
42     AccountController controller;
43
44     public AccountView(AccountController controller) {
45         super();
46         this.controller = controller;
47
48         setRenderer(new AccountListRenderer());
49     }
50 }
51
52
53  class AccountListRenderer extends JLabel JavaDoc implements ListCellRenderer JavaDoc {
54     protected ImageIcon JavaDoc image1;
55     protected ImageIcon JavaDoc image2;
56
57     public AccountListRenderer() {
58         setOpaque(true);
59         image1 = ImageLoader.getSmallIcon(IconKeys.COMPUTER);
60         image2 = ImageLoader.getSmallIcon(IconKeys.SERVER);
61     }
62
63     public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value,
64         int index, boolean isSelected, boolean cellHasFocus) {
65         if (isSelected) {
66             setBackground(list.getSelectionBackground());
67             setForeground(list.getSelectionForeground());
68         } else {
69             setBackground(list.getBackground());
70             setForeground(list.getForeground());
71         }
72
73         if (value != null) {
74             AccountItem item = (AccountItem) value;
75             String JavaDoc accountName = item.getName();
76             Address identity = item.getIdentity().getAddress();
77
78             setText(accountName + ": " + identity.toString());
79             //setText(accountName);
80

81             if (item.isPopAccount()) {
82                 setIcon(image1);
83             } else {
84                 setIcon(image2);
85             }
86         }
87
88         return this;
89     }
90 }
91
Popular Tags