|
| 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.Text; |
| 28 | + |
| 29 | +/** |
| 30 | + * @author josson smith |
| 31 | + * |
| 32 | + * 2006-8-1 |
| 33 | + */ |
| 34 | +public class TextTest extends AsyncTestCase { |
| 35 | + |
| 36 | + public void testMultiTextStringSize() { |
| 37 | + Display display = new Display (); |
| 38 | + final Shell shell = new Shell(display); |
| 39 | + shell.setLayout(new GridLayout()); |
| 40 | + final Text txt0 = new Text(shell, SWT.WRAP | SWT.MULTI); |
| 41 | + txt0.setText("423424x fww"); |
| 42 | + final Text txt1 = new Text(shell, SWT.BORDER | SWT.READ_ONLY | SWT.MULTI); |
| 43 | + txt1.setText("42999xxxxxxxx xx"); |
| 44 | + txt1.setLayoutData(new GridData(120, 20)); |
| 45 | + final Text txt2 = new Text(shell, SWT.BORDER | SWT.MULTI); |
| 46 | + txt2.setText(" "); |
| 47 | + final Text txt3 = new Text(shell, SWT.FLAT | SWT.MULTI); |
| 48 | + txt3.setText("-----=2 ===---==="); |
| 49 | + final Text txt4 = new Text(shell, SWT.WRAP | SWT.FLAT | SWT.MULTI); |
| 50 | + txt4.setText("-----=2== =---==="); |
| 51 | + final Text txt5 = new Text(shell, SWT.NONE | SWT.MULTI); |
| 52 | + txt5.setText("---- -=2===---== ="); |
| 53 | + shell.pack(); |
| 54 | + shell.open (); |
| 55 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 56 | + public void run() { |
| 57 | + System.out.println(txt0.getSize()); |
| 58 | + System.out.println(txt1.getSize()); |
| 59 | + System.out.println(txt2.getSize()); |
| 60 | + System.out.println(txt3.getSize()); |
| 61 | + System.out.println(txt4.getSize()); |
| 62 | + System.out.println(txt5.getSize()); |
| 63 | + assertEquals(txt0.getSize(), new Point(71, 13)); |
| 64 | + assertEquals(txt1.getSize(), new Point(132, 26)); |
| 65 | + assertEquals(txt2.getSize(), new Point(15, 19)); |
| 66 | + assertEquals(txt3.getSize(), new Point(103, 13)); |
| 67 | + assertEquals(txt4.getSize(), new Point(103, 13)); |
| 68 | + assertEquals(txt5.getSize(), new Point(106, 13)); |
| 69 | + } |
| 70 | + }); |
| 71 | + display.dispose (); |
| 72 | + //AsyncSWT.setShellAutoClose(true); |
| 73 | + } |
| 74 | + |
| 75 | + public void testTextStringSize() { |
| 76 | + Display display = new Display (); |
| 77 | + final Shell shell = new Shell(display); |
| 78 | + shell.setLayout(new GridLayout()); |
| 79 | + final Text txt0 = new Text(shell, SWT.WRAP); |
| 80 | + txt0.setText("423424xfww"); |
| 81 | + final Text txt1 = new Text(shell, SWT.BORDER | SWT.READ_ONLY); |
| 82 | + txt1.setText("42999xxx"); |
| 83 | + txt1.setLayoutData(new GridData(120, 20)); |
| 84 | + final Text txt2 = new Text(shell, SWT.BORDER); |
| 85 | + txt2.setText(" "); |
| 86 | + final Text txt3 = new Text(shell, SWT.FLAT); |
| 87 | + txt3.setText("-----=2===---==="); |
| 88 | + final Text txt4 = new Text(shell, SWT.WRAP | SWT.FLAT); |
| 89 | + txt4.setText("-----=2===---==="); |
| 90 | + final Text txt5 = new Text(shell, SWT.NONE); |
| 91 | + txt5.setText("-----=2===---==="); |
| 92 | + shell.pack(); |
| 93 | + shell.open (); |
| 94 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 95 | + public void run() { |
| 96 | + System.out.println(txt0.getSize()); |
| 97 | + System.out.println(txt1.getSize()); |
| 98 | + System.out.println(txt2.getSize()); |
| 99 | + System.out.println(txt3.getSize()); |
| 100 | + System.out.println(txt4.getSize()); |
| 101 | + System.out.println(txt5.getSize()); |
| 102 | + assertEquals(txt0.getSize(), new Point(68, 13)); |
| 103 | + assertEquals(txt1.getSize(), new Point(127, 26)); |
| 104 | + assertEquals(txt2.getSize(), new Point(10, 19)); |
| 105 | + assertEquals(txt3.getSize(), new Point(95, 13)); |
| 106 | + assertEquals(txt4.getSize(), new Point(100, 13)); |
| 107 | + assertEquals(txt5.getSize(), new Point(95, 13)); |
| 108 | + } |
| 109 | + }); |
| 110 | + display.dispose (); |
| 111 | + //AsyncSWT.setShellAutoClose(true); |
| 112 | + } |
| 113 | + |
| 114 | + public void testTextSize() { |
| 115 | + Display display = new Display (); |
| 116 | + final Shell shell = new Shell(display); |
| 117 | + shell.setLayout(new GridLayout()); |
| 118 | + final Text txt1 = new Text(shell, SWT.BORDER | SWT.READ_ONLY); |
| 119 | + txt1.setLayoutData(new GridData(120, 20)); |
| 120 | + final Text txt0 = new Text(shell, SWT.WRAP); |
| 121 | + final Text txt2 = new Text(shell, SWT.BORDER); |
| 122 | + final Text txt3 = new Text(shell, SWT.FLAT); |
| 123 | + shell.pack(); |
| 124 | + shell.open (); |
| 125 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 126 | + public void run() { |
| 127 | + System.out.println(txt0.getSize()); |
| 128 | + System.out.println(txt1.getSize()); |
| 129 | + System.out.println(txt2.getSize()); |
| 130 | + System.out.println(txt3.getSize()); |
| 131 | + assertEquals(txt0.getSize(), new Point(70, 13)); |
| 132 | + assertEquals(txt1.getSize(), new Point(127, 26)); |
| 133 | + assertEquals(txt2.getSize(), new Point(71, 19)); |
| 134 | + assertEquals(txt3.getSize(), new Point(65, 13)); |
| 135 | + } |
| 136 | + }); |
| 137 | + display.dispose (); |
| 138 | + //AsyncSWT.setShellAutoClose(true); |
| 139 | + } |
| 140 | + |
| 141 | + public void testFilledTextSize() { |
| 142 | + Display display = new Display (); |
| 143 | + final Shell shell = new Shell(display); |
| 144 | + shell.setLayout(new FillLayout()); |
| 145 | + final Text txt1 = new Text(shell, SWT.NONE); |
| 146 | + final Text txt2 = new Text(shell, SWT.BORDER); |
| 147 | + shell.pack(); |
| 148 | + shell.open (); |
| 149 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 150 | + public void run() { |
| 151 | + System.out.println(txt1.getSize()); |
| 152 | + System.out.println(txt2.getSize()); |
| 153 | + assertEquals(txt1.getSize(), new Point(71, 19)); |
| 154 | + assertEquals(txt2.getSize(), new Point(71, 19)); |
| 155 | + } |
| 156 | + }); |
| 157 | + display.dispose (); |
| 158 | + } |
| 159 | + |
| 160 | + |
| 161 | + public void testSetTextSize() { |
| 162 | + Display display = new Display (); |
| 163 | + final Shell shell = new Shell(display); |
| 164 | + shell.setLayout(new GridLayout()); |
| 165 | + final Text txt1 = new Text(shell, SWT.NONE); |
| 166 | + txt1.setLayoutData(new GridData(120, 40)); |
| 167 | + txt1.setEnabled(false); |
| 168 | + final Text txt2 = new Text(shell, SWT.BORDER); |
| 169 | + txt2.setLayoutData(new GridData(150, 50)); |
| 170 | + final Text txt3 = new Text(shell, SWT.NONE); |
| 171 | + txt3.setLayoutData(new GridData(120, 30)); |
| 172 | + final Text txt0 = new Text(shell, SWT.NONE); |
| 173 | + txt0.setLayoutData(new GridData(120, 24)); |
| 174 | + final Text txt4 = new Text(shell, SWT.NONE); |
| 175 | + txt4.setLayoutData(new GridData(120, 20)); |
| 176 | + final Text txt5 = new Text(shell, SWT.NONE); |
| 177 | + txt5.setLayoutData(new GridData(120, 10)); |
| 178 | + final Text txt6 = new Text(shell, SWT.NONE); |
| 179 | + txt6.setLayoutData(new GridData(120, 16)); |
| 180 | + shell.pack(); |
| 181 | + shell.open (); |
| 182 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 183 | + public void run() { |
| 184 | + System.out.println(txt1.getSize()); |
| 185 | + System.out.println(txt2.getSize()); |
| 186 | + assertEquals(txt1.getSize(), new Point(121, 40)); |
| 187 | + assertEquals(txt2.getSize(), new Point(157, 56)); |
| 188 | + } |
| 189 | + }); |
| 190 | + display.dispose (); |
| 191 | + } |
| 192 | + |
| 193 | + public static void main(String[] args) { |
| 194 | + AsyncSWT.setShellAutoClose(false); |
| 195 | + AsyncTestRunner.asyncRun (TextTest.class); |
| 196 | + } |
| 197 | +} |
0 commit comments