2
* Copyright (c) 2005-2010 Substance Kirill Grouchnikov. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
10
* o Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
14
* o Neither the name of Substance Kirill Grouchnikov nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
package org.pushingpixels.substance.internal.utils;
32
import java.awt.Color;
34
import javax.swing.JComponent;
36
import org.pushingpixels.substance.internal.ui.SubstanceTableUI;
40
* This class is used to speed up the striping of lists, tables, trees and
41
* comboboxes that use Substance default renderers. This class if for internal
49
* <li>Call {@link #setup(JComponent)} before starting painting the component
51
* {@link SubstanceTableUI#paint(java.awt.Graphics, JComponent)} that should
52
* call this method prior to the call to its <code>paintCells</code>.</li>
53
* <li>The specific renderer should call
54
* {@link #applyStripedBackground(JComponent, int, JComponent)}.</li>
55
* <li>After all cells have been renderered, call {@link #tearDown(JComponent)}.
58
* @author Kirill Grouchnikov
60
public class SubstanceStripingUtils {
62
* Name of the client property that stores the background fill color of odd
63
* rows. The value should be an instance of {@link Color}.
65
private static final String ODD_COLOR = "substancelaf.internal.stripingColor.odd";
68
* Name of the client property that stores the background fill color of even
69
* rows. The value should be an instance of {@link Color}.
71
private static final String EVEN_COLOR = "substancelaf.internal.stripingColor.even";
74
* Sets up the specified component for the UI delegate striping.
79
public static void setup(JComponent comp) {
80
comp.putClientProperty(EVEN_COLOR, SubstanceColorUtilities
81
.getStripedBackground(comp, 0));
82
comp.putClientProperty(ODD_COLOR, SubstanceColorUtilities
83
.getStripedBackground(comp, 1));
87
* Cleans the component after the UI delegate striping is over.
90
* Component. Should be the same as passed to
91
* {@link #setup(JComponent)
94
public static void tearDown(JComponent comp) {
95
comp.putClientProperty(EVEN_COLOR, null);
96
comp.putClientProperty(ODD_COLOR, null);
100
* Applies the striped background to the specified renderer.
103
* Component (should be the same as passed to
104
* {@link #setup(JComponent)
109
* Renderer component.
111
public static void applyStripedBackground(JComponent component,
112
int rowIndex, JComponent renderer) {
113
Color backgr = (Color) component
114
.getClientProperty((rowIndex % 2) == 0 ? EVEN_COLOR : ODD_COLOR);
117
renderer.setBackground(backgr);