view snippets/display/Snippet268.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.Snippet268;
  
/*
 * UI Automation (for testing tools) snippet: post mouse wheel events to a styled text
 *
 * For a list of all DWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 * 
 * @since 3.0
 */
import dwt.DWT;
import dwt.widgets.Display;
import dwt.widgets.Event;
import dwt.widgets.Listener;
import dwt.widgets.Shell;

import dwt.dwthelper.utils;

import dwt.custom.StyledText;
import dwt.graphics.Point;
import dwt.layout.FillLayout;

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

void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    StyledText styledText = new StyledText(shell, DWT.V_SCROLL);
    String multiLineString = "";
    for (int i = 0; i < 200; i++) {
        multiLineString ~= "This is line number " ~ to!(String)(i) ~
            " in the multi-line string.\n";
    }
    styledText.setText(multiLineString);
    shell.setSize(styledText.computeSize(DWT.DEFAULT, 400));
    shell.open();
    styledText.addListener(DWT.MouseWheel, dgListener( (Event e){
        Stdout.formatln("Mouse Wheel event \n"); //" + e);
        Stdout.flush();
    }));
    final Point pt = display.map(shell, null, 50, 50);
    Thread thread = new Thread({
        Event event;
        for (int i = 0; i < 50; i++) {
            event = new Event();
            event.type = DWT.MouseWheel;
            event.detail = DWT.SCROLL_LINE;
            event.x = pt.x;
            event.y = pt.y;
            event.count = -2;
            display.post(event);
            try {
                Thread.sleep(400/1000);
            } catch (InterruptedException e) {}
        }
        Stdout("Thread done\n").flush(); 
    });
  
    thread.start();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
}