SWT/JFace Eclipae 表单 可折叠面板 各位大佬,求教
package data;
import java.util.Vector;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.events.ExpansionAdapter;
import org.eclipse.ui.forms.events.ExpansionEvent;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import dao.StepDao;
import windows.MainWindow;
import windows.WindowDriverLookandModify;
public class foldedInterfaceData {
/**
* 主窗口
*/
private MainWindow mainWindow;
/**
* @author toolkit 表格工具
* @author form 表格滚动面板
* @author composite 存放面板
* @author section 内容显示区
* @author com 内容显示区控件存放面板f
*
*/
private Composite composite;
private FormToolkit toolkit;
private ScrolledForm form;
private Section section;
private Composite com;
private WindowDriverLookandModify wModify;
/**
* @category 步骤
* @author comboTitle 步骤类型下拉框
* @author combo 旋转方向
* @category textSpeet 目标速度
* @author textTorque 切换扭
* @author textAngle 角度
*/
private Combo comboTitle, combo;
private Text textSpeet, textTorque, textAngle;
/**
* @author 精准拧紧
* @author comboTitle1 步骤类型
* @author textTorque1 目标扭矩
* @author textprecision 目标精度
* @author textStop 停机目标值
* @author textSpeed 速度限制
*/
private Combo comboTitle1;
private Text textTorque1, textprecision, textStop, textSpeed;
private int tyep;
/**
* 控件展开为true 控件折叠为false
*/
private boolean temp = true;
private int id;
protected parameterConfigurationData data3;
/**
*
* @param mainWindow
* 主窗口
* @param wModify
* 紧固界面
* @param composite2
* 存放面板
* @param teyp
* 判断创建那一步
* @param id
* 表示第几组
* @param data3
* 数据参数
*/
public foldedInterfaceData(MainWindow mainWindow, WindowDriverLookandModify wModify, Composite composite2, int teyp,
int id, parameterConfigurationData data3) {
this.mainWindow = mainWindow;
this.wModify = wModify;
this.composite = composite2;
this.tyep = teyp;
this.id = id;
this.data3 = data3;
}
public foldedInterfaceData() {
super();
}
public void createStep() {
composite.setLayout(new FillLayout(SWT.VERTICAL));
toolkit = new FormToolkit(composite.getDisplay());
// 通过表单对象创建可滚动面板
form = toolkit.createScrolledForm(composite);
//// 按钮背景设为绿色
// 设置表单布局
form.getBody().setLayout(new FillLayout(SWT.HORIZONTAL));
// 创建内容区
section = toolkit.createSection(form.getBody(),
Section.TWISTIE | Section.TITLE_BAR | Section.DESCRIPTION | Section.EXPANDED | SWT.CHECK);
section.setBackground(new Color(Display.getDefault(), 224, 224, 224));
section.setText("控制步骤");
// 创建面板
com = toolkit.createComposite(section);
com.setLayout(new FillLayout());
Button buttonde = new Button(section, SWT.None);
buttonde.setText(" 删除 ");
buttonde.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
section.dispose();
form.dispose();
toolkit.dispose();
Vector<foldedInterfaceData> vector = wModify.getVector();
if (vector.size() != 0) {
int of = vector.indexOf(getFoldedInterfaceDate());
StepDao dao = new StepDao();
dao.deleteStepsAndDecreaseAboveByParameterIdAndShowPosition(id, of);
vector.remove(of);
} else {
vector.clear();
}
composite.layout();
}
});
// 创建不同的控件
createContorl(tyep);
// 创建控件
section.setClient(com);
section.setTextClient(buttonde);
section.addExpansionListener(new ExpansionAdapter() {
@Override
public void expansionStateChanged(ExpansionEvent e) {
// TODO Auto-generated method stub
temp = e.getState();
form.reflow(true);
if (temp) {
// 设置展开还是关闭
section.setExpanded(true);
} else {
section.setExpanded(false);
}
composite.layout();
// if (temp) {
// Vector<foldedInterfaceData> vector = wModify.getVector();
// for (int i = 0; i < vector.size(); i++) {
// composite.setSize(860, 210 * (i + 1));
// }
// } else {
// Vector<foldedInterfaceData> vector = wModify.getVector();
// for (int i = 0; i < vector.size(); i++) {
// composite.setSize(860, 60 * (i + 1));
// }
//
// }
}
});
// 分割线
toolkit.createCompositeSeparator(section);
section.layout();
composite.layout();
}
public void createStep2() {
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.minimumHeight = 25;
GridData gridData2 = new GridData();
gridData2.horizontalAlignment = SWT.LEFT;
gridData2.grabExcessHorizontalSpace = true;
gridData2.horizontalSpan = 3;
Group group = new Group(com, SWT.NONE);
group.setText("扭矩角度控制步骤1");
GridLayout grid = new GridLayout(4, true);
grid.horizontalSpacing = 5;
grid.verticalSpacing = 15;
group.setLayout(grid);
Label labelTitle = new Label(group, SWT.NONE);
labelTitle.setText("步骤类型");
labelTitle.setLayoutData(gridData);
comboTitle = new Combo(group, SWT.READ_ONLY);
comboTitle.setItems("开始入牙步骤", "扭矩角度控制步骤1", "扭矩角度控制步骤2", "扭矩角度控制步骤3", "精准拧紧控制步骤");
comboTitle.setLayoutData(gridData2);
comboTitle.select(0);
Label label = toolkit.createLabel(group, "目标速度(RPM)", SWT.NONE);
label.setLayoutData(gridData);
textSpeet = new Text(group, SWT.BORDER);
textSpeet.setLayoutData(gridData);
textSpeet.setText(data3.getSpeed() + "");
textSpeet.setToolTipText("设置电机速度");
Label label2 = toolkit.createLabel(group, "旋转方向", SWT.NONE);
label2.setLayoutData(gridData);
combo = new Combo(group, SWT.BORDER);
combo.setItems("顺时针", "逆时针");
combo.select(data3.getDirection());
combo.setLayoutData(gridData);
combo.setToolTipText("电机转动的方向");
Label label3 = toolkit.createLabel(group, " 切换扭矩", SWT.NONE);
label3.setText(" 切换扭矩(" + mainWindow.getScrewDriverTool().driverData.getTorqueUnit() + ")");
label3.setLayoutData(gridData);
textTorque = new Text(group, SWT.BORDER);
textTorque.setLayoutData(gridData);
textTorque.setText(data3.getTorque() + "");
textTorque.setToolTipText("0表示关闭扭矩控制");
Label label4 = toolkit.createLabel(group, "角度限制(°)", SWT.NONE);
label4.setLayoutData(gridData);
textAngle = new Text(group, SWT.BORDER);
textAngle.setLayoutData(gridData);
textAngle.setText(data3.getAngle() + "");
textAngle.setToolTipText("0表示关闭角度监控");
comboTitle.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// TODO Auto-generated method stub
String text = comboTitle.getText();
if ("开始入牙步骤".equals(text)) {
updataText(0);
} else if ("扭矩角度控制步骤1".equals(text)) {
updataText(1);
} else if ("扭矩角度控制步骤2".equals(text)) {
updataText(2);
} else if ("扭矩角度控制步骤3".equals(text)) {
updataText(3);
} else if ("精准拧紧控制步骤".equals(text)) {
System.out.println("调用精准拧紧");
group.dispose();
combo.dispose();
label.dispose();
label2.dispose();
label3.dispose();
label4.dispose();
labelTitle.dispose();
textAngle.dispose();
textSpeet.dispose();
textTorque.dispose();
comboTitle.dispose();
createStep5();
}
section.layout();
composite.layout();
}
});
section.layout();
composite.layout();
}
public void createStep5() {
GridData gridData = new GridData();
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.minimumHeight = 25;
GridData gridData2 = new GridData();
gridData2.horizontalAlignment = SWT.LEFT;
gridData2.grabExcessHorizontalSpace = true;
gridData2.horizontalSpan = 3;
Group group = new Group(com, SWT.NONE);
group.setText("精确拧紧控制步骤");
GridLayout grid = new GridLayout(4, true);
grid.horizontalSpacing = 5;
grid.verticalSpacing = 15;
group.setLayout(grid);
Label labelTitle = new Label(group, SWT.NONE);
labelTitle.setText("步骤类型");
labelTitle.setLayoutData(gridData);
comboTitle1 = new Combo(group, SWT.READ_ONLY);
comboTitle1.setItems("开始入牙步骤", "扭矩角度控制步骤1", "扭矩角度控制步骤2", "扭矩角度控制步骤3", "精确拧紧控制步骤");
comboTitle1.setLayoutData(gridData2);
comboTitle1.select(4);
Label label = toolkit.createLabel(group, "", SWT.NONE);
label.setText(" 目标扭矩(" + mainWindow.getScrewDriverTool().driverData.getTorqueUnit() + ")");
label.setLayoutData(gridData);
textTorque1 = new Text(group, SWT.BORDER);
textTorque1.setLayoutData(gridData);
textTorque1.setText(data3.getSpeed() + "");
textTorque1.setToolTipText("设置目标扭矩");
Label label2 = toolkit.createLabel(group, "目标扭矩精度(%)", SWT.NONE);
label2.setLayoutData(gridData);
label2.setToolTipText("设置允许目标扭矩精度要求(0-25%)");
textprecision = new Text(group, SWT.BORDER);
textprecision.setText(data3.getDirection() + "");
textprecision.setLayoutData(gridData);
Label label3 = toolkit.createLabel(group, "停机目标值(%)", SWT.NONE);
label3.setLayoutData(gridData);
textStop = new Text(group, SWT.BORDER);
textStop.setText(data3.getTorque() + "");
textStop.setLayoutData(gridData);
textStop.setToolTipText("根据实际情况调整停止时机,使得螺丝刀最终停止扭矩在目标值左右均匀分布。");
Label label4 = toolkit.createLabel(group, "速度限制(PRM)", SWT.NONE);
label4.setLayoutData(gridData);
textSpeed = new Text(group, SWT.BORDER);
textSpeed.setText(data3.getAngle() + "");
textSpeed.setLayoutData(gridData);
textSpeed.setToolTipText("速度设置");
comboTitle1.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String text = comboTitle1.getText();
group.dispose();
label.dispose();
label2.dispose();
label3.dispose();
label4.dispose();
labelTitle.dispose();
textprecision.dispose();
textTorque1.dispose();
textStop.dispose();
textSpeed.dispose();
if ("开始入牙步骤".equals(text)) {
comboTitle1.dispose();
createStep2();
} else if ("扭矩角度控制步骤1".equals(text)) {
comboTitle1.dispose();
createStep2();
} else if ("扭矩角度控制步骤2".equals(text)) {
comboTitle1.dispose();
createStep2();
} else if ("扭矩角度控制步骤3".equals(text)) {
comboTitle1.dispose();
createStep2();
} else {
createStep5();
}
section.layout();
composite.layout();
}
});
section.layout();
composite.layout();
}
// 释放控件
public void dissplay() {
if (toolkit != null) {
System.out.println("调用方法删除");
toolkit.dispose();
form.dispose();
section.dispose();
}
}
/**
* 设置文本内容
*/
public void updataText(int dat) {
Display.getDefault().asyncExec(() -> {
switch (dat) {
case 0:
comboTitle.select(dat);
combo.select(data3.getDirection());
textSpeet.setText(data3.getSpeed() + "");
textTorque.setText(data3.getTorque() + "");
textAngle.setText(data3.getAngle() + "");
break;
case 1:
comboTitle.select(dat);
combo.select(data3.getDirection());
textSpeet.setText(data3.getSpeed() + "");
textTorque.setText(data3.getTorque() + "");
textAngle.setText(data3.getAngle() + "");
break;
case 2:
comboTitle.select(dat);
combo.select(data3.getDirection());
textSpeet.setText(data3.getSpeed() + "");
textTorque.setText(data3.getTorque() + "");
textAngle.setText(data3.getAngle() + "");
break;
case 3:
comboTitle.select(dat);
combo.select(data3.getDirection());
textSpeet.setText(data3.getSpeed() + "");
textTorque.setText(data3.getTorque() + "");
textAngle.setText(data3.getAngle() + "");
break;
case 4:
comboTitle1.select(dat);
textTorque1.setText(data3.getDirection() + "");
textprecision.setText(data3.getSpeed() + "");
textStop.setText(data3.getTorque() + "");
textSpeed.setText(data3.getAngle() + "");
break;
default:
break;
}
});
}
/**
*
* @param type
* 不同的控件界面
*/
public void createContorl(int type) {
if (tyep == 0) {
createStep2();
// 设置文本
updataText(0);
} else if (tyep == 1) {
createStep2();
updataText(1);
} else if (tyep == 2) {
createStep2();
updataText(2);
} else if (tyep == 3) {
createStep2();
updataText(3);
} else if (tyep == 4) {
createStep5();
updataText(4);
}
}
public void close(boolean temp) {
section.setExpanded(temp);
}
public Combo getComboTitle() {
return comboTitle;
}
public void setComboTitle(Combo comboTitle) {
this.comboTitle = comboTitle;
}
public Combo getComboTitle1() {
return comboTitle1;
}
public void setComboTitle1(Combo comboTitle1) {
this.comboTitle1 = comboTitle1;
}
public Combo getCombo() {
return combo;
}
public void setCombo(Combo combo) {
this.combo = combo;
}
public Text getTextSpeet() {
return textSpeet;
}
public void setTextSpeet(Text textSpeet) {
this.textSpeet = textSpeet;
}
public Text getTextTorque() {
return textTorque;
}
public void setTextTorque(Text textTorque) {
this.textTorque = textTorque;
}
public Text getTextAngle() {
return textAngle;
}
public void setTextAngle(Text textAngle) {
this.textAngle = textAngle;
}
public Text getTextTorque1() {
return textTorque1;
}
public void setTextTorque1(Text textTorque1) {
this.textTorque1 = textTorque1;
}
public Text getTextprecision() {
return textprecision;
}
public void setTextprecision(Text textprecision) {
this.textprecision = textprecision;
}
public Text getTextStop() {
return textStop;
}
public void setTextStop(Text textStop) {
this.textStop = textStop;
}
public Text getTextSpeed() {
return textSpeed;
}
public void setTextSpeed(Text textSpeed) {
this.textSpeed = textSpeed;
}
public boolean isTemp() {
return temp;
}
public void setTemp(boolean temp) {
this.temp = temp;
}
public foldedInterfaceData getFoldedInterfaceDate() {
return this;
}
}
怎么才能达到这种效果
折叠时效果
展开一个的效果