1
2
3
4
5
6
7
8
9
10
11
12 package sk.uniba.euromath.editor;
13
14 import org.eclipse.draw2d.FigureCanvas;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.graphics.Point;
17 import org.eclipse.swt.graphics.Rectangle;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Control;
20 import org.eclipse.swt.widgets.Layout;
21
22 import sk.uniba.euromath.editor.xmlEditor.policies.FigureSelectionPolicy;
23
24 /***
25 * @author Tomáš Studva 12.10.2005
26 */
27 public class PreferredByControlLayout extends Layout {
28
29 /***
30 * Constructs a new instance of this class.
31 */
32 public PreferredByControlLayout() {
33 super();
34 }
35
36
37
38
39
40
41
42 @Override
43 protected Point computeSize(Composite composite, int wHint, int hHint,
44 boolean flushCache) {
45 if (composite.getChildren().length == 0)
46 return new Point(0, 0);
47 int width, height;
48 width = 0;
49 height = 0;
50 if (wHint != SWT.DEFAULT)
51 width = wHint;
52 if (hHint != SWT.DEFAULT)
53 height = hHint;
54 return new Point(width, height);
55 }
56
57 @Override
58 protected boolean flushCache(Control control) {
59 return true;
60 }
61
62
63
64
65
66
67
68 @Override
69 protected void layout(Composite composite, boolean flushCache) {
70 org.eclipse.draw2d.geometry.Point scrollOffset = new org.eclipse.draw2d.geometry.Point(
71 0, 0);
72 if (composite instanceof FigureCanvas) {
73 scrollOffset = ((FigureCanvas) composite).getViewport()
74 .getViewLocation();
75 }
76 Control[] children = composite.getChildren();
77 int count = children.length;
78 if (count == 0)
79 return;
80 for (int i = 0; i < count; i++) {
81 Rectangle rect = (Rectangle) children[i].getLayoutData();
82 children[i].setBounds(rect.x - scrollOffset.x, rect.y
83 - scrollOffset.y, rect.width+2*FigureSelectionPolicy.SELECION_BORDER_WIDTH,
84 rect.height+2*FigureSelectionPolicy.SELECION_BORDER_WIDTH );
85 }
86 }
87
88 /***
89 * Returns a string containing a concise, human-readable description of the
90 * receiver.
91 *
92 * @return a string representation of the event
93 */
94 @Override
95 public String toString() {
96 String string = getClass().getName();
97 int index = string.lastIndexOf('.');
98 if (index == -1)
99 return string;
100 return string.substring(index + 1, string.length());
101 }
102
103 }