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