1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  *  The Contents of this file are made available subject to the terms of
4*cdf0e10cSrcweir  *  the BSD license.
5*cdf0e10cSrcweir  *
6*cdf0e10cSrcweir  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7*cdf0e10cSrcweir  *  All rights reserved.
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  *  Redistribution and use in source and binary forms, with or without
10*cdf0e10cSrcweir  *  modification, are permitted provided that the following conditions
11*cdf0e10cSrcweir  *  are met:
12*cdf0e10cSrcweir  *  1. Redistributions of source code must retain the above copyright
13*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer.
14*cdf0e10cSrcweir  *  2. Redistributions in binary form must reproduce the above copyright
15*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer in the
16*cdf0e10cSrcweir  *     documentation and/or other materials provided with the distribution.
17*cdf0e10cSrcweir  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18*cdf0e10cSrcweir  *     contributors may be used to endorse or promote products derived
19*cdf0e10cSrcweir  *     from this software without specific prior written permission.
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22*cdf0e10cSrcweir  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23*cdf0e10cSrcweir  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24*cdf0e10cSrcweir  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25*cdf0e10cSrcweir  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26*cdf0e10cSrcweir  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27*cdf0e10cSrcweir  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28*cdf0e10cSrcweir  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29*cdf0e10cSrcweir  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30*cdf0e10cSrcweir  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31*cdf0e10cSrcweir  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*cdf0e10cSrcweir  *
33*cdf0e10cSrcweir  *************************************************************************/
34*cdf0e10cSrcweir import java.awt.Color;
35*cdf0e10cSrcweir import java.awt.Component;
36*cdf0e10cSrcweir import java.awt.FontMetrics;
37*cdf0e10cSrcweir import java.awt.Graphics;
38*cdf0e10cSrcweir import java.awt.SystemColor;
39*cdf0e10cSrcweir import javax.swing.Icon;
40*cdf0e10cSrcweir import javax.swing.ImageIcon;
41*cdf0e10cSrcweir import javax.swing.JLabel;
42*cdf0e10cSrcweir import javax.swing.JTree;
43*cdf0e10cSrcweir import javax.swing.tree.DefaultMutableTreeNode;
44*cdf0e10cSrcweir import javax.swing.tree.DefaultTreeCellRenderer;
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir public class UnoTreeRenderer extends DefaultTreeCellRenderer{
49*cdf0e10cSrcweir     private Icon m_oMethodIcon;
50*cdf0e10cSrcweir     private Icon m_oPropertyIcon;
51*cdf0e10cSrcweir     private Icon m_oContainerIcon;
52*cdf0e10cSrcweir     private Icon m_oContentIcon;
53*cdf0e10cSrcweir     private Icon m_oServiceIcon;
54*cdf0e10cSrcweir     private Icon m_oInterfaceIcon;
55*cdf0e10cSrcweir     private Icon m_oPropertyValueIcon;
56*cdf0e10cSrcweir     private boolean bSelected;
57*cdf0e10cSrcweir     private int nWidth = 0;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir     /** Creates a new instance of UnoTreeRenderer */
61*cdf0e10cSrcweir     public UnoTreeRenderer(){
62*cdf0e10cSrcweir         super();
63*cdf0e10cSrcweir         try {
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir             final ClassLoader loader = ClassLoader.getSystemClassLoader();
66*cdf0e10cSrcweir             m_oMethodIcon = new ImageIcon(loader.getResource("images/methods_16.png"));
67*cdf0e10cSrcweir             m_oPropertyIcon = new ImageIcon("images/properties_16.png");
68*cdf0e10cSrcweir             m_oPropertyValueIcon = new ImageIcon("images/properties_16.png");
69*cdf0e10cSrcweir             m_oContainerIcon = new ImageIcon("images/containers_16.png");
70*cdf0e10cSrcweir             m_oServiceIcon = new ImageIcon("images/services_16.png");
71*cdf0e10cSrcweir             m_oInterfaceIcon = new ImageIcon("images/interfaces_16.png");
72*cdf0e10cSrcweir             m_oContentIcon = new ImageIcon("images/content_16.png");
73*cdf0e10cSrcweir         } catch (RuntimeException e) {
74*cdf0e10cSrcweir             System.out.println("Sorry, could not locate resourecs, treecell icons will not be displayed.");
75*cdf0e10cSrcweir         }
76*cdf0e10cSrcweir     }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir     public synchronized Component getTreeCellRendererComponent(JTree tree,Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus){
80*cdf0e10cSrcweir         try{
81*cdf0e10cSrcweir             bSelected = sel;
82*cdf0e10cSrcweir             DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
83*cdf0e10cSrcweir             Component rc = super.getTreeCellRendererComponent( tree, value, sel,expanded, leaf, row,hasFocus);
84*cdf0e10cSrcweir             String	sLabelText = (String)node.getUserObject();
85*cdf0e10cSrcweir             if (sLabelText != null){
86*cdf0e10cSrcweir                 if (sLabelText.equals(XUnoFacetteNode.SCONTAINERDESCRIPTION)){
87*cdf0e10cSrcweir //                setIcon(m_oContainerIcon);
88*cdf0e10cSrcweir                 } else if (sLabelText.equals(XUnoFacetteNode.SCONTENTDESCRIPTION)){
89*cdf0e10cSrcweir //                setIcon(m_oContentIcon);
90*cdf0e10cSrcweir                 } else if (sLabelText.equals(XUnoFacetteNode.SINTERFACEDESCRIPTION)){
91*cdf0e10cSrcweir //                setIcon(m_oInterfaceIcon);
92*cdf0e10cSrcweir                 } else if (sLabelText.equals(XUnoFacetteNode.SMETHODDESCRIPTION)){
93*cdf0e10cSrcweir //                setIcon(m_oMethodIcon);
94*cdf0e10cSrcweir                 } else if (sLabelText.equals(XUnoFacetteNode.SPROPERTYDESCRIPTION)){
95*cdf0e10cSrcweir //                setIcon(m_oPropertyIcon);
96*cdf0e10cSrcweir                 } else if (sLabelText.startsWith(XUnoFacetteNode.SPROPERTYINFODESCRIPTION)){
97*cdf0e10cSrcweir //                setIcon(m_oPropertyIcon);
98*cdf0e10cSrcweir                 } else if (sLabelText.equals(XUnoFacetteNode.SPROPERTYVALUEDESCRIPTION)){
99*cdf0e10cSrcweir //                setIcon(m_oPropertyValueIcon);
100*cdf0e10cSrcweir                 } else if (sLabelText.equals(XUnoFacetteNode.SSERVICEDESCRIPTION)){
101*cdf0e10cSrcweir //                setIcon(m_oServiceIcon);
102*cdf0e10cSrcweir                 } else{
103*cdf0e10cSrcweir                     setText(sLabelText);
104*cdf0e10cSrcweir                     rc.validate();
105*cdf0e10cSrcweir                 }
106*cdf0e10cSrcweir                 setSize(getPreferredSize()); //fm.stringWidth(sLabelText), (int) getSize().getHeight());
107*cdf0e10cSrcweir                 rc.validate();
108*cdf0e10cSrcweir //            nWidth = (int) rc.getPreferredSize().getWidth();
109*cdf0e10cSrcweir                 doLayout();
110*cdf0e10cSrcweir             }
111*cdf0e10cSrcweir         } catch (RuntimeException e) {
112*cdf0e10cSrcweir             System.out.println("Sorry, icon for treecell could not be displayed.");
113*cdf0e10cSrcweir         }
114*cdf0e10cSrcweir         return this;
115*cdf0e10cSrcweir     }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     public void paintComponent(Graphics g) {
120*cdf0e10cSrcweir         FontMetrics fm = getFontMetrics(getFont());
121*cdf0e10cSrcweir         int x, y;
122*cdf0e10cSrcweir         y = fm.getAscent() + 2;
123*cdf0e10cSrcweir         if(getIcon() == null) {
124*cdf0e10cSrcweir             x = 0;
125*cdf0e10cSrcweir         } else {
126*cdf0e10cSrcweir             x = getIcon().getIconWidth() + getIconTextGap();
127*cdf0e10cSrcweir         }
128*cdf0e10cSrcweir         g.setColor(getForeground());
129*cdf0e10cSrcweir //         g.fillRect(x,y,x + fm.stringWidth(getText()),y);
130*cdf0e10cSrcweir //        System.out.println("Text: " + getText());
131*cdf0e10cSrcweir         super.paintComponent(g);
132*cdf0e10cSrcweir     }
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 
136