1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package com.sun.star.xml.security.uno; 25 26 import javax.swing.tree.DefaultTreeCellRenderer; 27 import org.w3c.dom.Node; 28 import javax.swing.ImageIcon; 29 import java.awt.Component; 30 import javax.swing.JTree; 31 32 /* 33 * a TreeCellRender which can show a graph on the current 34 * tree node. 35 */ 36 class XMLTreeCellRanderer extends DefaultTreeCellRenderer 37 { 38 /* 39 * the icon for the current Node 40 */ 41 private ImageIcon m_currentIcon; 42 43 /* 44 * the current Node 45 */ 46 private Node m_currentNode; 47 48 XMLTreeCellRanderer(Node currentNode) 49 { 50 m_currentNode = currentNode; 51 m_currentIcon = new ImageIcon("current.gif"); 52 } 53 54 public Component getTreeCellRendererComponent( 55 JTree tree, 56 Object value, 57 boolean sel, 58 boolean expanded, 59 boolean leaf, 60 int row, 61 boolean hasFocus) 62 { 63 super.getTreeCellRendererComponent( 64 tree, value, sel, 65 expanded, leaf, row, 66 hasFocus); 67 68 if (((AdapterNode)value).getNode() == m_currentNode) 69 { 70 setIcon(m_currentIcon); 71 setToolTipText("This is the current element."); 72 } 73 else 74 { 75 setToolTipText(null); /* no tool tip */ 76 } 77 78 return this; 79 } 80 } 81 82