01: /*
02: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
07: *
08: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
09: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
10: * the license for the specific language governing your rights and limitations.
11: *
12: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
13: */
14: package org.pentaho.reportdesigner.lib.client.components.tabbedpane;
15:
16: import org.jetbrains.annotations.NotNull;
17: import org.pentaho.reportdesigner.lib.client.components.Category;
18:
19: import javax.swing.*;
20: import javax.swing.border.Border;
21: import javax.swing.border.EmptyBorder;
22: import java.awt.*;
23:
24: /**
25: * User: Martin
26: * Date: 14.03.2005
27: * Time: 17:34:17
28: */
29: public class ListTabbedPaneListCellRenderer extends
30: DefaultListCellRenderer {
31: @NotNull
32: private static final Border EMPTY_BORDER = new EmptyBorder(10, 5,
33: 10, 5);
34:
35: public ListTabbedPaneListCellRenderer() {
36: }
37:
38: @NotNull
39: public Component getListCellRendererComponent(@NotNull
40: JList list, @NotNull
41: Object value, int index, boolean isSelected, boolean cellHasFocus) {
42: setComponentOrientation(list.getComponentOrientation());
43: if (isSelected) {
44: setBackground(list.getSelectionBackground());
45: setForeground(list.getSelectionForeground());
46: } else {
47: setBackground(list.getBackground());
48: setForeground(list.getForeground());
49: }
50:
51: if (value instanceof Category) {
52: Category<?> category = (Category<?>) value;
53: setText(category.getTitle());
54: setIcon(category.getIconBig());
55: }
56:
57: setHorizontalTextPosition(JLabel.CENTER);
58: setVerticalTextPosition(JLabel.BOTTOM);
59:
60: setHorizontalAlignment(JLabel.CENTER);
61:
62: setEnabled(list.isEnabled());
63: setFont(list.getFont());
64: setBorder(EMPTY_BORDER);
65:
66: Dimension ms = getPreferredSize();
67: if (ms.width < 80) {
68: ms.width = 80;
69: setPreferredSize(ms);
70: } else {
71: setPreferredSize(null);
72: }
73:
74: return this;
75: }
76: }
|