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.Snippet251;
|
|
14
|
|
15 /*
|
|
16 * DateTime example snippet: create a DateTime calendar, date, and time in a dialog.
|
|
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.events.SelectionAdapter;
|
|
23 import org.eclipse.swt.events.SelectionEvent;
|
|
24 import org.eclipse.swt.layout.FillLayout;
|
|
25 import org.eclipse.swt.layout.GridData;
|
|
26 import org.eclipse.swt.layout.GridLayout;
|
|
27 import org.eclipse.swt.widgets.Button;
|
|
28 import org.eclipse.swt.widgets.DateTime;
|
|
29 import org.eclipse.swt.widgets.Dialog;
|
|
30 import org.eclipse.swt.widgets.Display;
|
|
31 import org.eclipse.swt.widgets.Label;
|
|
32 import org.eclipse.swt.widgets.Shell;
|
|
33
|
|
34 import java.lang.all;
|
|
35
|
|
36 import tango.io.Stdout;
|
|
37
|
|
38 void main (String [] args) {
|
|
39 /* These cannot be local in the
|
|
40 * listener, hence we put it here and not at the
|
|
41 * constructor. (THD)
|
|
42 * (dmd.1.028)
|
|
43 */
|
|
44 DateTime calendar, date, time;
|
|
45 Shell dialog;
|
|
46
|
|
47 Display display = new Display ();
|
|
48 Shell shell = new Shell (display);
|
|
49 shell.setLayout(new FillLayout());
|
|
50
|
|
51 Button open = new Button (shell, SWT.PUSH);
|
|
52 open.setText ("Open Dialog");
|
|
53 open.addSelectionListener (new class() SelectionAdapter{
|
|
54 public void widgetSelected (SelectionEvent e) {
|
|
55 dialog = new Shell (shell, SWT.DIALOG_TRIM);
|
|
56 dialog.setLayout (new GridLayout (3, false));
|
|
57
|
|
58 calendar = new DateTime (dialog, SWT.CALENDAR | DWT.BORDER);
|
|
59 date = new DateTime (dialog, SWT.DATE | DWT.SHORT);
|
|
60 time = new DateTime (dialog, SWT.TIME | DWT.SHORT);
|
|
61
|
|
62 new Label (dialog, SWT.NONE);
|
|
63 new Label (dialog, SWT.NONE);
|
|
64 Button ok = new Button (dialog, SWT.PUSH);
|
|
65 ok.setText ("OK");
|
|
66 ok.setLayoutData(new GridData (SWT.FILL, DWT.CENTER, false, false));
|
|
67 ok.addSelectionListener (new class() SelectionAdapter{
|
|
68 void widgetSelected (SelectionEvent e) {
|
|
69 Stdout.formatln("Calendar date selected (MM/DD/YYYY) = {:d02}/{:d02}/{:d04}",
|
|
70 (calendar.getMonth () + 1),calendar.getDay (),calendar.getYear ());
|
|
71 Stdout.formatln("Date selected (MM/YYYY)= {:d02}/{:d04}",
|
|
72 (date.getMonth () + 1), date.getYear ());
|
|
73 Stdout.formatln("Time selected (HH:MM) = {:d02}:{:d02}",
|
|
74 time.getHours(), time.getMinutes());
|
|
75 Stdout.flush();
|
|
76 dialog.close ();
|
|
77 }
|
|
78 });
|
|
79 dialog.setDefaultButton (ok);
|
|
80 dialog.pack ();
|
|
81 dialog.open ();
|
|
82 }
|
|
83 });
|
|
84 shell.pack ();
|
|
85 shell.open ();
|
|
86
|
|
87 while (!shell.isDisposed ()) {
|
|
88 if (!display.readAndDispatch ()) display.sleep ();
|
|
89 }
|
|
90 display.dispose ();
|
|
91 }
|
|
92
|