Search in sources :

Example 26 with Clipboard

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 });
    }
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 27 with Clipboard

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();
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) Clipboard(org.eclipse.swt.dnd.Clipboard) SorterComparatorAdapter(bndtools.model.obr.SorterComparatorAdapter) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 28 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 29 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)

Example 30 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)

Aggregations

Clipboard (org.eclipse.swt.dnd.Clipboard)49 TextTransfer (org.eclipse.swt.dnd.TextTransfer)38 Transfer (org.eclipse.swt.dnd.Transfer)13 Point (org.eclipse.swt.graphics.Point)8 TableItem (org.eclipse.swt.widgets.TableItem)8 StyledText (org.eclipse.swt.custom.StyledText)7 Control (org.eclipse.swt.widgets.Control)6 ArrayList (java.util.ArrayList)4 IAction (org.eclipse.jface.action.IAction)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 GridData (org.eclipse.swt.layout.GridData)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Composite (org.eclipse.swt.widgets.Composite)4 Button (org.eclipse.swt.widgets.Button)3 Label (org.eclipse.swt.widgets.Label)3 Shell (org.eclipse.swt.widgets.Shell)3 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)2 ICopiableFromTable (com.cubrid.common.ui.query.editor.ICopiableFromTable)2 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)2