📄 checkboxeditor.java
字号:
/*
* Copyright (c) 2008 胜利油田胜利软件有限责任公司. All rights reserved.
*/
package com.victorysoft.swt.base;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
/**
*
* @author 于景洋
* @newtime Oct 31, 2008,4:39:34 PM
* @version 1.0
* @see
* @since JDK 1.5.0
*/
public class CheckBoxEditor implements ControlEditor {
private Table table;
private TableEditor editor;
public CheckBoxEditor(Table table, int col) {
this.table = table;
this.setControl(col);
}
public CheckBoxEditor(Table table, int col, TableEditor editor) {
this.table = table;
this.editor = editor;
this.setControl(col);
}
private TableEditor getTableEditor() {
TableEditor editor = new TableEditor(table);
if (this.editor == null) {
editor.horizontalAlignment = SWT.CENTER;
editor.verticalAlignment = SWT.CENTER;
editor.grabHorizontal = false;
editor.grabVertical = false;
editor.minimumWidth = 12;
editor.minimumHeight = 12;
} else {
editor.horizontalAlignment = this.editor.horizontalAlignment;
editor.verticalAlignment = this.editor.verticalAlignment;
editor.grabHorizontal = this.editor.grabHorizontal;
editor.grabVertical = this.editor.grabVertical;
editor.minimumWidth = this.editor.minimumWidth;
editor.minimumHeight = this.editor.minimumHeight;
}
return editor;
}
public void setControl(int col) {
TableItem[] items = table.getItems();
for (int i = 0; i < items.length; i++) {
TableEditor editor = this.getTableEditor();
Button btn = new Button(table, SWT.CHECK);
btn.setVisible(true);
items[i].setData("CheckBox_" + col, btn);
editor.setEditor(btn, items[i], col);
items[i].setText(col, "");
}
}
public void setSelectionListener(int col, SelectionListener listener) {
TableItem[] items = table.getItems();
for (int i = 0; i < items.length; i++) {
Button btn = (Button) items[i].getData("CheckBox_" + col);
btn.addSelectionListener(listener);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -