/**************************************************************************** * Copyright (c) 2008, 2009 Jeremy Dowdall * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * * Contributors: * Jeremy Dowdall - initial API and implementation *****************************************************************************/ package org.eclipse.nebula.widgets.cdatetime.snippets; import java.util.Date; import org.eclipse.nebula.widgets.cdatetime.CDT; import org.eclipse.nebula.widgets.cdatetime.CDateTime; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class CDTSnippet02 { /** * @param args */ public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("CDateTime"); GridLayout layout = new GridLayout(); layout.marginHeight = 25; layout.marginWidth = 25; shell.setLayout(layout); CDateTime cdt = new CDateTime(shell, CDT.BORDER | CDT.COMPACT | CDT.DROP_DOWN | CDT.DATE_LONG | CDT.TIME_MEDIUM); cdt.setSelection(new Date()); cdt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); shell.pack(); Point size = shell.getSize(); Rectangle screen = display.getMonitors()[0].getBounds(); shell.setBounds( (screen.width-size.x)/2, (screen.height-size.y)/2, size.x, size.y ); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }