?? editietypedialog.java
字號:
package com.intotherain.examples.SimpleCellEditor.CellEditors;
import org.eclipse.jface.util.Geometry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;
import com.intotherain.examples.SimpleCellEditor.model.IETypeEnum;
import com.intotherain.examples.SimpleCellEditor.model.Record;
/**
*
* @author intotherain
*
*/
class EditIETypeDialog extends Dialog {
private Record record;
IETypeEnum result;
Button button_1;
Button button_2;
Button button_3;
public EditIETypeDialog(Shell parentShell, Record record) {
super(parentShell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
this.record = record;
}
public void createContents(final Shell shell) {
final Group group = new Group(shell, SWT.NONE);
final GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER
| GridData.VERTICAL_ALIGN_END);
gridData.heightHint = 84;
gridData.widthHint = 173;
group.setLayoutData(gridData);
group.setLayout(new GridLayout());
button_1 = new Button(group, SWT.CHECK);
button_1.setText("Internet Explorer"); //$NON-NLS-1$
button_1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (button_1.getSelection()) {
button_2.setSelection(false);
button_3.setSelection(false);
}
}
});
button_2 = new Button(group, SWT.CHECK);
button_2.setText("Opera"); //$NON-NLS-1$
button_2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (button_2.getSelection()) {
button_1.setSelection(false);
button_3.setSelection(false);
}
}
});
button_3 = new Button(group, SWT.CHECK);
button_3.setText("Firefox"); //$NON-NLS-1$
button_3.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (button_3.getSelection())
button_1.setSelection(false);
button_2.setSelection(false);
}
});
final Composite composite = new Composite(shell, SWT.NONE);
final GridData gridData_1 = new GridData(GridData.VERTICAL_ALIGN_END);
gridData_1.heightHint = 27;
gridData_1.widthHint = 190;
composite.setLayoutData(gridData_1);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
composite.setLayout(gridLayout);
final Button button_ok = new Button(composite, SWT.NONE);
final GridData gridData_2 = new GridData();
gridData_2.widthHint = 87;
button_ok.setLayoutData(gridData_2);
button_ok.setText("Ok"); //$NON-NLS-1$
button_ok.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
result = IETypeEnum.Other;
if (button_1.getSelection())
result = IETypeEnum.MisrcoSoft_IE;
else if (button_2.getSelection())
result = IETypeEnum.Opera;
else if (button_3.getSelection())
result = IETypeEnum.FireFox;
shell.close();
}
});
final Button button_cancel = new Button(composite, SWT.NONE);
final GridData gridData_3 = new GridData();
gridData_3.widthHint = 80;
button_cancel.setLayoutData(gridData_3);
button_cancel.setText("Cancel");
button_cancel.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
result = null;
shell.close();
}
});
}
//init checkbox
private void initSelection() {
switch (record.getIeType()) {
case MisrcoSoft_IE:
button_1.setSelection(true);
break;
case Opera:
button_2.setSelection(true);
break;
case FireFox:
button_3.setSelection(true);
break;
default:
break;
}
}
public IETypeEnum open() {
Shell shell = new Shell(getParent(), getStyle());
shell.setText("Choose your IE type");
shell.setSize(207, 184);
shell.setLayout(new GridLayout());
createContents(shell);
initSelection();
shell.pack();
centerShell(shell);
shell.open();
Display display = getParent().getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
// Return the entered value, or null
return result;
}
private void centerShell(Shell shell){
Composite parent = shell.getParent();
Monitor monitor = shell.getDisplay().getPrimaryMonitor();
if (parent != null) {
monitor = parent.getMonitor();
}
Rectangle monitorBounds = monitor.getClientArea();
Point centerPoint;
if (parent != null) {
centerPoint = Geometry.centerPoint(parent.getBounds());
} else {
centerPoint = Geometry.centerPoint(monitorBounds);
}
Point initialSize = shell.getSize();
int x = centerPoint.x - (initialSize.x / 2);
int y = centerPoint.y - (initialSize.y / 2);
shell.setLocation(x, y);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -