01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //limitations under the License.
10: //
11: //The Original Code is "The Columba Project"
12: //
13: //The Initial Developers of the Original Code are Frederik Dietz and Timo
14: // Stich.
15: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16: //
17: //All Rights Reserved.
18: package org.columba.mail.gui.contact.list;
19:
20: import java.awt.Component;
21:
22: import javax.swing.ImageIcon;
23: import javax.swing.JLabel;
24: import javax.swing.JList;
25: import javax.swing.ListCellRenderer;
26:
27: import org.columba.addressbook.facade.IHeaderItem;
28: import org.columba.core.resourceloader.ImageLoader;
29: import org.columba.mail.resourceloader.MailImageLoader;
30:
31: public class ContactListRenderer extends JLabel implements
32: ListCellRenderer {
33: ImageIcon image1 = MailImageLoader.getSmallIcon("contact-new.png");
34:
35: ImageIcon image2 = ImageLoader
36: .getSmallIcon(org.columba.core.resourceloader.IconKeys.USER);
37:
38: public ContactListRenderer() {
39: setOpaque(true);
40: setHorizontalAlignment(LEFT);
41: setVerticalAlignment(CENTER);
42: }
43:
44: public Component getListCellRendererComponent(JList list,
45: Object value, int index, boolean isSelected,
46: boolean cellHasFocus) {
47: if (isSelected) {
48: setBackground(list.getSelectionBackground());
49: setForeground(list.getSelectionForeground());
50: } else {
51: setBackground(list.getBackground());
52: setForeground(list.getForeground());
53: }
54:
55: IHeaderItem item = (IHeaderItem) value;
56:
57: setText(item.getName());
58:
59: if (item.isContact())
60: setIcon(image1);
61: else
62: setIcon(image2);
63:
64: setToolTipText(HeaderItemToolTipFactory.createToolTip(item));
65:
66: return this;
67: }
68:
69: }
|