📄 querydialog.java
字号:
package net.sf.pim.view;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sf.component.calendar.SWTCalendar;
import net.sf.component.calendar.SWTCalendarEvent;
import net.sf.component.calendar.SWTCalendarListener;
import net.sf.pim.URLUtil;
import net.sf.pim.UiUtil;
import net.sf.pim.model.psp.WorkCondition;
import net.sf.util.ConfigHelper;
import net.sf.util.StringUtil;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class QueryDialog extends Dialog {
//条件
private WorkCondition workCondition = new WorkCondition();
//控件,参见WorkCondition
private Text rq1, rq2,key;
private SWTCalendar calendar1;
private SWTCalendar calendar2;
public QueryDialog(Shell shell) {
super(shell);
}
protected void configureShell(Shell shell) {
super.configureShell(shell);
shell.setText("工作记录--查询条件");
Image image = ImageDescriptor.createFromURL(URLUtil.getResourceURL("icons/search3.gif")).createImage(shell.getDisplay());
shell.setImage(image);
image.dispose();
}
protected Control createDialogArea(Composite parent) {
Composite composite=new Composite(parent,SWT.NULL);
GridLayout gl=new GridLayout();
gl.numColumns=3;
composite.setLayout(gl);
Label dummy=new Label(composite,SWT.NULL); //占个位置
dummy.setText("");
rq1 = new Text(composite, SWT.NULL);
rq1.addVerifyListener(new VerifyListener(){
public void verifyText(VerifyEvent e) {
//几种情况,输入控制键,输入中文,输入字符,输入数字
//整数验证
Pattern pattern = Pattern.compile("[0-9]\\d*");
Matcher matcher = pattern.matcher(e.text);
if(matcher.matches()) //处理数字
e.doit=true;
else if(e.text.length() > 0) //有字符情况,包含中文、空格
e.doit=false;
else //控制键
e.doit=true;
}});
rq1.addFocusListener(new FocusListener(){
public void focusGained(FocusEvent e) {
}
public void focusLost(FocusEvent e) {
UiUtil.syncCalendar(rq1.getText(),calendar1);
}});
rq2 = new Text(composite, SWT.NULL);
rq2.addFocusListener(new FocusListener(){
public void focusGained(FocusEvent e) {
}
public void focusLost(FocusEvent e) {
UiUtil.syncCalendar(rq2.getText(),calendar2);
}});
String[] s3 = ConfigHelper.getSearch3();
rq1.setText(s3[0]);
rq2.setText(s3[1]);
rq1.setFont(UiUtil.getFont());
rq2.setFont(UiUtil.getFont());
Label labelsRq = new Label(composite, SWT.NULL);
labelsRq.setText("起始日期:");
calendar1 = new SWTCalendar(composite,SWT.NONE|SWTCalendar.RED_SUNDAY);
calendar1.addSWTCalendarListener(new SWTCalendarListener(){
public void dateChanged(SWTCalendarEvent event) {
rq1.setText(StringUtil.getDefaultDateFormat().format(event.getCalendar().getTime()));
}});
calendar2 = new SWTCalendar(composite,SWT.NONE|SWTCalendar.RED_SUNDAY);
calendar2.addSWTCalendarListener(new SWTCalendarListener(){
public void dateChanged(SWTCalendarEvent event) {
rq2.setText(StringUtil.getDefaultDateFormat().format(event.getCalendar().getTime()));
}});
//赋初值
UiUtil.syncCalendar(s3[0], calendar1);
UiUtil.syncCalendar(s3[1], calendar2);
Label labelsKey = new Label(composite, SWT.NULL);
labelsKey.setText("关键词:");
key = new Text(composite, SWT.NULL);
GridData gd=new GridData(GridData.FILL_BOTH);
gd.horizontalSpan=2;
key.setLayoutData(gd);
key.setFont(UiUtil.getFont());
key.forceFocus();
return composite;
}
protected void okPressed() {
workCondition.setRq1(rq1.getText());
workCondition.setRq2(rq2.getText());
workCondition.setKey(key.getText());
super.okPressed();
}
public WorkCondition getWorkCondition() {
return workCondition;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -