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