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.Insets; |
42 | |
import java.awt.event.ActionEvent; |
43 | |
|
44 | |
import javax.swing.DefaultListModel; |
45 | |
import javax.swing.JComboBox; |
46 | |
import javax.swing.JLabel; |
47 | |
import javax.swing.JList; |
48 | |
import javax.swing.JPanel; |
49 | |
import javax.swing.JScrollPane; |
50 | |
import javax.swing.JTextArea; |
51 | |
import javax.swing.JTextField; |
52 | |
import javax.swing.ListCellRenderer; |
53 | |
|
54 | |
import org.argouml.cognitive.Designer; |
55 | |
import org.argouml.cognitive.ListSet; |
56 | |
import org.argouml.cognitive.ToDoItem; |
57 | |
import org.argouml.cognitive.Translator; |
58 | |
import org.argouml.ui.targetmanager.TargetManager; |
59 | |
import org.argouml.uml.cognitive.UMLToDoItem; |
60 | |
import org.argouml.util.ArgoDialog; |
61 | |
import org.tigris.swidgets.Dialog; |
62 | |
import org.tigris.swidgets.LabelledLayout; |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public class AddToDoItemDialog extends ArgoDialog { |
68 | |
|
69 | |
|
70 | |
|
71 | 0 | private static final String[] PRIORITIES = { |
72 | |
Translator.localize("misc.level.high"), |
73 | |
Translator.localize("misc.level.medium"), |
74 | |
Translator.localize("misc.level.low"), |
75 | |
}; |
76 | |
private static final int TEXT_ROWS = 8; |
77 | |
private static final int TEXT_COLUMNS = 30; |
78 | |
|
79 | |
private static final int INSET_PX = 3; |
80 | |
|
81 | |
|
82 | |
|
83 | |
private JTextField headLineTextField; |
84 | |
private JComboBox priorityComboBox; |
85 | |
private JTextField moreinfoTextField; |
86 | |
private JList offenderList; |
87 | |
private JTextArea descriptionTextArea; |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
public AddToDoItemDialog(ListCellRenderer renderer) { |
96 | 0 | super(Translator.localize("dialog.title.add-todo-item"), |
97 | |
Dialog.OK_CANCEL_OPTION, true); |
98 | |
|
99 | 0 | headLineTextField = new JTextField(TEXT_COLUMNS); |
100 | 0 | priorityComboBox = new JComboBox(PRIORITIES); |
101 | 0 | moreinfoTextField = new JTextField(TEXT_COLUMNS); |
102 | 0 | descriptionTextArea = new JTextArea(TEXT_ROWS, TEXT_COLUMNS); |
103 | |
|
104 | 0 | DefaultListModel dlm = new DefaultListModel(); |
105 | 0 | Object[] offObj = |
106 | |
TargetManager.getInstance().getModelTargets().toArray(); |
107 | 0 | for (int i = 0; i < offObj.length; i++) { |
108 | 0 | if (offObj[i] != null) { |
109 | 0 | dlm.addElement(offObj[i]); |
110 | |
} |
111 | |
} |
112 | |
|
113 | 0 | offenderList = new JList(dlm); |
114 | 0 | offenderList.setCellRenderer(renderer); |
115 | 0 | JScrollPane offenderScroll = new JScrollPane(offenderList); |
116 | 0 | offenderScroll.setOpaque(true); |
117 | |
|
118 | 0 | JLabel headlineLabel = |
119 | |
new JLabel(Translator.localize("label.headline")); |
120 | 0 | JLabel priorityLabel = |
121 | |
new JLabel(Translator.localize("label.priority")); |
122 | 0 | JLabel moreInfoLabel = |
123 | |
new JLabel(Translator.localize("label.more-info-url")); |
124 | 0 | JLabel offenderLabel = |
125 | |
new JLabel(Translator.localize("label.offenders")); |
126 | 0 | priorityComboBox.setSelectedItem(PRIORITIES[0]); |
127 | |
|
128 | 0 | JPanel panel = new JPanel(new LabelledLayout(getLabelGap(), |
129 | |
getComponentGap())); |
130 | |
|
131 | 0 | headlineLabel.setLabelFor(headLineTextField); |
132 | 0 | panel.add(headlineLabel); |
133 | 0 | panel.add(headLineTextField); |
134 | |
|
135 | 0 | priorityLabel.setLabelFor(priorityComboBox); |
136 | 0 | panel.add(priorityLabel); |
137 | 0 | panel.add(priorityComboBox); |
138 | |
|
139 | 0 | moreInfoLabel.setLabelFor(moreinfoTextField); |
140 | 0 | panel.add(moreInfoLabel); |
141 | 0 | panel.add(moreinfoTextField); |
142 | |
|
143 | 0 | offenderLabel.setLabelFor(offenderScroll); |
144 | 0 | panel.add(offenderLabel); |
145 | 0 | panel.add(offenderScroll); |
146 | |
|
147 | 0 | descriptionTextArea.setLineWrap(true); |
148 | 0 | descriptionTextArea.setWrapStyleWord(true); |
149 | 0 | descriptionTextArea.setText(Translator.localize("label.enter-todo-item") |
150 | |
+ "\n"); |
151 | 0 | descriptionTextArea.setMargin(new Insets(INSET_PX, INSET_PX, |
152 | |
INSET_PX, INSET_PX)); |
153 | 0 | JScrollPane descriptionScroller = new JScrollPane(descriptionTextArea); |
154 | 0 | descriptionScroller.setPreferredSize( |
155 | |
descriptionTextArea.getPreferredSize()); |
156 | 0 | panel.add(descriptionScroller); |
157 | |
|
158 | 0 | setContent(panel); |
159 | 0 | } |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
@Override |
166 | |
public void actionPerformed(ActionEvent e) { |
167 | 0 | super.actionPerformed(e); |
168 | 0 | if (e.getSource() == getOkButton()) { |
169 | 0 | doAdd(); |
170 | |
} |
171 | 0 | } |
172 | |
|
173 | |
private void doAdd() { |
174 | 0 | Designer designer = Designer.theDesigner(); |
175 | 0 | String headline = headLineTextField.getText(); |
176 | 0 | int priority = ToDoItem.HIGH_PRIORITY; |
177 | 0 | switch (priorityComboBox.getSelectedIndex()) { |
178 | |
case 0: |
179 | 0 | priority = ToDoItem.HIGH_PRIORITY; |
180 | 0 | break; |
181 | |
case 1: |
182 | 0 | priority = ToDoItem.MED_PRIORITY; |
183 | 0 | break; |
184 | |
case 2: |
185 | 0 | priority = ToDoItem.LOW_PRIORITY; |
186 | |
break; |
187 | |
} |
188 | 0 | String desc = descriptionTextArea.getText(); |
189 | 0 | String moreInfoURL = moreinfoTextField.getText(); |
190 | 0 | ListSet newOffenders = new ListSet(); |
191 | 0 | for (int i = 0; i < offenderList.getModel().getSize(); i++) { |
192 | 0 | newOffenders.add(offenderList.getModel().getElementAt(i)); |
193 | |
} |
194 | 0 | ToDoItem item = |
195 | |
new UMLToDoItem(designer, headline, priority, desc, moreInfoURL, newOffenders); |
196 | 0 | designer.getToDoList().addElement(item); |
197 | 0 | Designer.firePropertyChange(Designer.MODEL_TODOITEM_ADDED, null, item); |
198 | 0 | } |
199 | |
} |
200 | |
|