|
24 | 24 | import org.eclipse.swt.graphics.Rectangle; |
25 | 25 | import org.eclipse.swt.layout.GridData; |
26 | 26 | import org.eclipse.swt.layout.GridLayout; |
| 27 | +import org.eclipse.swt.widgets.Combo; |
27 | 28 | import org.eclipse.swt.widgets.Display; |
28 | 29 | import org.eclipse.swt.widgets.Shell; |
29 | 30 | import org.eclipse.swt.widgets.ToolBar; |
|
36 | 37 | */ |
37 | 38 | public class ToolBarTest extends AsyncTestCase { |
38 | 39 |
|
| 40 | + public void testComboToolItem2() { |
| 41 | + Display display = new Display (); |
| 42 | + final Shell shell = new Shell(display); |
| 43 | + shell.setLayout(new GridLayout()); |
| 44 | + |
| 45 | + final ToolBar bar = new ToolBar(shell, SWT.NONE); |
| 46 | + final ToolItem toolItem = new ToolItem(bar, SWT.NONE); |
| 47 | + toolItem.setText("Hello World"); |
| 48 | + final ToolBar bar2 = new ToolBar(shell, SWT.NONE); |
| 49 | + new ToolItem(bar2, SWT.NONE).setText("Hello"); |
| 50 | + final ToolItem itemDrowdown = new ToolItem(bar2, SWT.DROP_DOWN); |
| 51 | + itemDrowdown.setText("World"); |
| 52 | + final ToolBar bar3 = new ToolBar(shell, SWT.NONE); |
| 53 | + new ToolItem(bar3, SWT.NONE).setText("Hello"); |
| 54 | + final ToolItem toolItemSep = new ToolItem(bar3, SWT.SEPARATOR); |
| 55 | + toolItemSep.setText("World"); |
| 56 | + final Combo combo = new Combo(bar3, SWT.DROP_DOWN); |
| 57 | + combo.setItems (new String [] {"250", "500", "750"}); |
| 58 | + combo.setText (combo.getItem (0)); |
| 59 | + combo.pack (); |
| 60 | + toolItemSep.setWidth (combo.getSize ().x); |
| 61 | + toolItemSep.setControl(combo); |
| 62 | + |
| 63 | + final ToolItem followItem = new ToolItem(bar3, SWT.NONE); |
| 64 | + followItem.setText("Hello world"); |
| 65 | + |
| 66 | + new ToolItem(bar3, SWT.NONE).setText("World is small"); |
| 67 | + final ToolBar bar4 = new ToolBar(shell, SWT.NONE); |
| 68 | + new ToolItem(bar4, SWT.NONE).setText("Hello"); |
| 69 | + new ToolItem(bar4, SWT.DROP_DOWN);//.setText("World"); |
| 70 | + final ToolBar bar5 = new ToolBar(shell, SWT.NONE); |
| 71 | + new ToolItem(bar5, SWT.NONE).setText("Hello World"); |
| 72 | + new ToolItem(bar5, SWT.DROP_DOWN);//.setText("World"); |
| 73 | + final ToolBar bar6 = new ToolBar(shell, SWT.NONE); |
| 74 | + new ToolItem(bar6, SWT.NONE).setText("Hello World"); |
| 75 | + final ToolItem toolItem2 = new ToolItem(bar6, SWT.DROP_DOWN);//.setText("World"); |
| 76 | + new ToolItem(bar6, SWT.NONE);//.setText("World"); |
| 77 | + |
| 78 | + final ToolBar bar7 = new ToolBar(shell, SWT.NONE); |
| 79 | + new ToolItem(bar7, SWT.NONE); |
| 80 | + final ToolItem toolItem3 = new ToolItem(bar7, SWT.DROP_DOWN);//.setText("World"); |
| 81 | + new ToolItem(bar7, SWT.NONE).setText("Hello World");//.setText("World"); |
| 82 | + new ToolItem(bar7, SWT.NONE).setText("World longing for"); |
| 83 | + |
| 84 | + shell.pack(); |
| 85 | + shell.open (); |
| 86 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 87 | + public void run() { |
| 88 | + System.out.println(bar.getSize()); |
| 89 | + System.out.println(bar2.getSize()); |
| 90 | + System.out.println(bar3.getSize()); |
| 91 | + System.out.println(bar4.getSize()); |
| 92 | + System.out.println(bar5.getSize()); |
| 93 | + System.out.println(bar6.getSize()); |
| 94 | + System.out.println(bar7.getSize()); |
| 95 | + System.out.println(toolItem.getBounds()); |
| 96 | + System.out.println(toolItemSep.getBounds()); |
| 97 | + System.out.println(combo.getBounds()); |
| 98 | + System.out.println(followItem.getBounds()); |
| 99 | + System.out.println(itemDrowdown.getBounds()); |
| 100 | + System.out.println(toolItem2.getBounds()); |
| 101 | + System.out.println(toolItem3.getBounds()); |
| 102 | + assertEquals(bar.getSize(), new Point(65, 23)); |
| 103 | + assertEquals(bar2.getSize(), new Point(86, 23)); |
| 104 | + assertEquals(bar3.getSize(), new Point(213, 23)); |
| 105 | + assertEquals(bar4.getSize(), new Point(77, 23)); |
| 106 | + assertEquals(bar5.getSize(), new Point(139, 23)); |
| 107 | + assertEquals(bar6.getSize(), new Point(200, 23)); |
| 108 | + assertEquals(bar7.getSize(), new Point(349, 23)); |
| 109 | + assertEquals(toolItem.getBounds(), new Rectangle(0, 2, 65, 21)); |
| 110 | + assertEquals(toolItemSep.getBounds(), new Rectangle(34, 2, 41, 21)); |
| 111 | + assertEquals(combo.getBounds(), new Rectangle(34, 2, 41, 21)); |
| 112 | + assertEquals(followItem.getBounds(), new Rectangle(75, 2, 63, 21)); |
| 113 | + assertEquals(itemDrowdown.getBounds(), new Rectangle(34, 2, 52, 21)); |
| 114 | + assertEquals(toolItem2.getBounds(), new Rectangle(65, 2, 74, 21)); |
| 115 | + assertEquals(toolItem3.getBounds(), new Rectangle(89, 2, 102, 21)); |
| 116 | + } |
| 117 | + }); |
| 118 | + display.dispose (); |
| 119 | + } |
| 120 | + |
| 121 | + public void testComboToolItem() { |
| 122 | + Display display = new Display (); |
| 123 | + final Shell shell = new Shell(display); |
| 124 | + shell.setLayout(new GridLayout()); |
| 125 | + |
| 126 | + final ToolBar bar = new ToolBar(shell, SWT.NONE); |
| 127 | + final ToolItem toolItem = new ToolItem(bar, SWT.NONE); |
| 128 | + toolItem.setText("Hello World"); |
| 129 | + final ToolBar bar2 = new ToolBar(shell, SWT.NONE); |
| 130 | + new ToolItem(bar2, SWT.NONE).setText("Hello"); |
| 131 | + final ToolItem itemDrowdown = new ToolItem(bar2, SWT.DROP_DOWN); |
| 132 | + itemDrowdown.setText("World"); |
| 133 | + final ToolBar bar3 = new ToolBar(shell, SWT.NONE); |
| 134 | + new ToolItem(bar3, SWT.NONE).setText("Hello"); |
| 135 | + final ToolItem toolItemSep = new ToolItem(bar3, SWT.SEPARATOR); |
| 136 | + toolItemSep.setText("World"); |
| 137 | + final Combo combo = new Combo(bar3, SWT.DROP_DOWN); |
| 138 | + toolItemSep.setControl(combo); |
| 139 | + |
| 140 | + new ToolItem(bar3, SWT.NONE).setText("Hello world"); |
| 141 | + new ToolItem(bar3, SWT.NONE).setText("World is small"); |
| 142 | + final ToolBar bar4 = new ToolBar(shell, SWT.NONE); |
| 143 | + new ToolItem(bar4, SWT.NONE).setText("Hello"); |
| 144 | + new ToolItem(bar4, SWT.DROP_DOWN);//.setText("World"); |
| 145 | + final ToolBar bar5 = new ToolBar(shell, SWT.NONE); |
| 146 | + new ToolItem(bar5, SWT.NONE).setText("Hello World"); |
| 147 | + new ToolItem(bar5, SWT.DROP_DOWN);//.setText("World"); |
| 148 | + final ToolBar bar6 = new ToolBar(shell, SWT.NONE); |
| 149 | + new ToolItem(bar6, SWT.NONE).setText("Hello World"); |
| 150 | + final ToolItem toolItem2 = new ToolItem(bar6, SWT.DROP_DOWN);//.setText("World"); |
| 151 | + new ToolItem(bar6, SWT.NONE);//.setText("World"); |
| 152 | + |
| 153 | + final ToolBar bar7 = new ToolBar(shell, SWT.NONE); |
| 154 | + new ToolItem(bar7, SWT.NONE); |
| 155 | + final ToolItem toolItem3 = new ToolItem(bar7, SWT.DROP_DOWN);//.setText("World"); |
| 156 | + new ToolItem(bar7, SWT.NONE).setText("Hello World");//.setText("World"); |
| 157 | + new ToolItem(bar7, SWT.NONE).setText("World longing for"); |
| 158 | + |
| 159 | + shell.pack(); |
| 160 | + shell.open (); |
| 161 | + AsyncSWT.waitLayout(shell, new AsyncTestRunnable(this) { |
| 162 | + public void run() { |
| 163 | + System.out.println(bar.getSize()); |
| 164 | + System.out.println(bar2.getSize()); |
| 165 | + System.out.println(bar3.getSize()); |
| 166 | + System.out.println(bar4.getSize()); |
| 167 | + System.out.println(bar5.getSize()); |
| 168 | + System.out.println(bar6.getSize()); |
| 169 | + System.out.println(bar7.getSize()); |
| 170 | + System.out.println(toolItem.getBounds()); |
| 171 | + System.out.println(toolItemSep.getBounds()); |
| 172 | + System.out.println(combo.getBounds()); |
| 173 | + System.out.println(itemDrowdown.getBounds()); |
| 174 | + System.out.println(toolItem2.getBounds()); |
| 175 | + System.out.println(toolItem3.getBounds()); |
| 176 | + assertEquals(bar.getSize(), new Point(65, 23)); |
| 177 | + assertEquals(bar2.getSize(), new Point(86, 23)); |
| 178 | + assertEquals(bar3.getSize(), new Point(180, 23)); |
| 179 | + assertEquals(bar4.getSize(), new Point(77, 23)); |
| 180 | + assertEquals(bar5.getSize(), new Point(139, 23)); |
| 181 | + assertEquals(bar6.getSize(), new Point(200, 23)); |
| 182 | + assertEquals(bar7.getSize(), new Point(349, 23)); |
| 183 | + assertEquals(toolItem.getBounds(), new Rectangle(0, 2, 65, 21)); |
| 184 | + assertEquals(toolItemSep.getBounds(), new Rectangle(34, 2, 8, 21)); |
| 185 | + assertEquals(combo.getBounds(), new Rectangle(34, 2, 8, 21)); |
| 186 | + assertEquals(itemDrowdown.getBounds(), new Rectangle(34, 2, 52, 21)); |
| 187 | + assertEquals(toolItem2.getBounds(), new Rectangle(65, 2, 74, 21)); |
| 188 | + assertEquals(toolItem3.getBounds(), new Rectangle(89, 2, 102, 21)); |
| 189 | + } |
| 190 | + }); |
| 191 | + display.dispose (); |
| 192 | + } |
| 193 | + |
39 | 194 | public void testFlatToolBarImageItemSize() { |
40 | 195 | Display display = new Display (); |
41 | 196 | final Shell shell = new Shell(display); |
|
0 commit comments