javax.help.plaf.basic.BasicIndexCellRenderer Maven / Gradle / Ivy
/*
* @(#) BasicIndexCellRenderer.java 1.20 - last change made 08/24/01
*
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the confidential and proprietary information of Sun
* Microsystems, Inc. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Sun.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
* THIS SOFTWARE OR ITS DERIVATIVES.
*/
package javax.help.plaf.basic;
import javax.help.*;
import javax.swing.tree.*;
import javax.swing.JTree;
import java.awt.Component;
import java.util.Locale;
/**
* Cell Renderer for the index UI.
*
* @author Roger D. Brinkley
* @author Eduardo Pelegri-Llopart
* @author Stepan Marek
* @version %I 08/24/01
*/
public class BasicIndexCellRenderer extends DefaultTreeCellRenderer {
/**
* Configures the renderer based on the passed in components.
* The value is set from messaging the tree with
* convertValueToText
, which ultimately invokes
* toString
on value
.
* The foreground color is set based on the selection and the icon
* is set based on on leaf and expanded.
*/
public Component getTreeCellRendererComponent(JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf, int row,
boolean hasFocus) {
// variable hasFocus was private to DefaultTreeCellRenderer since jdk1.3
try {
this.hasFocus = hasFocus;
} catch (IllegalAccessError e) {
}
IndexItem item
= (IndexItem) ((DefaultMutableTreeNode) value).getUserObject();
String stringValue = "";
if (item != null) {
stringValue = item.getName();
}
setText(stringValue);
if (sel)
setForeground(getTextSelectionColor());
else
setForeground(getTextNonSelectionColor());
setIcon(null);
selected = sel;
// Set the locale of this if there is a lang value
if (item != null) {
Locale locale = item.getLocale();
if (locale != null) {
setLocale(locale);
}
}
return this;
}
}