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; |
40 | |
|
41 | |
import org.tigris.gef.undo.Memento; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | 31761 | public class NotationSettings { |
54 | |
|
55 | 900 | private static final NotationSettings DEFAULT_SETTINGS = |
56 | |
initializeDefaultSettings(); |
57 | |
|
58 | |
private NotationSettings parent; |
59 | |
|
60 | |
private String notationLanguage; |
61 | |
|
62 | |
|
63 | |
|
64 | |
private boolean showAssociationNames; |
65 | |
|
66 | 4010 | private boolean showAssociationNamesSet = false; |
67 | |
|
68 | |
private boolean showVisibilities; |
69 | |
|
70 | 4010 | private boolean showVisibilitiesSet = false; |
71 | |
|
72 | |
private boolean showPaths; |
73 | |
|
74 | 4010 | private boolean showPathsSet = false; |
75 | |
|
76 | |
private boolean fullyHandleStereotypes; |
77 | |
|
78 | 4010 | private boolean fullyHandleStereotypesSet = false; |
79 | |
|
80 | |
private boolean useGuillemets; |
81 | |
|
82 | 4010 | private boolean useGuillemetsSet = false; |
83 | |
|
84 | |
private boolean showMultiplicities; |
85 | |
|
86 | 4010 | private boolean showMultiplicitiesSet = false; |
87 | |
|
88 | |
private boolean showSingularMultiplicities; |
89 | |
|
90 | 4010 | private boolean showSingularMultiplicitiesSet = false; |
91 | |
|
92 | |
|
93 | |
private boolean showTypes; |
94 | |
|
95 | 4010 | private boolean showTypesSet = false; |
96 | |
|
97 | |
private boolean showProperties; |
98 | |
|
99 | 4010 | private boolean showPropertiesSet = false; |
100 | |
|
101 | |
private boolean showInitialValues; |
102 | |
|
103 | 4010 | private boolean showInitialValuesSet = false; |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
public NotationSettings() { |
112 | 4010 | super(); |
113 | 4010 | parent = getDefaultSettings(); |
114 | 4010 | } |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
public NotationSettings(NotationSettings parentSettings) { |
122 | 1071 | this(); |
123 | 1071 | parent = parentSettings; |
124 | 1071 | } |
125 | |
|
126 | |
|
127 | |
private static NotationSettings initializeDefaultSettings() { |
128 | 900 | NotationSettings settings = new NotationSettings(); |
129 | 900 | settings.parent = null; |
130 | 900 | settings.setNotationLanguage(Notation.DEFAULT_NOTATION); |
131 | 900 | settings.setFullyHandleStereotypes(false); |
132 | 900 | settings.setShowAssociationNames(true); |
133 | 900 | settings.setShowInitialValues(false); |
134 | 900 | settings.setShowMultiplicities(false); |
135 | 900 | settings.setShowPaths(false); |
136 | 900 | settings.setShowProperties(false); |
137 | 900 | settings.setShowSingularMultiplicities(true); |
138 | 900 | settings.setShowTypes(true); |
139 | 900 | settings.setShowVisibilities(false); |
140 | 900 | settings.setUseGuillemets(false); |
141 | 900 | return settings; |
142 | |
} |
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
public static NotationSettings getDefaultSettings() { |
148 | 4010 | return DEFAULT_SETTINGS; |
149 | |
} |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
public String getNotationLanguage() { |
155 | 157 | if (notationLanguage == null) { |
156 | 0 | if (parent != null) { |
157 | 0 | return parent.getNotationLanguage(); |
158 | |
} else { |
159 | 0 | return Notation.DEFAULT_NOTATION; |
160 | |
} |
161 | |
} |
162 | 157 | return notationLanguage; |
163 | |
} |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
public boolean setNotationLanguage(final String newLanguage) { |
171 | 1869 | if (notationLanguage != null |
172 | |
&& notationLanguage.equals(newLanguage)) { |
173 | 0 | return true; |
174 | |
} |
175 | |
|
176 | |
|
177 | 1869 | if (Notation.findNotation(newLanguage) == null) { |
178 | |
|
179 | 0 | return false; |
180 | |
} |
181 | |
|
182 | 1869 | final String oldLanguage = notationLanguage; |
183 | |
|
184 | 1869 | Memento memento = new Memento() { |
185 | |
public void redo() { |
186 | 1869 | notationLanguage = newLanguage; |
187 | |
|
188 | |
|
189 | 1869 | } |
190 | |
|
191 | |
public void undo() { |
192 | 0 | notationLanguage = oldLanguage; |
193 | |
|
194 | |
|
195 | 0 | } |
196 | |
}; |
197 | 1869 | doUndoable(memento); |
198 | 1869 | return true; |
199 | |
} |
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
public boolean isFullyHandleStereotypes() { |
208 | 0 | if (fullyHandleStereotypesSet) { |
209 | 0 | return fullyHandleStereotypes; |
210 | |
} else { |
211 | 0 | if (parent != null) { |
212 | 0 | return parent.isFullyHandleStereotypes(); |
213 | |
} else { |
214 | 0 | return getDefaultSettings().isFullyHandleStereotypes(); |
215 | |
} |
216 | |
} |
217 | |
} |
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
public void setFullyHandleStereotypes(boolean newValue) { |
225 | 900 | fullyHandleStereotypes = newValue; |
226 | 900 | fullyHandleStereotypesSet = true; |
227 | 900 | } |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
public boolean isShowSingularMultiplicities() { |
233 | 120 | if (showSingularMultiplicitiesSet) { |
234 | 120 | return showSingularMultiplicities; |
235 | 0 | } else if (parent != null) { |
236 | 0 | return parent.isShowSingularMultiplicities(); |
237 | |
} |
238 | 0 | return getDefaultSettings().isShowSingularMultiplicities(); |
239 | |
} |
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
public void setShowSingularMultiplicities(final boolean showem) { |
245 | 1880 | if (showSingularMultiplicities == showem |
246 | |
&& showSingularMultiplicitiesSet) { |
247 | 12 | return; |
248 | |
} |
249 | |
|
250 | 1868 | final boolean oldValid = showSingularMultiplicitiesSet; |
251 | 1868 | Memento memento = new Memento() { |
252 | |
public void redo() { |
253 | 1868 | showSingularMultiplicities = showem; |
254 | 1868 | showSingularMultiplicitiesSet = true; |
255 | 1868 | } |
256 | |
|
257 | |
public void undo() { |
258 | 0 | showSingularMultiplicities = !showem; |
259 | 0 | showSingularMultiplicitiesSet = oldValid; |
260 | 0 | } |
261 | |
}; |
262 | 1868 | doUndoable(memento); |
263 | 1868 | } |
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
public boolean isUseGuillemets() { |
269 | 132 | if (useGuillemetsSet) { |
270 | 132 | return useGuillemets; |
271 | 0 | } else if (parent != null) { |
272 | 0 | return parent.isUseGuillemets(); |
273 | |
} |
274 | 0 | return getDefaultSettings().isUseGuillemets(); |
275 | |
} |
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
public void setUseGuillemets(final boolean showem) { |
281 | 1868 | if (useGuillemets == showem && useGuillemetsSet) { |
282 | 0 | return; |
283 | |
} |
284 | |
|
285 | 1868 | final boolean oldValid = useGuillemetsSet; |
286 | |
|
287 | 1868 | Memento memento = new Memento() { |
288 | |
public void redo() { |
289 | 1868 | useGuillemets = showem; |
290 | 1868 | useGuillemetsSet = true; |
291 | 1868 | } |
292 | |
|
293 | |
public void undo() { |
294 | 0 | useGuillemets = !showem; |
295 | 0 | useGuillemetsSet = oldValid; |
296 | 0 | } |
297 | |
}; |
298 | 1868 | doUndoable(memento); |
299 | 1868 | } |
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
public boolean isShowTypes() { |
305 | 120 | if (showTypesSet) { |
306 | 120 | return showTypes; |
307 | 0 | } else if (parent != null) { |
308 | 0 | return parent.isShowTypes(); |
309 | |
} |
310 | 0 | return getDefaultSettings().isShowTypes(); |
311 | |
} |
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
public void setShowTypes(final boolean showem) { |
318 | 1880 | if (showTypes == showem && showTypesSet) { |
319 | 12 | return; |
320 | |
} |
321 | |
|
322 | 1868 | final boolean oldValid = showTypesSet; |
323 | |
|
324 | 1868 | Memento memento = new Memento() { |
325 | |
public void redo() { |
326 | 1868 | showTypes = showem; |
327 | 1868 | showTypesSet = true; |
328 | 1868 | } |
329 | |
|
330 | |
public void undo() { |
331 | 0 | showTypes = !showem; |
332 | 0 | showTypesSet = oldValid; |
333 | 0 | } |
334 | |
}; |
335 | 1868 | doUndoable(memento); |
336 | |
|
337 | 1868 | } |
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
public boolean isShowProperties() { |
343 | 120 | if (showPropertiesSet) { |
344 | 120 | return showProperties; |
345 | 0 | } else if (parent != null) { |
346 | 0 | return parent.isShowProperties(); |
347 | |
} |
348 | 0 | return getDefaultSettings().isShowProperties(); |
349 | |
} |
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
public void setShowProperties(final boolean showem) { |
355 | 1880 | if (showProperties == showem && showPropertiesSet) { |
356 | 12 | return; |
357 | |
} |
358 | |
|
359 | 1868 | final boolean oldValid = showPropertiesSet; |
360 | |
|
361 | 1868 | Memento memento = new Memento() { |
362 | |
public void redo() { |
363 | 1868 | showProperties = showem; |
364 | 1868 | showPropertiesSet = true; |
365 | 1868 | } |
366 | |
|
367 | |
public void undo() { |
368 | 0 | showProperties = !showem; |
369 | 0 | showPropertiesSet = oldValid; |
370 | 0 | } |
371 | |
}; |
372 | 1868 | doUndoable(memento); |
373 | |
|
374 | 1868 | } |
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
public boolean isShowInitialValues() { |
380 | 120 | if (showInitialValuesSet) { |
381 | 120 | return showInitialValues; |
382 | 0 | } else if (parent != null) { |
383 | 0 | return parent.isShowInitialValues(); |
384 | |
} |
385 | 0 | return getDefaultSettings().isShowInitialValues(); |
386 | |
} |
387 | |
|
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | |
public void setShowInitialValues(final boolean showem) { |
393 | 1880 | if (showInitialValues == showem && showInitialValuesSet) { |
394 | 12 | return; |
395 | |
} |
396 | |
|
397 | 1868 | final boolean oldValid = showInitialValuesSet; |
398 | |
|
399 | 1868 | Memento memento = new Memento() { |
400 | |
public void redo() { |
401 | 1868 | showInitialValues = showem; |
402 | 1868 | showInitialValuesSet = true; |
403 | 1868 | } |
404 | |
|
405 | |
public void undo() { |
406 | 0 | showInitialValues = !showem; |
407 | 0 | showInitialValuesSet = oldValid; |
408 | 0 | } |
409 | |
}; |
410 | 1868 | doUndoable(memento); |
411 | |
|
412 | 1868 | } |
413 | |
|
414 | |
|
415 | |
|
416 | |
|
417 | |
public boolean isShowMultiplicities() { |
418 | 120 | if (showMultiplicitiesSet) { |
419 | 120 | return showMultiplicities; |
420 | 0 | } else if (parent != null) { |
421 | 0 | return parent.isShowMultiplicities(); |
422 | |
} |
423 | 0 | return getDefaultSettings().isShowMultiplicities(); |
424 | |
} |
425 | |
|
426 | |
|
427 | |
|
428 | |
|
429 | |
public void setShowMultiplicities(final boolean showem) { |
430 | 1880 | if (showMultiplicities == showem && showMultiplicitiesSet) { |
431 | 10 | return; |
432 | |
} |
433 | |
|
434 | 1870 | final boolean oldValid = showMultiplicitiesSet; |
435 | |
|
436 | 1870 | Memento memento = new Memento() { |
437 | |
public void redo() { |
438 | 1870 | showMultiplicities = showem; |
439 | 1870 | showMultiplicitiesSet = true; |
440 | 1870 | } |
441 | |
|
442 | |
public void undo() { |
443 | 0 | showMultiplicities = !showem; |
444 | 0 | showMultiplicitiesSet = oldValid; |
445 | 0 | } |
446 | |
}; |
447 | 1870 | doUndoable(memento); |
448 | 1870 | } |
449 | |
|
450 | |
|
451 | |
|
452 | |
|
453 | |
|
454 | |
|
455 | |
public boolean isShowAssociationNames() { |
456 | 120 | if (showAssociationNamesSet) { |
457 | 120 | return showAssociationNames; |
458 | 0 | } else if (parent != null) { |
459 | 0 | return parent.isShowAssociationNames(); |
460 | |
} |
461 | 0 | return getDefaultSettings().isShowAssociationNames(); |
462 | |
} |
463 | |
|
464 | |
|
465 | |
|
466 | |
|
467 | |
public void setShowAssociationNames(final boolean showem) { |
468 | 1880 | if (showAssociationNames == showem && showAssociationNamesSet) { |
469 | 12 | return; |
470 | |
} |
471 | |
|
472 | 1868 | final boolean oldValid = showAssociationNamesSet; |
473 | |
|
474 | 1868 | Memento memento = new Memento() { |
475 | |
|
476 | |
public void redo() { |
477 | 1868 | showAssociationNames = showem; |
478 | 1868 | showAssociationNamesSet = true; |
479 | 1868 | } |
480 | |
|
481 | |
public void undo() { |
482 | 0 | showAssociationNames = !showem; |
483 | 0 | showAssociationNamesSet = oldValid; |
484 | 0 | } |
485 | |
}; |
486 | 1868 | doUndoable(memento); |
487 | 1868 | } |
488 | |
|
489 | |
|
490 | |
|
491 | |
|
492 | |
public boolean isShowVisibilities() { |
493 | 120 | if (showVisibilitiesSet) { |
494 | 120 | return showVisibilities; |
495 | 0 | } else if (parent != null) { |
496 | 0 | return parent.isShowVisibilities(); |
497 | |
} |
498 | 0 | return getDefaultSettings().isShowVisibilities(); |
499 | |
} |
500 | |
|
501 | |
|
502 | |
|
503 | |
|
504 | |
|
505 | |
public void setShowVisibilities(final boolean showem) { |
506 | |
|
507 | 1880 | if (showVisibilities == showem && showVisibilitiesSet) { |
508 | 12 | return; |
509 | |
} |
510 | |
|
511 | 1868 | final boolean oldValid = showVisibilitiesSet; |
512 | |
|
513 | 1868 | Memento memento = new Memento() { |
514 | |
public void redo() { |
515 | 1868 | showVisibilities = showem; |
516 | 1868 | showVisibilitiesSet = true; |
517 | 1868 | } |
518 | |
|
519 | |
public void undo() { |
520 | 0 | showVisibilities = !showem; |
521 | 0 | showVisibilitiesSet = oldValid; |
522 | 0 | } |
523 | |
}; |
524 | 1868 | doUndoable(memento); |
525 | 1868 | } |
526 | |
|
527 | |
|
528 | |
|
529 | |
|
530 | |
public boolean isShowPaths() { |
531 | 0 | if (showPathsSet) { |
532 | 0 | return showPaths; |
533 | 0 | } else if (parent != null) { |
534 | 0 | return parent.isShowPaths(); |
535 | |
} |
536 | 0 | return getDefaultSettings().isShowPaths(); |
537 | |
} |
538 | |
|
539 | |
|
540 | |
|
541 | |
|
542 | |
|
543 | |
public void setShowPaths(boolean showPaths) { |
544 | 900 | this.showPaths = showPaths; |
545 | 900 | showPathsSet = true; |
546 | 900 | } |
547 | |
|
548 | |
|
549 | |
|
550 | |
private void doUndoable(Memento memento) { |
551 | |
|
552 | |
|
553 | |
|
554 | |
|
555 | |
|
556 | 16815 | memento.redo(); |
557 | |
|
558 | 16815 | } |
559 | |
|
560 | |
} |