略全局对象,一一创建即可。。。
/**
* Create the dialog.
*
* @param parent
* @param style
*/
public
demo2(Shell parent,
int
style) {
super
(parent, style);
this
.parent = parent;
setText(
"SWT Dialog"
);
}
/**
* Open the dialog.
*
* @return the result
*/
public
Object open() {
createContents();
LayoutUtil.bottomrightShell(parent.getDisplay(), shell);
shell.setLayout(
new
FormLayout());
Composite composite =
new
Composite(shell, SWT.BORDER);
composite.setBackground(SWTResourceManager.getColor(
127
,
255
,
212
));
FormData fd_composite =
new
FormData();
fd_composite.right =
new
FormAttachment(
0
,
340
);
fd_composite.top =
new
FormAttachment(
0
);
fd_composite.left =
new
FormAttachment(
0
);
fd_composite.bottom =
new
FormAttachment(
0
,
27
);
composite.setLayoutData(fd_composite);
text =
new
Text(composite, SWT.BORDER | SWT.CENTER);
text.setEnabled(
false
);
text.setText(
"通知栏"
);
text.setBounds(
5
,
1
,
73
,
23
);
Button button_1 =
new
Button(composite, SWT.TOGGLE | SWT.CENTER);
button_1.addSelectionListener(
new
SelectionAdapter() {
@Override
public
void
widgetSelected(SelectionEvent e) {
shell.close();
}
});
button_1.setText(
"×"
);
button_1.setBounds(
309
,
0
,
27
,
27
);
final
Button button_2 =
new
Button(composite, SWT.ARROW | SWT.DOWN);
button_2.addSelectionListener(
new
SelectionAdapter() {
@Override
public
void
widgetSelected(SelectionEvent e) {
makeList();
}
});
button_2.setBounds(
276
,
0
,
27
,
27
);
list_1 =
new
List(shell, SWT.BORDER);
list_1.setLocation(
184
,
27
);
list_1.setItems(
new
String[] {
"不再通知"
,
"实时提醒"
,
"最小化"
});
FormData fd_list_1 =
new
FormData();
fd_list_1.bottom =
new
FormAttachment(composite,
55
, SWT.BOTTOM);
fd_list_1.top =
new
FormAttachment(composite);
fd_list_1.right =
new
FormAttachment(
100
, -
38
);
fd_list_1.left =
new
FormAttachment(
100
, -
157
);
list_1.setLayoutData(fd_list_1);
list_1.setVisible(
false
);
parent.getDisplay().addFilter(SWT.MouseMove,
new
Listener() {
@Override
public
void
handleEvent(Event e) {
if
(list_1!=
null
&&!list_1.isDisposed()){
int
x = e.x;
int
y = e.y;
Rectangle r = list_1.getBounds();
int
xbegin = r.x;
int
xend = r.x + r.width;
int
ybegin = r.y;
int
yend = r.y + r.height;
if
((x+xbegin) >= xbegin && (x+xbegin)<= xend && (y+ybegin) >= ybegin &&(y+ybegin) <= yend) {
}
else
{
if
(list_1.isVisible()) {
list_1.setVisible(
false
);
}
}
}
}
});
ScrolledComposite scrolledComposite =
new
ScrolledComposite(shell,
SWT.BORDER | SWT.V_SCROLL);
FormData fd_scrolledComposite =
new
FormData();
fd_scrolledComposite.bottom =
new
FormAttachment(
100
, -
30
);
fd_scrolledComposite.right =
new
FormAttachment(
100
);
fd_scrolledComposite.top =
new
FormAttachment(composite);
fd_scrolledComposite.left =
new
FormAttachment(
0
);
scrolledComposite.setLayoutData(fd_scrolledComposite);
scrolledComposite.setExpandHorizontal(
true
);
scrolledComposite.setExpandVertical(
true
);
table =
new
Table(scrolledComposite, SWT.BORDER | SWT.FULL_SELECTION
| SWT.H_SCROLL);
table.setLinesVisible(
true
);
tableColumn =
new
TableColumn(table, SWT.NONE);
tableColumn.setWidth(
310
);
showDate();
scrolledComposite.setContent(table);
scrolledComposite.setMinSize(table
.computeSize(SWT.DEFAULT, SWT.DEFAULT));
lblNewLabel =
new
CLabel(shell, SWT.NONE);
lblNewLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
lblNewLabel.setFont(SWTResourceManager.getFont(
"微软雅黑"
,
9
, SWT.BOLD));
lblNewLabel.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
FormData fd_lblNewLabel =
new
FormData();
fd_lblNewLabel.bottom =
new
FormAttachment(
100
, -
1
);
fd_lblNewLabel.left =
new
FormAttachment(composite,
0
, SWT.LEFT);
lblNewLabel.setLayoutData(fd_lblNewLabel);
lblNewLabel.setText(
"查看全部"
);
label =
new
CLabel(shell, SWT.NONE);
label.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
label.setFont(SWTResourceManager.getFont(
"微软雅黑"
,
9
, SWT.BOLD));
label.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
label.setText(
"忽略全部"
);
FormData fd_label =
new
FormData();
fd_label.top =
new
FormAttachment(lblNewLabel, -
23
);
fd_label.left =
new
FormAttachment(
100
, -
54
);
fd_label.bottom =
new
FormAttachment(lblNewLabel,
0
, SWT.BOTTOM);
fd_label.right =
new
FormAttachment(
100
);
label.setLayoutData(fd_label);
shell.open();
shell.layout();
Display display = getParent().getDisplay();
while
(!shell.isDisposed()) {
if
(!display.readAndDispatch()) {
display.sleep();
}
}
return
result;
}
private
void
showDate() {
tableItem =
new
TableItem(table, SWT.NONE);
tableItem.setText(
"待处理的财务申请"
);
tableItem_1 =
new
TableItem(table, SWT.NONE);
tableItem_1.setText(
"待处理的未读邮件"
);
for
(
int
i =
0
; i <
20
; i++) {
tableItem_1 =
new
TableItem(table, SWT.NONE);
tableItem_1.setText(
"待处理的未读邮件"
);
}
}
protected
void
makeList() {
if
(list_1 !=
null
&& !list_1.isVisible()) {
list_1.setVisible(
true
);
}
else
if
(list_1 !=
null
&& list_1.isVisible()) {
list_1.setVisible(
false
);
}
}
/**
* Create contents of the dialog.
*/
private
void
createContents() {
shell =
new
Shell(getParent(), SWT.NO_TRIM | SWT.BORDER);
shell.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
shell.setSize(
340
,
243
);
shell.setText(getText());
}
}