1*34dd1e25SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*34dd1e25SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*34dd1e25SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*34dd1e25SAndrew Rist * distributed with this work for additional information 6*34dd1e25SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*34dd1e25SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*34dd1e25SAndrew Rist * "License"); you may not use this file except in compliance 9*34dd1e25SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*34dd1e25SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*34dd1e25SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*34dd1e25SAndrew Rist * software distributed under the License is distributed on an 15*34dd1e25SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*34dd1e25SAndrew Rist * KIND, either express or implied. See the License for the 17*34dd1e25SAndrew Rist * specific language governing permissions and limitations 18*34dd1e25SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*34dd1e25SAndrew Rist *************************************************************/ 21*34dd1e25SAndrew Rist 22*34dd1e25SAndrew Rist 23cdf0e10cSrcweir import java.awt.Color; 24cdf0e10cSrcweir import java.awt.Component; 25cdf0e10cSrcweir import java.awt.FontMetrics; 26cdf0e10cSrcweir import java.awt.Graphics; 27cdf0e10cSrcweir import java.awt.SystemColor; 28cdf0e10cSrcweir import javax.swing.Icon; 29cdf0e10cSrcweir import javax.swing.ImageIcon; 30cdf0e10cSrcweir import javax.swing.JLabel; 31cdf0e10cSrcweir import javax.swing.JTree; 32cdf0e10cSrcweir import javax.swing.tree.DefaultMutableTreeNode; 33cdf0e10cSrcweir import javax.swing.tree.DefaultTreeCellRenderer; 34cdf0e10cSrcweir 35cdf0e10cSrcweir 36cdf0e10cSrcweir 37cdf0e10cSrcweir public class UnoTreeRenderer extends DefaultTreeCellRenderer{ 38cdf0e10cSrcweir private Icon m_oMethodIcon; 39cdf0e10cSrcweir private Icon m_oPropertyIcon; 40cdf0e10cSrcweir private Icon m_oContainerIcon; 41cdf0e10cSrcweir private Icon m_oContentIcon; 42cdf0e10cSrcweir private Icon m_oServiceIcon; 43cdf0e10cSrcweir private Icon m_oInterfaceIcon; 44cdf0e10cSrcweir private Icon m_oPropertyValueIcon; 45cdf0e10cSrcweir private boolean bSelected; 46cdf0e10cSrcweir private int nWidth = 0; 47cdf0e10cSrcweir 48cdf0e10cSrcweir 49cdf0e10cSrcweir /** Creates a new instance of UnoTreeRenderer */ 50cdf0e10cSrcweir public UnoTreeRenderer(){ 51cdf0e10cSrcweir super(); 52cdf0e10cSrcweir try { 53cdf0e10cSrcweir 54cdf0e10cSrcweir final ClassLoader loader = ClassLoader.getSystemClassLoader(); 55cdf0e10cSrcweir m_oMethodIcon = new ImageIcon(loader.getResource("images/methods_16.png")); 56cdf0e10cSrcweir m_oPropertyIcon = new ImageIcon("images/properties_16.png"); 57cdf0e10cSrcweir m_oPropertyValueIcon = new ImageIcon("images/properties_16.png"); 58cdf0e10cSrcweir m_oContainerIcon = new ImageIcon("images/containers_16.png"); 59cdf0e10cSrcweir m_oServiceIcon = new ImageIcon("images/services_16.png"); 60cdf0e10cSrcweir m_oInterfaceIcon = new ImageIcon("images/interfaces_16.png"); 61cdf0e10cSrcweir m_oContentIcon = new ImageIcon("images/content_16.png"); 62cdf0e10cSrcweir } catch (RuntimeException e) { 63cdf0e10cSrcweir System.out.println("Sorry, could not locate resourecs, treecell icons will not be displayed."); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir 68cdf0e10cSrcweir public synchronized Component getTreeCellRendererComponent(JTree tree,Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus){ 69cdf0e10cSrcweir try{ 70cdf0e10cSrcweir bSelected = sel; 71cdf0e10cSrcweir DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; 72cdf0e10cSrcweir Component rc = super.getTreeCellRendererComponent( tree, value, sel,expanded, leaf, row,hasFocus); 73cdf0e10cSrcweir String sLabelText = (String)node.getUserObject(); 74cdf0e10cSrcweir if (sLabelText != null){ 75cdf0e10cSrcweir if (sLabelText.equals(XUnoFacetteNode.SCONTAINERDESCRIPTION)){ 76cdf0e10cSrcweir // setIcon(m_oContainerIcon); 77cdf0e10cSrcweir } else if (sLabelText.equals(XUnoFacetteNode.SCONTENTDESCRIPTION)){ 78cdf0e10cSrcweir // setIcon(m_oContentIcon); 79cdf0e10cSrcweir } else if (sLabelText.equals(XUnoFacetteNode.SINTERFACEDESCRIPTION)){ 80cdf0e10cSrcweir // setIcon(m_oInterfaceIcon); 81cdf0e10cSrcweir } else if (sLabelText.equals(XUnoFacetteNode.SMETHODDESCRIPTION)){ 82cdf0e10cSrcweir // setIcon(m_oMethodIcon); 83cdf0e10cSrcweir } else if (sLabelText.equals(XUnoFacetteNode.SPROPERTYDESCRIPTION)){ 84cdf0e10cSrcweir // setIcon(m_oPropertyIcon); 85cdf0e10cSrcweir } else if (sLabelText.startsWith(XUnoFacetteNode.SPROPERTYINFODESCRIPTION)){ 86cdf0e10cSrcweir // setIcon(m_oPropertyIcon); 87cdf0e10cSrcweir } else if (sLabelText.equals(XUnoFacetteNode.SPROPERTYVALUEDESCRIPTION)){ 88cdf0e10cSrcweir // setIcon(m_oPropertyValueIcon); 89cdf0e10cSrcweir } else if (sLabelText.equals(XUnoFacetteNode.SSERVICEDESCRIPTION)){ 90cdf0e10cSrcweir // setIcon(m_oServiceIcon); 91cdf0e10cSrcweir } else{ 92cdf0e10cSrcweir setText(sLabelText); 93cdf0e10cSrcweir rc.validate(); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir setSize(getPreferredSize()); //fm.stringWidth(sLabelText), (int) getSize().getHeight()); 96cdf0e10cSrcweir rc.validate(); 97cdf0e10cSrcweir // nWidth = (int) rc.getPreferredSize().getWidth(); 98cdf0e10cSrcweir doLayout(); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir } catch (RuntimeException e) { 101cdf0e10cSrcweir System.out.println("Sorry, icon for treecell could not be displayed."); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir return this; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir 107cdf0e10cSrcweir 108cdf0e10cSrcweir public void paintComponent(Graphics g) { 109cdf0e10cSrcweir FontMetrics fm = getFontMetrics(getFont()); 110cdf0e10cSrcweir int x, y; 111cdf0e10cSrcweir y = fm.getAscent() + 2; 112cdf0e10cSrcweir if(getIcon() == null) { 113cdf0e10cSrcweir x = 0; 114cdf0e10cSrcweir } else { 115cdf0e10cSrcweir x = getIcon().getIconWidth() + getIconTextGap(); 116cdf0e10cSrcweir } 117cdf0e10cSrcweir g.setColor(getForeground()); 118cdf0e10cSrcweir // g.fillRect(x,y,x + fm.stringWidth(getText()),y); 119cdf0e10cSrcweir // System.out.println("Text: " + getText()); 120cdf0e10cSrcweir super.paintComponent(g); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir 125