Parent: [r7] (diff)

Download this file

TreeRenderer.java    110 lines (92 with data), 3.3 kB

  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
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
/*
* SPDXVersion: SPDX-1.1
* Creator: Person: Nuno Brito (nuno.brito@triplecheck.de)
* Creator: Organization: TripleCheck (contact@triplecheck.de)
* Created: 2013-09-17T00:00:00Z
* LicenseName: NOASSERTION
* FileName: TreeRenderer.java
* FileType: SOURCE
* FileCopyrightText: <text> Copyright 2013 Nuno Brito, TripleCheck </text>
* FileComment: <text> Add the pretty icons on tree objects </text>
*/
package GUI;
import java.awt.Component;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
import main.core;
public class TreeRenderer extends DefaultTreeCellRenderer {
// get our icons
private Icon get(String what){
return new ImageIcon(core.getIcon(what).getAbsolutePath());
}
Icon
none = get("blue-document-node.png"),
person = get("stickman.png"),
//person = get("user-medium-silhouette.png"),
sectionCreator = get("fingerprint.png"),
sectionPackage = get("box.png"),
sectionFile = get("documents-stack.png"),
sectionReview = get("geolocation.png"),
//dependency = get("envelope.png"),
file = get("document-number.png"),
home = get("home.png"),
folderClosed = get("folder-horizontal.png"),
folderOpen = get("folder-horizontal-open.png");
// medal-premium.png
@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);
TreeNodeSPDX node = (TreeNodeSPDX) value;
// if there is an icon defined for this node, set it up here.
if(node.icon != null){
setIcon(node.icon);
}
else // do the switch based on type of icon
switch(node.nodeType){
case none:
setIcon(none);
break;
case file:
setIcon(file);
break;
case folder:
setIcon(folderClosed);
node.iconWhenSelected = get("folder-horizontal-open.png");
break;
case person:
setIcon(person);
break;
case sectionCreator:
setIcon(sectionCreator);
break;
case sectionPackage:
setIcon(sectionPackage);
break;
case sectionFile:
setIcon(sectionFile);
break;
case sectionReview:
setIcon(sectionReview);
break;
// case home:
// setIcon(home);
// break;
case home:
setIcon(home);
break;
}
// is this icon selected?
if(sel == true){
if(node.iconWhenSelected != null){
setIcon(node.iconWhenSelected);
}
}
// write the title of this product
setText(node.toString());
return this;
}
}