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.Dimension; |
42 | |
import java.awt.GridBagConstraints; |
43 | |
import java.awt.GridBagLayout; |
44 | |
import java.util.Hashtable; |
45 | |
import java.util.List; |
46 | |
|
47 | |
import javax.swing.BorderFactory; |
48 | |
import javax.swing.JLabel; |
49 | |
import javax.swing.JPanel; |
50 | |
import javax.swing.JScrollPane; |
51 | |
import javax.swing.JSlider; |
52 | |
import javax.swing.SwingConstants; |
53 | |
import javax.swing.event.ChangeEvent; |
54 | |
import javax.swing.event.ChangeListener; |
55 | |
|
56 | |
import org.argouml.cognitive.Decision; |
57 | |
import org.argouml.cognitive.DecisionModel; |
58 | |
import org.argouml.cognitive.Designer; |
59 | |
import org.argouml.cognitive.Translator; |
60 | |
import org.argouml.util.ArgoDialog; |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public class DesignIssuesDialog extends ArgoDialog implements ChangeListener { |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | 0 | private JPanel mainPanel = new JPanel(); |
74 | 0 | private Hashtable<JSlider, Decision> slidersToDecisions = |
75 | |
new Hashtable<JSlider, Decision>(); |
76 | 0 | private Hashtable<JSlider, JLabel> slidersToDigits = |
77 | |
new Hashtable<JSlider, JLabel>(); |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
public DesignIssuesDialog() { |
86 | 0 | super(Translator.localize("dialog.title.design-issues"), false); |
87 | |
|
88 | 0 | final int width = 320; |
89 | 0 | final int height = 400; |
90 | |
|
91 | 0 | initMainPanel(); |
92 | |
|
93 | 0 | JScrollPane scroll = new JScrollPane(mainPanel); |
94 | 0 | scroll.setPreferredSize(new Dimension(width, height)); |
95 | |
|
96 | 0 | setContent(scroll); |
97 | 0 | } |
98 | |
|
99 | |
|
100 | |
private void initMainPanel() { |
101 | 0 | DecisionModel dm = Designer.theDesigner().getDecisionModel(); |
102 | 0 | List<Decision> decs = dm.getDecisionList(); |
103 | |
|
104 | 0 | GridBagLayout gb = new GridBagLayout(); |
105 | 0 | mainPanel.setLayout(gb); |
106 | 0 | mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
107 | |
|
108 | 0 | GridBagConstraints c = new GridBagConstraints(); |
109 | 0 | c.fill = GridBagConstraints.BOTH; |
110 | 0 | c.weightx = 1.0; |
111 | 0 | c.weighty = 0.0; |
112 | 0 | c.ipadx = 3; c.ipady = 3; |
113 | |
|
114 | |
|
115 | 0 | c.gridy = 0; |
116 | 0 | c.gridx = 0; |
117 | 0 | c.gridwidth = 1; |
118 | 0 | JLabel decTitleLabel = new JLabel( |
119 | |
Translator.localize("label.decision")); |
120 | 0 | gb.setConstraints(decTitleLabel, c); |
121 | 0 | mainPanel.add(decTitleLabel); |
122 | |
|
123 | 0 | c.gridy = 0; |
124 | 0 | c.gridx = 2; |
125 | 0 | c.gridwidth = 8; |
126 | 0 | JLabel priLabel = new JLabel( |
127 | |
Translator.localize("label.decision-priority")); |
128 | 0 | gb.setConstraints(priLabel, c); |
129 | 0 | mainPanel.add(priLabel); |
130 | |
|
131 | 0 | c.gridy = 1; |
132 | 0 | c.gridx = 2; |
133 | 0 | c.gridwidth = 2; |
134 | 0 | JLabel offLabel = new JLabel(Translator.localize("label.off")); |
135 | 0 | gb.setConstraints(offLabel, c); |
136 | 0 | mainPanel.add(offLabel); |
137 | |
|
138 | 0 | c.gridy = 1; |
139 | 0 | c.gridx = 4; |
140 | 0 | c.gridwidth = 2; |
141 | 0 | JLabel lowLabel = new JLabel(Translator.localize("label.low")); |
142 | 0 | gb.setConstraints(lowLabel, c); |
143 | 0 | mainPanel.add(lowLabel); |
144 | |
|
145 | 0 | c.gridy = 1; |
146 | 0 | c.gridx = 6; |
147 | 0 | c.gridwidth = 2; |
148 | 0 | JLabel mediumLabel = new JLabel(Translator.localize("label.medium")); |
149 | 0 | gb.setConstraints(mediumLabel, c); |
150 | 0 | mainPanel.add(mediumLabel); |
151 | |
|
152 | 0 | c.gridy = 1; |
153 | 0 | c.gridx = 8; |
154 | 0 | c.gridwidth = 2; |
155 | 0 | JLabel highLabel = new JLabel(Translator.localize("label.high")); |
156 | 0 | gb.setConstraints(highLabel, c); |
157 | 0 | mainPanel.add(highLabel); |
158 | |
|
159 | |
|
160 | 0 | c.gridy = 2; |
161 | 0 | for (Decision d : decs) { |
162 | 0 | JLabel decLabel = new JLabel(d.getName()); |
163 | 0 | JLabel valueLabel = new JLabel(getValueText(d.getPriority())); |
164 | 0 | JSlider decSlide = |
165 | |
new JSlider(SwingConstants.HORIZONTAL, |
166 | |
1, 4, (d.getPriority() == 0 ? 4 : d.getPriority())); |
167 | |
|
168 | 0 | decSlide.setInverted(true); |
169 | 0 | decSlide.setMajorTickSpacing(1); |
170 | 0 | decSlide.setPaintTicks(true); |
171 | 0 | decSlide.setSnapToTicks(true); |
172 | |
|
173 | 0 | decSlide.addChangeListener(this); |
174 | 0 | Dimension origSize = decSlide.getPreferredSize(); |
175 | 0 | Dimension smallSize = |
176 | |
new Dimension(origSize.width / 2, origSize.height); |
177 | 0 | decSlide.setSize(smallSize); |
178 | 0 | decSlide.setPreferredSize(smallSize); |
179 | |
|
180 | 0 | slidersToDecisions.put(decSlide, d); |
181 | 0 | slidersToDigits.put(decSlide, valueLabel); |
182 | |
|
183 | 0 | c.gridx = 0; |
184 | 0 | c.gridwidth = 1; |
185 | 0 | c.weightx = 0.0; |
186 | 0 | c.ipadx = 3; |
187 | 0 | gb.setConstraints(decLabel, c); |
188 | 0 | mainPanel.add(decLabel); |
189 | |
|
190 | 0 | c.gridx = 1; |
191 | 0 | c.gridwidth = 1; |
192 | 0 | c.weightx = 0.0; |
193 | 0 | c.ipadx = 0; |
194 | 0 | gb.setConstraints(valueLabel, c); |
195 | 0 | mainPanel.add(valueLabel); |
196 | |
|
197 | 0 | c.gridx = 2; |
198 | 0 | c.gridwidth = 8; |
199 | 0 | c.weightx = 1.0; |
200 | 0 | gb.setConstraints(decSlide, c); |
201 | 0 | mainPanel.add(decSlide); |
202 | |
|
203 | 0 | c.gridy++; |
204 | 0 | } |
205 | 0 | } |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
public void stateChanged(ChangeEvent ce) { |
214 | 0 | JSlider srcSlider = (JSlider) ce.getSource(); |
215 | 0 | Decision d = slidersToDecisions.get(srcSlider); |
216 | 0 | JLabel valLab = slidersToDigits.get(srcSlider); |
217 | 0 | int pri = srcSlider.getValue(); |
218 | 0 | d.setPriority((pri == 4) ? 0 : pri); |
219 | 0 | valLab.setText(getValueText(pri)); |
220 | 0 | } |
221 | |
|
222 | |
private String getValueText(int priority) { |
223 | 0 | String label = ""; |
224 | 0 | switch(priority) { |
225 | |
case 1: |
226 | 0 | label = " 1"; |
227 | 0 | break; |
228 | |
case 2: |
229 | 0 | label = " 2"; |
230 | 0 | break; |
231 | |
case 3: |
232 | 0 | label = " 3"; |
233 | 0 | break; |
234 | |
case 0: |
235 | |
case 4: |
236 | 0 | label = Translator.localize("label.off"); |
237 | |
break; |
238 | |
} |
239 | 0 | return label; |
240 | |
} |
241 | |
|
242 | |
} |
243 | |
|
244 | |
|
245 | |
|
246 | |
|