001/* 002 * $Id: BusyLabelAddon.java 2565 2008-01-03 19:08:32Z rah003 $ 003 * 004 * Copyright 2004 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 javax.swing.UIManager; 024import javax.swing.border.AbstractBorder; 025import javax.swing.border.Border; 026import javax.swing.plaf.UIResource; 027 028import org.jdesktop.swingx.JXList; 029 030/** 031 * Addon for <code>JXList</code>. 032 * <p> 033 * 034 * Install a custom ui to support sorting/filtering in JXList. 035 */ 036public class XListAddon extends AbstractComponentAddon { 037 038 public XListAddon() { 039 super("JXList"); 040 } 041 042 @Override 043 protected void addBasicDefaults(LookAndFeelAddons addon, 044 DefaultsList defaults) { 045 defaults.add(JXList.uiClassID, 046 "org.jdesktop.swingx.plaf.basic.core.BasicXListUI"); 047 if (isGTK()) { 048 replaceListTableBorders(addon, defaults); 049 } 050 } 051 052 @Override 053 protected void addNimbusDefaults(LookAndFeelAddons addon, 054 DefaultsList defaults) { 055 defaults.add(JXList.uiClassID, 056 "org.jdesktop.swingx.plaf.synth.SynthXListUI"); 057 } 058 059 060 private void replaceListTableBorders(LookAndFeelAddons addon, 061 DefaultsList defaults) { 062 replaceBorder(defaults, "List.", "focusCellHighlightBorder"); 063 replaceBorder(defaults, "List.", "focusSelectedCellHighlightBorder"); 064 replaceBorder(defaults, "List.", "noFocusBorder"); 065 } 066 067 068 069 /** 070 * @param defaults 071 * @param componentPrefix 072 * @param borderKey 073 */ 074 private void replaceBorder(DefaultsList defaults, String componentPrefix, 075 String borderKey) { 076 String key = componentPrefix + borderKey; 077 Border border = UIManager.getBorder(componentPrefix + borderKey); 078 if (border instanceof AbstractBorder && border instanceof UIResource 079 && border.getClass().getName().contains("ListTable")) { 080 border = new SafeBorder((AbstractBorder) border); 081 // PENDING JW: this is fishy ... adding to lookAndFeelDefaults is taken 082 UIManager.getLookAndFeelDefaults().put(key, border); 083 // adding to defaults is not 084// defaults.add(key, border); 085 086 } 087 } 088 089 090 091 /** 092 * 093 * @return true if the LF is GTK. 094 */ 095 private boolean isGTK() { 096 return "GTK".equals(UIManager.getLookAndFeel().getID()); 097 } 098 099 100}