1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
package myWindow;
import java.awt.Component;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
public class MyRenderer extends DefaultTreeCellRenderer {
private static final long serialVersionUID = -3991603773928897980L;
private ImageIcon launcher;
private ImageIcon device;
private ImageIcon interfaceRule;
private ImageIcon smtpServer;
private ImageIcon group;
private ImageIcon person;
private ImageIcon rule;
public MyRenderer(String l, String d, String ir, String ss, String g, String p, String r) {
launcher = new ImageIcon(l);
device = new ImageIcon(d);
interfaceRule = new ImageIcon(ir);
smtpServer = new ImageIcon(ss);
group = new ImageIcon(g);
person = new ImageIcon(p);
rule = new ImageIcon(r);
}
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);
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
String nodeInfo = (String)(node.getUserObject());
if (nodeInfo.equals("DEVICE")) {
setIcon(device);
} else if (nodeInfo.equals("INTERFACERULE")) {
setIcon(interfaceRule);
} else if (nodeInfo.equals("GROUP")) {
setIcon(group);
} else if (nodeInfo.equals("PERSON")) {
setIcon(person);
} else if (nodeInfo.equals("RULE")) {
setIcon(rule);
} else if (nodeInfo.equals("SMTPSERVER")) {
setIcon(smtpServer);
} else if (nodeInfo.equals("LAUNCHER")) {
setIcon(launcher);
}
return this;
}
} |
Partager