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 | |
package org.argouml.cognitive.ui; |
40 | |
|
41 | |
import java.awt.Color; |
42 | |
import java.awt.Component; |
43 | |
|
44 | |
import javax.swing.ImageIcon; |
45 | |
import javax.swing.JLabel; |
46 | |
import javax.swing.JTree; |
47 | |
import javax.swing.plaf.metal.MetalIconFactory; |
48 | |
import javax.swing.tree.DefaultTreeCellRenderer; |
49 | |
|
50 | |
import org.argouml.application.helpers.ResourceLoaderWrapper; |
51 | |
import org.argouml.cognitive.Decision; |
52 | |
import org.argouml.cognitive.Designer; |
53 | |
import org.argouml.cognitive.Goal; |
54 | |
import org.argouml.cognitive.Poster; |
55 | |
import org.argouml.cognitive.ToDoItem; |
56 | |
import org.argouml.model.Model; |
57 | |
import org.argouml.uml.ui.UMLTreeCellRenderer; |
58 | |
import org.tigris.gef.base.Diagram; |
59 | |
import org.tigris.gef.base.Globals; |
60 | |
import org.tigris.gef.presentation.Fig; |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | 900 | public class ToDoTreeRenderer extends DefaultTreeCellRenderer { |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | 900 | private final ImageIcon postIt0 = lookupIconResource("PostIt0"); |
73 | 900 | private final ImageIcon postIt25 = lookupIconResource("PostIt25"); |
74 | 900 | private final ImageIcon postIt50 = lookupIconResource("PostIt50"); |
75 | 900 | private final ImageIcon postIt75 = lookupIconResource("PostIt75"); |
76 | 900 | private final ImageIcon postIt99 = lookupIconResource("PostIt99"); |
77 | 900 | private final ImageIcon postIt100 = lookupIconResource("PostIt100"); |
78 | |
|
79 | |
|
80 | 900 | private final ImageIcon postItD0 = lookupIconResource("PostItD0"); |
81 | 900 | private final ImageIcon postItD25 = lookupIconResource("PostItD25"); |
82 | 900 | private final ImageIcon postItD50 = lookupIconResource("PostItD50"); |
83 | 900 | private final ImageIcon postItD75 = lookupIconResource("PostItD75"); |
84 | 900 | private final ImageIcon postItD99 = lookupIconResource("PostItD99"); |
85 | 900 | private final ImageIcon postItD100 = lookupIconResource("PostItD100"); |
86 | |
|
87 | 900 | private UMLTreeCellRenderer treeCellRenderer = new UMLTreeCellRenderer(); |
88 | |
|
89 | |
private static ImageIcon lookupIconResource(String name) { |
90 | 10800 | return ResourceLoaderWrapper.lookupIconResource(name); |
91 | |
} |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public Component getTreeCellRendererComponent(JTree tree, Object value, |
102 | |
boolean sel, |
103 | |
boolean expanded, |
104 | |
boolean leaf, int row, |
105 | |
boolean hasTheFocus) { |
106 | |
|
107 | 11466 | Component r = super.getTreeCellRendererComponent(tree, value, sel, |
108 | |
expanded, leaf, |
109 | |
row, hasTheFocus); |
110 | |
|
111 | 11466 | if (r instanceof JLabel) { |
112 | 11466 | JLabel lab = (JLabel) r; |
113 | 11466 | if (value instanceof ToDoItem) { |
114 | 0 | ToDoItem item = (ToDoItem) value; |
115 | 0 | Poster post = item.getPoster(); |
116 | 0 | if (post instanceof Designer) { |
117 | 0 | if (item.getProgress() == 0) lab.setIcon(postItD0); |
118 | 0 | else if (item.getProgress() <= 25) lab.setIcon(postItD25); |
119 | 0 | else if (item.getProgress() <= 50) lab.setIcon(postItD50); |
120 | 0 | else if (item.getProgress() <= 75) lab.setIcon(postItD75); |
121 | 0 | else if (item.getProgress() <= 100) lab.setIcon(postItD99); |
122 | 0 | else lab.setIcon(postItD100); |
123 | |
} else { |
124 | 0 | if (item.getProgress() == 0) lab.setIcon(postIt0); |
125 | 0 | else if (item.getProgress() <= 25) lab.setIcon(postIt25); |
126 | 0 | else if (item.getProgress() <= 50) lab.setIcon(postIt50); |
127 | 0 | else if (item.getProgress() <= 75) lab.setIcon(postIt75); |
128 | 0 | else if (item.getProgress() <= 100) lab.setIcon(postIt99); |
129 | 0 | else lab.setIcon(postIt100); |
130 | |
} |
131 | |
|
132 | 0 | } else if (value instanceof Decision) { |
133 | 0 | lab.setIcon(MetalIconFactory.getTreeFolderIcon()); |
134 | 11466 | } else if (value instanceof Goal) { |
135 | 0 | lab.setIcon(MetalIconFactory.getTreeFolderIcon()); |
136 | 11466 | } else if (value instanceof Poster) { |
137 | 0 | lab.setIcon(MetalIconFactory.getTreeFolderIcon()); |
138 | 11466 | } else if (value instanceof PriorityNode) { |
139 | 9666 | lab.setIcon(MetalIconFactory.getTreeFolderIcon()); |
140 | 1800 | } else if (value instanceof KnowledgeTypeNode) { |
141 | 0 | lab.setIcon(MetalIconFactory.getTreeFolderIcon()); |
142 | 1800 | } else if (value instanceof Diagram) { |
143 | 0 | return treeCellRenderer.getTreeCellRendererComponent(tree, |
144 | |
value, |
145 | |
sel, |
146 | |
expanded, |
147 | |
leaf, |
148 | |
row, |
149 | |
hasTheFocus); |
150 | |
} else { |
151 | 1800 | Object newValue = value; |
152 | 1800 | if (newValue instanceof Fig) { |
153 | 0 | newValue = ((Fig) value).getOwner(); |
154 | |
} |
155 | 1800 | if (Model.getFacade().isAUMLElement(newValue)) { |
156 | 0 | return treeCellRenderer.getTreeCellRendererComponent( |
157 | |
tree, newValue, sel, expanded, leaf, row, |
158 | |
hasTheFocus); |
159 | |
} |
160 | |
} |
161 | |
|
162 | |
|
163 | |
|
164 | 11466 | String tip = lab.getText() + " "; |
165 | 11466 | lab.setToolTipText(tip); |
166 | 11466 | tree.setToolTipText(tip); |
167 | |
|
168 | 11466 | if (!sel) { |
169 | 11466 | lab.setBackground(getBackgroundNonSelectionColor()); |
170 | |
} else { |
171 | 0 | Color high = Globals.getPrefs().getHighlightColor(); |
172 | 0 | high = high.brighter().brighter(); |
173 | 0 | lab.setBackground(high); |
174 | |
} |
175 | 11466 | lab.setOpaque(sel); |
176 | |
} |
177 | 11466 | return r; |
178 | |
} |
179 | |
|
180 | |
|
181 | |
} |