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 | |
|
40 | |
package org.argouml.uml.diagram.static_structure.ui; |
41 | |
|
42 | |
import java.awt.Color; |
43 | |
import java.awt.Dimension; |
44 | |
import java.awt.Point; |
45 | |
import java.awt.Polygon; |
46 | |
import java.awt.Rectangle; |
47 | |
import java.awt.event.ActionEvent; |
48 | |
import java.awt.event.MouseEvent; |
49 | |
import java.beans.PropertyChangeEvent; |
50 | |
import java.beans.PropertyVetoException; |
51 | |
import java.util.List; |
52 | |
import java.util.Vector; |
53 | |
|
54 | |
import javax.swing.JOptionPane; |
55 | |
|
56 | |
import org.apache.log4j.Logger; |
57 | |
import org.argouml.application.helpers.ResourceLoaderWrapper; |
58 | |
import org.argouml.i18n.Translator; |
59 | |
import org.argouml.kernel.Project; |
60 | |
import org.argouml.model.Model; |
61 | |
import org.argouml.model.RemoveAssociationEvent; |
62 | |
import org.argouml.ui.ArgoJMenu; |
63 | |
import org.argouml.ui.UndoableAction; |
64 | |
import org.argouml.ui.explorer.ExplorerEventAdaptor; |
65 | |
import org.argouml.ui.targetmanager.TargetManager; |
66 | |
import org.argouml.uml.diagram.ArgoDiagram; |
67 | |
import org.argouml.uml.diagram.DiagramFactory; |
68 | |
import org.argouml.uml.diagram.DiagramFactory.DiagramType; |
69 | |
import org.argouml.uml.diagram.DiagramSettings; |
70 | |
import org.argouml.uml.diagram.StereotypeContainer; |
71 | |
import org.argouml.uml.diagram.VisibilityContainer; |
72 | |
import org.argouml.uml.diagram.ui.ArgoFig; |
73 | |
import org.argouml.uml.diagram.ui.ArgoFigText; |
74 | |
import org.argouml.uml.diagram.ui.FigNodeModelElement; |
75 | |
import org.tigris.gef.base.Editor; |
76 | |
import org.tigris.gef.base.Geometry; |
77 | |
import org.tigris.gef.base.Globals; |
78 | |
import org.tigris.gef.base.LayerPerspective; |
79 | |
import org.tigris.gef.presentation.Fig; |
80 | |
import org.tigris.gef.presentation.FigPoly; |
81 | |
import org.tigris.gef.presentation.FigRect; |
82 | |
import org.tigris.gef.presentation.FigText; |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | 0 | public class FigPackage extends FigNodeModelElement |
116 | |
implements StereotypeContainer, VisibilityContainer { |
117 | |
|
118 | 0 | private static final Logger LOG = Logger.getLogger(FigPackage.class); |
119 | |
|
120 | |
|
121 | |
private static final int MIN_HEIGHT = 21; |
122 | |
|
123 | |
private static final int MIN_WIDTH = 50; |
124 | |
|
125 | |
|
126 | 0 | private int width = 140; |
127 | |
|
128 | 0 | private int height = 100; |
129 | |
|
130 | |
|
131 | 0 | private int indentX = 50; |
132 | |
|
133 | 0 | private int textH = 20; |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | 0 | private int tabHeight = 20; |
139 | |
|
140 | |
private FigPackageFigText body; |
141 | |
private PackageBackground background; |
142 | |
|
143 | |
private FigPoly figPoly; |
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | 0 | private boolean stereotypeVisible = true; |
152 | |
|
153 | |
@Override |
154 | |
protected Fig createBigPortFig() { |
155 | 0 | PackagePortFigRect ppfr = |
156 | |
new PackagePortFigRect(0, 0, width, height, indentX, tabHeight); |
157 | 0 | ppfr.setFilled(false); |
158 | 0 | ppfr.setLineWidth(0); |
159 | 0 | return ppfr; |
160 | |
} |
161 | |
|
162 | |
private void initialize() { |
163 | 0 | body.setEditable(false); |
164 | |
|
165 | 0 | background = new PackageBackground(0, 0, width, height, indentX, tabHeight); |
166 | |
|
167 | 0 | getNameFig().setBounds(0, 0, width - indentX, textH + 2); |
168 | 0 | getNameFig().setJustification(FigText.JUSTIFY_LEFT); |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | 0 | getStereotypeFig().setVisible(false); |
175 | |
|
176 | |
|
177 | 0 | addFig(getBigPort()); |
178 | 0 | addFig(background); |
179 | 0 | addFig(getNameFig()); |
180 | 0 | addFig(getStereotypeFig()); |
181 | 0 | addFig(body); |
182 | |
|
183 | 0 | setBlinkPorts(false); |
184 | |
|
185 | |
|
186 | 0 | setFilled(true); |
187 | 0 | setFillColor(FILL_COLOR); |
188 | 0 | setLineColor(LINE_COLOR); |
189 | 0 | setLineWidth(LINE_WIDTH); |
190 | |
|
191 | 0 | updateEdges(); |
192 | 0 | } |
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
public FigPackage(Object owner, Rectangle bounds, |
203 | |
DiagramSettings settings) { |
204 | 0 | super(owner, bounds, settings); |
205 | |
|
206 | |
|
207 | 0 | body = new FigPackageFigText(getOwner(), |
208 | |
new Rectangle(0, textH, width, height - textH), getSettings()); |
209 | |
|
210 | 0 | initialize(); |
211 | |
|
212 | 0 | if (bounds != null) { |
213 | 0 | setLocation(bounds.x, bounds.y); |
214 | |
} |
215 | 0 | setBounds(getBounds()); |
216 | 0 | } |
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
@Override |
222 | |
public Object clone() { |
223 | 0 | FigPackage figClone = (FigPackage) super.clone(); |
224 | 0 | for (Fig thisFig : (List<Fig>) getFigs()) { |
225 | 0 | if (thisFig == body) { |
226 | 0 | figClone.body = (FigPackageFigText) thisFig; |
227 | |
} |
228 | |
} |
229 | 0 | return figClone; |
230 | |
} |
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
protected FigPoly getFigPoly() { |
236 | 0 | return figPoly; |
237 | |
} |
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
protected void setFigPoly(FigPoly figPoly) { |
243 | 0 | this.figPoly = figPoly; |
244 | 0 | } |
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
@Override |
250 | |
public void setLineColor(Color col) { |
251 | 0 | super.setLineColor(col); |
252 | 0 | getStereotypeFig().setLineColor(null); |
253 | 0 | getNameFig().setLineColor(col); |
254 | 0 | body.setLineColor(col); |
255 | 0 | if (figPoly != null) { |
256 | 0 | figPoly.setLineColor(col); |
257 | |
} |
258 | 0 | } |
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
@Override |
264 | |
public Color getLineColor() { |
265 | 0 | return body.getLineColor(); |
266 | |
} |
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
@Override |
272 | |
public Color getFillColor() { |
273 | 0 | return background.getFillColor(); |
274 | |
} |
275 | |
|
276 | |
@Override |
277 | |
public boolean isFilled() { |
278 | 0 | return background.isFilled(); |
279 | |
} |
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
@Override |
285 | |
public void setLineWidth(int w) { |
286 | |
|
287 | 0 | getNameFig().setLineWidth(w); |
288 | 0 | body.setLineWidth(w); |
289 | 0 | } |
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
@Override |
295 | |
public int getLineWidth() { |
296 | 0 | return body.getLineWidth(); |
297 | |
} |
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
@Override |
303 | |
protected void updateStereotypeText() { |
304 | 0 | Object modelElement = getOwner(); |
305 | |
|
306 | 0 | if (modelElement == null) { |
307 | 0 | return; |
308 | |
} |
309 | |
|
310 | 0 | Rectangle rect = getBounds(); |
311 | |
|
312 | |
|
313 | 0 | if (Model.getFacade().getStereotypes(modelElement).isEmpty()) { |
314 | 0 | if (getStereotypeFig().isVisible()) { |
315 | 0 | getNameFig().setTopMargin(0); |
316 | 0 | getStereotypeFig().setVisible(false); |
317 | |
} |
318 | |
} else { |
319 | |
|
320 | |
|
321 | 0 | super.updateStereotypeText(); |
322 | 0 | if (!isStereotypeVisible()) { |
323 | |
|
324 | 0 | getNameFig().setTopMargin(0); |
325 | 0 | getStereotypeFig().setVisible(false); |
326 | 0 | } else if (!getStereotypeFig().isVisible()) { |
327 | 0 | getNameFig().setTopMargin( |
328 | |
getStereotypeFig().getMinimumSize().height); |
329 | 0 | getStereotypeFig().setVisible(true); |
330 | |
} |
331 | |
} |
332 | |
|
333 | 0 | forceRepaintShadow(); |
334 | 0 | setBounds(rect.x, rect.y, rect.width, rect.height); |
335 | 0 | } |
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | |
|
345 | |
protected void updateBounds() { |
346 | 0 | if (!isCheckSize()) { |
347 | 0 | return; |
348 | |
} |
349 | 0 | Rectangle bbox = getBounds(); |
350 | 0 | Dimension minSize = getMinimumSize(); |
351 | 0 | bbox.width = Math.max(bbox.width, minSize.width); |
352 | 0 | bbox.height = Math.max(bbox.height, minSize.height); |
353 | 0 | setBounds(bbox.x, bbox.y, bbox.width, bbox.height); |
354 | 0 | } |
355 | |
|
356 | |
|
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
@Override |
362 | |
public String classNameAndBounds() { |
363 | 0 | return super.classNameAndBounds() |
364 | |
+ "stereotypeVisible=" + isStereotypeVisible() |
365 | |
+ ";" |
366 | |
+ "visibilityVisible=" + isVisibilityVisible(); |
367 | |
} |
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
@Override |
374 | |
public boolean getUseTrapRect() { |
375 | 0 | return true; |
376 | |
} |
377 | |
|
378 | |
|
379 | |
|
380 | |
|
381 | |
@Override |
382 | |
public Dimension getMinimumSize() { |
383 | |
|
384 | |
|
385 | 0 | Dimension aSize = new Dimension(getNameFig().getMinimumSize()); |
386 | |
|
387 | 0 | if (figPoly != null) { |
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | 0 | Dimension symbol = figPoly.getSize(); |
393 | 0 | aSize.width += symbol.width; |
394 | 0 | aSize.height = Math.max(aSize.height, symbol.height); |
395 | |
} |
396 | |
|
397 | 0 | aSize.height = Math.max(aSize.height, MIN_HEIGHT); |
398 | 0 | aSize.width = Math.max(aSize.width, MIN_WIDTH); |
399 | |
|
400 | |
|
401 | |
|
402 | 0 | if (isStereotypeVisible()) { |
403 | 0 | Dimension st = getStereotypeFig().getMinimumSize(); |
404 | 0 | aSize.width = |
405 | |
Math.max(aSize.width, st.width); |
406 | |
} |
407 | |
|
408 | |
|
409 | 0 | aSize.width += indentX + 1; |
410 | |
|
411 | |
|
412 | 0 | aSize.height += 28 + 2 * getLineWidth(); |
413 | |
|
414 | |
|
415 | 0 | return aSize; |
416 | |
} |
417 | |
|
418 | |
|
419 | |
|
420 | |
|
421 | |
|
422 | |
|
423 | |
|
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
|
429 | |
|
430 | |
|
431 | |
|
432 | |
|
433 | |
|
434 | |
|
435 | |
|
436 | |
|
437 | |
|
438 | |
|
439 | |
|
440 | |
@Override |
441 | |
protected void setStandardBounds(int xa, int ya, int w, int h) { |
442 | |
|
443 | |
|
444 | |
|
445 | |
|
446 | 0 | Rectangle oldBounds = getBounds(); |
447 | |
|
448 | |
|
449 | 0 | Dimension minimumSize = getMinimumSize(); |
450 | 0 | int newW = Math.max(w, minimumSize.width); |
451 | 0 | int newH = Math.max(h, minimumSize.height); |
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
|
458 | 0 | Dimension nameMin = getNameFig().getMinimumSize(); |
459 | 0 | int minNameHeight = Math.max(nameMin.height, MIN_HEIGHT); |
460 | |
|
461 | |
|
462 | |
|
463 | |
|
464 | |
|
465 | |
|
466 | 0 | int currentY = ya; |
467 | |
|
468 | 0 | int tabWidth = newW - indentX; |
469 | |
|
470 | 0 | if (isStereotypeVisible()) { |
471 | 0 | Dimension stereoMin = getStereotypeFig().getMinimumSize(); |
472 | 0 | getNameFig().setTopMargin(stereoMin.height); |
473 | 0 | getNameFig().setBounds(xa, currentY, tabWidth + 1, minNameHeight); |
474 | |
|
475 | 0 | getStereotypeFig().setBounds(xa, ya, |
476 | |
tabWidth, stereoMin.height + 1); |
477 | |
|
478 | 0 | if (tabWidth < stereoMin.width + 1) { |
479 | 0 | tabWidth = stereoMin.width + 2; |
480 | |
} |
481 | 0 | } else { |
482 | 0 | getNameFig().setBounds(xa, currentY, tabWidth + 1, minNameHeight); |
483 | |
} |
484 | |
|
485 | |
|
486 | |
|
487 | |
|
488 | |
|
489 | |
|
490 | 0 | currentY += minNameHeight - 1; |
491 | 0 | body.setBounds(xa, currentY, newW, newH + ya - currentY); |
492 | |
|
493 | 0 | tabHeight = currentY - ya; |
494 | |
|
495 | |
|
496 | 0 | getBigPort().setBounds(xa, ya, newW, newH); |
497 | |
|
498 | 0 | if (figPoly != null) { |
499 | |
|
500 | |
|
501 | |
|
502 | |
|
503 | |
|
504 | 0 | Rectangle previousBounds = figPoly.getBounds(); |
505 | 0 | Rectangle name = getNameFig().getBounds(); |
506 | 0 | int nx = name.x + name.width - figPoly.getWidth() |
507 | |
- getLineWidth() - getNameFig().getRightMargin(); |
508 | 0 | int ny = name.y + getLineWidth() + getNameFig().getTopMargin(); |
509 | 0 | figPoly.translate((nx - previousBounds.x), |
510 | |
ny - previousBounds.y); |
511 | |
} |
512 | |
|
513 | |
|
514 | |
|
515 | |
|
516 | |
|
517 | 0 | background.setBounds(xa, ya, w, h); |
518 | |
|
519 | 0 | calcBounds(); |
520 | 0 | updateEdges(); |
521 | 0 | firePropChange("bounds", oldBounds, getBounds()); |
522 | 0 | } |
523 | |
|
524 | |
|
525 | |
|
526 | |
|
527 | |
|
528 | |
|
529 | |
|
530 | |
|
531 | |
@Override |
532 | |
public Vector getPopUpActions(MouseEvent me) { |
533 | 0 | Vector popUpActions = super.getPopUpActions(me); |
534 | |
|
535 | |
|
536 | 0 | popUpActions.add( |
537 | |
popUpActions.size() - getPopupAddOffset(), |
538 | |
buildModifierPopUp(ABSTRACT | LEAF | ROOT)); |
539 | |
|
540 | |
|
541 | 0 | popUpActions.add( |
542 | |
popUpActions.size() - getPopupAddOffset(), |
543 | |
buildVisibilityPopUp()); |
544 | |
|
545 | 0 | return popUpActions; |
546 | |
} |
547 | |
|
548 | |
@Override |
549 | |
protected ArgoJMenu buildShowPopUp() { |
550 | 0 | ArgoJMenu showMenu = super.buildShowPopUp(); |
551 | |
|
552 | 0 | Editor ce = Globals.curEditor(); |
553 | 0 | List<Fig> figs = ce.getSelectionManager().getFigs(); |
554 | 0 | boolean sOn = false; |
555 | 0 | boolean sOff = false; |
556 | 0 | boolean vOn = false; |
557 | 0 | boolean vOff = false; |
558 | 0 | for (Fig f : figs) { |
559 | 0 | if (f instanceof StereotypeContainer) { |
560 | 0 | boolean v = ((StereotypeContainer) f).isStereotypeVisible(); |
561 | 0 | if (v) { |
562 | 0 | sOn = true; |
563 | |
} else { |
564 | 0 | sOff = true; |
565 | |
} |
566 | 0 | v = ((VisibilityContainer) f).isVisibilityVisible(); |
567 | 0 | if (v) { |
568 | 0 | vOn = true; |
569 | |
} else { |
570 | 0 | vOff = true; |
571 | |
} |
572 | 0 | } |
573 | |
} |
574 | |
|
575 | 0 | if (sOn) { |
576 | 0 | showMenu.add(new HideStereotypeAction()); |
577 | |
} |
578 | |
|
579 | 0 | if (sOff) { |
580 | 0 | showMenu.add(new ShowStereotypeAction()); |
581 | |
} |
582 | |
|
583 | 0 | if (vOn) { |
584 | 0 | showMenu.add(new HideVisibilityAction()); |
585 | |
} |
586 | |
|
587 | 0 | if (vOff) { |
588 | 0 | showMenu.add(new ShowVisibilityAction()); |
589 | |
} |
590 | |
|
591 | 0 | return showMenu; |
592 | |
} |
593 | |
|
594 | |
|
595 | |
|
596 | |
|
597 | |
|
598 | |
|
599 | |
private void doStereotype(boolean value) { |
600 | 0 | Editor ce = Globals.curEditor(); |
601 | 0 | List<Fig> figs = ce.getSelectionManager().getFigs(); |
602 | 0 | for (Fig f : figs) { |
603 | 0 | if (f instanceof StereotypeContainer) { |
604 | 0 | ((StereotypeContainer) f).setStereotypeVisible(value); |
605 | |
} |
606 | 0 | if (f instanceof FigNodeModelElement) { |
607 | 0 | ((FigNodeModelElement) f).forceRepaintShadow(); |
608 | 0 | ((ArgoFig) f).renderingChanged(); |
609 | |
} |
610 | 0 | f.damage(); |
611 | |
} |
612 | 0 | } |
613 | |
|
614 | |
|
615 | |
|
616 | |
|
617 | |
|
618 | |
|
619 | |
private void doVisibility(boolean value) { |
620 | 0 | Editor ce = Globals.curEditor(); |
621 | 0 | List<Fig> figs = ce.getSelectionManager().getFigs(); |
622 | 0 | for (Fig f : figs) { |
623 | 0 | if (f instanceof VisibilityContainer) { |
624 | 0 | ((VisibilityContainer) f).setVisibilityVisible(value); |
625 | |
} |
626 | 0 | f.damage(); |
627 | |
} |
628 | 0 | } |
629 | |
|
630 | |
|
631 | |
|
632 | |
|
633 | |
|
634 | |
|
635 | |
|
636 | |
class FigPackageFigText extends ArgoFigText { |
637 | |
|
638 | |
|
639 | |
|
640 | |
|
641 | |
|
642 | |
|
643 | |
|
644 | |
|
645 | |
|
646 | |
public FigPackageFigText(Object owner, Rectangle bounds, |
647 | 0 | DiagramSettings settings) { |
648 | 0 | super(owner, bounds, settings, false); |
649 | 0 | } |
650 | |
|
651 | |
|
652 | |
|
653 | |
|
654 | |
|
655 | |
|
656 | |
|
657 | |
|
658 | |
|
659 | |
@Override |
660 | |
public void mouseClicked(MouseEvent me) { |
661 | |
|
662 | 0 | String lsDefaultName = "main"; |
663 | |
|
664 | |
|
665 | |
|
666 | |
|
667 | |
|
668 | |
|
669 | |
|
670 | 0 | if (me.getClickCount() >= 2) { |
671 | 0 | Object lPkg = FigPackage.this.getOwner(); |
672 | 0 | if (lPkg != null) { |
673 | 0 | Object lNS = lPkg; |
674 | |
|
675 | 0 | Project lP = getProject(); |
676 | |
|
677 | 0 | List<ArgoDiagram> diags = lP.getDiagramList(); |
678 | 0 | ArgoDiagram lFirst = null; |
679 | 0 | for (ArgoDiagram lDiagram : diags) { |
680 | 0 | Object lDiagramNS = lDiagram.getNamespace(); |
681 | 0 | if ((lNS == null && lDiagramNS == null) |
682 | |
|| (lNS.equals(lDiagramNS))) { |
683 | |
|
684 | 0 | if (lFirst == null) { |
685 | 0 | lFirst = lDiagram; |
686 | |
} |
687 | |
|
688 | 0 | if (lDiagram.getName() != null |
689 | |
&& lDiagram.getName().startsWith( |
690 | |
lsDefaultName)) { |
691 | 0 | me.consume(); |
692 | 0 | super.mouseClicked(me); |
693 | 0 | TargetManager.getInstance().setTarget(lDiagram); |
694 | 0 | return; |
695 | |
} |
696 | |
} |
697 | 0 | } |
698 | |
|
699 | |
|
700 | |
|
701 | |
|
702 | 0 | if (lFirst != null) { |
703 | 0 | me.consume(); |
704 | 0 | super.mouseClicked(me); |
705 | |
|
706 | 0 | TargetManager.getInstance().setTarget(lFirst); |
707 | 0 | return; |
708 | |
} |
709 | |
|
710 | |
|
711 | |
|
712 | 0 | me.consume(); |
713 | 0 | super.mouseClicked(me); |
714 | |
try { |
715 | 0 | createClassDiagram(lNS, lsDefaultName, lP); |
716 | 0 | } catch (Exception ex) { |
717 | 0 | LOG.error(ex); |
718 | 0 | } |
719 | |
|
720 | 0 | return; |
721 | |
|
722 | |
} |
723 | |
} |
724 | 0 | super.mouseClicked(me); |
725 | 0 | } |
726 | |
|
727 | |
public void setFilled(boolean f) { |
728 | 0 | super.setFilled(false); |
729 | 0 | } |
730 | |
|
731 | |
public void setFillColor(Color c) { |
732 | 0 | super.setFillColor(c); |
733 | 0 | } |
734 | |
|
735 | |
|
736 | |
|
737 | |
|
738 | |
private static final long serialVersionUID = -1355316218065323634L; |
739 | |
} |
740 | |
|
741 | |
private void createClassDiagram( |
742 | |
Object namespace, |
743 | |
String defaultName, |
744 | |
Project project) throws PropertyVetoException { |
745 | |
|
746 | |
String namespaceDescr; |
747 | 0 | if (namespace != null |
748 | |
&& Model.getFacade().getName(namespace) != null) { |
749 | 0 | namespaceDescr = Model.getFacade().getName(namespace); |
750 | |
} else { |
751 | 0 | namespaceDescr = Translator.localize("misc.name.anon"); |
752 | |
} |
753 | |
|
754 | 0 | String dialogText = "Add new class diagram to " + namespaceDescr + "?"; |
755 | 0 | int option = |
756 | |
JOptionPane.showConfirmDialog( |
757 | |
null, |
758 | |
dialogText, |
759 | |
"Add new class diagram?", |
760 | |
JOptionPane.YES_NO_OPTION); |
761 | |
|
762 | 0 | if (option == JOptionPane.YES_OPTION) { |
763 | |
|
764 | 0 | ArgoDiagram classDiagram = |
765 | |
DiagramFactory.getInstance(). |
766 | |
createDiagram(DiagramType.Class, namespace, null); |
767 | |
|
768 | 0 | String diagramName = defaultName + "_" + classDiagram.getName(); |
769 | |
|
770 | 0 | project.addMember(classDiagram); |
771 | |
|
772 | 0 | TargetManager.getInstance().setTarget(classDiagram); |
773 | |
|
774 | 0 | classDiagram.setName(diagramName); |
775 | 0 | ExplorerEventAdaptor.getInstance().structureChanged(); |
776 | |
} |
777 | 0 | } |
778 | |
|
779 | |
|
780 | |
|
781 | |
|
782 | |
public boolean isStereotypeVisible() { |
783 | 0 | return stereotypeVisible; |
784 | |
} |
785 | |
|
786 | |
|
787 | |
|
788 | |
|
789 | |
public void setStereotypeVisible(boolean isVisible) { |
790 | 0 | stereotypeVisible = isVisible; |
791 | 0 | renderingChanged(); |
792 | 0 | damage(); |
793 | 0 | } |
794 | |
|
795 | |
|
796 | |
|
797 | |
|
798 | |
public boolean isVisibilityVisible() { |
799 | 0 | return getNotationSettings().isShowVisibilities(); |
800 | |
} |
801 | |
|
802 | |
|
803 | |
|
804 | |
|
805 | |
public void setVisibilityVisible(boolean isVisible) { |
806 | 0 | getNotationSettings().setShowVisibilities(isVisible); |
807 | 0 | renderingChanged(); |
808 | 0 | damage(); |
809 | 0 | } |
810 | |
|
811 | |
|
812 | |
|
813 | |
|
814 | |
@Override |
815 | |
protected void textEditStarted(FigText ft) { |
816 | |
|
817 | 0 | if (ft == getNameFig()) { |
818 | 0 | showHelp("parsing.help.fig-package"); |
819 | |
} |
820 | 0 | } |
821 | |
|
822 | |
|
823 | |
|
824 | |
|
825 | |
@Override |
826 | |
public Point getClosestPoint(Point anotherPt) { |
827 | 0 | Rectangle r = getBounds(); |
828 | 0 | int[] xs = { |
829 | |
r.x, r.x + r.width - indentX, r.x + r.width - indentX, |
830 | |
r.x + r.width, r.x + r.width, r.x, r.x, |
831 | |
}; |
832 | 0 | int[] ys = { |
833 | |
r.y, r.y, r.y + tabHeight, |
834 | |
r.y + tabHeight, r.y + r.height, r.y + r.height, r.y, |
835 | |
}; |
836 | 0 | Point p = |
837 | |
Geometry.ptClosestTo( |
838 | |
xs, |
839 | |
ys, |
840 | |
7, |
841 | |
anotherPt); |
842 | 0 | return p; |
843 | |
} |
844 | |
|
845 | |
@Override |
846 | |
protected void modelChanged(PropertyChangeEvent mee) { |
847 | |
|
848 | 0 | if (mee instanceof RemoveAssociationEvent |
849 | |
&& "ownedElement".equals(mee.getPropertyName()) |
850 | |
&& mee.getSource() == getOwner()) { |
851 | |
|
852 | |
|
853 | |
|
854 | |
|
855 | |
|
856 | |
|
857 | 0 | if (LOG.isInfoEnabled() && mee.getNewValue() == null) { |
858 | 0 | LOG.info(Model.getFacade().getName(mee.getOldValue()) |
859 | |
+ " has been removed from the namespace of " |
860 | |
+ Model.getFacade().getName(getOwner()) |
861 | |
+ " by notice of " + mee.toString()); |
862 | |
} |
863 | 0 | LayerPerspective layer = (LayerPerspective) getLayer(); |
864 | 0 | Fig f = layer.presentationFor(mee.getOldValue()); |
865 | 0 | if (f != null && f.getEnclosingFig() == this) { |
866 | 0 | removeEnclosedFig(f); |
867 | 0 | f.setEnclosingFig(null); |
868 | |
} |
869 | |
} |
870 | 0 | super.modelChanged(mee); |
871 | 0 | } |
872 | |
|
873 | |
|
874 | |
|
875 | |
|
876 | |
private static final long serialVersionUID = 3617092272529451041L; |
877 | |
|
878 | |
private class HideStereotypeAction extends UndoableAction { |
879 | |
|
880 | |
|
881 | |
|
882 | |
private static final String ACTION_KEY = |
883 | |
"menu.popup.show.hide-stereotype"; |
884 | |
|
885 | |
|
886 | |
|
887 | |
|
888 | 0 | HideStereotypeAction() { |
889 | 0 | super(Translator.localize(ACTION_KEY), |
890 | |
ResourceLoaderWrapper.lookupIcon(ACTION_KEY)); |
891 | 0 | } |
892 | |
|
893 | |
|
894 | |
|
895 | |
|
896 | |
@Override |
897 | |
public void actionPerformed(ActionEvent ae) { |
898 | 0 | super.actionPerformed(ae); |
899 | 0 | doStereotype(false); |
900 | 0 | } |
901 | |
|
902 | |
|
903 | |
|
904 | |
|
905 | |
private static final long serialVersionUID = |
906 | |
1999499813643610674L; |
907 | |
} |
908 | |
|
909 | |
private class ShowStereotypeAction extends UndoableAction { |
910 | |
|
911 | |
|
912 | |
|
913 | |
private static final String ACTION_KEY = |
914 | |
"menu.popup.show.show-stereotype"; |
915 | |
|
916 | |
|
917 | |
|
918 | |
|
919 | 0 | ShowStereotypeAction() { |
920 | 0 | super(Translator.localize(ACTION_KEY), |
921 | |
ResourceLoaderWrapper.lookupIcon(ACTION_KEY)); |
922 | 0 | } |
923 | |
|
924 | |
|
925 | |
|
926 | |
|
927 | |
@Override |
928 | |
public void actionPerformed(ActionEvent ae) { |
929 | 0 | super.actionPerformed(ae); |
930 | 0 | doStereotype(true); |
931 | 0 | } |
932 | |
|
933 | |
|
934 | |
|
935 | |
|
936 | |
private static final long serialVersionUID = |
937 | |
-4327161642276705610L; |
938 | |
} |
939 | |
|
940 | |
private class HideVisibilityAction extends UndoableAction { |
941 | |
|
942 | |
|
943 | |
|
944 | |
private static final String ACTION_KEY = |
945 | |
"menu.popup.show.hide-visibility"; |
946 | |
|
947 | |
|
948 | |
|
949 | |
|
950 | 0 | HideVisibilityAction() { |
951 | 0 | super(Translator.localize(ACTION_KEY), |
952 | |
ResourceLoaderWrapper.lookupIcon(ACTION_KEY)); |
953 | 0 | } |
954 | |
|
955 | |
|
956 | |
|
957 | |
|
958 | |
@Override |
959 | |
public void actionPerformed(ActionEvent ae) { |
960 | 0 | super.actionPerformed(ae); |
961 | 0 | doVisibility(false); |
962 | 0 | } |
963 | |
|
964 | |
|
965 | |
|
966 | |
|
967 | |
private static final long serialVersionUID = |
968 | |
8574809709777267866L; |
969 | |
} |
970 | |
|
971 | |
private class ShowVisibilityAction extends UndoableAction { |
972 | |
|
973 | |
|
974 | |
|
975 | |
private static final String ACTION_KEY = |
976 | |
"menu.popup.show.show-visibility"; |
977 | |
|
978 | |
|
979 | |
|
980 | |
|
981 | 0 | ShowVisibilityAction() { |
982 | 0 | super(Translator.localize(ACTION_KEY), |
983 | |
ResourceLoaderWrapper.lookupIcon(ACTION_KEY)); |
984 | 0 | } |
985 | |
|
986 | |
|
987 | |
|
988 | |
|
989 | |
@Override |
990 | |
public void actionPerformed(ActionEvent ae) { |
991 | 0 | super.actionPerformed(ae); |
992 | 0 | doVisibility(true); |
993 | 0 | } |
994 | |
|
995 | |
|
996 | |
|
997 | |
|
998 | |
private static final long serialVersionUID = |
999 | |
7722093402948975834L; |
1000 | |
} |
1001 | |
|
1002 | |
private class PackageBackground extends FigPoly { |
1003 | |
|
1004 | |
int indentX; |
1005 | |
int tabHeight; |
1006 | |
|
1007 | |
|
1008 | |
|
1009 | |
|
1010 | |
|
1011 | |
|
1012 | |
|
1013 | |
|
1014 | |
|
1015 | |
|
1016 | |
|
1017 | 0 | public PackageBackground(int x, int y, int w, int h, int ix, int th) { |
1018 | 0 | super(x, y); |
1019 | 0 | addPoint(x + ix - 1, y); |
1020 | 0 | addPoint(x + ix - 1, y + th); |
1021 | 0 | addPoint(x + w - 1, y + th); |
1022 | 0 | addPoint(x + w - 1, y + h); |
1023 | 0 | addPoint(x, y + h); |
1024 | 0 | addPoint(x, y); |
1025 | 0 | setFilled(true); |
1026 | 0 | this.indentX = ix; |
1027 | 0 | tabHeight = 30; |
1028 | 0 | } |
1029 | |
|
1030 | |
|
1031 | |
|
1032 | |
|
1033 | |
@Override |
1034 | |
public Point getClosestPoint(Point anotherPt) { |
1035 | 0 | Rectangle r = getBounds(); |
1036 | 0 | int[] xs = { |
1037 | |
r.x, r.x + r.width - indentX, r.x + r.width - indentX, |
1038 | |
r.x + r.width, r.x + r.width, r.x, r.x, |
1039 | |
}; |
1040 | 0 | int[] ys = { |
1041 | |
r.y, r.y, r.y + tabHeight, |
1042 | |
r.y + tabHeight, r.y + r.height, r.y + r.height, r.y, |
1043 | |
}; |
1044 | 0 | Point p = |
1045 | |
Geometry.ptClosestTo( |
1046 | |
xs, |
1047 | |
ys, |
1048 | |
7, |
1049 | |
anotherPt); |
1050 | 0 | return p; |
1051 | |
}; |
1052 | |
|
1053 | |
public void setBoundsImpl( |
1054 | |
final int x, |
1055 | |
final int y, |
1056 | |
final int w, |
1057 | |
final int h) { |
1058 | |
|
1059 | 0 | final int labelWidth = getNameBounds().width; |
1060 | 0 | final int labelHeight = getNameBounds().height; |
1061 | |
|
1062 | 0 | final int xs[] = new int[7]; |
1063 | 0 | final int ys[] = new int[7]; |
1064 | 0 | xs[0] = x; |
1065 | 0 | ys[0] = y; |
1066 | |
|
1067 | 0 | xs[1] = x + labelWidth - 1; |
1068 | 0 | ys[1] = y; |
1069 | |
|
1070 | 0 | xs[2] = x + labelWidth - 1; |
1071 | 0 | ys[2] = y + labelHeight - 1; |
1072 | |
|
1073 | 0 | xs[3] = x + w - 1; |
1074 | 0 | ys[3] = y + labelHeight - 1; |
1075 | |
|
1076 | 0 | xs[4] = x + w - 1; |
1077 | 0 | ys[4] = y + h - 1; |
1078 | |
|
1079 | 0 | xs[5] = x; |
1080 | 0 | ys[5] = y + h - 1; |
1081 | |
|
1082 | 0 | xs[6] = x; |
1083 | 0 | ys[6] = y; |
1084 | |
|
1085 | 0 | Polygon p = new Polygon(xs, ys, 7); |
1086 | |
|
1087 | 0 | super.setPolygon(p); |
1088 | 0 | setFilled(true); |
1089 | 0 | setLineWidth(0); |
1090 | 0 | } |
1091 | |
|
1092 | |
public void setLineWidth(int w) { |
1093 | 0 | super.setLineWidth(0); |
1094 | 0 | } |
1095 | |
} |
1096 | |
|
1097 | |
} |
1098 | |
|
1099 | |
|
1100 | |
|
1101 | |
|
1102 | |
|
1103 | |
|
1104 | |
|
1105 | |
class PackagePortFigRect extends FigRect { |
1106 | |
private int indentX; |
1107 | |
private int tabHeight; |
1108 | |
|
1109 | |
|
1110 | |
|
1111 | |
|
1112 | |
|
1113 | |
|
1114 | |
|
1115 | |
|
1116 | |
|
1117 | |
|
1118 | |
|
1119 | |
public PackagePortFigRect(int x, int y, int w, int h, int ix, int th) { |
1120 | 0 | super(x, y, w, h, null, null); |
1121 | 0 | this.indentX = ix; |
1122 | 0 | tabHeight = th; |
1123 | 0 | } |
1124 | |
|
1125 | |
|
1126 | |
|
1127 | |
|
1128 | |
@Override |
1129 | |
public Point getClosestPoint(Point anotherPt) { |
1130 | 0 | Rectangle r = getBounds(); |
1131 | 0 | int[] xs = { |
1132 | |
r.x, r.x + r.width - indentX, r.x + r.width - indentX, |
1133 | |
r.x + r.width, r.x + r.width, r.x, r.x, |
1134 | |
}; |
1135 | 0 | int[] ys = { |
1136 | |
r.y, r.y, r.y + tabHeight, |
1137 | |
r.y + tabHeight, r.y + r.height, r.y + r.height, r.y, |
1138 | |
}; |
1139 | 0 | Point p = |
1140 | |
Geometry.ptClosestTo( |
1141 | |
xs, |
1142 | |
ys, |
1143 | |
7, |
1144 | |
anotherPt); |
1145 | 0 | return p; |
1146 | |
} |
1147 | |
|
1148 | |
public void setFilled(boolean f) { |
1149 | 0 | super.setFilled(false); |
1150 | 0 | } |
1151 | |
|
1152 | |
public void setFillColor(Color c) { |
1153 | 0 | super.setFillColor(null); |
1154 | 0 | } |
1155 | |
|
1156 | |
|
1157 | |
|
1158 | |
|
1159 | |
private static final long serialVersionUID = -7083102131363598065L; |
1160 | |
} |
1161 | |
|