use of org.eclipse.swt.dnd.TextTransfer in project translationstudio8 by heartsome.
the class SegmentViewer method copy.
/**
* 执行复制时对标记的处理,复制后在OS系统中不能包含标记占位符 ;
*/
private void copy() {
super.doOperation(ITextOperationTarget.COPY);
TextTransfer plainTextTransfer = TextTransfer.getInstance();
XLiffTextTransfer hsTextTransfer = XLiffTextTransfer.getInstance();
Clipboard clipboard = new Clipboard(getTextWidget().getDisplay());
String plainText = (String) clipboard.getContents(plainTextTransfer);
if (plainText == null || plainText.length() == 0) {
return;
}
plainText = plainText.replaceAll(Utils.getLineSeparator(), "\n");
plainText = plainText.replaceAll(Constants.LINE_SEPARATOR_CHARACTER + "", "");
plainText = plainText.replaceAll(Constants.TAB_CHARACTER + "", "\t");
plainText = plainText.replaceAll(Constants.SPACE_CHARACTER + "", " ");
plainText = plainText.replaceAll("", "");
clipboard.clearContents();
Object[] data = new Object[] { PATTERN.matcher(plainText).replaceAll(""), plainText };
Transfer[] types = new Transfer[] { plainTextTransfer, hsTextTransfer };
clipboard.setContents(data, types, DND.CLIPBOARD);
clipboard.dispose();
}
use of org.eclipse.swt.dnd.TextTransfer 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.dnd.TextTransfer in project translationstudio8 by heartsome.
the class GridCopyEnable method copy.
void copy() {
if (focusContent == null || focusContent.equals("")) {
return;
}
if (selection.x != selection.y) {
String plainText = focusContent.substring(selection.x, selection.y);
Object[] data = new Object[] { plainText };
TextTransfer plainTextTransfer = TextTransfer.getInstance();
Transfer[] types = new Transfer[] { plainTextTransfer };
clipboard.setContents(data, types);
}
}
use of org.eclipse.swt.dnd.TextTransfer in project translationstudio8 by heartsome.
the class CopyDataToClipboardSerializer method serialize.
public void serialize() {
final Clipboard clipboard = command.getClipboard();
final String cellDelimeter = command.getCellDelimeter();
final String rowDelimeter = command.getRowDelimeter();
final TextTransfer textTransfer = TextTransfer.getInstance();
final StringBuilder textData = new StringBuilder();
int currentRow = 0;
for (LayerCell[] cells : copiedCells) {
int currentCell = 0;
for (LayerCell cell : cells) {
final String delimeter = ++currentCell < cells.length ? cellDelimeter : "";
if (cell != null) {
textData.append(cell.getDataValue() + delimeter);
} else {
textData.append(delimeter);
}
}
if (++currentRow < copiedCells.length) {
textData.append(rowDelimeter);
}
}
clipboard.setContents(new Object[] { textData.toString() }, new Transfer[] { textTransfer });
}
use of org.eclipse.swt.dnd.TextTransfer in project eclipse.platform.swt by eclipse.
the class ClipboardExample method createTextTransfer.
void createTextTransfer(Composite copyParent, Composite pasteParent) {
// TextTransfer
Label l = new Label(copyParent, SWT.NONE);
// $NON-NLS-1$
l.setText("TextTransfer:");
final Text copyText = new Text(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
copyText.setText("some\nplain\ntext");
GridData data = new GridData(GridData.FILL_BOTH);
data.widthHint = HSIZE;
data.heightHint = VSIZE;
copyText.setLayoutData(data);
Button b = new Button(copyParent, SWT.PUSH);
b.setText("Copy");
b.addSelectionListener(widgetSelectedAdapter(e -> {
String textData = copyText.getText();
if (textData.length() > 0) {
status.setText("");
clipboard.setContents(new Object[] { textData }, new Transfer[] { TextTransfer.getInstance() });
} else {
status.setText("No text to copy");
}
}));
l = new Label(pasteParent, SWT.NONE);
// $NON-NLS-1$
l.setText("TextTransfer:");
final Text pasteText = new Text(pasteParent, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
data = new GridData(GridData.FILL_BOTH);
data.widthHint = HSIZE;
data.heightHint = VSIZE;
pasteText.setLayoutData(data);
b = new Button(pasteParent, SWT.PUSH);
b.setText("Paste");
b.addSelectionListener(widgetSelectedAdapter(e -> {
String textData = (String) clipboard.getContents(TextTransfer.getInstance());
if (textData != null && textData.length() > 0) {
status.setText("");
pasteText.setText("begin paste>" + textData + "<end paste");
} else {
status.setText("No text to paste");
}
}));
}
Aggregations