001/* 002 * $Id: ShadingColorHighlighter.java 3100 2008-10-14 22:33:10Z rah003 $ 003 * 004 * Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle, 005 * Santa Clara, California 95054, U.S.A. All rights reserved. 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 020 */ 021package org.jdesktop.swingx.decorator; 022 023import java.awt.Color; 024import java.awt.Component; 025 026/** 027 * Experimental replacement of HierarchicalColumnHighligher. 028 * Darkens the component's background. 029 * 030 * @author Jeanette Winzenburg 031 */ 032public class ShadingColorHighlighter extends ColorHighlighter { 033 034 /** 035 * Instantiates a Highlighter with null colors using the default 036 * HighlightPredicate. 037 * 038 */ 039 public ShadingColorHighlighter() { 040 this(null); 041 } 042 043 /** 044 * Instantiates a Highlighter with null colors using the specified 045 * HighlightPredicate. 046 * 047 * @param predicate the HighlightPredicate to use. 048 */ 049 public ShadingColorHighlighter(HighlightPredicate predicate) { 050 super(predicate, null, null); 051 } 052 053 /** 054 * Applies a suitable background for the renderer component within the 055 * specified adapter. <p> 056 * 057 * This implementation applies its a darkened background to an unselected 058 * adapter. Does nothing for selected cells. 059 * 060 * @param renderer the cell renderer component that is to be decorated 061 * @param adapter the ComponentAdapter for this decorate operation 062 */ 063 @Override 064 protected void applyBackground(Component renderer, ComponentAdapter adapter) { 065 if (adapter.isSelected()) 066 return; 067 // PENDING JW: really? That would be applying a absolute color, instead 068 // of shading whatever the renderer has. 069 Color background = getBackground(); 070 if (background == null) { 071 background = renderer.getBackground(); 072 } 073 // Change to the following 074// Color background = renderer.getBackground(); 075 if (background != null) { 076 renderer.setBackground(computeBackgroundSeed(background)); 077 } 078 } 079 080 protected Color computeBackgroundSeed(Color seed) { 081 return new Color(Math.max((int) (seed.getRed() * 0.95), 0), Math.max( 082 (int) (seed.getGreen() * 0.95), 0), Math.max((int) (seed 083 .getBlue() * 0.95), 0)); 084 } 085 086}