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.BorderLayout; |
42 | |
import java.awt.event.ComponentEvent; |
43 | |
import java.awt.event.ComponentListener; |
44 | |
|
45 | |
import javax.swing.Action; |
46 | |
import javax.swing.JPanel; |
47 | |
import javax.swing.JToolBar; |
48 | |
import javax.swing.SwingConstants; |
49 | |
|
50 | |
import org.argouml.application.api.AbstractArgoJPanel; |
51 | |
import org.argouml.cognitive.ToDoItem; |
52 | |
import org.argouml.cognitive.critics.Wizard; |
53 | |
import org.argouml.configuration.Configuration; |
54 | |
import org.argouml.swingext.LeftArrowIcon; |
55 | |
import org.argouml.ui.TabToDoTarget; |
56 | |
import org.argouml.ui.targetmanager.TargetEvent; |
57 | |
import org.argouml.ui.targetmanager.TargetManager; |
58 | |
import org.tigris.swidgets.BorderSplitPane; |
59 | |
import org.tigris.swidgets.Horizontal; |
60 | |
import org.tigris.swidgets.Vertical; |
61 | |
import org.tigris.toolbar.ToolBarFactory; |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public class TabToDo extends AbstractArgoJPanel |
68 | |
implements TabToDoTarget, ComponentListener { |
69 | |
|
70 | |
private static int numHushes; |
71 | |
|
72 | 900 | private static final Action actionNewToDoItem = new ActionNewToDoItem(); |
73 | 900 | private static final ToDoItemAction actionResolve = new ActionResolve(); |
74 | 900 | private static final ToDoItemAction actionSnooze = new ActionSnooze(); |
75 | |
|
76 | 900 | private WizDescription description = new WizDescription(); |
77 | |
private JPanel lastPanel; |
78 | |
private BorderSplitPane splitPane; |
79 | |
private Object target; |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
public static void incrementNumHushes() { |
85 | 0 | numHushes++; |
86 | 0 | } |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public TabToDo() { |
92 | 900 | super("tab.todo-item"); |
93 | 900 | setIcon(new LeftArrowIcon()); |
94 | |
|
95 | 900 | String position = |
96 | |
Configuration.getString(Configuration.makeKey("layout", |
97 | |
"tabtodo")); |
98 | 900 | setOrientation( |
99 | |
((position.equals("West") || position.equals("East")) |
100 | |
? Vertical.getInstance() : Horizontal.getInstance())); |
101 | |
|
102 | 900 | setLayout(new BorderLayout()); |
103 | |
|
104 | 900 | Object[] actions = {actionNewToDoItem, actionResolve, actionSnooze }; |
105 | 900 | ToolBarFactory factory = new ToolBarFactory(actions); |
106 | 900 | factory.setRollover(true); |
107 | 900 | factory.setFloatable(false); |
108 | 900 | factory.setOrientation(SwingConstants.VERTICAL); |
109 | 900 | JToolBar toolBar = factory.createToolBar(); |
110 | 900 | toolBar.setName(getTitle()); |
111 | 900 | add(toolBar, BorderLayout.WEST); |
112 | |
|
113 | 900 | splitPane = new BorderSplitPane(); |
114 | 900 | add(splitPane, BorderLayout.CENTER); |
115 | 900 | setTarget(null); |
116 | |
|
117 | 900 | addComponentListener(this); |
118 | |
|
119 | |
|
120 | |
|
121 | 900 | } |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
public void showDescription() { |
127 | 2291 | if (lastPanel != null) { |
128 | 1391 | splitPane.remove(lastPanel); |
129 | |
} |
130 | 2291 | splitPane.add(description, BorderSplitPane.CENTER); |
131 | 2291 | lastPanel = description; |
132 | 2291 | validate(); |
133 | 2291 | repaint(); |
134 | 2291 | } |
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
public void setTree(ToDoPane tdp) { |
140 | 0 | if (getOrientation().equals(Horizontal.getInstance())) { |
141 | 0 | splitPane.add(tdp, BorderSplitPane.WEST); |
142 | |
} else { |
143 | 0 | splitPane.add(tdp, BorderSplitPane.NORTH); |
144 | |
} |
145 | 0 | } |
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
public void showStep(JPanel ws) { |
151 | |
|
152 | |
|
153 | |
|
154 | 0 | if (lastPanel != null) { |
155 | 0 | splitPane.remove(lastPanel); |
156 | |
} |
157 | 0 | if (ws != null) { |
158 | 0 | splitPane.add(ws, BorderSplitPane.CENTER); |
159 | 0 | lastPanel = ws; |
160 | |
} else { |
161 | 0 | splitPane.add(description, BorderSplitPane.CENTER); |
162 | 0 | lastPanel = description; |
163 | |
} |
164 | 0 | validate(); |
165 | 0 | repaint(); |
166 | 0 | } |
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
public void setTarget(Object item) { |
174 | 2353 | target = item; |
175 | 2353 | if (isVisible()) { |
176 | 1152 | setTargetInternal(item); |
177 | |
} |
178 | |
|
179 | |
|
180 | |
|
181 | 2353 | } |
182 | |
|
183 | |
private void setTargetInternal(Object item) { |
184 | |
|
185 | 2291 | description.setTarget(item); |
186 | 2291 | Wizard w = null; |
187 | 2291 | if (item instanceof ToDoItem) { |
188 | 0 | w = ((ToDoItem) item).getWizard(); |
189 | |
} |
190 | 2291 | if (w != null) { |
191 | 0 | showStep(w.getCurrentPanel()); |
192 | |
} else { |
193 | 2291 | showDescription(); |
194 | |
} |
195 | 2291 | updateActionsEnabled(item); |
196 | 2291 | } |
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
public Object getTarget() { |
204 | 0 | return target; |
205 | |
} |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
public void refresh() { |
212 | 0 | setTarget(TargetManager.getInstance().getTarget()); |
213 | 0 | } |
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
protected static void updateActionsEnabled(Object item) { |
221 | 2291 | actionResolve.setEnabled(actionResolve.isEnabled()); |
222 | 2291 | actionResolve.updateEnabled(item); |
223 | 2291 | actionSnooze.setEnabled(actionSnooze.isEnabled()); |
224 | 2291 | actionSnooze.updateEnabled(item); |
225 | 2291 | } |
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
public void targetAdded(TargetEvent e) { |
232 | 0 | setTarget(e.getNewTarget()); |
233 | 0 | } |
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
public void targetRemoved(TargetEvent e) { |
240 | |
|
241 | |
|
242 | 88 | setTarget(e.getNewTarget()); |
243 | 88 | } |
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
public void targetSet(TargetEvent e) { |
249 | 1239 | setTarget(e.getNewTarget()); |
250 | 1239 | } |
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
private static final long serialVersionUID = 4819730646847978729L; |
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
public void componentShown(ComponentEvent e) { |
261 | |
|
262 | 126 | setTargetInternal(target); |
263 | 126 | } |
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
public void componentHidden(ComponentEvent e) { |
269 | |
|
270 | 1013 | setTargetInternal(null); |
271 | 1013 | } |
272 | |
|
273 | |
public void componentMoved(ComponentEvent e) { |
274 | |
|
275 | 900 | } |
276 | |
|
277 | |
public void componentResized(ComponentEvent e) { |
278 | |
|
279 | 900 | } |
280 | |
|
281 | |
|
282 | |
} |