1 package de.matthias_burbach.mosaique.swing;
2
3 import java.awt.Component;
4
5 import javax.swing.Icon;
6 import javax.swing.JTree;
7 import javax.swing.tree.DefaultTreeCellRenderer;
8
9 import de.matthias_burbach.mosaique.core.Mosaique;
10
11 /***
12 * The tree cell renderer responsible for displaying tree node specific
13 * icons in the tree.
14 *
15 * @author Matthias Burbach
16 */
17 public class MosaiqueTreeCellRenderer extends DefaultTreeCellRenderer {
18 /***
19 * For some reason it doesn't work to use a non-empty path for icons.
20 * Icons would not be found when running Mosaique outside of Eclipse.
21 */
22 private String iconPath = "";
23
24 /***
25 * The white component icon for Struts configs.
26 */
27 private Icon whiteComponentIcon =
28 SwingHelper.createImageIcon(iconPath + "white-component.gif", "");
29
30 /***
31 * The icon for logical pages.
32 */
33 private Icon logicalPageIcon =
34 SwingHelper.createImageIcon(iconPath + "logical-page.gif", "");
35
36 /***
37 * The icon for Tiles definitions.
38 */
39 private Icon definitionIcon =
40 SwingHelper.createImageIcon(iconPath + "definition.gif", "");
41
42 /***
43 * The icon for JSPs.
44 */
45 private Icon jspIcon =
46 SwingHelper.createImageIcon(iconPath + "jsp.gif", "");
47
48 /***
49 * The icon for insert tags.
50 */
51 private Icon insertIcon =
52 SwingHelper.createImageIcon(iconPath + "insert.gif", "");
53
54 /***
55 * The icon for the puts node.
56 */
57 private Icon putsIcon =
58 SwingHelper.createImageIcon(iconPath + "puts.gif", "");
59
60 /***
61 * The icon for put nodes of an even definition hierarchy level.
62 */
63 private Icon evenPutIcon =
64 SwingHelper.createImageIcon(iconPath + "green-bullet.gif", "");
65
66 /***
67 * The icon for put nodes of an odd definition hierarchy level.
68 */
69 private Icon oddPutIcon =
70 SwingHelper.createImageIcon(iconPath + "empty-bullet.gif", "");
71
72 /***
73 * The icon for put nodes defined dynamically on a JSP.
74 */
75 private Icon dynamicPutIcon =
76 SwingHelper.createImageIcon(iconPath + "red-bullet.gif", "");
77
78 /***
79 * @param mosaique The Mosaique core application.
80 */
81 public MosaiqueTreeCellRenderer(final Mosaique mosaique) {
82
83 }
84
85
86
87
88
89
90
91
92
93
94
95
96 /***
97 * {@inheritDoc}
98 */
99 public Component getTreeCellRendererComponent(
100 final JTree tree,
101 final Object value,
102 final boolean sel,
103 final boolean expanded,
104 final boolean leaf,
105 final int row,
106 final boolean focused) {
107 Component component = super.getTreeCellRendererComponent(
108 tree,
109 value,
110 sel,
111 expanded,
112 leaf,
113 row,
114 focused);
115 if (value instanceof StrutsConfigNode) {
116 setIcon(whiteComponentIcon);
117 } else if (value instanceof LogicalPageNode) {
118 setIcon(logicalPageIcon);
119 } else if (value instanceof DefinitionNode) {
120 setIcon(definitionIcon);
121 } else if (value instanceof JspNode) {
122 setIcon(jspIcon);
123 } else if (value instanceof InsertNode) {
124 setIcon(insertIcon);
125 } else if (value instanceof PutsNode) {
126 setIcon(putsIcon);
127 } else if (value instanceof PutNode) {
128 PutNode putNode = (PutNode) value;
129 if (putNode.getPut().isDynamicPut()) {
130 setIcon(dynamicPutIcon);
131 } else {
132 int level = putNode.getPut().getLevel();
133 boolean isEven = (level % 2) == 0;
134 if (isEven) {
135 setIcon(evenPutIcon);
136 } else {
137 setIcon(oddPutIcon);
138 }
139 }
140 }
141 return component;
142 }
143 }