view snippets/display/Snippet7.d @ 132:104f5ed240fc

More snippets from TomD, thanks!
author Frank Benoit <benoit@tionex.de>
date Tue, 29 Jul 2008 01:50:10 +0200
parents
children
line wrap: on
line source

/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 * D Port:
 *     Thomas Demmer <t_demmer AT web DOT de>
 *******************************************************************************/
module display.Snippet7;

/*
 * example snippet: create a table (lazy)
 *
 * For a list of all DWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 */
import dwt.DWT;
import dwt.layout.FillLayout;
import dwt.graphics.GC;
import dwt.graphics.Image;
import dwt.widgets.Display;
import dwt.widgets.Item;
import dwt.widgets.Shell;
import dwt.widgets.Table;
import dwt.widgets.TableItem;

import dwt.dwthelper.Runnable;
import dwt.dwthelper.utils;

import tango.core.Thread;
import tango.util.Convert;

void main (String [] args) {
    Display display = new Display ();
    Image image = new Image (display, 16, 16);
    GC gc = new GC (image);
    gc.setBackground (display.getSystemColor (DWT.COLOR_RED));
    gc.fillRectangle (image.getBounds ());
    gc.dispose ();
  
    Shell shell = new Shell (display);
    shell.setText ("Lazy Table");
    shell.setLayout (new FillLayout ());
    Table table = new Table (shell, DWT.BORDER | DWT.MULTI);
    table.setSize (200, 200);
    Thread thread = new Thread({
        for(int i=0; i< 20000; i++){
            if (table.isDisposed ()) return;

            int [] index =  [i];
            display.syncExec (new class() Runnable{
                public void run () {
                    if (table.isDisposed ()) return;
                    TableItem item = new TableItem (table, DWT.NONE);
                    item.setText ("Table Item " ~ to!(String)(index [0]));
                    item.setImage (image);
                }
        });
        }
    });

    thread.start ();
    shell.setSize (200, 200);
    shell.open ();
    while (!shell.isDisposed ()) {
        if (!display.readAndDispatch ()) display.sleep ();
    }
    image.dispose ();
    display.dispose ();
}