1 #!/usr/bin/env dub 2 /+ 3 dub.sdl: 4 name "snippet251" 5 dependency "dwt" path="../../../../../../" 6 libs \ 7 "atk-1.0" \ 8 "cairo" \ 9 "dl" \ 10 "fontconfig" \ 11 "gdk-x11-2.0" \ 12 "gdk_pixbuf-2.0" \ 13 "glib-2.0" \ 14 "gmodule-2.0" \ 15 "gnomeui-2" \ 16 "gnomevfs-2" \ 17 "gobject-2.0" \ 18 "gthread-2.0" \ 19 "gtk-x11-2.0" \ 20 "pango-1.0" \ 21 "pangocairo-1.0" \ 22 "X11" \ 23 "Xcomposite" \ 24 "Xcursor" \ 25 "Xdamage" \ 26 "Xext" \ 27 "Xfixes" \ 28 "Xi" \ 29 "Xinerama" \ 30 "Xrandr" \ 31 "Xrender" \ 32 "Xtst" \ 33 platform="linux" 34 +/ 35 36 /******************************************************************************* 37 * Copyright (c) 2000, 2004 IBM Corporation and others. 38 * All rights reserved. This program and the accompanying materials 39 * are made available under the terms of the Eclipse Public License v1.0 40 * which accompanies this distribution, and is available at 41 * http://www.eclipse.org/legal/epl-v10.html 42 * 43 * Contributors: 44 * IBM Corporation - initial API and implementation 45 * D Port: 46 * Thomas Demmer <t_demmer AT web DOT de> 47 *******************************************************************************/ 48 module org.eclipse.swt.snippets.Snippet251; 49 50 /* 51 * DateTime example snippet: create a DateTime calendar, date, and time in a dialog. 52 * 53 * For a list of all SWT example snippets see 54 * http://www.eclipse.org/swt/snippets/ 55 */ 56 import org.eclipse.swt.SWT; 57 import org.eclipse.swt.events.SelectionAdapter; 58 import org.eclipse.swt.events.SelectionEvent; 59 import org.eclipse.swt.layout.FillLayout; 60 import org.eclipse.swt.layout.GridData; 61 import org.eclipse.swt.layout.GridLayout; 62 import org.eclipse.swt.widgets.Button; 63 import org.eclipse.swt.widgets.DateTime; 64 import org.eclipse.swt.widgets.Dialog; 65 import org.eclipse.swt.widgets.Display; 66 import org.eclipse.swt.widgets.Label; 67 import org.eclipse.swt.widgets.Shell; 68 69 import java.lang.all; 70 71 version(Tango){ 72 import tango.io.Stdout; 73 } else { // Phobos 74 import std.stdio; 75 } 76 77 void main () { 78 /* These cannot be local in the 79 * listener, hence we put it here and not at the 80 * constructor. (THD) 81 * (dmd.1.028) 82 */ 83 DateTime calendar, date, time; 84 Shell dialog; 85 86 Display display = new Display (); 87 Shell shell = new Shell (display); 88 shell.setLayout(new FillLayout()); 89 90 Button open = new Button (shell, SWT.PUSH); 91 open.setText ("Open Dialog"); 92 open.addSelectionListener (new class SelectionAdapter{ 93 override 94 public void widgetSelected (SelectionEvent e) { 95 dialog = new Shell (shell, SWT.DIALOG_TRIM); 96 dialog.setLayout (new GridLayout (3, false)); 97 98 calendar = new DateTime (dialog, SWT.CALENDAR | SWT.BORDER); 99 date = new DateTime (dialog, SWT.DATE | SWT.SHORT); 100 time = new DateTime (dialog, SWT.TIME | SWT.SHORT); 101 102 new Label (dialog, SWT.NONE); 103 new Label (dialog, SWT.NONE); 104 Button ok = new Button (dialog, SWT.PUSH); 105 ok.setText ("OK"); 106 ok.setLayoutData(new GridData (SWT.FILL, SWT.CENTER, false, false)); 107 ok.addSelectionListener (new class SelectionAdapter{ 108 override 109 void widgetSelected (SelectionEvent e) { 110 version(Tango){ 111 Stdout.formatln("Calendar date selected (MM/DD/YYYY) = {:d02}/{:d02}/{:d04}", 112 (calendar.getMonth () + 1),calendar.getDay (),calendar.getYear ()); 113 Stdout.formatln("Date selected (MM/YYYY)= {:d02}/{:d04}", 114 (date.getMonth () + 1), date.getYear ()); 115 Stdout.formatln("Time selected (HH:MM) = {:d02}:{:d02}", 116 time.getHours(), time.getMinutes()); 117 Stdout.flush(); 118 } else { // Phobos 119 writefln("Calendar date selected (MM/DD/YYYY) = %02d/%02d/%04d", 120 (calendar.getMonth () + 1),calendar.getDay (),calendar.getYear ()); 121 writefln("Date selected (MM/YYYY)= %02d/%04d", 122 (date.getMonth () + 1), date.getYear ()); 123 writefln("Time selected (HH:MM) = %02d:%02d", 124 time.getHours(), time.getMinutes()); 125 } 126 dialog.close (); 127 } 128 }); 129 dialog.setDefaultButton (ok); 130 dialog.pack (); 131 dialog.open (); 132 } 133 }); 134 shell.pack (); 135 shell.open (); 136 137 while (!shell.isDisposed ()) { 138 if (!display.readAndDispatch ()) display.sleep (); 139 } 140 display.dispose (); 141 } 142