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.Component; 021import java.awt.Font; 022 023import javax.swing.JTree; 024 025import org.opends.guitools.controlpanel.browser.BrowserController; 026import org.opends.guitools.controlpanel.ui.ColorAndFontConstants; 027import org.opends.guitools.controlpanel.ui.nodes.BasicNode; 028 029/** 030 * The renderer used to render the nodes in the LDAP entry browser. 031 * 032 */ 033public class BrowserCellRenderer extends TreeCellRenderer { 034 035 private static final long serialVersionUID = 6756291700611741513L; 036 Font defaultFont = ColorAndFontConstants.treeFont; 037 Font italicFont = defaultFont.deriveFont(Font.ITALIC); 038 Font boldFont = defaultFont.deriveFont(Font.BOLD); 039 Font italicBoldFont = defaultFont.deriveFont(Font.ITALIC|Font.BOLD); 040 BasicNode inspectedNode; 041 042 /** 043 * Sets which is the inspected node. This method simply marks the selected 044 * node in the tree so that it can have a different rendering. This is 045 * useful for instance when the right panel has a list of entries to which 046 * the menu action apply, to make a difference between the selected node in 047 * the tree (to which the action in the main menu will not apply) and the 048 * selected nodes in the right pane. 049 * @param node the selected node. 050 */ 051 public void setInspectedNode(BasicNode node) { 052 inspectedNode = node; 053 } 054 055 /** {@inheritDoc} */ 056 public Component getTreeCellRendererComponent( 057 JTree tree, 058 Object value, 059 boolean isSelected, 060 boolean isExpanded, 061 boolean isLeaf, 062 int row, 063 boolean cellHasFocus) 064 { 065 BasicNode node = (BasicNode)value; 066 super.getTreeCellRendererComponent(tree, node, isSelected, 067 isExpanded, isLeaf, 068 row, cellHasFocus); 069 070 setIcon(node.getIcon()); 071 setText(node.getDisplayName()); 072 073 Font newFont = defaultFont; 074 int style = node.getFontStyle(); 075 if (node == inspectedNode) { 076 style |= Font.BOLD; 077 } 078 if ((style & Font.ITALIC & Font.BOLD) != 0) { 079 newFont = italicBoldFont; 080 } 081 else if ((style & Font.ITALIC) != 0) { 082 newFont = italicFont; 083 } 084 else if ((style & Font.BOLD) != 0) { 085 newFont = boldFont; 086 } 087 else { 088 newFont = defaultFont; 089 } 090 setFont(newFont); 091 return this; 092 } 093 094 095 /** 096 * Returns the row height for the provided browser controller. 097 * @param controller the browser controller. 098 * @return the row height for the provided browser controller. 099 */ 100 public static int calculateRowHeight(BrowserController controller) { 101 return 16; 102 } 103}