001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008 Sun Microsystems, Inc. 015 * Portions Copyright 2015 ForgeRock AS. 016 */ 017 018package org.opends.guitools.controlpanel.ui.renderer; 019 020import java.awt.Color; 021import java.awt.Component; 022 023import javax.swing.BorderFactory; 024import javax.swing.JTree; 025import javax.swing.border.Border; 026import javax.swing.tree.DefaultTreeCellRenderer; 027 028import org.opends.guitools.controlpanel.ui.ColorAndFontConstants; 029 030/** 031 * An extension of the DefaultTreeCellRenderer that uses a customized border, 032 * foreground and background. 033 * 034 */ 035public class TreeCellRenderer extends DefaultTreeCellRenderer 036{ 037 private static final long serialVersionUID = 4045260951231311206L; 038 039 /** 040 * Background when the cell is not selected. 041 */ 042 public static final Color nonselectionBackground = 043 ColorAndFontConstants.background; 044 private static final Color nonselectionForeground = 045 ColorAndFontConstants.foreground; 046 047 /** 048 * Background when the cell is selected. 049 */ 050 public static final Color selectionBackground = 051 ColorAndFontConstants.mouseOverBackground; 052 053 private static final Color selectionForeground = 054 ColorAndFontConstants.mouseOverForeground; 055 056 057 private Border rootBorder = BorderFactory.createEmptyBorder(0, 5, 0, 0); 058 private Border normalBorder = BorderFactory.createEmptyBorder(0, 0, 0, 0); 059 060 /** Constructor of the renderer. */ 061 public TreeCellRenderer() 062 { 063 backgroundNonSelectionColor = nonselectionBackground; 064 backgroundSelectionColor = selectionBackground; 065 textNonSelectionColor = nonselectionForeground; 066 textSelectionColor = selectionForeground; 067 setFont(ColorAndFontConstants.treeFont); 068 } 069 070 /** {@inheritDoc} */ 071 public Component getTreeCellRendererComponent(JTree tree, Object value, 072 boolean isSelected, boolean isExpanded, boolean isLeaf, int row, 073 boolean hasFocus) 074 { 075 super.getTreeCellRendererComponent(tree, value, isSelected, isExpanded, 076 isLeaf, row, hasFocus); 077 setIcon(null); 078 079 if (row == 0 && tree.isRootVisible()) 080 { 081 setBorder(rootBorder); 082 } 083 else 084 { 085 setBorder(normalBorder); 086 } 087 return this; 088 } 089}