Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet43.d @ 125:c43718956f21 default tip
Updated the snippets status.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Thu, 11 Aug 2011 19:55:14 +0200 |
parents | 536e43f63c81 |
children |
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.Snippet43; | |
14 /* | |
15 * Caret example snippet: create a caret (using an image) | |
16 * | |
17 * For a list of all SWT example snippets see | |
18 * http://www.eclipse.org/swt/snippets/ | |
19 */ | |
20 import org.eclipse.swt.SWT; | |
21 import org.eclipse.swt.graphics.Color; | |
22 import org.eclipse.swt.graphics.GC; | |
23 import org.eclipse.swt.graphics.Image; | |
24 | |
25 import org.eclipse.swt.widgets.Caret; | |
26 import org.eclipse.swt.widgets.Display; | |
27 import org.eclipse.swt.widgets.Shell; | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
28
diff
changeset
|
28 import org.eclipse.swt.widgets.Event; |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
28
diff
changeset
|
29 import org.eclipse.swt.widgets.Listener; |
28 | 30 |
31 import java.lang.all; | |
32 | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
28
diff
changeset
|
33 void main () { |
28 | 34 Display display = new Display (); |
35 Shell shell = new Shell (display); | |
36 Caret caret = new Caret (shell, SWT.NONE); | |
37 Color white = display.getSystemColor (SWT.COLOR_WHITE); | |
38 Color black = display.getSystemColor (SWT.COLOR_BLACK); | |
39 Image image = new Image (display, 20, 20); | |
40 GC gc = new GC (image); | |
41 gc.setBackground (black); | |
42 gc.fillRectangle (0, 0, 20, 20); | |
43 gc.setForeground (white); | |
44 gc.drawLine (0, 0, 19, 19); | |
45 gc.drawLine (19, 0, 0, 19); | |
46 gc.dispose (); | |
47 caret.setLocation (10, 10); | |
48 caret.setImage (image); | |
49 caret.setVisible (true); | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
28
diff
changeset
|
50 shell.addListener(SWT.Paint, new class Listener { |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
28
diff
changeset
|
51 public void handleEvent(Event event) { |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
28
diff
changeset
|
52 GC gc = event.gc; |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
28
diff
changeset
|
53 gc.drawImage (image, 10, 64); |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
28
diff
changeset
|
54 gc.drawString ("Test", 12, 12); |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
28
diff
changeset
|
55 } |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
28
diff
changeset
|
56 }); |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
28
diff
changeset
|
57 shell.open (); |
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
28
diff
changeset
|
58 |
28 | 59 while (!shell.isDisposed ()) { |
60 if (!display.readAndDispatch ()) display.sleep (); | |
61 } | |
62 image.dispose (); | |
63 display.dispose (); | |
64 } |