1 | /* |
2 | ----------------------------------------------------------------------------- |
3 | (c) Copyright IBM Corp. 2003 All rights reserved. |
4 | |
5 | The sample program(s) is/are owned by International Business Machines |
6 | Corporation or one of its subsidiaries ("IBM") and is/are copyrighted and |
7 | licensed, not sold. |
8 | |
9 | You may copy, modify, and distribute this/these sample program(s) in any form |
10 | without payment to IBM, for any purpose including developing, using, marketing |
11 | or distributing programs that include or are derivative works of the sample |
12 | program(s). |
13 | |
14 | The sample program(s) is/are provided to you on an "AS IS" basis, without |
15 | warranty of any kind. IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER |
16 | EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
17 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Some jurisdictions do |
18 | not allow for the exclusion or limitation of implied warranties, so the above |
19 | limitations or exclusions may not apply to you. IBM shall not be liable for |
20 | any damages you suffer as a result of using, modifying or distributing the |
21 | sample program(s) or its/their derivatives. |
22 | |
23 | Each copy of any portion of this/these sample program(s) or any derivative |
24 | work, must include the above copyright notice and disclaimer of warranty. |
25 | |
26 | ----------------------------------------------------------------------------- |
27 | */ |
28 | |
29 | package swing2swt.layout; |
30 | |
31 | import java.awt.Dimension; |
32 | |
33 | import org.eclipse.swt.graphics.Point; |
34 | import org.eclipse.swt.widgets.Control; |
35 | import org.eclipse.swt.widgets.Layout; |
36 | |
37 | /** |
38 | * Superclass for all the AWT layouts ported to SWT. |
39 | * @author Yannick Saillet |
40 | */ |
41 | public abstract class AWTLayout extends Layout { |
42 | |
43 | /** |
44 | * Key under which an eventual preferred size (set with setPreferredSize) |
45 | * is stored as a user data in the SWT control. |
46 | */ |
47 | public final static String KEY_PREFERRED_SIZE = "preferredSize"; |
48 | |
49 | /** |
50 | * Gets the preferred size of a component. |
51 | * If a preferred size has been set with setPreferredSize, returns it, |
52 | * otherwise returns the component computed preferred size. |
53 | */ |
54 | protected Point getPreferredSize( |
55 | Control control, |
56 | int wHint, |
57 | int hHint, |
58 | boolean changed) { |
59 | // check if a preferred size was set on the control with |
60 | // SWTComponent.setPreferredSize(Dimension) |
61 | Dimension d = (Dimension)control.getData(KEY_PREFERRED_SIZE); |
62 | if (d != null) |
63 | return new Point(d.width, d.height); |
64 | return control.computeSize(wHint, hHint, changed); |
65 | } |
66 | } |