1 #!/usr/bin/env dub 2 /+ 3 dub.sdl: 4 name "snippet7" 5 dependency "dwt" path="../../../../../../" version="*" 6 libs \ 7 "atk-1.0" \ 8 "cairo" \ 9 "dl" \ 10 "fontconfig" \ 11 "gdk-x11-2.0" \ 12 "gdk_pixbuf-2.0" \ 13 "gio-2.0" \ 14 "glib-2.0" \ 15 "gmodule-2.0" \ 16 "gobject-2.0" \ 17 "gthread-2.0" \ 18 "gtk-x11-2.0" \ 19 "pango-1.0" \ 20 "pangocairo-1.0" \ 21 "X11" \ 22 "Xcomposite" \ 23 "Xcursor" \ 24 "Xdamage" \ 25 "Xext" \ 26 "Xfixes" \ 27 "Xi" \ 28 "Xinerama" \ 29 "Xrandr" \ 30 "Xrender" \ 31 "Xtst" \ 32 platform="linux" 33 +/ 34 35 /******************************************************************************* 36 * Copyright (c) 2000, 2016 IBM Corporation and others. 37 * All rights reserved. This program and the accompanying materials 38 * are made available under the terms of the Eclipse Public License v1.0 39 * which accompanies this distribution, and is available at 40 * http://www.eclipse.org/legal/epl-v10.html 41 * 42 * Contributors: 43 * IBM Corporation - initial API and implementation 44 * D Port: 45 * Thomas Demmer <t_demmer AT web DOT de> 46 *******************************************************************************/ 47 module org.eclipse.swt.snippets.Snippet7; 48 49 /* 50 * example snippet: create a table (lazy) 51 * 52 * For a list of all SWT example snippets see 53 * http://www.eclipse.org/swt/snippets/ 54 */ 55 import org.eclipse.swt.SWT; 56 import org.eclipse.swt.layout.FillLayout; 57 import org.eclipse.swt.graphics.GC; 58 import org.eclipse.swt.graphics.Image; 59 import org.eclipse.swt.widgets.Display; 60 import org.eclipse.swt.widgets.Item; 61 import org.eclipse.swt.widgets.Shell; 62 import org.eclipse.swt.widgets.Table; 63 import org.eclipse.swt.widgets.TableItem; 64 65 import java.lang.all; 66 67 import T = core.thread; 68 import std.conv; 69 70 void main () { 71 Display display = new Display (); 72 Image image = new Image (display, 16, 16); 73 GC gc = new GC (image); 74 gc.setBackground (display.getSystemColor (SWT.COLOR_RED)); 75 gc.fillRectangle (image.getBounds ()); 76 gc.dispose (); 77 78 Shell shell = new Shell (display); 79 shell.setText ("Lazy Table"); 80 shell.setLayout (new FillLayout ()); 81 Table table = new Table (shell, SWT.BORDER | SWT.MULTI); 82 table.setSize (200, 200); 83 T.Thread thread = new T.Thread({ 84 for(int i=0; i< 20000; i++){ 85 if (table.isDisposed ()) return; 86 87 int [] index = [i]; 88 display.syncExec (new class Runnable{ 89 public void run () { 90 if (table.isDisposed ()) return; 91 TableItem item = new TableItem (table, SWT.NONE); 92 item.setText ("Table Item " ~ to!(String)(index [0])); 93 item.setImage (image); 94 } 95 }); 96 } 97 }); 98 99 thread.start (); 100 shell.setSize (200, 200); 101 shell.open (); 102 while (!shell.isDisposed ()) { 103 if (!display.readAndDispatch ()) display.sleep (); 104 } 105 image.dispose (); 106 display.dispose (); 107 }