use of org.eclipse.swt.custom.StyledText in project translationstudio8 by heartsome.
the class GetActiveKeyDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite tparent = (Composite) super.createDialogArea(parent);
GridLayout layout = new GridLayout();
layout.marginWidth = 10;
layout.marginTop = 10;
tparent.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, true).applyTo(tparent);
Composite compNav = new Composite(tparent, SWT.NONE);
GridLayout navLayout = new GridLayout();
compNav.setLayout(navLayout);
createNavigation(compNav);
Group groupActivekey = new Group(tparent, SWT.NONE);
groupActivekey.setText(Messages.getString("license.GetActiveKeyDialog.activekey"));
GridDataFactory.fillDefaults().grab(true, true).applyTo(groupActivekey);
GridLayout layoutGroup = new GridLayout(2, false);
layoutGroup.marginWidth = 5;
layoutGroup.marginHeight = 20;
groupActivekey.setLayout(layoutGroup);
StyledText text = new StyledText(groupActivekey, SWT.WRAP | SWT.READ_ONLY);
text.setBackground(text.getParent().getBackground());
text.setText(Messages.getString("license.GetActiveKeyDialog.activemessage"));
GridData dataText = new GridData();
dataText.horizontalSpan = 2;
dataText.widthHint = 470;
text.setLayoutData(dataText);
int start = Messages.getString("license.GetActiveKeyDialog.activemessage").indexOf(Messages.getString("license.GetActiveKeyDialog.ts"));
int length = Messages.getString("license.GetActiveKeyDialog.ts").length();
StyleRange styleRange = new StyleRange();
styleRange.start = start;
styleRange.length = length;
styleRange.fontStyle = SWT.BOLD;
styleRange.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
text.setStyleRange(styleRange);
Label label = new Label(groupActivekey, SWT.WRAP | SWT.NONE);
label.setText(Messages.getString("license.GetActiveKeyDialog.activemessage1"));
GridDataFactory.fillDefaults().span(2, 1).applyTo(label);
textActivekey = new Text(groupActivekey, SWT.MULTI | SWT.WRAP);
textActivekey.setEditable(false);
textActivekey.setText(activekey);
textActivekey.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 150).applyTo(textActivekey);
Button btnCopy = new Button(groupActivekey, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.END).applyTo(btnCopy);
btnCopy.setImage(Activator.getImageDescriptor("images/help/copy.png").createImage());
btnCopy.setToolTipText(Messages.getString("license.GetActiveKeyDialog.copytoclipboard"));
btnCopy.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
Clipboard cb = new Clipboard(Display.getCurrent());
String textData = textActivekey.getText();
TextTransfer textTransfer = TextTransfer.getInstance();
cb.setContents(new Object[] { textData }, new Transfer[] { textTransfer });
}
});
return tparent;
}
use of org.eclipse.swt.custom.StyledText in project translationstudio8 by heartsome.
the class XLIFFEditorActionHandler method addTextViewer.
/**
* Add a <code>Text</code> control to the handler so that the Cut, Copy, Paste, Delete, Undo, Redo and Select All
* actions are redirected to it when active.
* @param viewer
* the inline <code>Text</code> control
*/
public void addTextViewer(SegmentViewer viewer) {
if (viewer == null) {
return;
}
this.viewer = viewer;
StyledText textControl = viewer.getTextWidget();
// 移除 StyledText 默认绑定的 Delete 键。解决“按下 Delete 键后会删除两次”的 Bug。
textControl.setKeyBinding(SWT.DEL, SWT.NULL);
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
updateActionsEnableState();
}
});
textControl.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
updateActionsEnableState();
}
});
actionBar.setGlobalActionHandler(ActionFactory.CUT.getId(), textCutAction);
actionBar.setGlobalActionHandler(ActionFactory.COPY.getId(), textCopyAction);
actionBar.setGlobalActionHandler(ActionFactory.PASTE.getId(), textPasteAction);
actionBar.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), textSelectAllAction);
actionBar.setGlobalActionHandler(ActionFactory.DELETE.getId(), textDeleteAction);
actionBar.setGlobalActionHandler(ActionFactory.UNDO.getId(), textUndoAction);
actionBar.setGlobalActionHandler(ActionFactory.REDO.getId(), textRedoAction);
if (textControl.isFocusControl()) {
updateActionsEnableState();
} else {
actionBar.updateActionBars();
}
}
use of org.eclipse.swt.custom.StyledText in project translationstudio8 by heartsome.
the class DeleteToEndOrToTagHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof XLIFFEditorImplWithNatTable) {
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
String deleteType = event.getParameter("DeleteContent");
if (deleteType == null) {
return null;
}
StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
if (cellEditor == null || !cellEditor.getCellType().equals(NatTableConstant.TARGET)) {
return null;
}
if (!cellEditor.isEditable()) {
// cellEditor.showUneditableMessage();
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteToEndOrToTagHandler.msgTitle"), cellEditor.getEditableManager().getUneditableMessage());
return null;
}
StyledText styledText = cellEditor.getSegmentViewer().getTextWidget();
int offset = styledText.getCaretOffset();
Point p = styledText.getSelection();
if (p != null) {
int len = styledText.getText().length();
String preText = "";
String nextText = "";
SegmentViewer viewer = (SegmentViewer) cellEditor.getSegmentViewer();
if (offset > 0) {
preText = styledText.getText(0, offset - 1);
preText = viewer.convertDisplayTextToOriginalText(preText);
}
// 删除标记前所有内容
if (deleteType.equals("DeleteToTag") && offset < len) {
nextText = styledText.getText(offset, len - 1);
Matcher matcher = PATTERN.matcher(nextText);
if (matcher.find()) {
int index = matcher.start();
nextText = nextText.substring(index);
} else {
// 选择删除标记前所有内容时,如果当前光标之后没有标记,则删除光标之后的所有内容
nextText = "";
}
}
nextText = viewer.convertDisplayTextToOriginalText(nextText);
String newText = preText + nextText;
Hashtable<String, String> map = new Hashtable<String, String>();
// Fix Bug #2883 删除光标后内容--同时选择多个文本段进行操作时,界面出错 By Jason
// for (String rowId : xliffEditor.getSelectedRowIds()) {
// map.put(rowId, newText);
// }
int index = cellEditor.getRowIndex();
String rowId = xliffEditor.getXLFHandler().getRowId(index);
map.put(rowId, newText);
xliffEditor.updateSegments(map, xliffEditor.getTgtColumnIndex(), null, null);
// 定位光标
styledText.setCaretOffset(offset);
}
}
return null;
}
use of org.eclipse.swt.custom.StyledText in project otertool by wuntee.
the class SmaliController method saveTab.
public void saveTab(CTabItem tab) throws IOException {
if ((Boolean) tab.getData(MODIFIED) == true) {
String file = (String) tab.getData(FILENAME);
logger.debug("Saving file: " + file);
BufferedWriter out = new BufferedWriter(new FileWriter(file));
StyledText styledText = (StyledText) tab.getData(StyledText.class.getName());
out.write(styledText.getText());
out.flush();
out.close();
// Change the tab object to show it has been saved
tab.setData(ORIGINAL_TEXT, styledText.getText());
tab.setData(MODIFIED, false);
tab.setText(tab.getText().substring(2));
}
}
use of org.eclipse.swt.custom.StyledText in project otertool by wuntee.
the class CTabItemWithHexViewer method createEditor.
private void createEditor() {
CTabItem tabItem = new CTabItem(parent, style);
tabItem.setText(name);
Composite composite = new Composite(parent, SWT.NONE);
tabItem.setControl(composite);
GridLayout gl_composite = new GridLayout(4, false);
gl_composite.marginWidth = 0;
gl_composite.verticalSpacing = 0;
gl_composite.marginHeight = 0;
gl_composite.horizontalSpacing = 0;
composite.setLayout(gl_composite);
counter = new StyledText(composite, SWT.BORDER | SWT.READ_ONLY);
//counter.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
counter.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true, 1, 1));
counter.setFont(SWTResourceManager.getFont("Courier New", 11, SWT.NORMAL));
addListeners(counter);
hexContent = new StyledText(composite, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL);
hexContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
hexContent.setFont(SWTResourceManager.getFont("Courier New", 11, SWT.NORMAL));
addListeners(hexContent);
binContent = new StyledText(composite, SWT.BORDER | SWT.READ_ONLY);
binContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
//binContent.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, true, 1, 1));
binContent.setFont(SWTResourceManager.getFont("Courier New", 11, SWT.NORMAL));
addListeners(binContent);
parent.setSelection(tabItem);
}
Aggregations