| 1 |
/******************************************************************************* |
|---|
| 2 |
* Copyright (c) 2000, 2004 IBM Corporation and others. |
|---|
| 3 |
* All rights reserved. This program and the accompanying materials |
|---|
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
|---|
| 5 |
* which accompanies this distribution, and is available at |
|---|
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
|---|
| 7 |
* |
|---|
| 8 |
* Contributors: |
|---|
| 9 |
* IBM Corporation - initial API and implementation |
|---|
| 10 |
* D Port: |
|---|
| 11 |
* Jesse Phillips <Jesse.K.Phillips+D> gmail.com |
|---|
| 12 |
*******************************************************************************/ |
|---|
| 13 |
//module table.Snippet144; |
|---|
| 14 |
|
|---|
| 15 |
/* |
|---|
| 16 |
* Virtual Table example snippet: create a table with 1,000,000 items (lazy) |
|---|
| 17 |
* |
|---|
| 18 |
* For a list of all SWT example snippets see |
|---|
| 19 |
* http://www.eclipse.org/swt/snippets/ |
|---|
| 20 |
* |
|---|
| 21 |
* @since 3.0 |
|---|
| 22 |
* |
|---|
| 23 |
*/ |
|---|
| 24 |
|
|---|
| 25 |
/* |
|---|
| 26 |
* This sample triggers "ArrayBoundsException@dwt.widgets.Table(198): Array index out of bounds" |
|---|
| 27 |
* when using DWT 3.4-1. Tango 0.99.7, DMD 1.033. |
|---|
| 28 |
* |
|---|
| 29 |
* build command: bud tablebug.d -odobj -g -debug -Xtango tango-user-dmd.lib -L/su:console:4 -L/rc:dwt |
|---|
| 30 |
* |
|---|
| 31 |
* Different ways to make the crash go away: |
|---|
| 32 |
* 1. Comment out the EraseItem listener. |
|---|
| 33 |
* 2. Comment out the PaintItem listener. |
|---|
| 34 |
* 3. Create the table with DWT.FULL_SELECTION. |
|---|
| 35 |
* |
|---|
| 36 |
* I don't know if the table has to be virtual or not yet. |
|---|
| 37 |
* |
|---|
| 38 |
* -torhu |
|---|
| 39 |
*/ |
|---|
| 40 |
|
|---|
| 41 |
import dwt.DWT; |
|---|
| 42 |
import dwt.graphics.TextLayout; |
|---|
| 43 |
import dwt.widgets.Button; |
|---|
| 44 |
import dwt.widgets.Display; |
|---|
| 45 |
import dwt.widgets.Event; |
|---|
| 46 |
import dwt.widgets.Label; |
|---|
| 47 |
import dwt.widgets.Listener; |
|---|
| 48 |
import dwt.widgets.Shell; |
|---|
| 49 |
import dwt.widgets.Table; |
|---|
| 50 |
import dwt.widgets.TableItem; |
|---|
| 51 |
import dwt.layout.RowLayout; |
|---|
| 52 |
import dwt.layout.RowData; |
|---|
| 53 |
|
|---|
| 54 |
import tango.io.Stdout; |
|---|
| 55 |
import tango.time.StopWatch; |
|---|
| 56 |
import tango.util.Convert; |
|---|
| 57 |
|
|---|
| 58 |
const int COUNT = 1000000; |
|---|
| 59 |
|
|---|
| 60 |
void main() { |
|---|
| 61 |
auto display = new Display (); |
|---|
| 62 |
auto shell = new Shell (display); |
|---|
| 63 |
shell.setLayout (new RowLayout (DWT.VERTICAL)); |
|---|
| 64 |
auto table = new Table (shell, DWT.VIRTUAL | DWT.BORDER); |
|---|
| 65 |
//auto table = new Table (shell, DWT.VIRTUAL | DWT.BORDER | DWT.FULL_SELECTION); |
|---|
| 66 |
table.addListener (DWT.SetData, new class Listener { |
|---|
| 67 |
public void handleEvent (Event event) { |
|---|
| 68 |
auto item = cast(TableItem) event.item; |
|---|
| 69 |
auto index = table.indexOf (item); |
|---|
| 70 |
item.setText ("Item " ~ to!(char[])(index)); |
|---|
| 71 |
Stdout(item.getText ()).newline; |
|---|
| 72 |
} |
|---|
| 73 |
}); |
|---|
| 74 |
table.addListener (DWT.EraseItem, new class Listener { |
|---|
| 75 |
public void handleEvent (Event e) { |
|---|
| 76 |
Stdout("e").flush; |
|---|
| 77 |
} |
|---|
| 78 |
}); |
|---|
| 79 |
table.addListener (DWT.PaintItem, new class Listener { |
|---|
| 80 |
public void handleEvent (Event e) { |
|---|
| 81 |
Stdout("p").flush; |
|---|
| 82 |
} |
|---|
| 83 |
}); |
|---|
| 84 |
table.setLayoutData (new RowData (200, 200)); |
|---|
| 85 |
auto button = new Button (shell, DWT.PUSH); |
|---|
| 86 |
button.setText ("Add Items"); |
|---|
| 87 |
auto label = new Label(shell, DWT.NONE); |
|---|
| 88 |
button.addListener (DWT.Selection, new class Listener { |
|---|
| 89 |
public void handleEvent (Event event) { |
|---|
| 90 |
StopWatch elapsed; |
|---|
| 91 |
elapsed.start; |
|---|
| 92 |
table.setItemCount (COUNT); |
|---|
| 93 |
auto t = elapsed.stop; |
|---|
| 94 |
label.setText ("Items: " ~ to!(char[])(COUNT) ~ |
|---|
| 95 |
", Time: " ~ to!(char[])(t) ~ " (sec)"); |
|---|
| 96 |
shell.layout (); |
|---|
| 97 |
} |
|---|
| 98 |
}); |
|---|
| 99 |
shell.pack (); |
|---|
| 100 |
shell.open (); |
|---|
| 101 |
while (!shell.isDisposed ()) { |
|---|
| 102 |
if (!display.readAndDispatch ()) display.sleep (); |
|---|
| 103 |
} |
|---|
| 104 |
display.dispose (); |
|---|
| 105 |
} |
|---|