1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast.backward.figure;
19
20 import org.eclipse.draw2d.ColorConstants;
21 import org.eclipse.draw2d.Figure;
22 import org.eclipse.draw2d.IFigure;
23 import org.eclipse.draw2d.PositionConstants;
24 import org.eclipse.draw2d.ToolbarLayout;
25 import org.eclipse.draw2d.text.FlowPage;
26 import org.eclipse.draw2d.text.TextFlow;
27
28
29
30
31
32
33 public class NodeFigure extends Figure implements ILabeledFigure {
34
35
36
37
38 protected ImageFigure icon;
39
40 private FlowPage flowPage;
41
42 private TextFlow textFlow;
43
44
45
46
47 public NodeFigure() {
48 super();
49 }
50
51
52
53
54
55
56
57
58
59 public NodeFigure(String label, String imageId) {
60 init(label, imageId);
61 }
62
63 public IFigure getIcon() {
64 return icon;
65 }
66
67
68
69
70
71
72 public String getLabel() {
73 return textFlow.getText();
74 }
75
76
77
78
79
80
81 public void setLabel(String label) {
82 textFlow.setText(label);
83 }
84
85
86
87
88
89
90
91
92
93 protected void init(String label, String imageId) {
94
95 flowPage = new FlowPage();
96 textFlow = new TextFlow(label);
97 flowPage.add(textFlow);
98 flowPage.setHorizontalAligment(PositionConstants.CENTER);
99 flowPage.setBackgroundColor(ColorConstants.listBackground);
100 flowPage.setOpaque(true);
101
102 icon = new ImageFigure(imageId);
103
104 add(icon);
105 add(flowPage);
106
107 ToolbarLayout layout = new ToolbarLayout();
108 layout.setStretchMinorAxis(false);
109 layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
110 setLayoutManager(layout);
111
112 }
113
114 public Figure getLabelFigure() {
115 return flowPage;
116 }
117
118 }