|
Lines 7-12
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* Frank Appel - initial API and implementation |
9 |
* Frank Appel - initial API and implementation |
|
|
10 |
* EclipseSource - ongoing development |
| 10 |
******************************************************************************/ |
11 |
******************************************************************************/ |
| 11 |
package org.eclipse.rwt.internal.textsize; |
12 |
package org.eclipse.rwt.internal.textsize; |
| 12 |
|
13 |
|
|
Lines 21-27
Link Here
|
| 21 |
import org.eclipse.swt.events.ControlListener; |
22 |
import org.eclipse.swt.events.ControlListener; |
| 22 |
import org.eclipse.swt.graphics.*; |
23 |
import org.eclipse.swt.graphics.*; |
| 23 |
import org.eclipse.swt.internal.widgets.ControlUtil; |
24 |
import org.eclipse.swt.internal.widgets.ControlUtil; |
| 24 |
import org.eclipse.swt.layout.FillLayout; |
25 |
import org.eclipse.swt.layout.*; |
| 25 |
import org.eclipse.swt.widgets.*; |
26 |
import org.eclipse.swt.widgets.*; |
| 26 |
|
27 |
|
| 27 |
|
28 |
|
|
Lines 29-88
Link Here
|
| 29 |
private static final FontData FONT_DATA = new FontData( "arial", 23, SWT.BOLD ); |
30 |
private static final FontData FONT_DATA = new FontData( "arial", 23, SWT.BOLD ); |
| 30 |
private static final String TEXT_TO_MEASURE = "textToMeasure"; |
31 |
private static final String TEXT_TO_MEASURE = "textToMeasure"; |
| 31 |
|
32 |
|
|
|
33 |
private Display display; |
| 32 |
private Shell shell; |
34 |
private Shell shell; |
| 33 |
private Composite scrolledCompositeContent; |
35 |
private Composite scrolledCompositeContent; |
| 34 |
private ResizeListener shellResizeListener; |
36 |
private ResizeListener shellResizeListener; |
| 35 |
private ResizeListener scrolledCompositeContentResizeListener; |
37 |
private ResizeListener scrolledCompositeContentResizeListener; |
| 36 |
private Label packedControl; |
38 |
private Label packedControl; |
| 37 |
|
|
|
| 38 |
|
| 39 |
private final class ResizeListener implements ControlListener { |
| 40 |
private int resizeCount; |
| 41 |
|
| 42 |
public void controlResized( ControlEvent e ) { |
| 43 |
resizeCount++; |
| 44 |
} |
| 45 |
|
39 |
|
| 46 |
public void controlMoved( ControlEvent e ) { |
40 |
protected void setUp() throws Exception { |
| 47 |
} |
41 |
Fixture.setUp(); |
|
|
42 |
display = new Display(); |
| 43 |
shell = new Shell( display ); |
| 44 |
} |
| 48 |
|
45 |
|
| 49 |
public int resizeCount() { |
46 |
protected void tearDown() throws Exception { |
| 50 |
return resizeCount; |
47 |
Fixture.tearDown(); |
| 51 |
} |
|
|
| 52 |
} |
48 |
} |
| 53 |
|
49 |
|
| 54 |
|
|
|
| 55 |
public void testExecute() { |
50 |
public void testExecute() { |
| 56 |
createWidgetTree(); |
51 |
createWidgetTree(); |
| 57 |
registerResizeListeners(); |
52 |
registerResizeListeners(); |
| 58 |
turnOnImmediateResizeEventHandling(); |
53 |
turnOnImmediateResizeEventHandling(); |
| 59 |
fakeMeasurementResults(); |
54 |
fakeMeasurementResults(); |
| 60 |
TextSizeRecalculation recalculation = new TextSizeRecalculation(); |
55 |
TextSizeRecalculation recalculation = new TextSizeRecalculation(); |
| 61 |
|
56 |
|
| 62 |
recalculation.execute(); |
57 |
recalculation.execute(); |
| 63 |
|
58 |
|
| 64 |
checkResizeTookPlace(); |
59 |
checkResizeTookPlace(); |
| 65 |
checkRePackTookPlace(); |
60 |
checkRePackTookPlace(); |
| 66 |
} |
61 |
} |
| 67 |
|
62 |
|
| 68 |
public void testIControlAdapterIsPacked() { |
63 |
public void testIControlAdapterIsPacked() { |
| 69 |
Display display = new Display(); |
|
|
| 70 |
Shell control = new Shell( display ); |
64 |
Shell control = new Shell( display ); |
| 71 |
assertFalse( ControlUtil.getControlAdapter( control ).isPacked() ); |
65 |
assertFalse( ControlUtil.getControlAdapter( control ).isPacked() ); |
| 72 |
|
66 |
|
| 73 |
control.pack(); |
67 |
control.pack(); |
| 74 |
assertTrue( ControlUtil.getControlAdapter( control ).isPacked() ); |
68 |
assertTrue( ControlUtil.getControlAdapter( control ).isPacked() ); |
| 75 |
|
69 |
|
| 76 |
control.setBounds( new Rectangle( 1, 1, 2, 2 ) ); |
70 |
control.setBounds( new Rectangle( 1, 1, 2, 2 ) ); |
| 77 |
assertFalse( ControlUtil.getControlAdapter( control ).isPacked() ); |
71 |
assertFalse( ControlUtil.getControlAdapter( control ).isPacked() ); |
| 78 |
} |
72 |
} |
| 79 |
|
73 |
|
| 80 |
protected void setUp() throws Exception { |
74 |
public void testLayoutOfCompositeWithFixedSize() { |
| 81 |
Fixture.setUp(); |
75 |
turnOnImmediateResizeEventHandling(); |
| 82 |
} |
76 |
createShellWithLayout(); |
| 83 |
|
77 |
Composite fixedSizeComposite = createFixedSizeComposite(); |
| 84 |
protected void tearDown() throws Exception { |
78 |
Label label = new Label( fixedSizeComposite, SWT.NONE ); |
| 85 |
Fixture.tearDown(); |
79 |
label.setText( "text" ); |
|
|
80 |
shell.pack(); |
| 81 |
// simulate smaller size because of text estimation |
| 82 |
label.setSize( 5, 5 ); |
| 83 |
ResizeListener resizeListener = new ResizeListener(); |
| 84 |
label.addControlListener( resizeListener ); |
| 85 |
|
| 86 |
TextSizeRecalculation recalculation = new TextSizeRecalculation(); |
| 87 |
recalculation.execute(); |
| 88 |
|
| 89 |
assertEquals( 1, resizeListener.resizeCount() ); |
| 86 |
} |
90 |
} |
| 87 |
|
91 |
|
| 88 |
private void checkResizeTookPlace() { |
92 |
private void checkResizeTookPlace() { |
|
Lines 91-97
Link Here
|
| 91 |
assertEquals( 2, shellResizeListener.resizeCount() ); |
95 |
assertEquals( 2, shellResizeListener.resizeCount() ); |
| 92 |
assertEquals( 2, scrolledCompositeContentResizeListener.resizeCount() ); |
96 |
assertEquals( 2, scrolledCompositeContentResizeListener.resizeCount() ); |
| 93 |
} |
97 |
} |
| 94 |
|
98 |
|
| 95 |
private void checkRePackTookPlace() { |
99 |
private void checkRePackTookPlace() { |
| 96 |
assertEquals( new Point( 100, 22 ), packedControl.getSize() ); |
100 |
assertEquals( new Point( 100, 22 ), packedControl.getSize() ); |
| 97 |
} |
101 |
} |
|
Lines 105-112
Link Here
|
| 105 |
} |
109 |
} |
| 106 |
|
110 |
|
| 107 |
private void createWidgetTree() { |
111 |
private void createWidgetTree() { |
| 108 |
Display display = new Display(); |
112 |
createShellWithLayout(); |
| 109 |
createShellWithLayout( display ); |
|
|
| 110 |
createScrolledCompositeWithContent(); |
113 |
createScrolledCompositeWithContent(); |
| 111 |
createPackedControl(); |
114 |
createPackedControl(); |
| 112 |
} |
115 |
} |
|
Lines 124-132
Link Here
|
| 124 |
scrolledComposite.setContent( scrolledCompositeContent ); |
127 |
scrolledComposite.setContent( scrolledCompositeContent ); |
| 125 |
} |
128 |
} |
| 126 |
|
129 |
|
| 127 |
private void createShellWithLayout( Display display ) { |
130 |
private void createShellWithLayout() { |
| 128 |
shell = new Shell( display ); |
131 |
shell.setLayout( new GridLayout() ); |
| 129 |
shell.setLayout( new FillLayout() ); |
132 |
} |
|
|
133 |
|
| 134 |
private Composite createFixedSizeComposite() { |
| 135 |
Composite result = new Composite( shell, SWT.NONE ); |
| 136 |
result.setLayout( new GridLayout() ); |
| 137 |
result.setLayoutData( new GridData( 200, SWT.DEFAULT ) ); |
| 138 |
return result; |
| 130 |
} |
139 |
} |
| 131 |
|
140 |
|
| 132 |
private void registerResizeListeners() { |
141 |
private void registerResizeListeners() { |
|
Lines 135-141
Link Here
|
| 135 |
shell.addControlListener( shellResizeListener ); |
144 |
shell.addControlListener( shellResizeListener ); |
| 136 |
scrolledCompositeContent.addControlListener( scrolledCompositeContentResizeListener ); |
145 |
scrolledCompositeContent.addControlListener( scrolledCompositeContentResizeListener ); |
| 137 |
} |
146 |
} |
| 138 |
|
147 |
|
| 139 |
private void turnOnImmediateResizeEventHandling() { |
148 |
private void turnOnImmediateResizeEventHandling() { |
| 140 |
Fixture.fakePhase( PhaseId.PROCESS_ACTION ); |
149 |
Fixture.fakePhase( PhaseId.PROCESS_ACTION ); |
| 141 |
} |
150 |
} |
|
Lines 145-148
Link Here
|
| 145 |
RWTFactory.getTextSizeStorage().storeFont( FONT_DATA ); |
154 |
RWTFactory.getTextSizeStorage().storeFont( FONT_DATA ); |
| 146 |
TextSizeStorageUtil.store( FONT_DATA, TEXT_TO_MEASURE, 0, new Point( 100, 20 ) ); |
155 |
TextSizeStorageUtil.store( FONT_DATA, TEXT_TO_MEASURE, 0, new Point( 100, 20 ) ); |
| 147 |
} |
156 |
} |
|
|
157 |
|
| 158 |
private final class ResizeListener implements ControlListener { |
| 159 |
private int resizeCount; |
| 160 |
|
| 161 |
public void controlResized( ControlEvent e ) { |
| 162 |
resizeCount++; |
| 163 |
} |
| 164 |
|
| 165 |
public void controlMoved( ControlEvent e ) { |
| 166 |
} |
| 167 |
|
| 168 |
public int resizeCount() { |
| 169 |
return resizeCount; |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 148 |
} |
173 |
} |