/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* [url=http://www.eclipse.org/legal/epl-v10.html]Eclipse Public License - Version 1.0[/url]
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*
* DateTime example snippet: create a DateTime calendar and a DateTime time.
*
* For a list of all SWT example snippets see
* [url=http://www.eclipse.org/swt/snippets/]SWT Snippets[/url]
*/
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Snippet250 {
public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setLayout (new RowLayout ());
final DateTime calendar = new DateTime (shell, SWT.CALENDAR);
calendar.addSelectionListener (new SelectionAdapter () {
public void widgetSelected (SelectionEvent e) {
System.out.println ("calendar date changed");
}
});
DateTime time = new DateTime (shell, SWT.TIME);
time.addSelectionListener (new SelectionAdapter () {
public void widgetSelected (SelectionEvent e) {
System.out.println ("time changed");
}
});
calendar.addFocusListener(new FocusAdapter()
{
public void focusLost(FocusEvent e)
{
((DateTime)e.getSource()).setVisible(false);
}
});
Button b=new Button(shell, SWT.PUSH);
b.setText("Show Calendar");
b.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
calendar.setVisible(true);
}
});
shell.pack ();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}