use of org.eclipse.swt.dnd.Clipboard in project yamcs-studio by yamcs.
the class CloneCommand method getWidgetsFromClipboard.
/**
* Returns a list with widget models that are currently stored on the
* clipboard.
*
* @return a list with widget models or an empty list
*/
@SuppressWarnings("unchecked")
private List<AbstractWidgetModel> getWidgetsFromClipboard() {
Clipboard clipboard = new Clipboard(Display.getCurrent());
List<AbstractWidgetModel> result = (List<AbstractWidgetModel>) clipboard.getContents(OPIWidgetsTransfer.getInstance());
return result;
}
use of org.eclipse.swt.dnd.Clipboard in project cubrid-manager by CUBRID.
the class CopyNodeAction method run.
public void run() {
Object[] selectedObjs = this.getSelectedObj();
if (selectedObjs == null || selectedObjs.length == 0) {
return;
}
StringBuilder names = new StringBuilder();
for (Object obj : selectedObjs) {
if (!(obj instanceof ICubridNode)) {
continue;
}
ICubridNode cubridNode = (ICubridNode) obj;
String type = cubridNode.getType();
if (names.length() > 0) {
names.append(",");
}
if (type.equals(NodeType.TABLE_COLUMN)) {
TableColumn tc = (TableColumn) cubridNode.getAdapter(TableColumn.class);
names.append(tc.getColumnName());
} else {
names.append(cubridNode.getLabel());
}
}
if (names.length() > 0) {
TextTransfer textTransfer = TextTransfer.getInstance();
Clipboard clipboard = CommonUITool.getClipboard();
clipboard.setContents(new Object[] { names.toString() }, new Transfer[] { textTransfer });
}
}
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();
}
}
}
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++;
}
}
}
}
Aggregations