annotate snippets/control/Snippet214.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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, 2005 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 control.Snippet214;
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 * Control example snippet: set a background image (a dynamic gradient)
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 * @since 3.2
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
22 */
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
23 import dwt.DWT;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
24
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
25 import dwt.graphics.GC;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
26 import dwt.graphics.Image;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
27 import dwt.graphics.Rectangle;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
28 import dwt.layout.FillLayout;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
29 import dwt.layout.RowLayout;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
30 import dwt.widgets.Button;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
31 import dwt.widgets.Display;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
32 import dwt.widgets.Event;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
33 import dwt.widgets.Group;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
34 import dwt.widgets.Listener;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
35 import dwt.widgets.Shell;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
36 import dwt.layout.RowLayout;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
37
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
38 import dwt.dwthelper.utils;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
39
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
40 import tango.util.Convert;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
41
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
42 static Image oldImage;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
43 void main(String [] args) {
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
44 Display display = new Display ();
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
45 Shell shell = new Shell (display);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
46 shell.setBackgroundMode (DWT.INHERIT_DEFAULT);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
47 FillLayout layout1 = new FillLayout (DWT.VERTICAL);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
48 layout1.marginWidth = layout1.marginHeight = 10;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
49 shell.setLayout (layout1);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
50 Group group = new Group (shell, DWT.NONE);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
51 group.setText ("Group ");
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
52 RowLayout layout2 = new RowLayout (DWT.VERTICAL);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
53 layout2.marginWidth = layout2.marginHeight = layout2.spacing = 10;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
54 group.setLayout (layout2);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
55 for (int i=0; i<8; i++) {
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
56 Button button = new Button (group, DWT.RADIO);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
57 button.setText ("Button " ~ to!(char[])(i));
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
58 }
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
59 shell.addListener (DWT.Resize, new class() Listener {
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
60 public void handleEvent (Event event) {
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
61 Rectangle rect = shell.getClientArea ();
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
62 Image newImage = new Image (display, Math.max (1, rect.width), 1);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
63 GC gc = new GC (newImage);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
64 gc.setForeground (display.getSystemColor (DWT.COLOR_WHITE));
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
65 gc.setBackground (display.getSystemColor (DWT.COLOR_BLUE));
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
66 gc.fillGradientRectangle (rect.x, rect.y, rect.width, 1, false);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
67 gc.dispose ();
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
68 shell.setBackgroundImage (newImage);
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
69 if (oldImage !is null) oldImage.dispose ();
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
70 oldImage = newImage;
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
71 }
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
72 });
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
73 shell.pack ();
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
74 shell.open ();
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
75 while (!shell.isDisposed ()) {
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
76 if (!display.readAndDispatch ()) display.sleep ();
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
77 }
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
78 if (oldImage !is null) oldImage.dispose ();
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
79 display.dispose ();
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
80 }
9a1be6ff19a2 More snippets, thanks to Tom D.
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
81