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