1 package org.ozoneDB.adminGui.feature.account.groups; 8 9 import java.awt.Color ; 10 import java.awt.Component ; 11 import java.awt.Font ; 12 import javax.swing.ImageIcon ; 13 import javax.swing.JTree ; 14 import javax.swing.tree.DefaultTreeCellRenderer ; 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 31 33 public class GroupTreeRenderer extends DefaultTreeCellRenderer { 34 35 40 private void setIcons(int type) { 41 ImageIcon nodeIcon; 42 43 switch (type) { 45 case Account.NODE_IS_USER: 46 nodeIcon = new ImageIcon (Images.TREE_USER, null); 47 break; 48 case Account.NODE_IS_GROUP: 49 nodeIcon = new ImageIcon (Images.TREE_GROUP, null); 50 break; 51 case Account.NODE_IS_ACCOUNT: 52 nodeIcon = new ImageIcon (Images.TREE_GROUPS, null); 53 break; 54 default: 55 nodeIcon = null; 56 break; 57 } 58 59 this.setIcon(nodeIcon); 61 } 63 75 public Component getTreeCellRendererComponent(JTree tree, Object 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 this.setForeground(Color.black); 82 this.setFont(this.getFont().deriveFont(Font.PLAIN)); 83 84 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 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 else if (value instanceof AccountItem) 109 setIcons(Account.NODE_IS_ACCOUNT); 110 111 else 113 setIcons(-99); 114 115 return this; 117 } 118 119 } 121 | Popular Tags |