| 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.Snippet38; |
|---|
| 14 |
|
|---|
| 15 |
/* |
|---|
| 16 |
* Table example snippet: create a table (columns, headers, lines) |
|---|
| 17 |
* |
|---|
| 18 |
* For a list of all DWT example snippets see |
|---|
| 19 |
* http://www.eclipse.org/swt/snippets/ |
|---|
| 20 |
*/ |
|---|
| 21 |
import dwt.DWT; |
|---|
| 22 |
import dwt.widgets.Display; |
|---|
| 23 |
import dwt.widgets.Event; |
|---|
| 24 |
import dwt.widgets.Listener; |
|---|
| 25 |
import dwt.widgets.Shell; |
|---|
| 26 |
import dwt.widgets.Table; |
|---|
| 27 |
import dwt.widgets.TableColumn; |
|---|
| 28 |
import dwt.widgets.TableItem; |
|---|
| 29 |
|
|---|
| 30 |
import tango.io.Stdout; |
|---|
| 31 |
import tango.util.Convert; |
|---|
| 32 |
|
|---|
| 33 |
void main () { |
|---|
| 34 |
auto display = new Display (); |
|---|
| 35 |
auto shell = new Shell (display); |
|---|
| 36 |
//auto table = new Table (shell, DWT.MULTI | DWT.BORDER | DWT.FULL_SELECTION); |
|---|
| 37 |
auto table = new Table (shell, DWT.MULTI | DWT.BORDER); |
|---|
| 38 |
table.setLinesVisible (true); |
|---|
| 39 |
table.setHeaderVisible (true); |
|---|
| 40 |
char[][] titles = [" ", "C", "!", "Description", "Resource", "In Folder", "Location"]; |
|---|
| 41 |
int[] styles = [DWT.NONE, DWT.LEFT, DWT.RIGHT, DWT.CENTER, DWT.NONE, DWT.NONE, DWT.NONE]; |
|---|
| 42 |
foreach (i,title; titles) { |
|---|
| 43 |
auto column = new TableColumn (table, styles[i]); |
|---|
| 44 |
column.setText (title); |
|---|
| 45 |
} |
|---|
| 46 |
int count = 128; |
|---|
| 47 |
for (int i=0; i<count; i++) { |
|---|
| 48 |
auto item = new TableItem (table, DWT.NONE); |
|---|
| 49 |
item.setText (0, "x"); |
|---|
| 50 |
item.setText (1, "y"); |
|---|
| 51 |
item.setText (2, "!"); |
|---|
| 52 |
item.setText (3, "this stuff behaves the way I expect"); |
|---|
| 53 |
item.setText (4, "almost everywhere"); |
|---|
| 54 |
item.setText (5, "some.folder"); |
|---|
| 55 |
item.setText (6, "line " ~ to!(char[])(i) ~ " in nowhere"); |
|---|
| 56 |
} |
|---|
| 57 |
for (int i=0; i<titles.length; i++) { |
|---|
| 58 |
table.getColumn (i).pack (); |
|---|
| 59 |
} |
|---|
| 60 |
table.setSize (table.computeSize (DWT.DEFAULT, 200)); |
|---|
| 61 |
table.addListener (DWT.EraseItem, new class Listener { |
|---|
| 62 |
public void handleEvent (Event e) { |
|---|
| 63 |
//e.detail &= ~DWT.FOREGROUND; |
|---|
| 64 |
Stdout("e").flush; |
|---|
| 65 |
} |
|---|
| 66 |
}); |
|---|
| 67 |
table.addListener (DWT.PaintItem, new class Listener { |
|---|
| 68 |
public void handleEvent (Event e) { |
|---|
| 69 |
Stdout("p").flush; |
|---|
| 70 |
} |
|---|
| 71 |
}); |
|---|
| 72 |
|
|---|
| 73 |
shell.pack (); |
|---|
| 74 |
shell.open (); |
|---|
| 75 |
while (!shell.isDisposed ()) { |
|---|
| 76 |
if (!display.readAndDispatch ()) display.sleep (); |
|---|
| 77 |
} |
|---|
| 78 |
display.dispose (); |
|---|
| 79 |
} |
|---|