analyseWriter/src/fenetres/MyTreeCellRenderer.java

63 lines
2.1 KiB
Java
Raw Normal View History

2022-06-19 21:01:30 +02:00
package fenetres;
import java.awt.Color;
import java.awt.Component;
2022-11-13 08:58:51 +01:00
import java.awt.Font;
2022-11-13 08:58:51 +01:00
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import cXML.node;
public class MyTreeCellRenderer extends DefaultTreeCellRenderer {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel, boolean exp, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, exp, leaf, row, hasFocus);
2022-11-13 08:58:51 +01:00
DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) tree.getCellRenderer();
cellRenderer.setOpenIcon(new ImageIcon(create.class.getResource("/resources/treeOpen.png")));
cellRenderer.setClosedIcon(new ImageIcon(create.class.getResource("/resources/treeClose.png")));
cellRenderer.setLeafIcon(new ImageIcon(create.class.getResource("/resources/treeLeaf.png")));
cellRenderer.setBackgroundNonSelectionColor(new Color(255, 255, 255));
cellRenderer.setBackgroundSelectionColor(new Color(171, 255, 243)); //160,160,230
2022-11-13 08:58:51 +01:00
cellRenderer.setBorderSelectionColor(Color.black);
cellRenderer.setTextSelectionColor(Color.white);
cellRenderer.setTextNonSelectionColor(Color.blue);
node data = null;
if (value instanceof DefaultMutableTreeNode) {
final DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) value;
final Object userObject = node1.getUserObject();
if (userObject instanceof node) {
data = (node) userObject;
}
}
2022-11-13 08:58:51 +01:00
if(data!=null) {
if(data.isEvaluate()) {
setForeground(new Color(0, 105 ,5)); //230,20,30
2022-11-13 08:58:51 +01:00
setFont(new Font("Tahoma", Font.BOLD, 14));
}else {
setForeground(new Color(0, 0 ,0));
setFont(new Font("Tahoma", Font.PLAIN, 12));
}
}
2022-11-13 08:58:51 +01:00
return this;
}
}