1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast.tool;
19
20 import org.eclipse.draw2d.geometry.Rectangle;
21 import org.eclipse.gef.tools.CellEditorLocator;
22 import org.eclipse.jface.viewers.CellEditor;
23 import org.eclipse.swt.widgets.Text;
24
25 import pl.edu.agh.cast.figure.NodeFigure;
26
27
28
29
30
31
32 public class LabelCellEditorLocator implements CellEditorLocator {
33
34 private NodeFigure nodeFigure;
35
36 public NodeFigure getNodeFigure() {
37 return nodeFigure;
38 }
39
40
41
42
43
44
45
46 public LabelCellEditorLocator(NodeFigure nodeFigure) {
47 setLabel(nodeFigure);
48 }
49
50
51
52
53
54
55 @Override
56 public void relocate(CellEditor celleditor) {
57 Text text = (Text)celleditor.getControl();
58
59 Rectangle rect = new Rectangle(nodeFigure.getLabelFigure().getBounds());
60 nodeFigure.translateToAbsolute(rect);
61 org.eclipse.swt.graphics.Rectangle trim = text.computeTrim(0, 0, 0, 0);
62 rect.translate(trim.x, trim.y);
63 rect.width += trim.width;
64 rect.height += trim.height;
65
66 rect.width = Math.max(rect.width, 100);
67 text.setBounds(rect.x, rect.y, rect.width, rect.height);
68 }
69
70
71
72
73 protected NodeFigure getLabel() {
74 return nodeFigure;
75 }
76
77
78
79
80
81
82
83 protected void setLabel(NodeFigure stickyNote) {
84 this.nodeFigure = stickyNote;
85 }
86
87 }