1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast.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 import pl.edu.agh.cast.resource.ImageSize;
29
30
31
32
33
34
35 public class NodeFigure extends Figure implements ILabeledFigure {
36
37
38
39
40 protected ImageFigure icon;
41
42 private FlowPage flowPage;
43
44 private TextFlow textFlow;
45
46
47
48
49 public NodeFigure() {
50 super();
51 }
52
53
54
55
56
57
58
59
60
61
62
63 public NodeFigure(String label, String resourceId, ImageSize size) {
64 init(label, resourceId, size);
65 }
66
67 public IFigure getIcon() {
68 return icon;
69 }
70
71
72
73
74
75
76 public String getLabel() {
77 return textFlow.getText();
78 }
79
80
81
82
83
84
85 public void setLabel(String label) {
86 textFlow.setText(label);
87 }
88
89
90
91
92
93
94
95
96
97
98
99 protected void init(String label, String resourceId, ImageSize size) {
100 this.init(label, resourceId, size);
101 }
102
103
104
105
106
107
108
109
110
111
112
113
114
115 protected void init(String label, String resourceId, ImageSize size, String defaultResourceId) {
116
117 flowPage = new FlowPage();
118 textFlow = new TextFlow(label);
119 flowPage.add(textFlow);
120 flowPage.setHorizontalAligment(PositionConstants.CENTER);
121 flowPage.setBackgroundColor(ColorConstants.listBackground);
122 flowPage.setOpaque(true);
123
124 icon = new ImageFigure(resourceId, size, defaultResourceId);
125
126 add(icon);
127 add(flowPage);
128
129 ToolbarLayout layout = new ToolbarLayout();
130 layout.setStretchMinorAxis(false);
131 layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
132 setLayoutManager(layout);
133
134 }
135
136 public Figure getLabelFigure() {
137 return flowPage;
138 }
139
140 }