001/*
002 * $Id: DefaultXTreeCellRenderer.java 3304 2009-03-20 15:11:25Z kleopatra $
003 *
004 * Copyright 2007 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.tree;
023
024import javax.swing.UIManager;
025import javax.swing.tree.DefaultTreeCellRenderer;
026
027import org.jdesktop.swingx.SwingXUtilities;
028
029/**
030 * Quick fix for #1061-swingx (which actually is a core issue): 
031 * tree icons lost on toggle laf. Updates colors as well -
032 * but beware: this is incomplete as some of super's properties are private!
033 * 
034 * Will not do more because in the longer run (as soon as we've fixed the editor issues) 
035 * the JXTree's default renderer will be changed to SwingX DefaultTreeRenderer.
036 * 
037 * @author Jeanette Winzenburg
038 */
039public class DefaultXTreeCellRenderer extends DefaultTreeCellRenderer {
040
041    /**
042     * {@inheritDoc} <p>
043     * 
044     * Overridden to update icons and colors.
045     */
046    @Override
047    public void updateUI() {
048        super.updateUI();
049        updateIcons();
050        updateColors();
051    }
052
053    /**
054     * 
055     */
056    protected void updateColors() {
057        if (SwingXUtilities.isUIInstallable(getTextSelectionColor())) {
058            setTextSelectionColor(UIManager.getColor("Tree.selectionForeground"));
059        }
060        if (SwingXUtilities.isUIInstallable(getTextNonSelectionColor())) {
061            setTextNonSelectionColor(UIManager.getColor("Tree.textForeground"));
062        }
063        if (SwingXUtilities.isUIInstallable(getBackgroundSelectionColor())) {
064            setBackgroundSelectionColor(UIManager.getColor("Tree.selectionBackground"));
065        }
066        if (SwingXUtilities.isUIInstallable(getBackgroundNonSelectionColor())) {
067            setBackgroundNonSelectionColor(UIManager.getColor("Tree.textBackground"));
068        }
069        if (SwingXUtilities.isUIInstallable(getBorderSelectionColor())) {
070            setBorderSelectionColor(UIManager.getColor("Tree.selectionBorderColor"));
071        }
072//        Object value = UIManager.get("Tree.drawsFocusBorderAroundIcon");
073//        drawsFocusBorderAroundIcon = (value != null && ((Boolean)value).
074//                                      booleanValue());
075//        value = UIManager.get("Tree.drawDashedFocusIndicator");
076//        drawDashedFocusIndicator = (value != null && ((Boolean)value).
077//                                    booleanValue());
078    }
079
080    /**
081     * 
082     */
083    protected void updateIcons() {
084        if (SwingXUtilities.isUIInstallable(getLeafIcon())) {
085            setLeafIcon(UIManager.getIcon("Tree.leafIcon"));
086        }
087        if (SwingXUtilities.isUIInstallable(getClosedIcon())) {
088            setClosedIcon(UIManager.getIcon("Tree.closedIcon"));
089        }
090        if (SwingXUtilities.isUIInstallable(getOpenIcon())) {
091            setOpenIcon(UIManager.getIcon("Tree.openIcon"));
092        }
093
094    }
095    
096    
097
098}