1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package coras.client.ui;
22
23 import java.awt.Component;
24 import java.awt.Font;
25
26 import javax.swing.Icon;
27 import javax.swing.ImageIcon;
28 import javax.swing.JLabel;
29 import javax.swing.JTree;
30 import javax.swing.tree.DefaultMutableTreeNode;
31 import javax.swing.tree.DefaultTreeCellRenderer;
32
33 import coras.common.CorasAsset;
34 import coras.reuse.ExperiencePackage;
35 import coras.riskanalysis.RiskAnalysisProject;
36 import coras.structure.SubProcessEnum;
37 import coras.types.IDocument;
38 import coras.types.IFaultTree;
39 import coras.types.ITable;
40 import coras.types.IUMLModel;
41
42 /***
43 * @author fvr
44 *
45 * TODO To change the template for this generated type comment go to
46 * Window - Preferences - Java - Code Style - Code Templates
47 */
48 public class CorasTreeCellRenderer extends DefaultTreeCellRenderer {
49
50 private static Icon FOLDER_OPEN_ICON = null;
51 private static Icon FOLDER_CLOSED_ICON = null;
52 public static Icon UML_ICON = null;
53 public static Icon TABLE_ICON = null;
54 public static Icon DOCUMENT_ICON = null;
55 public static Icon FAULT_TREE_ICON = null;
56
57 static {
58 ClassLoader cl = CorasTreeCellRenderer.class.getClassLoader();
59 FOLDER_OPEN_ICON = new ImageIcon(cl.getResource("images/icons/folderOpen.gif"));
60 FOLDER_CLOSED_ICON = new ImageIcon(cl.getResource("images/icons/folderClosed.gif"));
61 UML_ICON = new ImageIcon(cl.getResource("images/icons/uml.gif"));
62 TABLE_ICON = new ImageIcon(cl.getResource("images/icons/table.gif"));
63 DOCUMENT_ICON = new ImageIcon(cl.getResource("images/icons/document.gif"));
64 FAULT_TREE_ICON = new ImageIcon(cl.getResource("images/icons/tree.gif"));
65 }
66
67 public Component getTreeCellRendererComponent(JTree tree, Object value,
68 boolean sel, boolean expanded, boolean leaf, int row,
69 boolean hasFocus) {
70 Component result = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
71 if (result instanceof JLabel) {
72 JLabel label = (JLabel) result;
73 Object userObject = value instanceof DefaultMutableTreeNode ? ((DefaultMutableTreeNode)value).getUserObject() : null;
74 label.setText(value != null ? value.toString() : "null");
75 Icon icon;
76 if (userObject instanceof RiskAnalysisProject || userObject instanceof ExperiencePackage || userObject instanceof SubProcessEnum) {
77 if (expanded) {
78
79 icon = super.getDefaultOpenIcon();
80 } else {
81
82 icon = super.getDefaultClosedIcon();
83 }
84 } else if (userObject instanceof IUMLModel) {
85 icon = UML_ICON;
86 } else if (userObject instanceof ITable) {
87 icon = TABLE_ICON;
88 } else if (userObject instanceof IDocument) {
89 icon = DOCUMENT_ICON;
90 } else if (userObject instanceof IFaultTree) {
91 icon = FAULT_TREE_ICON;
92 } else {
93 icon = null;
94 }
95 label.setIcon(icon);
96 Font font = label.getFont();
97 Font plainFont = font.isPlain() ? font : font.deriveFont(Font.PLAIN);
98 Font italicFont = font.isItalic() ? font : font.deriveFont(Font.ITALIC);
99 if (userObject instanceof CorasAsset && ((CorasAsset)userObject).isDeleted()) {
100 label.setFont(italicFont);
101 } else {
102 label.setFont(plainFont);
103 }
104 }
105 return result;
106 }
107 }