001/* 002 * $Id: UIColorHighlighterAddon.java 3513 2009-09-22 11:18:09Z kleopatra $ 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.plaf; 022 023import java.awt.Color; 024import java.util.logging.Logger; 025 026import javax.swing.UIManager; 027import javax.swing.plaf.ColorUIResource; 028import javax.swing.plaf.metal.MetalLookAndFeel; 029import javax.swing.plaf.metal.OceanTheme; 030 031import org.jdesktop.swingx.plaf.windows.WindowsLookAndFeelAddons; 032import org.jdesktop.swingx.util.OS; 033 034/** 035 * Loads LF specific background striping colors. 036 * 037 * The colors are based on the LF selection colors for certain 038 * LFs and themes, for unknown LFs/themes a generic grey is used. 039 * 040 * 041 * @author Jeanette Winzenburg 042 * @author Karl Schaefer 043 */ 044public class UIColorHighlighterAddon extends AbstractComponentAddon { 045 046 @SuppressWarnings("unused") 047 private static final Logger LOG = Logger 048 .getLogger(UIColorHighlighterAddon.class.getName()); 049 050 public UIColorHighlighterAddon() { 051 super("UIColorHighlighter"); 052 } 053 054 /** 055 * {@inheritDoc} 056 */ 057 @Override 058 protected void addBasicDefaults(LookAndFeelAddons addon, DefaultsList defaults) { 059 super.addBasicDefaults(addon, defaults); 060 061 defaults.add("UIColorHighlighter.stripingBackground", new ColorUIResource(229, 229, 229)); 062 } 063 064 /** 065 * {@inheritDoc} 066 */ 067 @Override 068 protected void addMacDefaults(LookAndFeelAddons addon, DefaultsList defaults) { 069 super.addMacDefaults(addon, defaults); 070 071 defaults.add("UIColorHighlighter.stripingBackground", new ColorUIResource(237, 243, 254)); 072 } 073 074 /** 075 * {@inheritDoc} 076 */ 077 @Override 078 protected void addMetalDefaults(LookAndFeelAddons addon, DefaultsList defaults) { 079 super.addMetalDefaults(addon, defaults); 080 081 if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme) { 082 defaults.add("UIColorHighlighter.stripingBackground", new ColorUIResource(230, 238, 246)); 083 } else { 084 defaults.add("UIColorHighlighter.stripingBackground", new ColorUIResource(235, 235, 255)); 085 } 086 } 087 088 /** 089 * {@inheritDoc} 090 */ 091 @Override 092 protected void addWindowsDefaults(LookAndFeelAddons addon, DefaultsList defaults) { 093 super.addWindowsDefaults(addon, defaults); 094 095 if (OS.isUsingWindowsVisualStyles()) { 096 String xpStyle = OS.getWindowsVisualStyle(); 097 098 if (WindowsLookAndFeelAddons.HOMESTEAD_VISUAL_STYLE 099 .equalsIgnoreCase(xpStyle)) { 100 defaults.add("UIColorHighlighter.stripingBackground", new ColorUIResource(228, 231, 219)); 101 } else if (WindowsLookAndFeelAddons.SILVER_VISUAL_STYLE 102 .equalsIgnoreCase(xpStyle)) { 103 defaults.add("UIColorHighlighter.stripingBackground", new ColorUIResource(235, 235, 236)); 104 } else { 105 // default blue 106 defaults.add("UIColorHighlighter.stripingBackground", new ColorUIResource(224, 233, 246)); 107 } 108 109 } else { 110 defaults.add("UIColorHighlighter.stripingBackground", new ColorUIResource(218, 222, 233)); 111 } 112 } 113 114 @Override 115 protected void addNimbusDefaults(LookAndFeelAddons addon, 116 DefaultsList defaults) { 117 super.addNimbusDefaults(addon, defaults); 118 // JW: Hacking around core issue #6882917 119 // which is the underlying reason for issue #1180-swingx 120 // (SwingX vs Nimbus table striping) 121 if (Boolean.TRUE.equals(UIManager.get("Nimbus.keepAlternateRowColor"))) return; 122 // PENDING JW: not entirely sure if it is safe to really grab the color here 123 // the Nimbus (Derived)Color is not yet fully installed at this moment 124 // so without a table to instantiate may be rgb = 0,0,0 125 Object value = UIManager.getLookAndFeelDefaults().remove("Table.alternateRowColor"); 126 if (value instanceof Color) { 127 defaults.add("UIColorHighlighter.stripingBackground", value, false); 128 } 129 } 130 131 132}