Child: [r12] (diff)

Download this file

ListRenderer.java    70 lines (54 with data), 1.7 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
/*
* SPDXVersion: SPDX-1.1
*
* Creator: Person: Nuno Brito (nuno.brito@triplecheck.de)
*
* Creator: Organization: TripleCheck (contact@triplecheck.de)
*
* Created: 2013-09-20T00:00:00Z
*
* LicenseName: NOASSERTION
*
* FileName: ListRenderer.java
*
* FileType: SOURCE
*
* FileCopyrightText: <text> Copyright 2013 Nuno Brito, TripleCheck </text>
*
* FileComment: <text> This class sets the icons that are displaed on the tree
* lists for each item.</text>
*/
package GUI;
import java.awt.Component;
import javax.swing.DefaultListCellRenderer;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JList;
import main.core;
public class ListRenderer
extends DefaultListCellRenderer {
// get our icons
private Icon get(String what){
return new ImageIcon(core.getIcon(what).getAbsolutePath());
}
Icon
defaultIcon = get("blue-document-node.png");
@Override
public Component getListCellRendererComponent(
JList list, Object value, int index,
boolean isSelected, boolean cellHasFocus) {
// inherit all the good stuff that comes as default
super.getListCellRendererComponent
(list, value, index, isSelected, cellHasFocus);
// get the product object
ListItem item = (ListItem) value;
// write the title of this product
//setText(item.toString());
if(item.icon == null){
setIcon(defaultIcon);
}else{
setIcon(item.icon);
}
return this;
}
}