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.notation.ui; |
40 | |
|
41 | |
import java.awt.BorderLayout; |
42 | |
import java.awt.Component; |
43 | |
import java.awt.FlowLayout; |
44 | |
import java.awt.GridBagConstraints; |
45 | |
import java.awt.GridBagLayout; |
46 | |
import java.awt.Insets; |
47 | |
|
48 | |
import javax.swing.BoxLayout; |
49 | |
import javax.swing.JCheckBox; |
50 | |
import javax.swing.JComboBox; |
51 | |
import javax.swing.JLabel; |
52 | |
import javax.swing.JPanel; |
53 | |
|
54 | |
import org.argouml.application.api.Argo; |
55 | |
import org.argouml.configuration.Configuration; |
56 | |
import org.argouml.configuration.ConfigurationKey; |
57 | |
import org.argouml.i18n.Translator; |
58 | |
import org.argouml.kernel.Project; |
59 | |
import org.argouml.kernel.ProjectSettings; |
60 | |
import org.argouml.notation.Notation; |
61 | |
import org.argouml.notation.NotationName; |
62 | |
import org.argouml.notation.NotationSettings; |
63 | |
import org.argouml.swingext.JLinkButton; |
64 | |
import org.argouml.ui.ActionProjectSettings; |
65 | |
import org.argouml.ui.GUIProjectSettingsTabInterface; |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | 900 | public class SettingsTabNotation |
81 | |
extends JPanel |
82 | |
implements GUIProjectSettingsTabInterface { |
83 | |
|
84 | |
private JPanel topPanel; |
85 | |
private JComboBox notationLanguage; |
86 | |
private JCheckBox useGuillemots; |
87 | |
private JCheckBox showAssociationNames; |
88 | |
private JCheckBox showVisibility; |
89 | |
private JCheckBox showMultiplicity; |
90 | |
private JCheckBox showInitialValue; |
91 | |
private JCheckBox showProperties; |
92 | |
private JCheckBox showTypes; |
93 | |
private JCheckBox showStereotypes; |
94 | |
private JCheckBox showSingularMultiplicities; |
95 | |
|
96 | |
private int scope; |
97 | |
private Project p; |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
public SettingsTabNotation(int settingsScope) { |
107 | 1800 | super(); |
108 | 1800 | scope = settingsScope; |
109 | 1800 | } |
110 | |
|
111 | |
private void buildPanel() { |
112 | 119 | setLayout(new BorderLayout()); |
113 | |
|
114 | 119 | topPanel = new JPanel(); |
115 | 119 | topPanel.setLayout(new BorderLayout()); |
116 | |
|
117 | 119 | if (scope == Argo.SCOPE_APPLICATION) { |
118 | 19 | JPanel warning = new JPanel(); |
119 | 19 | warning.setLayout(new BoxLayout(warning, BoxLayout.PAGE_AXIS)); |
120 | 19 | JLabel warningLabel = new JLabel(Translator |
121 | |
.localize("label.warning")); |
122 | 19 | warningLabel.setAlignmentX(Component.RIGHT_ALIGNMENT); |
123 | 19 | warning.add(warningLabel); |
124 | |
|
125 | 19 | JLinkButton projectSettings = new JLinkButton(); |
126 | 19 | projectSettings.setAction(new ActionProjectSettings()); |
127 | 19 | projectSettings.setText(Translator |
128 | |
.localize("button.project-settings")); |
129 | 19 | projectSettings.setIcon(null); |
130 | 19 | projectSettings.setAlignmentX(Component.RIGHT_ALIGNMENT); |
131 | 19 | warning.add(projectSettings); |
132 | |
|
133 | 19 | topPanel.add(warning, BorderLayout.NORTH); |
134 | |
} |
135 | |
|
136 | 119 | JPanel settings = new JPanel(); |
137 | 119 | settings.setLayout(new GridBagLayout()); |
138 | |
|
139 | 119 | GridBagConstraints constraints = new GridBagConstraints(); |
140 | 119 | constraints.anchor = GridBagConstraints.WEST; |
141 | 119 | constraints.fill = GridBagConstraints.HORIZONTAL; |
142 | 119 | constraints.gridy = 0; |
143 | 119 | constraints.gridx = 0; |
144 | 119 | constraints.gridwidth = 1; |
145 | 119 | constraints.gridheight = 1; |
146 | 119 | constraints.weightx = 1.0; |
147 | 119 | constraints.insets = new Insets(0, 30, 0, 4); |
148 | |
|
149 | 119 | constraints.gridy = GridBagConstraints.RELATIVE; |
150 | |
|
151 | 119 | JPanel notationLanguagePanel = |
152 | |
new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0)); |
153 | 119 | JLabel notationLanguageLabel = |
154 | |
createLabel("label.notation-language"); |
155 | 119 | notationLanguage = new NotationComboBox(); |
156 | 119 | notationLanguageLabel.setLabelFor(notationLanguage); |
157 | 119 | notationLanguagePanel.add(notationLanguageLabel); |
158 | 119 | notationLanguagePanel.add(notationLanguage); |
159 | 119 | settings.add(notationLanguagePanel, constraints); |
160 | |
|
161 | 119 | useGuillemots = createCheckBox("label.use-guillemots"); |
162 | 119 | settings.add(useGuillemots, constraints); |
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | 119 | showAssociationNames = createCheckBox("label.show-associationnames"); |
169 | 119 | settings.add(showAssociationNames, constraints); |
170 | |
|
171 | 119 | showVisibility = createCheckBox("label.show-visibility"); |
172 | 119 | settings.add(showVisibility, constraints); |
173 | |
|
174 | 119 | showMultiplicity = createCheckBox("label.show-multiplicity"); |
175 | 119 | settings.add(showMultiplicity, constraints); |
176 | |
|
177 | 119 | showInitialValue = createCheckBox("label.show-initialvalue"); |
178 | 119 | settings.add(showInitialValue, constraints); |
179 | |
|
180 | 119 | showProperties = createCheckBox("label.show-properties"); |
181 | 119 | settings.add(showProperties, constraints); |
182 | |
|
183 | 119 | showTypes = createCheckBox("label.show-types"); |
184 | 119 | settings.add(showTypes, constraints); |
185 | |
|
186 | 119 | showStereotypes = createCheckBox("label.show-stereotypes"); |
187 | 119 | settings.add(showStereotypes, constraints); |
188 | |
|
189 | 119 | showSingularMultiplicities = |
190 | |
createCheckBox("label.show-singular-multiplicities"); |
191 | 119 | settings.add(showSingularMultiplicities, constraints); |
192 | |
|
193 | 119 | topPanel.add(settings, BorderLayout.CENTER); |
194 | |
|
195 | 119 | add(topPanel, BorderLayout.NORTH); |
196 | 119 | } |
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
public void handleSettingsTabRefresh() { |
202 | 139 | if (scope == Argo.SCOPE_APPLICATION) { |
203 | 19 | useGuillemots.setSelected(getBoolean( |
204 | |
Notation.KEY_USE_GUILLEMOTS)); |
205 | 19 | notationLanguage.setSelectedItem(Notation.getConfiguredNotation()); |
206 | 19 | showAssociationNames.setSelected(Configuration.getBoolean( |
207 | |
Notation.KEY_SHOW_ASSOCIATION_NAMES, true)); |
208 | 19 | showVisibility.setSelected(getBoolean( |
209 | |
Notation.KEY_SHOW_VISIBILITY)); |
210 | 19 | showInitialValue.setSelected(getBoolean( |
211 | |
Notation.KEY_SHOW_INITIAL_VALUE)); |
212 | 19 | showProperties.setSelected(getBoolean( |
213 | |
Notation.KEY_SHOW_PROPERTIES)); |
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | 19 | showTypes.setSelected(Configuration.getBoolean( |
219 | |
Notation.KEY_SHOW_TYPES, true)); |
220 | 19 | showMultiplicity.setSelected(getBoolean( |
221 | |
Notation.KEY_SHOW_MULTIPLICITY)); |
222 | 19 | showStereotypes.setSelected(getBoolean( |
223 | |
Notation.KEY_SHOW_STEREOTYPES)); |
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | 19 | showSingularMultiplicities.setSelected(Configuration.getBoolean( |
231 | |
Notation.KEY_SHOW_SINGULAR_MULTIPLICITIES, true)); |
232 | |
} |
233 | 139 | if (scope == Argo.SCOPE_PROJECT) { |
234 | 120 | assert p != null; |
235 | 120 | ProjectSettings ps = p.getProjectSettings(); |
236 | 120 | NotationSettings ns = ps.getNotationSettings(); |
237 | |
|
238 | 120 | notationLanguage.setSelectedItem(Notation.findNotation( |
239 | |
ps.getNotationLanguage())); |
240 | 120 | useGuillemots.setSelected(ps.getUseGuillemotsValue()); |
241 | 120 | showAssociationNames.setSelected(ns.isShowAssociationNames()); |
242 | 120 | showVisibility.setSelected(ns.isShowVisibilities()); |
243 | 120 | showMultiplicity.setSelected(ns.isShowMultiplicities()); |
244 | 120 | showInitialValue.setSelected(ns.isShowInitialValues()); |
245 | 120 | showProperties.setSelected(ns.isShowProperties()); |
246 | 120 | showTypes.setSelected(ns.isShowTypes()); |
247 | 120 | showStereotypes.setSelected(ps.getShowStereotypesValue()); |
248 | 120 | showSingularMultiplicities.setSelected( |
249 | |
ns.isShowSingularMultiplicities()); |
250 | |
} |
251 | 139 | } |
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
protected static boolean getBoolean(ConfigurationKey key) { |
260 | 138 | return Configuration.getBoolean(key, false); |
261 | |
} |
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
public void handleSettingsTabSave() { |
267 | 12 | if (scope == Argo.SCOPE_APPLICATION) { |
268 | 0 | Notation.setDefaultNotation( |
269 | |
(NotationName) notationLanguage.getSelectedItem()); |
270 | 0 | Configuration.setBoolean(Notation.KEY_USE_GUILLEMOTS, |
271 | |
useGuillemots.isSelected()); |
272 | 0 | Configuration.setBoolean(Notation.KEY_SHOW_ASSOCIATION_NAMES, |
273 | |
showAssociationNames.isSelected()); |
274 | 0 | Configuration.setBoolean(Notation.KEY_SHOW_VISIBILITY, |
275 | |
showVisibility.isSelected()); |
276 | 0 | Configuration.setBoolean(Notation.KEY_SHOW_MULTIPLICITY, |
277 | |
showMultiplicity.isSelected()); |
278 | 0 | Configuration.setBoolean(Notation.KEY_SHOW_INITIAL_VALUE, |
279 | |
showInitialValue.isSelected()); |
280 | 0 | Configuration.setBoolean(Notation.KEY_SHOW_PROPERTIES, |
281 | |
showProperties.isSelected()); |
282 | 0 | Configuration.setBoolean(Notation.KEY_SHOW_TYPES, |
283 | |
showTypes.isSelected()); |
284 | 0 | Configuration.setBoolean(Notation.KEY_SHOW_STEREOTYPES, |
285 | |
showStereotypes.isSelected()); |
286 | 0 | Configuration.setBoolean(Notation.KEY_SHOW_SINGULAR_MULTIPLICITIES, |
287 | |
showSingularMultiplicities.isSelected()); |
288 | |
} |
289 | 12 | if (scope == Argo.SCOPE_PROJECT) { |
290 | 12 | assert p != null; |
291 | 12 | ProjectSettings ps = p.getProjectSettings(); |
292 | 12 | NotationSettings ns = ps.getNotationSettings(); |
293 | 12 | NotationName nn = (NotationName) notationLanguage.getSelectedItem(); |
294 | 12 | if (nn != null) { |
295 | 12 | ps.setNotationLanguage(nn.getConfigurationValue()); |
296 | |
} |
297 | 12 | ps.setUseGuillemots(useGuillemots.isSelected()); |
298 | 12 | ns.setShowAssociationNames(showAssociationNames.isSelected()); |
299 | 12 | ns.setShowVisibilities(showVisibility.isSelected()); |
300 | 12 | ns.setShowMultiplicities(showMultiplicity.isSelected()); |
301 | 12 | ns.setShowInitialValues(showInitialValue.isSelected()); |
302 | 12 | ns.setShowProperties(showProperties.isSelected()); |
303 | 12 | ns.setShowTypes(showTypes.isSelected()); |
304 | 12 | ps.setShowStereotypes(showStereotypes.isSelected()); |
305 | 12 | ns.setShowSingularMultiplicities( |
306 | |
showSingularMultiplicities.isSelected()); |
307 | |
} |
308 | 12 | } |
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
public void handleSettingsTabCancel() { |
314 | 6 | handleSettingsTabRefresh(); |
315 | 6 | } |
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | |
public void handleResetToDefault() { |
321 | 6 | if (scope == Argo.SCOPE_PROJECT) { |
322 | 6 | notationLanguage.setSelectedItem(Notation.getConfiguredNotation()); |
323 | 6 | useGuillemots.setSelected(getBoolean( |
324 | |
Notation.KEY_USE_GUILLEMOTS)); |
325 | 6 | showAssociationNames.setSelected(Configuration.getBoolean( |
326 | |
Notation.KEY_SHOW_ASSOCIATION_NAMES, true)); |
327 | 6 | showVisibility.setSelected(getBoolean( |
328 | |
Notation.KEY_SHOW_VISIBILITY)); |
329 | 6 | showMultiplicity.setSelected(getBoolean( |
330 | |
Notation.KEY_SHOW_MULTIPLICITY)); |
331 | 6 | showInitialValue.setSelected(getBoolean( |
332 | |
Notation.KEY_SHOW_INITIAL_VALUE)); |
333 | 6 | showProperties.setSelected(Configuration.getBoolean( |
334 | |
Notation.KEY_SHOW_PROPERTIES)); |
335 | 6 | showTypes.setSelected(Configuration.getBoolean( |
336 | |
Notation.KEY_SHOW_TYPES, true)); |
337 | 6 | showStereotypes.setSelected(Configuration.getBoolean( |
338 | |
Notation.KEY_SHOW_STEREOTYPES)); |
339 | 6 | showSingularMultiplicities.setSelected(Configuration.getBoolean( |
340 | |
Notation.KEY_SHOW_SINGULAR_MULTIPLICITIES)); |
341 | |
} |
342 | 6 | } |
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
public String getTabKey() { |
348 | 119 | return "tab.notation"; |
349 | |
} |
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
public JPanel getTabPanel() { |
355 | 119 | if (topPanel == null) { |
356 | 119 | buildPanel(); |
357 | |
} |
358 | 119 | return this; |
359 | |
} |
360 | |
|
361 | |
|
362 | |
|
363 | |
|
364 | |
|
365 | |
|
366 | |
|
367 | |
protected JCheckBox createCheckBox(String key) { |
368 | 1071 | JCheckBox j = new JCheckBox(Translator.localize(key)); |
369 | 1071 | return j; |
370 | |
} |
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
|
377 | |
|
378 | |
protected JLabel createLabel(String key) { |
379 | 119 | return new JLabel(Translator.localize(key)); |
380 | |
} |
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
public void setVisible(boolean visible) { |
386 | 136 | super.setVisible(visible); |
387 | 136 | if (visible) { |
388 | 14 | handleSettingsTabRefresh(); |
389 | |
} |
390 | 136 | } |
391 | |
|
392 | |
public void setProject(Project project) { |
393 | 100 | assert project != null; |
394 | 100 | p = project; |
395 | 100 | } |
396 | |
} |