1 | package de.ugoe.cs.swe.bnftools.ui.views.syntaxdiagram;
|
---|
2 |
|
---|
3 | import org.eclipse.draw2d.FlowLayout;
|
---|
4 | import org.eclipse.draw2d.Label;
|
---|
5 | import org.eclipse.draw2d.MarginBorder;
|
---|
6 | import org.eclipse.draw2d.PositionConstants;
|
---|
7 | import org.eclipse.draw2d.RectangleFigure;
|
---|
8 | import org.eclipse.draw2d.StackLayout;
|
---|
9 | import org.eclipse.swt.SWT;
|
---|
10 | import org.eclipse.swt.graphics.Color;
|
---|
11 |
|
---|
12 | public class NonTerminalFigure extends SyntaxDiagramFigure {
|
---|
13 | private String nonterminalString;
|
---|
14 |
|
---|
15 | public NonTerminalFigure(String nonterminalString) {
|
---|
16 | super();
|
---|
17 | this.nonterminalString = nonterminalString;
|
---|
18 |
|
---|
19 | SyntaxDiagramFigure innerFigure = new SyntaxDiagramFigure();
|
---|
20 | setBorder(new LineMarginBorder(0, 0, 0));
|
---|
21 | innerFigure.setLayoutManager(new StackLayout());
|
---|
22 |
|
---|
23 | FlowLayout layout = new FlowLayout();
|
---|
24 | layout.setMajorAlignment(FlowLayout.ALIGN_CENTER);
|
---|
25 | setLayoutManager(layout);
|
---|
26 |
|
---|
27 | RectangleFigure rectangle = new RectangleFigure();
|
---|
28 | rectangle.setAntialias(SWT.ON);
|
---|
29 | rectangle.setBackgroundColor(new Color(null, 220, 220, 220));
|
---|
30 | rectangle.setForegroundColor(new Color(null, 170, 170, 170));
|
---|
31 | innerFigure.add(rectangle);
|
---|
32 |
|
---|
33 | Label nonterminalStringLabel = new Label(this.nonterminalString);
|
---|
34 | nonterminalStringLabel.setForegroundColor(new Color(null, 200, 0, 0));
|
---|
35 | nonterminalStringLabel.setTextAlignment(PositionConstants.CENTER);
|
---|
36 | nonterminalStringLabel.setBorder(new MarginBorder(3,8,3,8));
|
---|
37 | innerFigure.add(nonterminalStringLabel);
|
---|
38 |
|
---|
39 | PathFigure leftPath = new PathFigure();
|
---|
40 | leftPath.setSourceAnchor(this.getLeftAnchor());
|
---|
41 | leftPath.setTargetAnchor(innerFigure.getLeftAnchor());
|
---|
42 |
|
---|
43 | PathFigure rightPath = new PathFigure();
|
---|
44 | rightPath.setTargetDecoration(null);
|
---|
45 | rightPath.setSourceAnchor(innerFigure.getRightAnchor());
|
---|
46 | rightPath.setTargetAnchor(this.getRightAnchor());
|
---|
47 |
|
---|
48 | add(leftPath);
|
---|
49 | add(rightPath);
|
---|
50 |
|
---|
51 | add(innerFigure);
|
---|
52 | }
|
---|
53 |
|
---|
54 | public String getTerminalString() {
|
---|
55 | return nonterminalString;
|
---|
56 | }
|
---|
57 |
|
---|
58 | public void setTerminalString(String terminalString) {
|
---|
59 | this.nonterminalString = terminalString;
|
---|
60 | }
|
---|
61 |
|
---|
62 | }
|
---|