📄 grouptreerenderer.java
字号:
// You can redistribute this software and/or modify it under the terms of
// the Ozone Library License version 1 published by ozone-db.org.
//
// The original code and portions created by SMB are
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
//
package org.ozoneDB.adminGui.feature.account.groups;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
import org.ozoneDB.adminGui.res.Images;
import org.ozoneDB.adminGui.feature.account.Account;
import org.ozoneDB.adminGui.feature.account.AccountItem;
import org.ozoneDB.adminGui.feature.account.users.UserItem;
//#############################################################################
/**
* This class is used to manage the groups tree renderer.
*
* @author <p align=center>Ibsen Ramos-Bonilla
* <br>Copyright © 1997-@year@ by SMB GmbH. All Rights Reserved.</p>
*
* @version 1.0
*/
//#############################################################################
public class GroupTreeRenderer extends DefaultTreeCellRenderer {
/**
* This method sets the icons based on the node type.
*
* @param type - the node type.
*/
private void setIcons(int type) {
ImageIcon nodeIcon;
//set icon based on the node type
switch (type) {
case Account.NODE_IS_USER:
nodeIcon = new ImageIcon(Images.TREE_USER, null);
break;
case Account.NODE_IS_GROUP:
nodeIcon = new ImageIcon(Images.TREE_GROUP, null);
break;
case Account.NODE_IS_ACCOUNT:
nodeIcon = new ImageIcon(Images.TREE_GROUPS, null);
break;
default:
nodeIcon = null;
break;
}
//set the icons based on the selected image
this.setIcon(nodeIcon);
} //----- setTaxonomyIcons -----//
/**
* The method used to create a new image item rendition.
*
* @param tree - the tree associated with this renderer.
* @param value - the value object returned from the tree.
* @param sel - determines if a node was selected in the tree.
* @param expanded - determines if the node is expanded.
* @param leaf - determines if the node is a leaf node.
* @param row - returns the row number of the node.
* @param hasFocus - determines if a tree node has the focus.
* @return Component - the created render for the component.
*/
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
row, hasFocus);
//set the font
this.setForeground(Color.black);
this.setFont(this.getFont().deriveFont(Font.PLAIN));
//working with an account branch
if (value instanceof UserItem) {
setIcons(Account.NODE_IS_USER);
if (((UserItem) value).isAdmin()) {
this.setForeground(Color.red);
this.setFont(this.getFont().deriveFont(Font.BOLD));
}
}
//working with a group branch
else if (value instanceof GroupItem) {
setIcons(Account.NODE_IS_GROUP);
if (((GroupItem) value).getId() == 0) {
this.setForeground(Color.red);
this.setFont(this.getFont().deriveFont(Font.BOLD));
}
this.setText(value.toString() + " [" +
((GroupItem) value).getId() + "]");
}
//working with an account branch
else if (value instanceof AccountItem)
setIcons(Account.NODE_IS_ACCOUNT);
//bad branch
else
setIcons(-99);
//return the component
return this;
}
} //--------------------------------- E O F -----------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -