📄 settingdialog.java
字号:
/*
* @author talent_marquis<甜菜侯爵>
* Email: talent_marquis@163.com
* Copyright (C) 2007 talent_marquis<甜菜侯爵>
* All rights reserved.
*/
package marquis.swt.shell;
import marquis.swt.util.DisplayUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Shell;
public class SettingDialog extends Dialog
{
private static int MAX_STORE_CLIP_NUMBER = 20;
private static int DEFAULT_STORE_CLIP_NUMBER = 5;
private static int MAX_CAPTURE_TIME = 1000;
private static int MIN_CAPTURE_TIME = 10;
private static int DEFAULT_CAPTURE_TIME = 50;
private static int MAX_MENU_STRING_LENGTH = 100;
private static int MIN_MENU_STRING_LENGTH = 10;
private static int DEFAULT_MENU_STRING_LENGTH = 40;
private static String CHARACTER_OF_MILLISECOND = "毫秒";
private String clipsNumber[] = new String[MAX_STORE_CLIP_NUMBER - 1];
// protected Object result;
protected int[] settings =
{
DEFAULT_STORE_CLIP_NUMBER,
DEFAULT_CAPTURE_TIME,
DEFAULT_MENU_STRING_LENGTH
};
private Combo clipsNumberSettingCMB;
private Label captureTimeLb, menuLengthLb;
private Scale captureTimeScale, stringLengthScale;
protected Shell shell;
/**
* Create the dialog
*
* @param parent
* @param style
*/
public SettingDialog(Shell parent, int style)
{
super(parent, style);
}
/**
* Create the dialog
*
* @param parent
*/
public SettingDialog(Shell parent)
{
this(parent, SWT.NONE);
}
public SettingDialog(Shell parent, int[] settings)
{
this(parent);
this.settings = settings;
}
/**
* Open the dialog
*
* @return the result
*/
public Object open()
{
createContents();
shell.open();
shell.layout();
Display display = getParent().getDisplay();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
return settings;
}
private void initClipsNumberString()
{
for (int i = 0; i < clipsNumber.length; i++)
{
clipsNumber[i] = (i + 2) + "";
}
}
/**
* Create contents of the dialog
*/
protected void createContents()
{
shell = new Shell(getParent(), SWT.CLOSE | SWT.TITLE
| SWT.APPLICATION_MODAL);
shell.setSize(284, 212);
DisplayUtil.showOnAtMouseLocation(shell);
shell.setText("设置");
initClipsNumberString();
final Button OKBtn = new Button(shell, SWT.NONE);
OKBtn.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
// result = clipsNumberSettingCMB.getText();
settings[0] = Integer.parseInt(clipsNumberSettingCMB.getText()); // 记录条数
settings[1] = captureTimeScale.getSelection(); // 监视时间间隔
settings[2] = stringLengthScale.getSelection(); // 记录字符串长度
shell.dispose();
}
});
OKBtn.setText("确定");
OKBtn.setBounds(120, 145, 44, 23);
final Button CancelBtn = new Button(shell, SWT.NONE);
CancelBtn.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
settings = null;
shell.dispose();
}
});
CancelBtn.setBounds(185, 145, 44, 23);
CancelBtn.setText("取消");
final Button DefaultBtn = new Button(shell, SWT.NONE);
DefaultBtn.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
settings[0] = DEFAULT_STORE_CLIP_NUMBER;
settings[1] = DEFAULT_CAPTURE_TIME;
settings[2] = DEFAULT_MENU_STRING_LENGTH;
clipsNumberSettingCMB.setText(settings[0] + "");
captureTimeScale.setSelection(settings[1]);
captureTimeLb.setText(settings[1] + CHARACTER_OF_MILLISECOND);
stringLengthScale.setSelection(settings[2]);
menuLengthLb.setText(settings[2] + "");
}
});
DefaultBtn.setBounds(45, 145, 54, 23);
DefaultBtn.setText("默认值");
clipsNumberSettingCMB = new Combo(shell, SWT.READ_ONLY);
clipsNumberSettingCMB.setVisibleItemCount(10);
clipsNumberSettingCMB.setItems(clipsNumber);
clipsNumberSettingCMB.setText(settings[0] + "");
clipsNumberSettingCMB.setBounds(105, 15, 44, 21);
captureTimeScale = new Scale(shell, SWT.NONE);
captureTimeScale.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
captureTimeLb.setText(captureTimeScale.getSelection()
+ CHARACTER_OF_MILLISECOND);
}
});
captureTimeScale.setIncrement(50);
captureTimeScale.setPageIncrement(100);
captureTimeScale.setMaximum(MAX_CAPTURE_TIME);
captureTimeScale.setMinimum(MIN_CAPTURE_TIME);
captureTimeScale.setSelection(settings[1]);
captureTimeScale.setBounds(95, 40, 138, 42);
stringLengthScale = new Scale(shell, SWT.NONE);
stringLengthScale.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
menuLengthLb.setText(stringLengthScale.getSelection() + "");
}
});
stringLengthScale.setPageIncrement(5);
stringLengthScale.setMaximum(MAX_MENU_STRING_LENGTH);
stringLengthScale.setMinimum(MIN_MENU_STRING_LENGTH);
stringLengthScale.setSelection(settings[2]);
stringLengthScale.setBounds(95, 83, 138, 42);
final Label clipsNumberLb = new Label(shell, SWT.CENTER);
clipsNumberLb.setText("存储记录条数:");
clipsNumberLb.setBounds(10, 20, 93, 13);
final Label clipsCaptureTimeLb = new Label(shell, SWT.CENTER);
clipsCaptureTimeLb.setBounds(10, 56, 93, 13);
clipsCaptureTimeLb.setText("监视时间间隔:");
final Label menuStringLengthLb = new Label(shell, SWT.CENTER | SWT.WRAP);
menuStringLengthLb.setBounds(10, 95, 93, 23);
menuStringLengthLb.setText("显示字符长度:");
captureTimeLb = new Label(shell, SWT.NONE);
captureTimeLb.setText(settings[1] + CHARACTER_OF_MILLISECOND);
captureTimeLb.setBounds(235, 55, 43, 13);
menuLengthLb = new Label(shell, SWT.NONE);
menuLengthLb.setText(settings[2] + "");
menuLengthLb.setBounds(235, 98, 43, 13);
//
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -