1 | package de.ugoe.cs.swe.bnftools.ui.views.syntaxdiagram;
|
---|
2 |
|
---|
3 | import org.eclipse.draw2d.BorderLayout;
|
---|
4 | import org.eclipse.draw2d.ColorConstants;
|
---|
5 | import org.eclipse.draw2d.LineBorder;
|
---|
6 | import org.eclipse.draw2d.ToolbarLayout;
|
---|
7 | import org.eclipse.draw2d.geometry.Dimension;
|
---|
8 |
|
---|
9 | public class RepetitionFigure extends SyntaxDiagramFigure {
|
---|
10 |
|
---|
11 | private BorderLayout layout;
|
---|
12 |
|
---|
13 | public RepetitionFigure(SyntaxDiagramFigure repetitionFigure) {
|
---|
14 | layout = new BorderLayout();
|
---|
15 |
|
---|
16 | setLayoutManager(layout);
|
---|
17 | addFigure(repetitionFigure);
|
---|
18 | setBorder(new LineMarginBorder(10,40,10,40,0));
|
---|
19 | }
|
---|
20 |
|
---|
21 | private void addFigure(SyntaxDiagramFigure f) {
|
---|
22 | SyntaxDiagramFigure upperContainer = new SyntaxDiagramFigure();
|
---|
23 | //upperContainer.setBorder(new LineBorder());
|
---|
24 | upperContainer.setLayoutManager(new ToolbarLayout());
|
---|
25 | upperContainer.setVisible(true);
|
---|
26 | add(upperContainer, BorderLayout.TOP);
|
---|
27 | setLeftAnchor(new SideAnchor(this, upperContainer.getLeftAnchor(), SideAnchor.LEFT_SIDE));
|
---|
28 | setRightAnchor(new SideAnchor(this, upperContainer.getRightAnchor(), SideAnchor.RIGHT_SIDE));
|
---|
29 | layout.setConstraint(upperContainer, BorderLayout.TOP);
|
---|
30 |
|
---|
31 | SyntaxDiagramFigure centerContainer = new SyntaxDiagramFigure();
|
---|
32 | //centerContainer.setBorder(new LineBorder());
|
---|
33 | ToolbarLayout loopLayout = new ToolbarLayout();
|
---|
34 | loopLayout.setStretchMinorAxis(false);
|
---|
35 | loopLayout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
|
---|
36 | loopLayout.setVertical(true);
|
---|
37 | centerContainer.setLayoutManager(loopLayout);
|
---|
38 | centerContainer.setPreferredSize(new Dimension(50,40));
|
---|
39 | //centerContainer.setForegroundColor(new Color(null,new RGB(255,0,0)));
|
---|
40 | centerContainer.setVisible(true);
|
---|
41 | add(centerContainer, BorderLayout.CENTER);
|
---|
42 | layout.setConstraint(centerContainer, BorderLayout.CENTER);
|
---|
43 |
|
---|
44 | upperContainer.add(f);
|
---|
45 |
|
---|
46 | PathFigure leftPath = new PathFigure();
|
---|
47 | leftPath.setTargetDecoration(null);
|
---|
48 | leftPath.setSourceAnchor(this.getLeftAnchor());
|
---|
49 | leftPath.setTargetAnchor(f.getLeftAnchor());
|
---|
50 | add(leftPath);
|
---|
51 |
|
---|
52 | PathFigure rightPath = new PathFigure();
|
---|
53 | rightPath.setTargetDecoration(null);
|
---|
54 | rightPath.setSourceAnchor(f.getRightAnchor());
|
---|
55 | rightPath.setTargetAnchor(this.getRightAnchor());
|
---|
56 | add(rightPath);
|
---|
57 |
|
---|
58 | PathFigure rightLoopPath = new PathFigure();
|
---|
59 | rightLoopPath.setSourceAnchor(upperContainer.getRightAnchor());
|
---|
60 | rightLoopPath.setTargetAnchor(centerContainer.getRightAnchor());
|
---|
61 | add(rightLoopPath);
|
---|
62 |
|
---|
63 | PathFigure leftLoopPath = new PathFigure();
|
---|
64 | leftLoopPath.setSourceAnchor(centerContainer.getLeftAnchor());
|
---|
65 | leftLoopPath.setTargetAnchor(upperContainer.getLeftAnchor());
|
---|
66 | add(leftLoopPath);
|
---|
67 |
|
---|
68 | SyntaxDiagramFigure dummy = new SyntaxDiagramFigure();
|
---|
69 | dummy.setBorder(new LineBorder());
|
---|
70 | dummy.setForegroundColor(ColorConstants.blue);
|
---|
71 | dummy.setLeftAnchor(new SideAnchor(dummy, centerContainer.getLeftAnchor(),SideAnchor.LEFT_SIDE));
|
---|
72 | dummy.setRightAnchor(new SideAnchor(dummy, centerContainer.getRightAnchor(),SideAnchor.RIGHT_SIDE));
|
---|
73 | dummy.setPreferredSize(-1, centerContainer.getPreferredSize().height);
|
---|
74 | dummy.setVisible(true);
|
---|
75 | centerContainer.add(dummy, BorderLayout.CENTER);
|
---|
76 |
|
---|
77 | PathFigure leftMainLoopPath = new PathFigure();
|
---|
78 | // leftMainLoopPath.setTargetDecoration(null);
|
---|
79 | leftMainLoopPath.setSourceAnchor(centerContainer.getRightAnchor());
|
---|
80 | leftMainLoopPath.setTargetAnchor(dummy.getRightAnchor());
|
---|
81 | centerContainer.add(leftMainLoopPath);
|
---|
82 |
|
---|
83 | PathFigure rightMainLoopPath = new PathFigure();
|
---|
84 | // rightMainLoopPath.setTargetDecoration(null);
|
---|
85 | rightMainLoopPath.setSourceAnchor(dummy.getLeftAnchor());
|
---|
86 | rightMainLoopPath.setTargetAnchor(centerContainer.getLeftAnchor());
|
---|
87 | centerContainer.add(rightMainLoopPath);
|
---|
88 | }
|
---|
89 |
|
---|
90 | }
|
---|