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 * D Port:
|
|
11 * Thomas Demmer <t_demmer AT web DOT de>
|
|
12 *******************************************************************************/
|
|
13 module org.eclipse.swt.snippets.Snippet68;
|
|
14
|
|
15 /*
|
|
16 * Display example snippet: stop a repeating timer when a button is pressed
|
|
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.Color;
|
|
23 import org.eclipse.swt.widgets.Button;
|
|
24 import org.eclipse.swt.widgets.Display;
|
|
25 import org.eclipse.swt.widgets.Event;
|
|
26 import org.eclipse.swt.widgets.Label;
|
|
27 import org.eclipse.swt.widgets.Listener;
|
|
28 import org.eclipse.swt.widgets.Shell;
|
|
29
|
|
30 import java.lang.all;
|
|
31
|
|
32 import org.eclipse.swt.layout.RowData;
|
|
33 import org.eclipse.swt.layout.RowLayout;
|
|
34
|
|
35 void main (String [] args) {
|
|
36 Display display = new Display ();
|
112
|
37 Color red = display.getSystemColor (SWT.COLOR_RED);
|
|
38 Color blue = display.getSystemColor (SWT.COLOR_BLUE);
|
28
|
39 Shell shell = new Shell (display);
|
|
40 shell.setLayout (new RowLayout ());
|
|
41 Button button = new Button (shell, SWT.PUSH);
|
|
42 button.setText ("Stop Timer");
|
112
|
43 Label label = new Label (shell, SWT.BORDER);
|
28
|
44 label.setBackground (red);
|
112
|
45 int time = 500;
|
28
|
46 Runnable timer;
|
|
47 timer = dgRunnable({
|
|
48 if (label.isDisposed ()) return;
|
|
49 Color color = label.getBackground ().opEquals (red) ? blue : red;
|
|
50 label.setBackground (color);
|
|
51 display.timerExec (time, timer);
|
|
52 });
|
|
53 display.timerExec (time, timer);
|
|
54 button.addListener (SWT.Selection, dgListener( (Event event) {
|
|
55 display.timerExec (-1, timer);
|
|
56 }));
|
|
57 button.pack ();
|
|
58 label.setLayoutData (new RowData (button.getSize ()));
|
|
59 shell.pack ();
|
|
60 shell.open ();
|
|
61 while (!shell.isDisposed ()) {
|
|
62 if (!display.readAndDispatch ()) display.sleep ();
|
|
63 }
|
|
64 display.dispose ();
|
|
65 }
|
|
66
|