Mercurial > projects > dwt-samples
annotate snippets/cursor/Snippet242.d @ 119:9a1be6ff19a2
More snippets, thanks to Tom D.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 20 Jul 2008 15:26:06 +0200 |
parents | |
children |
rev | line source |
---|---|
119
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
1 /******************************************************************************* |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
2 * Copyright (c) 2000, 2006 IBM Corporation and others. |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
3 * All rights reserved. This program and the accompanying materials |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
5 * which accompanies this distribution, and is available at |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
6 * http://www.eclipse.org/legal/epl-v10.html |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
7 * |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
8 * Contributors: |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
9 * IBM Corporation - initial API and implementation |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
10 * D Port: |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
11 * Thomas Demmer <t_demmer AT web DOT de> |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
12 *******************************************************************************/ |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
13 module cursor.Snippet242; |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
14 |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
15 /* |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
16 * Cursor snippet: Hide the Cursor over a control. |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
17 * |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
18 * For a list of all SWT example snippets see |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
19 * http://www.eclipse.org/swt/snippets/ |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
20 */ |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
21 |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
22 import dwt.DWT; |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
23 import dwt.events.PaintEvent; |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
24 import dwt.events.PaintListener; |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
25 import dwt.graphics.Color; |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
26 import dwt.graphics.Cursor; |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
27 import dwt.graphics.ImageData; |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
28 import dwt.graphics.PaletteData; |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
29 import dwt.widgets.Canvas; |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
30 import dwt.widgets.Display; |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
31 import dwt.widgets.Shell; |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
32 |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
33 import dwt.dwthelper.utils; |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
34 |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
35 void main(String [] args) { |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
36 Display display = new Display(); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
37 Shell shell = new Shell(display); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
38 shell.setBounds(10, 10, 200, 200); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
39 Canvas canvas = new Canvas(shell, DWT.BORDER); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
40 canvas.setBounds(10,50,150,100); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
41 canvas.addPaintListener(new class() PaintListener{ |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
42 public void paintControl(PaintEvent e) { |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
43 e.gc.drawString("hide Cursor here", 10, 10); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
44 } |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
45 }); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
46 |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
47 // create a cursor with a transparent image |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
48 Color white = display.getSystemColor (DWT.COLOR_WHITE); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
49 Color black = display.getSystemColor (DWT.COLOR_BLACK); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
50 PaletteData palette = new PaletteData ([white.getRGB(), black.getRGB()]); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
51 ImageData sourceData = new ImageData (16, 16, 1, palette); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
52 sourceData.transparentPixel = 0; |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
53 Cursor cursor = new Cursor(display, sourceData, 0, 0); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
54 |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
55 shell.open(); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
56 canvas.setCursor(cursor); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
57 while (!shell.isDisposed()) { |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
58 if (!display.readAndDispatch()) display.sleep(); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
59 } |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
60 cursor.dispose(); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
61 display.dispose(); |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
62 } |
9a1be6ff19a2
More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
63 |