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.addressbook.gui.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.gui.util.ToolTipFactory;
28: import org.columba.addressbook.model.ContactModelPartial;
29: import org.columba.addressbook.model.GroupModelPartial;
30: import org.columba.addressbook.model.BasicModelPartial;
31: import org.columba.addressbook.resourceloader.IconKeys;
32: import org.columba.core.resourceloader.ImageLoader;
33:
34: @SuppressWarnings({"serial","serial"})
35: public class AddressbookListRenderer extends JLabel implements
36: ListCellRenderer {
37: ImageIcon image1 = ImageLoader.getSmallIcon(IconKeys.EDIT_CONTACT);
38:
39: ImageIcon image2 = ImageLoader
40: .getSmallIcon(org.columba.core.resourceloader.IconKeys.USER);
41:
42: public AddressbookListRenderer() {
43: setOpaque(true);
44: setHorizontalAlignment(LEFT);
45: setVerticalAlignment(CENTER);
46: }
47:
48: public Component getListCellRendererComponent(JList list,
49: Object value, int index, boolean isSelected,
50: boolean cellHasFocus) {
51: if (isSelected) {
52: setBackground(list.getSelectionBackground());
53: setForeground(list.getSelectionForeground());
54: } else {
55: setBackground(list.getBackground());
56: setForeground(list.getForeground());
57: }
58:
59: BasicModelPartial item = (BasicModelPartial) value;
60:
61: setText(item.getName());
62:
63: if (item.isContact()) {
64: setIcon(image1);
65: setToolTipText(ToolTipFactory
66: .createToolTip((ContactModelPartial) item));
67:
68: } else {
69: setIcon(image2);
70: setToolTipText(ToolTipFactory
71: .createToolTip((GroupModelPartial) item));
72:
73: }
74:
75: return this;
76: }
77:
78: }
|