-
Notifications
You must be signed in to change notification settings - Fork 96
/
DropTestSnippet.java
106 lines (90 loc) · 2.8 KB
/
DropTestSnippet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/****************************************************************************
* Copyright (c) 2008 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 <jeremyd@aspencloud.com> - initial API and implementation
*****************************************************************************/
package org.eclipse.nebula.widgets.cdatetime.snippets;
import org.eclipse.nebula.cwt.base.BaseCombo;
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.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class DropTestSnippet {
/**
* @param args
*/
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("CDC");
shell.setLayout(new GridLayout());
GridLayout layout = new GridLayout(2, true);
shell.setLayout(layout);
final BaseCombo cdc1 = new CDateTime(shell, CDT.BORDER);
cdc1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
final BaseCombo cdc2 = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN);
cdc2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, 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();
}
}
class MyDialog extends Dialog {
/**
*
*/
Shell shell;
public MyDialog (Shell parent, int style) {
super(parent, style);
}
public void close() {
shell.close();
}
public void open() {
Shell parent = getParent();
final Shell shell = new Shell(parent, getStyle());
shell.setText("Testing");
shell.setLayout(new GridLayout());
final BaseCombo cdc2 = new CDateTime(shell, CDT.BORDER | CDT.DROP_DOWN);
cdc2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
Display display = parent.getDisplay();
shell.layout(true, true);
shell.pack();
int x = shell.getSize().x;
int y = shell.getSize().y;
shell.setLocation(
(display.getBounds().width-x)/2,
(display.getBounds().height-y)/2
);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
}
}