|
| 1 | +/******************************************************************************* |
| 2 | + * Java2Script Pacemaker (http://j2s.sourceforge.net) |
| 3 | + * |
| 4 | + * Copyright (c) 2006 ognize.com and others. |
| 5 | + * All rights reserved. This program and the accompanying materials |
| 6 | + * are made available under the terms of the Eclipse Public License v1.0 |
| 7 | + * which accompanies this distribution, and is available at |
| 8 | + * http://www.eclipse.org/legal/epl-v10.html |
| 9 | + * |
| 10 | + * Contributors: |
| 11 | + * ognize.com - initial API and implementation |
| 12 | + *******************************************************************************/ |
| 13 | + |
| 14 | +package net.sf.j2s.test.swt.ajunit; |
| 15 | + |
| 16 | +import net.sf.j2s.ajax.junit.AsyncSWT; |
| 17 | +import net.sf.j2s.ajax.junit.AsyncTestCase; |
| 18 | +import net.sf.j2s.ajax.junit.AsyncTestRunnable; |
| 19 | +import net.sf.j2s.ajax.junit.AsyncTestRunner; |
| 20 | +import org.eclipse.swt.SWT; |
| 21 | +import org.eclipse.swt.graphics.Point; |
| 22 | +import org.eclipse.swt.layout.FillLayout; |
| 23 | +import org.eclipse.swt.layout.GridData; |
| 24 | +import org.eclipse.swt.layout.GridLayout; |
| 25 | +import org.eclipse.swt.widgets.Display; |
| 26 | +import org.eclipse.swt.widgets.Shell; |
| 27 | +import org.eclipse.swt.widgets.Spinner; |
| 28 | + |
| 29 | +/** |
| 30 | + * @author josson smith |
| 31 | + * |
| 32 | + * 2006-8-1 |
| 33 | + */ |
| 34 | +public class SpinnerTest extends AsyncTestCase { |
| 35 | + |
| 36 | + public void testSpinnerValue() { |
| 37 | + Display display = new Display (); |
| 38 | + final Shell shell = new Shell(display); |
| 39 | + shell.setLayout(new GridLayout()); |
| 40 | + final Spinner spn1 = new Spinner(shell, SWT.BORDER | SWT.READ_ONLY); |
| 41 | + spn1.setLayoutData(new GridData(120, 20)); |
| 42 | + spn1.setMinimum(-120); |
| 43 | + spn1.setDigits(2); |
| 44 | + spn1.setIncrement(7); |
| 45 | +// spn1.setEnabled(false); |
| 46 | + final Spinner spn0 = new Spinner(shell, SWT.WRAP); |
| 47 | + final Spinner spn2 = new Spinner(shell, SWT.BORDER); |
| 48 | + shell.pack(); |
| 49 | + shell.open (); |
| 50 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 51 | + public void run() { |
| 52 | + System.out.println(spn0.getSize()); |
| 53 | + System.out.println(spn2.getSize()); |
| 54 | + assertEquals(spn0.getSize(), new Point(35, 16)); |
| 55 | + assertEquals(spn2.getSize(), new Point(41, 19)); |
| 56 | + } |
| 57 | + }); |
| 58 | + display.dispose (); |
| 59 | + AsyncSWT.setShellAutoClose(true); |
| 60 | + } |
| 61 | + |
| 62 | + public void testDefaultValue() { |
| 63 | + Display display = new Display (); |
| 64 | + Shell shell = new Shell(display); |
| 65 | + shell.setLayout(new GridLayout()); |
| 66 | + final Spinner scaleD = new Spinner(shell, SWT.NONE); |
| 67 | + final Spinner scaleB = new Spinner(shell, SWT.BORDER); |
| 68 | + final Spinner scaleV = new Spinner(shell, SWT.NONE); |
| 69 | + final Spinner scaleS = new Spinner(shell, SWT.NONE); |
| 70 | + shell.pack(); |
| 71 | + shell.open (); |
| 72 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 73 | + public void run() { |
| 74 | + System.out.println(scaleD.getMaximum()); |
| 75 | + System.out.println(scaleB.getMaximum()); |
| 76 | + System.out.println(scaleV.getMaximum()); |
| 77 | + System.out.println(scaleS.getMaximum()); |
| 78 | + |
| 79 | + assertEquals(scaleD.getMaximum(), 100); |
| 80 | + assertEquals(scaleB.getMaximum(), 100); |
| 81 | + assertEquals(scaleV.getMaximum(), 100); |
| 82 | + assertEquals(scaleS.getMaximum(), 100); |
| 83 | + } |
| 84 | + }); |
| 85 | + display.dispose (); |
| 86 | + } |
| 87 | + |
| 88 | + |
| 89 | + public void testSelectionValue() { |
| 90 | + Display display = new Display (); |
| 91 | + Shell shell = new Shell(display); |
| 92 | + shell.setLayout(new GridLayout()); |
| 93 | + final Spinner scaleD = new Spinner(shell, SWT.NONE); |
| 94 | + final Spinner scaleB = new Spinner(shell, SWT.BORDER); |
| 95 | + final Spinner scaleV = new Spinner(shell, SWT.NONE); |
| 96 | + final Spinner scaleS = new Spinner(shell, SWT.NONE); |
| 97 | + shell.pack(); |
| 98 | + shell.open (); |
| 99 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 100 | + public void run() { |
| 101 | + scaleD.setSelection(20); |
| 102 | + scaleB.setSelection(120); |
| 103 | + scaleV.setSelection(-20); |
| 104 | + scaleS.setSelection(100); |
| 105 | + |
| 106 | + assertEquals("Default", scaleD.getSelection(), 20); |
| 107 | + assertEquals("Border", scaleB.getSelection(), 100); |
| 108 | + assertEquals("Vertical", scaleV.getSelection(), 0); |
| 109 | + assertEquals("Smooth", scaleS.getSelection(), 100); |
| 110 | + } |
| 111 | + }); |
| 112 | + display.dispose (); |
| 113 | + } |
| 114 | + |
| 115 | + |
| 116 | + public void testMaximumValue() { |
| 117 | + Display display = new Display (); |
| 118 | + Shell shell = new Shell(display); |
| 119 | + shell.setLayout(new GridLayout()); |
| 120 | + final Spinner scaleD = new Spinner(shell, SWT.NONE); |
| 121 | + final Spinner scaleB = new Spinner(shell, SWT.BORDER); |
| 122 | + final Spinner scaleV = new Spinner(shell, SWT.NONE); |
| 123 | + final Spinner scaleS = new Spinner(shell, SWT.NONE); |
| 124 | + final Spinner scaleX = new Spinner(shell, SWT.NONE); |
| 125 | + shell.pack(); |
| 126 | + shell.open (); |
| 127 | + //AsyncSWT.setShellAutoClose(false); |
| 128 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 129 | + public void run() { |
| 130 | + scaleD.setSelection(20); |
| 131 | + scaleB.setSelection(-20); |
| 132 | + scaleV.setSelection(120); |
| 133 | + scaleS.setSelection(100); |
| 134 | + scaleX.setSelection(5); |
| 135 | + |
| 136 | + scaleD.setMaximum(40); |
| 137 | + scaleB.setMaximum(-80); |
| 138 | + scaleV.setMaximum(250); |
| 139 | + scaleS.setMaximum(50); |
| 140 | + |
| 141 | + assertEquals("Default", scaleD.getSelection(), 20); |
| 142 | + assertEquals("Border", scaleB.getSelection(), 0); |
| 143 | + assertEquals("Vertical", scaleV.getSelection(), 100); |
| 144 | + assertEquals("Smooth", scaleS.getSelection(), 50); |
| 145 | + assertEquals("Indeterminate", scaleX.getSelection(), 5); |
| 146 | + |
| 147 | + } |
| 148 | + }); |
| 149 | + display.dispose (); |
| 150 | + } |
| 151 | + |
| 152 | + |
| 153 | + public void testMinimumValue() { |
| 154 | + Display display = new Display (); |
| 155 | + Shell shell = new Shell(display); |
| 156 | + shell.setLayout(new GridLayout()); |
| 157 | + final Spinner scaleD = new Spinner(shell, SWT.NONE); |
| 158 | + final Spinner scaleB = new Spinner(shell, SWT.BORDER); |
| 159 | + final Spinner scaleV = new Spinner(shell, SWT.NONE); |
| 160 | + final Spinner scaleS = new Spinner(shell, SWT.NONE); |
| 161 | + final Spinner scaleX = new Spinner(shell, SWT.NONE); |
| 162 | + shell.pack(); |
| 163 | + shell.open (); |
| 164 | + //AsyncSWT.setShellAutoClose(false); |
| 165 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 166 | + public void run() { |
| 167 | + scaleD.setSelection(20); |
| 168 | + scaleB.setSelection(-20); |
| 169 | + scaleV.setSelection(120); |
| 170 | + scaleS.setSelection(100); |
| 171 | + scaleX.setSelection(45); |
| 172 | + |
| 173 | + scaleD.setMinimum(40); |
| 174 | + scaleB.setMinimum(-80); |
| 175 | + scaleV.setMinimum(250); |
| 176 | + scaleS.setMinimum(50); |
| 177 | + scaleX.setMinimum(70); |
| 178 | + |
| 179 | + assertEquals("Default", scaleD.getSelection(), 40); |
| 180 | + assertEquals("Border", scaleB.getSelection(), 0); |
| 181 | + assertEquals("Vertical", scaleV.getSelection(), 100); |
| 182 | + assertEquals("Smooth", scaleS.getSelection(), 100); |
| 183 | + assertEquals("Indeterminate", scaleX.getSelection(), 70); |
| 184 | + |
| 185 | + } |
| 186 | + }); |
| 187 | + display.dispose (); |
| 188 | + } |
| 189 | + |
| 190 | + public void testSpinnerSize() { |
| 191 | + Display display = new Display (); |
| 192 | + final Shell shell = new Shell(display); |
| 193 | + shell.setLayout(new GridLayout()); |
| 194 | + final Spinner spn1 = new Spinner(shell, SWT.NONE); |
| 195 | + final Spinner spn2 = new Spinner(shell, SWT.BORDER); |
| 196 | + shell.pack(); |
| 197 | + shell.open (); |
| 198 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 199 | + public void run() { |
| 200 | + System.out.println(spn1.getSize()); |
| 201 | + System.out.println(spn2.getSize()); |
| 202 | + assertEquals(spn1.getSize(), new Point(35, 16)); |
| 203 | + assertEquals(spn2.getSize(), new Point(41, 19)); |
| 204 | + } |
| 205 | + }); |
| 206 | + display.dispose (); |
| 207 | + } |
| 208 | + |
| 209 | + public void testFilledSpinnerSize() { |
| 210 | + Display display = new Display (); |
| 211 | + final Shell shell = new Shell(display); |
| 212 | + shell.setLayout(new FillLayout()); |
| 213 | + final Spinner spn1 = new Spinner(shell, SWT.NONE); |
| 214 | + final Spinner spn2 = new Spinner(shell, SWT.BORDER); |
| 215 | + shell.pack(); |
| 216 | + shell.open (); |
| 217 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 218 | + public void run() { |
| 219 | + System.out.println(spn1.getSize()); |
| 220 | + System.out.println(spn2.getSize()); |
| 221 | + assertEquals(spn1.getSize(), new Point(52, 19)); |
| 222 | + assertEquals(spn2.getSize(), new Point(53, 19)); |
| 223 | + } |
| 224 | + }); |
| 225 | + display.dispose (); |
| 226 | + } |
| 227 | + |
| 228 | + |
| 229 | + public void testSetSpinnerSize() { |
| 230 | + Display display = new Display (); |
| 231 | + final Shell shell = new Shell(display); |
| 232 | + shell.setLayout(new GridLayout()); |
| 233 | + final Spinner spn1 = new Spinner(shell, SWT.NONE); |
| 234 | + spn1.setLayoutData(new GridData(120, 40)); |
| 235 | + spn1.setEnabled(false); |
| 236 | + final Spinner spn2 = new Spinner(shell, SWT.BORDER); |
| 237 | + spn2.setLayoutData(new GridData(150, 50)); |
| 238 | + final Spinner spn3 = new Spinner(shell, SWT.NONE); |
| 239 | + spn3.setLayoutData(new GridData(120, 30)); |
| 240 | + final Spinner spn0 = new Spinner(shell, SWT.NONE); |
| 241 | + spn0.setLayoutData(new GridData(120, 24)); |
| 242 | + final Spinner spn4 = new Spinner(shell, SWT.NONE); |
| 243 | + spn4.setLayoutData(new GridData(120, 20)); |
| 244 | + final Spinner spn5 = new Spinner(shell, SWT.NONE); |
| 245 | + spn5.setLayoutData(new GridData(120, 10)); |
| 246 | + final Spinner spn6 = new Spinner(shell, SWT.NONE); |
| 247 | + spn6.setLayoutData(new GridData(120, 16)); |
| 248 | + shell.pack(); |
| 249 | + shell.open (); |
| 250 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 251 | + public void run() { |
| 252 | + System.out.println(spn1.getSize()); |
| 253 | + System.out.println(spn2.getSize()); |
| 254 | + assertEquals(spn1.getSize(), new Point(137, 40)); |
| 255 | + assertEquals(spn2.getSize(), new Point(173, 56)); |
| 256 | + } |
| 257 | + }); |
| 258 | + display.dispose (); |
| 259 | + } |
| 260 | + |
| 261 | + public static void main(String[] args) { |
| 262 | + AsyncSWT.setShellAutoClose(false); |
| 263 | + AsyncTestRunner.asyncRun (SpinnerTest.class); |
| 264 | + } |
| 265 | +} |
0 commit comments