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 java.util.List;
21
22 import org.eclipse.draw2d.ColorConstants;
23 import org.eclipse.draw2d.Figure;
24 import org.eclipse.draw2d.FrameBorder;
25 import org.eclipse.draw2d.ToolbarLayout;
26 import org.eclipse.draw2d.geometry.Rectangle;
27
28 import pl.edu.agh.cast.model.visual.Legend;
29 import pl.edu.agh.cast.util.Messages;
30
31
32
33
34
35
36 public abstract class AbstractLegendFigure extends Figure {
37
38
39
40
41 protected Legend legend;
42
43 private FrameBorder legendBorder;
44
45
46
47
48
49
50 protected abstract List<Figure> getLegendEntries();
51
52
53
54
55
56
57
58 public AbstractLegendFigure(Legend legend) {
59 super();
60 this.legend = legend;
61 }
62
63
64
65
66 public void refresh() {
67 if (getLegendEntries().size() == 0) {
68 setVisible(false);
69 return;
70 } else {
71 setVisible(true);
72 }
73
74 ToolbarLayout layout = new ToolbarLayout();
75 layout.setStretchMinorAxis(false);
76 layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
77 setLayoutManager(layout);
78
79 removeAll();
80 for (Figure legendEntry : getLegendEntries()) {
81 add(legendEntry);
82 }
83 legendBorder = new FrameBorder(Messages.Legend_0);
84 this.setBackgroundColor(ColorConstants.listBackground);
85 this.setOpaque(true);
86 this.setBorder(legendBorder);
87 this.setBounds(new Rectangle(getLocation(), getPreferredSize()));
88
89 }
90
91 }