01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
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;
20:
21: import javax.swing.ImageIcon;
22: import javax.swing.JComboBox;
23: import javax.swing.JLabel;
24: import javax.swing.JList;
25: import javax.swing.ListCellRenderer;
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 {
42: AccountController controller;
43:
44: public AccountView(AccountController controller) {
45: super ();
46: this .controller = controller;
47:
48: setRenderer(new AccountListRenderer());
49: }
50: }
51:
52: class AccountListRenderer extends JLabel implements ListCellRenderer {
53: protected ImageIcon image1;
54: protected ImageIcon image2;
55:
56: public AccountListRenderer() {
57: setOpaque(true);
58: image1 = ImageLoader.getSmallIcon(IconKeys.COMPUTER);
59: image2 = ImageLoader.getSmallIcon(IconKeys.SERVER);
60: }
61:
62: public Component getListCellRendererComponent(JList list,
63: Object value, int index, boolean isSelected,
64: 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 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: }
|