28
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2005 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.Snippet214;
|
|
14
|
|
15 /*
|
|
16 * Control example snippet: set a background image (a dynamic gradient)
|
|
17 *
|
|
18 * For a list of all SWT example snippets see
|
|
19 * http://www.eclipse.org/swt/snippets/
|
|
20 *
|
|
21 * @since 3.2
|
|
22 */
|
|
23 import org.eclipse.swt.SWT;
|
|
24
|
|
25 import org.eclipse.swt.graphics.GC;
|
|
26 import org.eclipse.swt.graphics.Image;
|
|
27 import org.eclipse.swt.graphics.Rectangle;
|
|
28 import org.eclipse.swt.layout.FillLayout;
|
|
29 import org.eclipse.swt.layout.RowLayout;
|
|
30 import org.eclipse.swt.widgets.Button;
|
|
31 import org.eclipse.swt.widgets.Display;
|
|
32 import org.eclipse.swt.widgets.Event;
|
|
33 import org.eclipse.swt.widgets.Group;
|
|
34 import org.eclipse.swt.widgets.Listener;
|
|
35 import org.eclipse.swt.widgets.Shell;
|
|
36 import org.eclipse.swt.layout.RowLayout;
|
|
37
|
|
38 import java.lang.all;
|
|
39
|
|
40 import tango.util.Convert;
|
|
41
|
|
42 static Image oldImage;
|
|
43 void main(String [] args) {
|
|
44 Display display = new Display ();
|
|
45 Shell shell = new Shell (display);
|
|
46 shell.setBackgroundMode (SWT.INHERIT_DEFAULT);
|
|
47 FillLayout layout1 = new FillLayout (SWT.VERTICAL);
|
|
48 layout1.marginWidth = layout1.marginHeight = 10;
|
|
49 shell.setLayout (layout1);
|
|
50 Group group = new Group (shell, SWT.NONE);
|
|
51 group.setText ("Group ");
|
|
52 RowLayout layout2 = new RowLayout (SWT.VERTICAL);
|
|
53 layout2.marginWidth = layout2.marginHeight = layout2.spacing = 10;
|
|
54 group.setLayout (layout2);
|
|
55 for (int i=0; i<8; i++) {
|
|
56 Button button = new Button (group, SWT.RADIO);
|
|
57 button.setText ("Button " ~ to!(char[])(i));
|
|
58 }
|
|
59 shell.addListener (SWT.Resize, new class() Listener {
|
|
60 public void handleEvent (Event event) {
|
|
61 Rectangle rect = shell.getClientArea ();
|
|
62 Image newImage = new Image (display, Math.max (1, rect.width), 1);
|
|
63 GC gc = new GC (newImage);
|
|
64 gc.setForeground (display.getSystemColor (SWT.COLOR_WHITE));
|
|
65 gc.setBackground (display.getSystemColor (SWT.COLOR_BLUE));
|
|
66 gc.fillGradientRectangle (rect.x, rect.y, rect.width, 1, false);
|
|
67 gc.dispose ();
|
|
68 shell.setBackgroundImage (newImage);
|
|
69 if (oldImage !is null) oldImage.dispose ();
|
|
70 oldImage = newImage;
|
|
71 }
|
|
72 });
|
|
73 shell.pack ();
|
|
74 shell.open ();
|
|
75 while (!shell.isDisposed ()) {
|
|
76 if (!display.readAndDispatch ()) display.sleep ();
|
|
77 }
|
|
78 if (oldImage !is null) oldImage.dispose ();
|
|
79 display.dispose ();
|
|
80 }
|
|
81
|