use of org.eclipse.swt.custom.StyledText in project translationstudio8 by heartsome.
the class TmMatchEditDialog method createDialogArea.
/**
* Create contents of the dialog.
* @param parent
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
container.setLayout(new GridLayout(1, false));
Group srcGroup = new Group(container, SWT.NONE);
srcGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
srcGroup.setLayout(new GridLayout(1, false));
String srcGroupTile = Messages.getString("dialog.TmMatchEditDialog.component.src");
srcGroupTile = MessageFormat.format(srcGroupTile, fuzzyResult.getTu().getSource().getLangCode());
srcGroup.setText(srcGroupTile);
srcSegmentViewer = new SegmentViewer(srcGroup, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL, null);
StyledText srcTextControl = srcSegmentViewer.getTextWidget();
srcTextControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
srcTextControl.setLineSpacing(Constants.SEGMENT_LINE_SPACING);
srcTextControl.setLeftMargin(Constants.SEGMENT_LEFT_MARGIN);
srcTextControl.setRightMargin(Constants.SEGMENT_RIGHT_MARGIN);
srcTextControl.setTopMargin(Constants.SEGMENT_TOP_MARGIN);
srcTextControl.setBottomMargin(Constants.SEGMENT_TOP_MARGIN);
srcTextControl.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
Group targetGroup = new Group(container, SWT.NONE);
targetGroup.setLayout(new GridLayout(1, false));
targetGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
String tgtGroupTile = Messages.getString("dialog.TmMatchEditDialog.component.tgt");
tgtGroupTile = MessageFormat.format(tgtGroupTile, fuzzyResult.getTu().getSource().getLangCode());
targetGroup.setText(tgtGroupTile);
tgtSegmentViewer = new SegmentViewer(targetGroup, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL, null);
StyledText tgtTextControl = tgtSegmentViewer.getTextWidget();
tgtTextControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
tgtTextControl.setLineSpacing(Constants.SEGMENT_LINE_SPACING);
tgtTextControl.setLeftMargin(Constants.SEGMENT_LEFT_MARGIN);
tgtTextControl.setRightMargin(Constants.SEGMENT_RIGHT_MARGIN);
tgtTextControl.setTopMargin(Constants.SEGMENT_TOP_MARGIN);
tgtTextControl.setBottomMargin(Constants.SEGMENT_TOP_MARGIN);
tgtTextControl.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
net.heartsome.cat.ts.ui.innertag.tagstyle.TagStyleConfigurator.configure(srcSegmentViewer);
net.heartsome.cat.ts.ui.innertag.tagstyle.TagStyleConfigurator.configure(tgtSegmentViewer);
TmMatchEditorBodyMenu srcMenu = new TmMatchEditorBodyMenu(srcSegmentViewer);
srcSegmentViewer.getTextWidget().setMenu(srcMenu.getBodyMenu());
TmMatchEditorBodyMenu tgtMenu = new TmMatchEditorBodyMenu(tgtSegmentViewer);
tgtSegmentViewer.getTextWidget().setMenu(tgtMenu.getBodyMenu());
loadData();
return container;
}
use of org.eclipse.swt.custom.StyledText in project translationstudio8 by heartsome.
the class XLFEditor method getTextWidgets.
/**
* 获取指定容器下的源文本框和目标文本框组件。第一个为源文本框,第二个为目标文本框。
* @param parent
* 每行的 txtComposite
* @return ;
*/
private StyledText[] getTextWidgets(Composite parent) {
StyledText[] sts = new StyledText[2];
Control[] ctrls = parent.getChildren();
for (Control ctrl : ctrls) {
if (ctrl instanceof StyledText) {
sts[0] = (StyledText) ctrl;
}
if (ctrl instanceof Composite) {
Control[] children = ((Composite) ctrl).getChildren();
for (Control child : children) {
if (child instanceof StyledText) {
sts[1] = (StyledText) child;
return sts;
}
}
}
}
return sts;
}
use of org.eclipse.swt.custom.StyledText in project translationstudio8 by heartsome.
the class XLFEditor method createEditorPart.
/**
* 创建编辑器组件。
*/
private void createEditorPart(Composite parent) {
bottomComposite = new Composite(parent, SWT.BORDER);
GridLayout glBottomCmp = new GridLayout(2, false);
glBottomCmp.marginHeight = HEIGHT_SPACE;
glBottomCmp.marginWidth = WIDTH_SPACE;
glBottomCmp.horizontalSpacing = 0;
glBottomCmp.verticalSpacing = 0;
bottomComposite.setLayout(glBottomCmp);
bottomComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
// 左上方,第一行,第一列,即表头容器
colHeaderComposite = new Composite(bottomComposite, SWT.NONE);
colHeaderComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
createTableHeader(colHeaderComposite);
// 右方,第二列,占两行。
editorVBar = new Slider(bottomComposite, SWT.V_SCROLL | SWT.BORDER);
GridData gdVBar = new GridData(GridData.FILL_VERTICAL);
// 合并两行,使之占满整个自定义表格位置。
gdVBar.verticalSpan = 2;
editorVBar.setLayoutData(gdVBar);
// 左下方,第二行,第一列,编辑器容器
oScrolledComposite = new ScrolledComposite(bottomComposite, SWT.H_SCROLL);
GridLayout glScrolledComposite = new GridLayout(1, false);
glScrolledComposite.horizontalSpacing = 0;
glScrolledComposite.verticalSpacing = 0;
glScrolledComposite.marginHeight = 0;
glScrolledComposite.marginWidth = 0;
oScrolledComposite.setLayout(glScrolledComposite);
oScrolledComposite.setExpandHorizontal(true);
oScrolledComposite.setExpandVertical(true);
oScrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
editorContentComposite = new Composite(oScrolledComposite, SWT.NONE);
GridLayout glEditorContentComposite = new GridLayout(1, true);
glEditorContentComposite.horizontalSpacing = 0;
glEditorContentComposite.verticalSpacing = 0;
glEditorContentComposite.marginHeight = 0;
glEditorContentComposite.marginWidth = 0;
editorContentComposite.setLayout(glEditorContentComposite);
editorContentComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
oScrolledComposite.setContent(editorContentComposite);
// TODO 需换成真实数据
// 初始化编辑器中表格行组件。
txtComposites = new Composite[ROWSOFPAGE];
tgtComposites = new Composite[ROWSOFPAGE];
statusComposites = new Composite[ROWSOFPAGE];
lblRowIndexs = new Label[ROWSOFPAGE];
for (int i = 0; i < ROWSOFPAGE; i++) {
Composite rowComposite = new Composite(editorContentComposite, SWT.NONE);
GridLayout glRowCmp = new GridLayout(2, false);
glRowCmp.marginHeight = 0;
glRowCmp.marginWidth = 0;
glRowCmp.horizontalSpacing = 0;
glRowCmp.verticalSpacing = 0;
rowComposite.setLayout(glRowCmp);
rowComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
lblRowIndexs[i] = new Label(rowComposite, SWT.BORDER);
lblRowIndexs[i].setAlignment(SWT.CENTER);
lblRowIndexs[i].setText(String.valueOf(i + 1));
GridData gdIndex = new GridData(GridData.FILL_VERTICAL);
gdIndex.widthHint = COLUMN_INDEX_WIDTH;
lblRowIndexs[i].setLayoutData(gdIndex);
txtComposites[i] = new Composite(rowComposite, SWT.NONE);
StyledText stSrc = new StyledText(txtComposites[i], SWT.MULTI | SWT.WRAP | SWT.READ_ONLY | SWT.BORDER);
stSrc.setCursor(cursorArrow);
stSrc.setData(DATAKEY_INDEX, i);
stSrc.setText("This is a test." + (i + 1));
GridData gdStSrc = new GridData(GridData.FILL_BOTH);
gdStSrc.minimumHeight = MINIMUM_ROW_HEIGHT;
gdStSrc.grabExcessVerticalSpace = true;
stSrc.setLayoutData(gdStSrc);
stSrc.addModifyListener(textModifyListener);
stSrc.addMouseListener(mouseListener);
stSrc.addKeyListener(keyListener);
stSrc.addMouseTrackListener(mouseTrackListener);
stSrc.setCaretOffset(-1);
tgtComposites[i] = new Composite(txtComposites[i], SWT.NONE);
statusComposites[i] = new Composite(tgtComposites[i], SWT.NONE);
Label lblApprovedStatus = new Label(statusComposites[i], SWT.NONE);
lblApprovedStatus.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
lblApprovedStatus.setToolTipText("翻译单元审批状态:已批准");
lblApprovedStatus.setLayoutData(new GridData(STATUS_FLAG_WIDTH, STATUS_FLAG_HEIGHT));
Label lblTranslatableStatus = new Label(statusComposites[i], SWT.NONE);
lblTranslatableStatus.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
lblTranslatableStatus.setToolTipText("翻译单元可译状态:可译");
lblTranslatableStatus.setLayoutData(new GridData(STATUS_FLAG_WIDTH, STATUS_FLAG_HEIGHT));
Label lblTranslationStatus = new Label(statusComposites[i], SWT.NONE);
lblTranslationStatus.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_CYAN));
lblTranslationStatus.setToolTipText("目标文本段状态:已翻译");
lblTranslationStatus.setLayoutData(new GridData(STATUS_FLAG_WIDTH, STATUS_FLAG_HEIGHT));
StyledText stTgt = new StyledText(tgtComposites[i], SWT.MULTI | SWT.WRAP | SWT.BORDER);
stTgt.setCursor(cursorArrow);
stTgt.setData(DATAKEY_INDEX, i);
GridData gdStTgt = new GridData(GridData.FILL_BOTH);
gdStTgt.minimumHeight = MINIMUM_ROW_HEIGHT;
gdStTgt.grabExcessVerticalSpace = true;
stTgt.setLayoutData(gdStTgt);
stTgt.addModifyListener(textModifyListener);
stTgt.addMouseListener(mouseListener);
stTgt.addKeyListener(keyListener);
stTgt.addMouseTrackListener(mouseTrackListener);
stTgt.setCaretOffset(-1);
}
// 模拟的编辑器数据模型
final List<SimpleModel> models = getModel(1000);
editorVBar.setIncrement(1);
editorVBar.setPageIncrement(ROWSOFPAGE);
editorVBar.setMaximum(models.size());
editorVBar.setMinimum(1);
editorVBar.setThumb(ROWSOFPAGE);
editorVBar.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int y = editorVBar.getSelection();
System.out.println("current y value:" + y);
System.out.println("thumb value:" + editorVBar.getThumb());
refreshContent(models, editorVBar.getSelection());
}
});
// 初始化界面 UI 的显示内容
// refreshContent(models, 1);
// 设置编辑器组件布局
setEditorLayout();
}
use of org.eclipse.swt.custom.StyledText in project translationstudio8 by heartsome.
the class FindReplaceDialog method doReplace.
/**
* 替换 ;
*/
private void doReplace() {
CellRegion activeCellRegion = ActiveCellRegion.getActiveCellRegion();
if (activeCellRegion == null) {
return;
}
StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
if (cellEditor != null) {
StyledText text = cellEditor.getSegmentViewer().getTextWidget();
String sleText = text.getSelectionText();
String findStr = cmbFind.getText();
if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
findStr = findStr.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
findStr = findStr.replaceAll("\\t", Constants.TAB_CHARACTER + "");
findStr = findStr.replaceAll(" ", Constants.SPACE_CHARACTER + "");
}
if (sleText != null && sleText.toLowerCase().equals(findStr.toLowerCase())) {
Point p = text.getSelection();
text.replaceTextRange(p.x, p.y - p.x, cmbReplace.getText());
}
}
}
use of org.eclipse.swt.custom.StyledText in project translationstudio8 by heartsome.
the class CustomMessageDialog method createMessageArea.
@Override
protected Control createMessageArea(Composite composite) {
Image image = getImage();
if (image != null) {
imageLabel = new Label(composite, SWT.NULL);
image.setBackground(imageLabel.getBackground());
imageLabel.setImage(image);
addAccessibleListeners(imageLabel, image);
GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING).applyTo(imageLabel);
}
// create message
if (message != null) {
text = new StyledText(composite, getMessageLabelStyle());
text.setBackground(composite.getBackground());
text.setText(message);
text.setEditable(false);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).hint(convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH), SWT.DEFAULT).applyTo(text);
setStyle();
}
return composite;
}
Aggregations