001/* 002 * $Id$ 003 * 004 * Copyright 2009 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 * 021 */ 022package org.jdesktop.swingx.plaf; 023 024import java.awt.Color; 025import java.util.logging.Logger; 026 027import javax.swing.UIManager; 028import javax.swing.border.AbstractBorder; 029import javax.swing.border.Border; 030import javax.swing.plaf.UIResource; 031 032/** 033 * TODO add type doc 034 * 035 * @author Jeanette Winzenburg 036 */ 037public class TableAddon extends AbstractComponentAddon { 038 039 @SuppressWarnings("unused") 040 private static final Logger LOG = Logger.getLogger(TableAddon.class 041 .getName()); 042 043 /** 044 * @param name 045 */ 046 public TableAddon() { 047 super("JXTable"); 048 } 049 050 051 052 @Override 053 protected void addNimbusDefaults(LookAndFeelAddons addon, 054 DefaultsList defaults) { 055 super.addNimbusDefaults(addon, defaults); 056 // JW: Hacking around core issue #6882917 057 // which is the underlying reason for issue #1180-swingx 058 // (SwingX vs Nimbus table striping) 059 if (Boolean.TRUE.equals(UIManager.get("Nimbus.keepAlternateRowColor"))) return; 060 Object value = UIManager.getLookAndFeelDefaults().remove("Table.alternateRowColor"); 061 if (value instanceof Color) { 062 defaults.add("UIColorHighlighter.stripingBackground", value, false); 063 } 064 } 065 066 067 068 /** 069 * @inherited <p> 070 * 071 * PENDING JW: move to addLinuxDefaults after testing 072 */ 073 @Override 074 protected void addBasicDefaults(LookAndFeelAddons addon, 075 DefaultsList defaults) { 076 super.addBasicDefaults(addon, defaults); 077 if (isGTK()) { 078 replaceListTableBorders(addon, defaults); 079 } 080 } 081 082 private void replaceListTableBorders(LookAndFeelAddons addon, 083 DefaultsList defaults) { 084 replaceBorder(defaults, "Table.", "focusCellHighlightBorder"); 085 replaceBorder(defaults, "Table.", "focusSelectedCellHighlightBorder"); 086 replaceBorder(defaults, "Table.", "noFocusBorder"); 087 } 088 089 090 091 /** 092 * @param defaults 093 * @param componentPrefix 094 * @param borderKey 095 */ 096 private void replaceBorder(DefaultsList defaults, String componentPrefix, 097 String borderKey) { 098 String key = componentPrefix + borderKey; 099 Border border = UIManager.getBorder(componentPrefix + borderKey); 100 if (border instanceof AbstractBorder && border instanceof UIResource 101 && border.getClass().getName().contains("ListTable")) { 102 border = new SafeBorder((AbstractBorder) border); 103 // PENDING JW: this is fishy ... adding to lookAndFeelDefaults is taken 104 UIManager.getLookAndFeelDefaults().put(key, border); 105 // adding to defaults is not 106// defaults.add(key, border); 107 108 } 109 } 110 111 112 113 /** 114 * 115 * @return true if the LF is GTK. 116 */ 117 private boolean isGTK() { 118 return "GTK".equals(UIManager.getLookAndFeel().getID()); 119 } 120 121 122}