KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > adminGui > feature > account > groups > GroupTreeRenderer


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
package org.ozoneDB.adminGui.feature.account.groups;
8
9 import java.awt.Color JavaDoc;
10 import java.awt.Component JavaDoc;
11 import java.awt.Font JavaDoc;
12 import javax.swing.ImageIcon JavaDoc;
13 import javax.swing.JTree JavaDoc;
14 import javax.swing.tree.DefaultTreeCellRenderer JavaDoc;
15
16 import org.ozoneDB.adminGui.res.Images;
17 import org.ozoneDB.adminGui.feature.account.Account;
18 import org.ozoneDB.adminGui.feature.account.AccountItem;
19 import org.ozoneDB.adminGui.feature.account.users.UserItem;
20
21
22 //#############################################################################
23
/**
24  * This class is used to manage the groups tree renderer.
25  *
26  * @author <p align=center>Ibsen Ramos-Bonilla
27  * <br>Copyright &copy 1997-@year@ by SMB GmbH. All Rights Reserved.</p>
28  *
29  * @version 1.0
30  */

31 //#############################################################################
32

33 public class GroupTreeRenderer extends DefaultTreeCellRenderer JavaDoc {
34
35     /**
36      * This method sets the icons based on the node type.
37      *
38      * @param type - the node type.
39      */

40     private void setIcons(int type) {
41         ImageIcon JavaDoc nodeIcon;
42
43         //set icon based on the node type
44
switch (type) {
45             case Account.NODE_IS_USER:
46                 nodeIcon = new ImageIcon JavaDoc(Images.TREE_USER, null);
47                 break;
48             case Account.NODE_IS_GROUP:
49                 nodeIcon = new ImageIcon JavaDoc(Images.TREE_GROUP, null);
50                 break;
51             case Account.NODE_IS_ACCOUNT:
52                 nodeIcon = new ImageIcon JavaDoc(Images.TREE_GROUPS, null);
53                 break;
54             default:
55                 nodeIcon = null;
56                 break;
57         }
58
59         //set the icons based on the selected image
60
this.setIcon(nodeIcon);
61     } //----- setTaxonomyIcons -----//
62

63     /**
64      * The method used to create a new image item rendition.
65      *
66      * @param tree - the tree associated with this renderer.
67      * @param value - the value object returned from the tree.
68      * @param sel - determines if a node was selected in the tree.
69      * @param expanded - determines if the node is expanded.
70      * @param leaf - determines if the node is a leaf node.
71      * @param row - returns the row number of the node.
72      * @param hasFocus - determines if a tree node has the focus.
73      * @return Component - the created render for the component.
74      */

75     public Component JavaDoc getTreeCellRendererComponent(JTree JavaDoc tree, Object JavaDoc value,
76                                                   boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
77         super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
78                 row, hasFocus);
79
80         //set the font
81
this.setForeground(Color.black);
82         this.setFont(this.getFont().deriveFont(Font.PLAIN));
83
84         //working with an account branch
85
if (value instanceof UserItem) {
86             setIcons(Account.NODE_IS_USER);
87
88             if (((UserItem) value).isAdmin()) {
89                 this.setForeground(Color.red);
90                 this.setFont(this.getFont().deriveFont(Font.BOLD));
91             }
92         }
93
94         //working with a group branch
95
else if (value instanceof GroupItem) {
96             setIcons(Account.NODE_IS_GROUP);
97
98             if (((GroupItem) value).getId() == 0) {
99                 this.setForeground(Color.red);
100                 this.setFont(this.getFont().deriveFont(Font.BOLD));
101             }
102
103             this.setText(value.toString() + " [" +
104                     ((GroupItem) value).getId() + "]");
105         }
106
107         //working with an account branch
108
else if (value instanceof AccountItem)
109             setIcons(Account.NODE_IS_ACCOUNT);
110
111         //bad branch
112
else
113             setIcons(-99);
114
115         //return the component
116
return this;
117     }
118
119 } //--------------------------------- E O F -----------------------------------
120

121
Popular Tags