Mercurial > projects > dwt-samples
comparison snippets/display/Snippet68.d @ 132:104f5ed240fc
More snippets from TomD, thanks!
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 29 Jul 2008 01:50:10 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
130:5c1906bfc206 | 132:104f5ed240fc |
---|---|
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 display.Snippet68; | |
14 | |
15 /* | |
16 * Display example snippet: stop a repeating timer when a button is pressed | |
17 * | |
18 * For a list of all DWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 */ | |
21 import dwt.DWT; | |
22 import dwt.graphics.Color; | |
23 import dwt.widgets.Button; | |
24 import dwt.widgets.Display; | |
25 import dwt.widgets.Event; | |
26 import dwt.widgets.Label; | |
27 import dwt.widgets.Listener; | |
28 import dwt.widgets.Shell; | |
29 | |
30 import dwt.dwthelper.utils; | |
31 import dwt.dwthelper.Runnable; | |
32 | |
33 import dwt.layout.RowData; | |
34 import dwt.layout.RowLayout; | |
35 | |
36 void main (String [] args) { | |
37 Display display = new Display (); | |
38 final Color red = display.getSystemColor (DWT.COLOR_RED); | |
39 final Color blue = display.getSystemColor (DWT.COLOR_BLUE); | |
40 Shell shell = new Shell (display); | |
41 shell.setLayout (new RowLayout ()); | |
42 Button button = new Button (shell, DWT.PUSH); | |
43 button.setText ("Stop Timer"); | |
44 final Label label = new Label (shell, DWT.BORDER); | |
45 label.setBackground (red); | |
46 final int time = 500; | |
47 Runnable timer; | |
48 timer = dgRunnable({ | |
49 if (label.isDisposed ()) return; | |
50 Color color = label.getBackground ().opEquals (red) ? blue : red; | |
51 label.setBackground (color); | |
52 display.timerExec (time, timer); | |
53 }); | |
54 display.timerExec (time, timer); | |
55 button.addListener (DWT.Selection, dgListener( (Event event) { | |
56 display.timerExec (-1, timer); | |
57 })); | |
58 button.pack (); | |
59 label.setLayoutData (new RowData (button.getSize ())); | |
60 shell.pack (); | |
61 shell.open (); | |
62 while (!shell.isDisposed ()) { | |
63 if (!display.readAndDispatch ()) display.sleep (); | |
64 } | |
65 display.dispose (); | |
66 } | |
67 |