Mercurial > projects > dwt-samples
comparison snippets/datetime/Snippet251.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 |
comparison
equal
deleted
inserted
replaced
118:7b1c122b4128 | 119:9a1be6ff19a2 |
---|---|
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 datetime.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 dwt.DWT; | |
22 import dwt.events.SelectionAdapter; | |
23 import dwt.events.SelectionEvent; | |
24 import dwt.layout.FillLayout; | |
25 import dwt.layout.GridData; | |
26 import dwt.layout.GridLayout; | |
27 import dwt.widgets.Button; | |
28 import dwt.widgets.DateTime; | |
29 import dwt.widgets.Dialog; | |
30 import dwt.widgets.Display; | |
31 import dwt.widgets.Label; | |
32 import dwt.widgets.Shell; | |
33 | |
34 import dwt.dwthelper.utils; | |
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, DWT.PUSH); | |
52 open.setText ("Open Dialog"); | |
53 open.addSelectionListener (new class() SelectionAdapter{ | |
54 public void widgetSelected (SelectionEvent e) { | |
55 dialog = new Shell (shell, DWT.DIALOG_TRIM); | |
56 dialog.setLayout (new GridLayout (3, false)); | |
57 | |
58 calendar = new DateTime (dialog, DWT.CALENDAR | DWT.BORDER); | |
59 date = new DateTime (dialog, DWT.DATE | DWT.SHORT); | |
60 time = new DateTime (dialog, DWT.TIME | DWT.SHORT); | |
61 | |
62 new Label (dialog, DWT.NONE); | |
63 new Label (dialog, DWT.NONE); | |
64 Button ok = new Button (dialog, DWT.PUSH); | |
65 ok.setText ("OK"); | |
66 ok.setLayoutData(new GridData (DWT.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 |