use of org.eclipse.swt.widgets.Spinner in project translationstudio8 by heartsome.
the class EquivalentPage method deleteEquiCmp.
/**
* 删除加权系数面板
* @param e
*/
public void deleteEquiCmp(SelectionEvent e) {
Button deleteBtn = (Button) e.getSource();
Composite cp = deleteBtn.getParent().getParent();
Composite cp_parent = cp.getParent();
Control[] ctr_cp = cp_parent.getChildren();
Composite currentCp;
Composite nextCp;
Control[] currentCtrls;
Control[] nextCtrls;
Spinner cuSp;
Spinner nextSp;
int next = 0;
int current = 0;
int uplimit = 0;
// get current rows index,we can get Composite by current rows index
current = Integer.parseInt(cp.getData("index").toString());
// if current composite is not the last Component
if (current < ctr_cp.length) {
next = current + 1;
currentCp = (Composite) ctr_cp[current - 1];
nextCp = (Composite) ctr_cp[next - 1];
currentCtrls = currentCp.getChildren();
nextCtrls = nextCp.getChildren();
cuSp = (Spinner) currentCtrls[3];
nextSp = (Spinner) nextCtrls[3];
cuSp.setEnabled(true);
nextSp.setEnabled(true);
nextSp.setSelection(cuSp.getSelection());
nextSp.setEnabled(false);
}
// delete current composite
ctr_cp[current - 1].dispose();
// reset index of whole container
uplimit = ctr_cp.length;
for (int j = current; j < uplimit; j++) {
Composite tempcp = (Composite) ctr_cp[j];
//$NON-NLS-1$
tempcp.setData("index", String.valueOf(j));
cp_parent.setData(String.valueOf(j), tempcp);
}
index = ctr_cp.length - 1;
// 设置每一个匹配区间的最小匹配率
for (int i = 1; i < matchParent.getChildren().length; i++) {
Composite _cmp = (Composite) matchParent.getChildren()[i];
Spinner _minSp = (Spinner) _cmp.getChildren()[0];
_minSp.setMinimum(matchParent.getChildren().length - i - 1);
Spinner _maxSp = (Spinner) _cmp.getChildren()[3];
_minSp.setMaximum(Integer.parseInt(_maxSp.getText()));
}
// cp_parent.pack();
// cp_parent.layout();
// cp_parent.getParent().layout();
// equiCmp.getParent().layout();
// equiCmp.getParent().getParent().layout();
equiCmp.getParent().getParent().getParent().layout();
}
use of org.eclipse.swt.widgets.Spinner in project translationstudio8 by heartsome.
the class EquivalentPage method selected.
/**
* 改变相对最小匹配率的大小时,动态改变下一行相对最大匹配率的大小
* @param arg0
*/
private void selected(SelectionEvent e) {
Composite currentCp, nextCp, parentCp;
int currentIndex = 0;
int currentValue = 0;
int upValue = 0;
int nextMinValue = 0;
Control[] paCtrls;
Control[] cuCtrls;
Control[] nextCtrls;
Spinner sp3 = (Spinner) e.getSource();
// 当前相对最小匹配值
currentValue = sp3.getSelection();
currentCp = sp3.getParent();
parentCp = currentCp.getParent();
paCtrls = parentCp.getChildren();
cuCtrls = currentCp.getChildren();
Spinner cuMinSp = (Spinner) cuCtrls[0];
cuMinSp.setSelection(currentValue);
Spinner cuMaxSp = (Spinner) cuCtrls[3];
upValue = cuMaxSp.getSelection();
currentIndex = Integer.parseInt(currentCp.getData("index").toString());
cuMinSp.setMinimum(paCtrls.length - currentIndex + MINRATE);
if (currentIndex >= paCtrls.length) {
if (currentValue > upValue) {
cuMinSp.setSelection(upValue);
}
parentCp.layout();
parentCp.redraw();
return;
}
// 从当前加权设置的下一条设置开始,直到结束,
for (int i = currentIndex + 1; i <= paCtrls.length; i++) {
int remain = paCtrls.length - i + MINRATE;
// 获取下一个加权设置面板
nextCp = (Composite) paCtrls[i - 1];
nextCtrls = nextCp.getChildren();
Spinner nextMinSp = (Spinner) nextCtrls[0];
// 最低值不能小于这个匹配之下所有匹配区间的总数
nextMinSp.setMinimum(remain);
nextMinValue = nextMinSp.getSelection();
Spinner nextMaxSp = (Spinner) nextCtrls[3];
// 如果当前循环的相对最小匹配值小于它的最大值,设成等于最大值
if (nextMinValue > (currentValue - 1)) {
nextMinSp.setSelection(currentValue - 1);
}
nextMaxSp.setSelection(currentValue - 1);
nextMinSp.setMaximum(nextMaxSp.getSelection());
currentValue = nextMinSp.getSelection();
}
parentCp.layout();
parentCp.redraw();
}
use of org.eclipse.swt.widgets.Spinner in project translationstudio8 by heartsome.
the class EquivalentPage method performOk.
@Override
public boolean performOk() {
if (!isInit) {
return true;
}
StringBuffer equivalSB = new StringBuffer();
// 先获取重复文本段的加权系数
Composite interRepeatCmp = (Composite) repeatCmp.getChildren()[0];
Text text = (Text) interRepeatCmp.getChildren()[2];
equivalSB.append(QAConstant._InternalRepeat + ":" + text.getText() + ";");
if (isUltimate) {
Composite exter101Cmp = (Composite) repeatCmp.getChildren()[1];
text = (Text) exter101Cmp.getChildren()[2];
equivalSB.append(QAConstant._External101 + ":" + text.getText() + ";");
}
Composite exter100Cmp = (Composite) repeatCmp.getChildren()[2 - (isUltimate ? 0 : 1)];
text = (Text) exter100Cmp.getChildren()[2];
equivalSB.append(QAConstant._External100 + ":" + text.getText() + ";");
for (int i = 0; i < matchParent.getChildren().length; i++) {
Composite cmp = (Composite) matchParent.getChildren()[i];
Control[] ctr_cmp = cmp.getChildren();
text = (Text) ctr_cmp[6];
Spinner minSp = (Spinner) ctr_cmp[0];
Spinner maxSp = (Spinner) ctr_cmp[3];
equivalSB.append(minSp.getSelection() + "-" + maxSp.getSelection() + ":" + text.getText() + ";");
}
preferenceStore.setValue(QAConstant.FA_PREF_equivalent, equivalSB.toString());
return true;
}
use of org.eclipse.swt.widgets.Spinner in project translationstudio8 by heartsome.
the class EquivalentPage method createEqui.
public void createEqui(Composite equiCmp) {
cmpData = new GridData(GridData.FILL_HORIZONTAL);
cmpData.widthHint = 570;
matchParent = new Composite(equiCmp, SWT.NONE);
matchParent.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 2).applyTo(matchParent);
Composite match = new Composite(matchParent, SWT.NONE);
match.setLayoutData(cmpData);
GridLayoutFactory.fillDefaults().margins(0, 0).numColumns(8).equalWidth(false).applyTo(match);
Spinner mininSpinner = new Spinner(match, SWT.BORDER);
int minSpinnerIndex = 55;
while (minSpinnerIndex <= 95) {
mininSpinner.setSelection(minSpinnerIndex);
minSpinnerIndex = minSpinnerIndex + 5;
}
mininSpinner.setMinimum(35);
mininSpinner.setMaximum(99);
mininSpinner.setIncrement(5);
mininSpinner.setSelection(defaultValue);
mininSpinner.setLayoutData(spinnerdata);
mininSpinner.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
selected(e);
}
});
Label perLabel1 = new Label(match, SWT.NONE);
perLabel1.setText("%");
Label waveLabel = new Label(match, SWT.NONE);
waveLabel.setText("~");
Spinner maxSpinner = new Spinner(match, SWT.BORDER);
maxSpinner.setSelection(99);
maxSpinner.setEnabled(false);
maxSpinner.setLayoutData(spinnerdata);
Label perLabel2 = new Label(match, SWT.NONE);
perLabel2.setText("%");
Label phLbl = new Label(match, SWT.NONE);
phLbl.setLayoutData(phLblData);
Text equiTxt = new Text(match, SWT.BORDER);
equiTxt.setLayoutData(equiTxtData);
validEquiTxt(equiTxt);
btn_data = new GridData();
btn_data.widthHint = 40;
btn_data.heightHint = 26;
btn_data.horizontalIndent = 5;
Composite btnCmp = new Composite(match, SWT.NONE);
GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).applyTo(btnCmp);
GridDataFactory.swtDefaults().hint(btnCmpWidth, SWT.DEFAULT).applyTo(btnCmp);
Button addBtn = new Button(btnCmp, SWT.NONE);
addBtn.setLayoutData(btn_data);
addBtn.setImage(addImage);
addBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (index < 11) {
addEquiCmp(e, null);
}
}
});
Label spaceLbl = new Label(btnCmp, SWT.NONE);
spaceLbl.setLayoutData(btn_data);
match.getParent().setData(String.valueOf(index), match);
match.setData("index", index);
match.pack();
match.layout();
match.redraw();
}
use of org.eclipse.swt.widgets.Spinner in project translationstudio8 by heartsome.
the class EquivalentPage method addEquiCmp.
/**
* 点击添加按钮时,添加加权系数匹配面板
* @param e
*/
public void addEquiCmp(SelectionEvent e, Button button) {
Composite cp;
if (button == null) {
Button btn = (Button) e.getSource();
cp = btn.getParent().getParent();
} else {
cp = button.getParent().getParent();
}
// 获取加权系数面板的父面板,即group
Composite cp_parent = cp.getParent();
int temp_index = cp_parent.getChildren().length;
Composite temp_cp = (Composite) cp_parent.getData(String.valueOf(temp_index));
Control[] ctrls = temp_cp.getChildren();
// 获取最小匹配率
Spinner tempMinSp = (Spinner) ctrls[0];
selectionvalue = tempMinSp.getSelection() - 1;
if (selectionvalue < MINRATE) {
MessageDialog.openInformation(tempMinSp.getShell(), Messages.getString("preference.EquivalentPage.msgTitle"), MessageFormat.format(Messages.getString("preference.EquivalentPage.msg1"), MINRATE));
return;
}
Composite new_cp = new Composite(cp_parent, SWT.NONE);
new_cp.setLayoutData(cmpData);
GridLayoutFactory.fillDefaults().margins(0, 0).numColumns(8).equalWidth(false).applyTo(new_cp);
Spinner minSp = new Spinner(new_cp, SWT.BORDER);
minSp.setMinimum(0);
minSp.setMaximum(selectionvalue);
minSp.setIncrement(5);
minSp.setLayoutData(spinnerdata);
minSp.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
selected(e);
}
});
if (tempMinSp.getSelection() - space_Number >= 0) {
minSp.setSelection(tempMinSp.getSelection() - space_Number);
} else {
minSp.setSelection(0);
}
Label perLabel1 = new Label(new_cp, SWT.NONE);
perLabel1.setText("%");
Label waveLabel = new Label(new_cp, SWT.NONE);
waveLabel.setText("~");
Spinner maxSp = new Spinner(new_cp, SWT.BORDER);
maxSp.setSelection(tempMinSp.getSelection() - 1);
maxSp.setEnabled(false);
maxSp.setLayoutData(spinnerdata);
Label perLabel2 = new Label(new_cp, SWT.NONE);
perLabel2.setText("%");
Label phLbl = new Label(new_cp, SWT.NONE);
phLbl.setLayoutData(phLblData);
Text equiTxt = new Text(new_cp, SWT.BORDER);
equiTxt.setLayoutData(equiTxtData);
validEquiTxt(equiTxt);
Composite btnCmp = new Composite(new_cp, SWT.NONE);
GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).applyTo(btnCmp);
GridDataFactory.swtDefaults().hint(btnCmpWidth, SWT.DEFAULT).applyTo(btnCmp);
// 增加加权系数面板的按钮及其事件
Button addBtn = new Button(btnCmp, SWT.NONE);
addBtn.setImage(addImage);
addBtn.setLayoutData(btn_data);
addBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (index < 11) {
addEquiCmp(e, null);
}
}
});
// 删除加权系数的按钮及其事件
Button deleteBtn = new Button(btnCmp, SWT.NONE);
deleteBtn.setImage(deleteimage);
deleteBtn.setLayoutData(btn_data);
deleteBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
deleteEquiCmp(e);
}
});
index = index + 1;
cp_parent.setData(String.valueOf(index), new_cp);
//$NON-NLS-1$
new_cp.setData("index", String.valueOf(index));
// new_cp.pack();
// new_cp.layout();
// cp_parent.layout();
// equiCmp.getParent().layout();
// equiCmp.getParent().getParent().layout();
equiCmp.getParent().getParent().getParent().layout();
}
Aggregations