Search in sources :

Example 41 with Clipboard

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;
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) List(java.util.List) LinkedList(java.util.LinkedList) Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 42 with Clipboard

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 });
    }
}
Also used : ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Clipboard(org.eclipse.swt.dnd.Clipboard) TableColumn(com.cubrid.cubridmanager.core.cubrid.table.model.TableColumn) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 43 with Clipboard

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();
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) BadLocationException(org.eclipse.jface.text.BadLocationException) InnerTag(net.heartsome.cat.common.ui.innertag.InnerTag) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Clipboard(org.eclipse.swt.dnd.Clipboard)

Example 44 with Clipboard

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();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) ImageData(org.eclipse.swt.graphics.ImageData) Clipboard(org.eclipse.swt.dnd.Clipboard) Image(org.eclipse.swt.graphics.Image) Display(org.eclipse.swt.widgets.Display)

Example 45 with Clipboard

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++;
            }
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) Clipboard(org.eclipse.swt.dnd.Clipboard) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Aggregations

Clipboard (org.eclipse.swt.dnd.Clipboard)73 TextTransfer (org.eclipse.swt.dnd.TextTransfer)50 Transfer (org.eclipse.swt.dnd.Transfer)19 Point (org.eclipse.swt.graphics.Point)12 StyledText (org.eclipse.swt.custom.StyledText)8 Composite (org.eclipse.swt.widgets.Composite)7 Display (org.eclipse.swt.widgets.Display)7 IAction (org.eclipse.jface.action.IAction)6 ISelection (org.eclipse.jface.viewers.ISelection)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 Control (org.eclipse.swt.widgets.Control)6 TableItem (org.eclipse.swt.widgets.TableItem)6 ArrayList (java.util.ArrayList)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 GridData (org.eclipse.swt.layout.GridData)5 Event (org.eclipse.swt.widgets.Event)4 Shell (org.eclipse.swt.widgets.Shell)4 Rectangle (org.eclipse.swt.graphics.Rectangle)3