Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet47.d @ 29:4e5843b771cc
First snippets buildable on windows
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 22 Mar 2009 19:55:00 +0100 |
parents | 69b1fa94a4a8 |
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 * Port to the D programming language: | |
11 * Bill Baxter <bill@billbaxter.com> | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.snippets.Snippet47; | |
14 | |
15 /* | |
16 * ToolBar example snippet: create tool bar (normal, hot and disabled images) | |
17 * | |
18 * For a list of all SWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 */ | |
21 import org.eclipse.swt.SWT; | |
22 import org.eclipse.swt.graphics.GC; | |
23 import org.eclipse.swt.graphics.Color; | |
24 import org.eclipse.swt.graphics.Image; | |
25 import org.eclipse.swt.widgets.Display; | |
26 import org.eclipse.swt.widgets.Shell; | |
27 import org.eclipse.swt.widgets.ToolBar; | |
28 import org.eclipse.swt.widgets.ToolItem; | |
29 | |
30 void main () { | |
31 Display display = new Display (); | |
32 Shell shell = new Shell (display); | |
33 | |
34 Image image = new Image (display, 20, 20); | |
35 Color color = display.getSystemColor (SWT.COLOR_BLUE); | |
36 GC gc = new GC (image); | |
37 gc.setBackground (color); | |
38 gc.fillRectangle (image.getBounds ()); | |
39 gc.dispose (); | |
40 | |
41 Image disabledImage = new Image (display, 20, 20); | |
42 color = display.getSystemColor (SWT.COLOR_GREEN); | |
43 gc = new GC (disabledImage); | |
44 gc.setBackground (color); | |
45 gc.fillRectangle (disabledImage.getBounds ()); | |
46 gc.dispose (); | |
47 | |
48 Image hotImage = new Image (display, 20, 20); | |
49 color = display.getSystemColor (SWT.COLOR_RED); | |
50 gc = new GC (hotImage); | |
51 gc.setBackground (color); | |
52 gc.fillRectangle (hotImage.getBounds ()); | |
53 gc.dispose (); | |
54 | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
55 ToolBar bar = new ToolBar (shell, SWT.BORDER | SWT.FLAT); |
28 | 56 bar.setSize (200, 32); |
57 for (int i=0; i<12; i++) { | |
58 ToolItem item = new ToolItem (bar, 0); | |
59 item.setImage (image); | |
60 item.setDisabledImage (disabledImage); | |
61 item.setHotImage (hotImage); | |
62 if (i % 3 == 0) item.setEnabled (false); | |
63 } | |
64 | |
65 shell.open (); | |
66 while (!shell.isDisposed ()) { | |
67 if (!display.readAndDispatch ()) display.sleep (); | |
68 } | |
69 image.dispose (); | |
70 disabledImage.dispose (); | |
71 hotImage.dispose (); | |
72 display.dispose (); | |
73 } | |
74 |