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.GridBagConstraints; |
42 | |
import java.awt.GridBagLayout; |
43 | |
import java.awt.Insets; |
44 | |
import java.awt.event.ActionEvent; |
45 | |
import java.awt.event.ActionListener; |
46 | |
|
47 | |
import javax.swing.ButtonGroup; |
48 | |
import javax.swing.JLabel; |
49 | |
import javax.swing.JOptionPane; |
50 | |
import javax.swing.JPanel; |
51 | |
import javax.swing.JRadioButton; |
52 | |
import javax.swing.JScrollPane; |
53 | |
import javax.swing.JTextArea; |
54 | |
|
55 | |
import org.apache.log4j.Logger; |
56 | |
import org.argouml.cognitive.Designer; |
57 | |
import org.argouml.cognitive.ToDoItem; |
58 | |
import org.argouml.cognitive.ToDoList; |
59 | |
import org.argouml.cognitive.Translator; |
60 | |
import org.argouml.cognitive.UnresolvableException; |
61 | |
import org.argouml.util.ArgoDialog; |
62 | |
import org.tigris.swidgets.Dialog; |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | 0 | public class DismissToDoItemDialog extends ArgoDialog { |
69 | |
|
70 | 0 | private static final Logger LOG = |
71 | |
Logger.getLogger(DismissToDoItemDialog.class); |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
private JRadioButton badGoalButton; |
77 | |
private JRadioButton badDecButton; |
78 | |
private JRadioButton explainButton; |
79 | |
private ButtonGroup actionGroup; |
80 | |
private JTextArea explanation; |
81 | |
private ToDoItem target; |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public DismissToDoItemDialog() { |
90 | 0 | super( |
91 | |
Translator.localize("dialog.title.dismiss-todo-item"), |
92 | |
Dialog.OK_CANCEL_OPTION, |
93 | |
true); |
94 | |
|
95 | 0 | JLabel instrLabel = |
96 | |
new JLabel(Translator.localize("label.remove-item")); |
97 | |
|
98 | 0 | badGoalButton = new JRadioButton(Translator.localize( |
99 | |
"button.not-relevant-to-my-goals")); |
100 | 0 | badDecButton = new JRadioButton(Translator.localize( |
101 | |
"button.not-of-concern-at-moment")); |
102 | 0 | explainButton = new JRadioButton(Translator.localize( |
103 | |
"button.reason-given-below")); |
104 | |
|
105 | 0 | badGoalButton.setMnemonic( |
106 | |
Translator.localize( |
107 | |
"button.not-relevant-to-my-goals.mnemonic") |
108 | |
.charAt(0)); |
109 | 0 | badDecButton.setMnemonic( |
110 | |
Translator.localize( |
111 | |
"button.not-of-concern-at-moment.mnemonic") |
112 | |
.charAt(0)); |
113 | 0 | explainButton.setMnemonic( |
114 | |
Translator.localize("button.reason-given-below.mnemonic").charAt( |
115 | |
0)); |
116 | |
|
117 | 0 | JPanel content = new JPanel(); |
118 | |
|
119 | 0 | GridBagLayout gb = new GridBagLayout(); |
120 | 0 | GridBagConstraints c = new GridBagConstraints(); |
121 | |
|
122 | 0 | c.fill = GridBagConstraints.BOTH; |
123 | 0 | c.weightx = 1.0; |
124 | 0 | c.gridwidth = 2; |
125 | |
|
126 | 0 | content.setLayout(gb); |
127 | |
|
128 | 0 | explanation = new JTextArea(6, 40); |
129 | 0 | explanation.setLineWrap(true); |
130 | 0 | explanation.setWrapStyleWord(true); |
131 | 0 | JScrollPane explain = new JScrollPane(explanation); |
132 | |
|
133 | 0 | c.gridx = 0; |
134 | 0 | c.gridy = 0; |
135 | |
|
136 | 0 | gb.setConstraints(instrLabel, c); |
137 | 0 | content.add(instrLabel); |
138 | |
|
139 | 0 | c.gridy = 1; |
140 | 0 | c.insets = new Insets(5, 0, 0, 0); |
141 | |
|
142 | 0 | gb.setConstraints(badGoalButton, c); |
143 | 0 | content.add(badGoalButton); |
144 | |
|
145 | 0 | c.gridy = 2; |
146 | |
|
147 | 0 | gb.setConstraints(badDecButton, c); |
148 | 0 | content.add(badDecButton); |
149 | |
|
150 | 0 | c.gridy = 3; |
151 | |
|
152 | 0 | gb.setConstraints(explainButton, c); |
153 | 0 | content.add(explainButton); |
154 | |
|
155 | 0 | c.gridy = 4; |
156 | 0 | c.weighty = 1.0; |
157 | |
|
158 | 0 | gb.setConstraints(explain, c); |
159 | 0 | content.add(explain); |
160 | |
|
161 | 0 | setContent(content); |
162 | |
|
163 | 0 | getOkButton().addActionListener(new ActionListener() { |
164 | |
public void actionPerformed(ActionEvent e) { |
165 | 0 | if (badGoalButton.getModel().isSelected()) { |
166 | 0 | badGoal(e); |
167 | |
} |
168 | 0 | else if (badDecButton.getModel().isSelected()) { |
169 | 0 | badDec(e); |
170 | |
} |
171 | 0 | else if (explainButton.getModel().isSelected()) { |
172 | 0 | explain(e); |
173 | |
} |
174 | |
else { |
175 | 0 | LOG.warn("DissmissToDoItemDialog: Unknown action: " + e); |
176 | |
} |
177 | 0 | } |
178 | |
}); |
179 | |
|
180 | 0 | actionGroup = new ButtonGroup(); |
181 | 0 | actionGroup.add(badGoalButton); |
182 | 0 | actionGroup.add(badDecButton); |
183 | 0 | actionGroup.add(explainButton); |
184 | 0 | actionGroup.setSelected(explainButton.getModel(), true); |
185 | |
|
186 | 0 | explanation.setText( |
187 | |
Translator.localize("label.enter-rationale-here")); |
188 | |
|
189 | 0 | badGoalButton.addActionListener(new ActionListener() { |
190 | |
public void actionPerformed(ActionEvent e) { |
191 | 0 | explanation.setEnabled(false); |
192 | 0 | } |
193 | |
}); |
194 | 0 | badDecButton.addActionListener(new ActionListener() { |
195 | |
public void actionPerformed(ActionEvent e) { |
196 | 0 | explanation.setEnabled(false); |
197 | 0 | } |
198 | |
}); |
199 | 0 | explainButton.addActionListener(new ActionListener() { |
200 | |
public void actionPerformed(ActionEvent e) { |
201 | 0 | explanation.setEnabled(true); |
202 | 0 | explanation.requestFocus(); |
203 | 0 | explanation.selectAll(); |
204 | 0 | } |
205 | |
}); |
206 | 0 | } |
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
public void setTarget(Object t) { |
212 | 0 | target = (ToDoItem) t; |
213 | 0 | } |
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
public void setVisible(boolean b) { |
221 | 0 | super.setVisible(b); |
222 | 0 | if (b) { |
223 | 0 | explanation.requestFocus(); |
224 | 0 | explanation.selectAll(); |
225 | |
} |
226 | 0 | } |
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
private void badGoal(ActionEvent e) { |
232 | |
|
233 | 0 | GoalsDialog d = new GoalsDialog(); |
234 | 0 | d.setVisible(true); |
235 | 0 | } |
236 | |
|
237 | |
private void badDec(ActionEvent e) { |
238 | |
|
239 | 0 | DesignIssuesDialog d = new DesignIssuesDialog(); |
240 | 0 | d.setVisible(true); |
241 | 0 | } |
242 | |
|
243 | |
private void explain(ActionEvent e) { |
244 | |
|
245 | 0 | ToDoList list = Designer.theDesigner().getToDoList(); |
246 | |
try { |
247 | 0 | list.explicitlyResolve(target, explanation.getText()); |
248 | 0 | Designer.firePropertyChange( |
249 | |
Designer.MODEL_TODOITEM_DISMISSED, null, null); |
250 | |
} |
251 | 0 | catch (UnresolvableException ure) { |
252 | 0 | LOG.error("Resolve failed (ure): ", ure); |
253 | 0 | JOptionPane.showMessageDialog( |
254 | |
this, |
255 | |
ure.getMessage(), |
256 | |
Translator.localize("optionpane.dismiss-failed"), |
257 | |
JOptionPane.ERROR_MESSAGE); |
258 | 0 | } |
259 | 0 | } |
260 | |
} |