01: /*
02: * The contents of this file are subject to the Mozilla Public License
03: * Version 1.1 (the "License"); you may not use this file except in
04: * compliance with the License. You may obtain a copy of the License at
05: * http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
09: * License for the specific language governing rights and limitations
10: * under the License.
11: *
12: * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
13: *
14: * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
15: * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
16: *
17: * Contributor(s):
18: * Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
19: *
20: * If you didn't download this code from the following link, you should check
21: * if you aren't using an obsolete version: http://www.isqlviewer.com
22: */
23: package org.isqlviewer.ui.laf;
24:
25: import java.awt.Color;
26: import java.awt.Component;
27:
28: import javax.swing.DefaultListCellRenderer;
29: import javax.swing.Icon;
30: import javax.swing.JList;
31:
32: import org.isqlviewer.swing.SwingUtilities;
33:
34: /**
35: * TODO Add EnhancedListCellRenderer JavaDoc inforamation
36: * <p>
37: *
38: * @author Mark A. Kobold <mkobold at isqlviewer dot com>
39: * @version 1.0
40: */
41: public class EnhancedListCellRenderer extends DefaultListCellRenderer {
42:
43: private static final long serialVersionUID = 8343296588805753937L;
44:
45: public Icon getIcon(Object aObject) {
46:
47: if (aObject == null) {
48: setHorizontalAlignment(CENTER);
49: } else {
50: setHorizontalAlignment(LEFT);
51: }
52: return aObject == null ? SwingUtilities.loadIconResource(
53: "unavailable", 16) : null;
54: }
55:
56: public String getText(Object aObject) {
57:
58: return aObject == null ? null : aObject.toString();
59: }
60:
61: @Override
62: public Component getListCellRendererComponent(JList list,
63: Object value, int row, boolean isSelected,
64: boolean cellHasFocus) {
65:
66: super .getListCellRendererComponent(list, value, row,
67: isSelected, cellHasFocus);
68: if (isSelected) {
69: if (list.hasFocus()) {
70: setBackground(EnhancedTableCellRenderer.selectedFocusedColor);
71: setForeground(Color.WHITE);
72: } else {
73: setBackground(EnhancedTableCellRenderer.selectedNotFocusedColor);
74: setForeground(Color.BLACK);
75: }
76: } else {
77: Color color = row % 2 == 0 ? EnhancedTableCellRenderer.evenRowColor
78: : EnhancedTableCellRenderer.oddRowColor;
79: setBackground(color);
80: setForeground(Color.BLACK);
81: }
82: setText(getText(value));
83: setIcon(getIcon(value));
84: return this;
85: }
86:
87: }
|