use of org.eclipse.swt.dnd.Clipboard in project cubrid-manager by CUBRID.
the class CommonUITool method copyContentToClipboard.
/**
* Copy the styled text conent to clipboard
*
* @param text the StyledText object
*/
public static void copyContentToClipboard(StyledText text) {
TextTransfer textTransfer = TextTransfer.getInstance();
Clipboard clipboard = CommonUITool.getClipboard();
String data = text.getSelectionText();
if (data == null || data.trim().length() == 0) {
data = text.getText();
}
if (data != null && !data.equals("")) {
clipboard.setContents(new Object[] { data }, new Transfer[] { textTransfer });
}
}
use of org.eclipse.swt.dnd.Clipboard in project bndtools by bndtools.
the class ResolutionFailurePanel method copyUnresolvedToClipboard.
// private void switchFailureViewMode() {
// Object input = unresolvedViewer.getInput();
// unresolvedViewer.setInput(null);
// setFailureViewMode();
// unresolvedViewer.setInput(input);
// unresolvedViewer.expandToLevel(2);
// }
private void copyUnresolvedToClipboard() {
StringBuilder builder = new StringBuilder();
Object input = unresolvedViewer.getInput();
if (input == null)
return;
ITreeContentProvider contentProvider = (ITreeContentProvider) unresolvedViewer.getContentProvider();
Object[] roots = contentProvider.getElements(input);
ViewerSorter sorter = unresolvedViewer.getSorter();
if (sorter != null)
Arrays.sort(roots, new SorterComparatorAdapter(unresolvedViewer, sorter));
for (Object root : roots) {
appendLabels(root, contentProvider, builder, 0);
}
/*
* TODO if (result != null) { StringBuilder buffer = new StringBuilder(); List<Reason> unresolved =
* result.getUnresolved(); if (unresolved != null) for (Iterator<Reason> iter = unresolved.iterator();
* iter.hasNext(); ) { Reason reason = iter.next();
* buffer.append(unresolvedLabelProvider.getLabel(reason.getRequirement ()).getString()); buffer.append('\t');
* buffer.append(unresolvedLabelProvider .getLabel(reason.getResource())); if (iter.hasNext())
* buffer.append('\n'); } }
*/
Clipboard clipboard = new Clipboard(composite.getDisplay());
TextTransfer transfer = TextTransfer.getInstance();
clipboard.setContents(new Object[] { builder.toString() }, new Transfer[] { transfer });
clipboard.dispose();
}
use of org.eclipse.swt.dnd.Clipboard in project cogtool by cogtool.
the class WindowsImageTransfer method main.
public static void main(String[] args) throws Exception {
Display display = new Display();
Shell shell = new Shell(display);
Clipboard c = new Clipboard(display);
System.out.println("types on the clipboard: " + Arrays.asList(c.getAvailableTypeNames()));
Object o = c.getContents(WindowsImageTransfer.getInstance());
ImageData d = (ImageData) o;
if (d == null) {
System.out.println("no image found on clipboard. try hitting the printscreen key, or using MS Paint to put an image on the clipboard.");
return;
}
//Change what's on the clipboard to show we can also put images on the
// clipboard.
c.setContents(new Object[] { "howdy" }, new Transfer[] { TextTransfer.getInstance() });
System.out.println("types on the clipboard: " + Arrays.asList(c.getAvailableTypeNames()));
//now put the ImageData back onto the clipboard.
c.setContents(new Object[] { d }, new Transfer[] { WindowsImageTransfer.getInstance() });
System.out.println("types on the clipboard: " + Arrays.asList(c.getAvailableTypeNames()));
//now read the CF_DIB (ImageData) back off the clipboard.
// and display it by using it as the image for the button.
ImageData imgData = (ImageData) c.getContents(WindowsImageTransfer.getInstance());
Image img = new Image(display, imgData);
Button button = new Button(shell, SWT.NONE);
button.setImage(img);
shell.pack();
button.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
button.dispose();
}
use of org.eclipse.swt.dnd.Clipboard in project translationstudio8 by heartsome.
the class DefaultCCPStrategy method paste.
/**
* Paste pastes textual context starting at the focussed cell (does not use the selection by now). Uses TAB and
* semicolon as delimiters (Excel uses TAB, semicolon for pasting csv).
*
* @param table the jaret table
*/
public void paste(JaretTable table) {
Clipboard cb = getClipboard();
TextTransfer textTransfer = TextTransfer.getInstance();
Object content = cb.getContents(textTransfer);
if (content != null) {
if (content instanceof String) {
String string = (String) content;
List<String> lines = new ArrayList<String>();
StringTokenizer tokenizer = new StringTokenizer(string, "\n");
while (tokenizer.hasMoreTokens()) {
lines.add(tokenizer.nextToken());
}
Point focus = table.getFocussedCellIdx();
if (focus == null) {
table.setFocus();
focus = table.getFocussedCellIdx();
}
int lineOff = 0;
for (String line : lines) {
tokenizer = new StringTokenizer(line, PASTE_DELIMITERS, true);
int colOff = 0;
String last = null;
while (tokenizer.hasMoreTokens()) {
String value = tokenizer.nextToken();
boolean ignore = false;
if (PASTE_DELIMITERS.indexOf(value) != -1) {
// delimiter
if (last != null && last.equals(value)) {
value = "";
} else {
ignore = true;
}
}
if (!ignore) {
try {
table.setValue(focus.x + colOff, focus.y + lineOff, value);
} catch (Exception e) {
// silently ignore -- this can happen
}
colOff++;
}
last = value;
}
lineOff++;
}
}
}
}
use of org.eclipse.swt.dnd.Clipboard in project translationstudio8 by heartsome.
the class SegmentViewer method parse.
/**
* 执行粘贴前对标记的处理 ;
*/
private void parse() {
Clipboard clipboard = null;
try {
if (getTextWidget().isDisposed()) {
return;
}
clipboard = new Clipboard(getTextWidget().getDisplay());
XLiffTextTransfer hsTextTransfer = XLiffTextTransfer.getInstance();
String hsText = (String) clipboard.getContents(hsTextTransfer);
String osText = (String) clipboard.getContents(TextTransfer.getInstance());
if (hsText == null || hsText.length() == 0) {
if (osText == null || osText.length() == 0) {
return;
}
super.doOperation(ITextOperationTarget.PASTE);
return;
}
String clearedTagText = hsText;
String selText = getTextWidget().getSelectionText();
if (selText.equals(hsText)) {
return;
}
if (getTextWidget().getSelectionCount() != getTextWidget().getText().length()) {
// 过滤掉系统剪切板中的标记。
clearedTagText = filterInnerTag(hsText);
} else {
StringBuffer bf = new StringBuffer(hsText);
Matcher matcher = PATTERN.matcher(hsText);
List<String> needRemove = new ArrayList<String>();
while (matcher.find()) {
String placeHolder = matcher.group();
InnerTag tag = InnerTagUtil.getInnerTag(innerTagCacheList, placeHolder);
if (tag == null) {
needRemove.add(placeHolder);
}
}
clearedTagText = bf.toString();
for (String r : needRemove) {
clearedTagText = clearedTagText.replaceAll(r, "");
}
}
if (clearedTagText == null || clearedTagText.length() == 0) {
return;
}
if (clearedTagText.equals(osText)) {
super.doOperation(ITextOperationTarget.PASTE);
return;
}
Object[] data = new Object[] { clearedTagText, hsText };
Transfer[] types = new Transfer[] { TextTransfer.getInstance(), hsTextTransfer };
try {
clipboard.setContents(data, types);
} catch (Exception e) {
e.printStackTrace();
}
super.doOperation(ITextOperationTarget.PASTE);
data = new Object[] { osText, hsText };
try {
clipboard.setContents(data, types);
} catch (Exception e) {
e.printStackTrace();
}
} finally {
if (clipboard != null && !clipboard.isDisposed()) {
clipboard.dispose();
}
}
}
Aggregations