1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package org.openoffice.setup.PanelHelper;
25 
26 import org.openoffice.setup.SetupData.DisplayPackageDescription;
27 import org.openoffice.setup.SetupData.PackageDescription;
28 import org.openoffice.setup.ResourceManager;
29 import java.awt.Component;
30 import javax.swing.ImageIcon;
31 import javax.swing.JTree;
32 import javax.swing.tree.DefaultMutableTreeNode;
33 import javax.swing.tree.DefaultTreeCellRenderer;
34 
35 public class TreeNodeRenderer extends DefaultTreeCellRenderer {
36 
37     ImageIcon    InstallIcon;
38     ImageIcon    InstalledIcon;
39     ImageIcon    DontInstallIcon;
40     ImageIcon    DontKnowIcon;
41     ImageIcon    RemoveIcon;
42 
43     public TreeNodeRenderer() {
44         InstallIcon     = ResourceManager.getIcon("Icon_Install");
45         InstalledIcon   = ResourceManager.getIcon("Icon_Installed");
46         DontInstallIcon = ResourceManager.getIcon("Icon_DontInstall");
47         DontKnowIcon    = ResourceManager.getIcon("Icon_DontKnow");
48         RemoveIcon      = ResourceManager.getIcon("Icon_Remove");
49     }
50 
51     public Component getTreeCellRendererComponent(
52                         JTree tree, Object value, boolean sel, boolean expanded,
53                         boolean leaf, int row, boolean hasFocus)    {
54 
55         super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
56 
57         DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
58         Object nodeObject = node.getUserObject();
59 
60         if (DisplayPackageDescription.is(nodeObject)) {
61             DisplayPackageDescription nodeInfo = (DisplayPackageDescription)nodeObject;
62 
63             switch (nodeInfo.getState()) {
64                 case PackageDescription.INSTALL:      setIcon(InstallIcon);      break;
65                 case PackageDescription.DONT_REMOVE:  setIcon(InstallIcon);      break;
66                 case PackageDescription.IGNORE:       setIcon(InstalledIcon);    break;
67                 case PackageDescription.INSTALL_SOME: setIcon(DontKnowIcon);     break;
68                 case PackageDescription.REMOVE_SOME:  setIcon(DontKnowIcon);     break;
69                 case PackageDescription.DONT_INSTALL: setIcon(DontInstallIcon);  break;
70                 case PackageDescription.REMOVE:       setIcon(RemoveIcon);       break;
71                 default: setIcon(InstalledIcon); break;
72             }
73         }
74 
75         if (sel) {
76             setBackground(super.getBackgroundSelectionColor());
77             setForeground(textSelectionColor);
78         } else {
79             setBackground(super.getBackgroundNonSelectionColor());
80             setForeground(textSelectionColor);
81         }
82 
83         return this;
84     }
85 }
86