Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet118.d @ 104:88652073d1c2
More work on icu
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 02 May 2009 11:27:24 +0200 |
parents | 4e5843b771cc |
children | 536e43f63c81 |
rev | line source |
---|---|
28 | 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 * Thomas Demmer <t_demmer AT web DOT de> | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.snippets.Snippet118; | |
14 | |
15 /* | |
16 * Cursor example snippet: create a color cursor from an image file | |
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 import org.eclipse.swt.SWT; | |
24 import org.eclipse.swt.graphics.Cursor; | |
25 import org.eclipse.swt.graphics.ImageData; | |
26 import org.eclipse.swt.graphics.Point; | |
27 import org.eclipse.swt.widgets.Button; | |
28 import org.eclipse.swt.widgets.Display; | |
29 import org.eclipse.swt.widgets.FileDialog; | |
30 import org.eclipse.swt.widgets.Event; | |
31 import org.eclipse.swt.widgets.Listener; | |
32 import org.eclipse.swt.widgets.Shell; | |
33 | |
34 import java.lang.all; | |
35 | |
36 void main (String [] args) { | |
37 Display display = new Display(); | |
38 Shell shell = new Shell(display); | |
39 shell.setSize(150, 150); | |
40 Cursor[] cursor = new Cursor[1]; | |
41 Button button = new Button(shell, SWT.PUSH); | |
42 button.setText("Change cursor"); | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
43 Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT); |
28 | 44 button.setSize(size); |
45 button.addListener(SWT.Selection, new class() Listener{ | |
46 public void handleEvent(Event e) { | |
47 FileDialog dialog = new FileDialog(shell); | |
48 dialog.setFilterExtensions(["*.ico", "*.gif", "*.*"]); | |
49 String name = dialog.open(); | |
50 if (name is null) return; | |
51 ImageData image = new ImageData(name); | |
52 Cursor oldCursor = cursor[0]; | |
53 cursor[0] = new Cursor(display, image, 0, 0); | |
54 shell.setCursor(cursor[0]); | |
55 if (oldCursor !is null) oldCursor.dispose(); | |
56 } | |
57 }); | |
58 shell.open(); | |
59 while (!shell.isDisposed()) { | |
60 if (!display.readAndDispatch()) | |
61 display.sleep(); | |
62 } | |
63 if (cursor[0] !is null) cursor[0].dispose(); | |
64 display.dispose(); | |
65 } | |
66 |