Java 类java.awt.datatransfer.Clipboard 实例源码

项目:incubator-netbeans    文件:MatchingObjectNode.java   
@Override
public void actionPerformed(ActionEvent e) {
    File f = FileUtil.toFile(
            matchingObject.getFileObject());
    if (f != null) {
        String path = f.getPath();
        Clipboard clipboard = Lookup.getDefault().lookup(
                ExClipboard.class);
        if (clipboard == null) {
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            if (toolkit != null) {
                clipboard = toolkit.getSystemClipboard();
            }
        }
        if (clipboard != null) {
            StringSelection strSel = new StringSelection(path);
            clipboard.setContents(strSel, null);
        }
    }
}
项目:incubator-netbeans    文件:NbClipboardTimeoutTest.java   
private static void makeSureSystemClipboardContainsString(
    Clipboard sys, NbClipboard clip
) throws InterruptedException {
    final CountDownLatch wait = new CountDownLatch(1);
    class FL implements FlavorListener {
        @Override
        public void flavorsChanged(FlavorEvent e) {
            wait.countDown();
        }
    }
    FL fl = new FL();
    sys.addFlavorListener(fl);
    StringSelection ss = new StringSelection("empty");
    clip.setContents(ss, ss);
    wait.await();
}
项目:incubator-netbeans    文件:NbClipboardNativeTest.java   
public void testClipboard() throws Exception {
    MockServices.setServices(Cnv.class);
    Clipboard c = Lookup.getDefault().lookup(Clipboard.class);
    ExClipboard ec = Lookup.getDefault().lookup(ExClipboard.class);
    assertEquals("Clipboard == ExClipboard", c, ec);
    assertNotNull(Lookup.getDefault().lookup(ExClipboard.Convertor.class));
    assertEquals(Cnv.class, Lookup.getDefault().lookup(ExClipboard.Convertor.class).getClass());
    c.setContents(new ExTransferable.Single(DataFlavor.stringFlavor) {
        protected Object getData() throws IOException, UnsupportedFlavorException {
            return "17";
        }
    }, null);
    Transferable t = c.getContents(null);
    assertTrue("still supports stringFlavor", t.isDataFlavorSupported(DataFlavor.stringFlavor));
    assertEquals("correct string in clipboard", "17", t.getTransferData(DataFlavor.stringFlavor));
    assertTrue("support Integer too", t.isDataFlavorSupported(MYFLAV));
    assertEquals("correct Integer", new Integer(17), t.getTransferData(MYFLAV));
}
项目:incubator-netbeans    文件:NbClipboardNativeTest.java   
public void testOwnershipLostEvent() throws Exception {
    final int[] holder = new int[] { 0 };
    ExTransferable transferable = ExTransferable.create (new StringSelection("A"));

    // listen on ownershipLost
    transferable.addTransferListener (new TransferListener () {
        public void accepted (int action) {}
        public void rejected () {}
        public void ownershipLost () { holder[0]++; }
    });

    Clipboard c = Lookup.getDefault().lookup(Clipboard.class);

    c.setContents(transferable, null);

    assertTrue("Still has ownership", holder[0] == 0);

    c.setContents(new StringSelection("B"), null);

    assertTrue("Exactly one ownershipLost event have happened.", holder[0] == 1);
}
项目:geomapapp    文件:TableDB.java   
void paste() throws IOException {
    Clipboard clip = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable contents = clip.getContents(this);
    DataFlavor[] flavors = contents.getTransferDataFlavors();
    for( int k=0 ; k<flavors.length ; k++) {
        try {
            if( flavors[k].getHumanPresentableName().indexOf("html")>=0 )continue;
            BufferedReader in = new BufferedReader(
                flavors[k].getReaderForText(contents));
    System.out.println( flavors[k].getHumanPresentableName());
            read( in );
            break;
        } catch( UnsupportedFlavorException e) {
        }
    }
}
项目:incubator-netbeans    文件:DebuggingActionsProvider.java   
static void stackToCLBD(List<JPDAThread> threads) {
    StringBuffer frameStr = new StringBuffer(512);
    for (JPDAThread t : threads) {
        if (frameStr.length() > 0) {
            frameStr.append('\n');
        }
        frameStr.append("\"");
        frameStr.append(t.getName());
        frameStr.append("\"\n");
        appendStackInfo(frameStr, t);
    }
    Clipboard systemClipboard = getClipboard();
    Transferable transferableText =
            new StringSelection(frameStr.toString());
    systemClipboard.setContents(
            transferableText,
            null);
}
项目:Yass    文件:YassTable.java   
/**
 * Description of the Method
 *
 * @param before Description of the Parameter
 * @return Description of the Return Value
 */
public int insertRows(boolean before) {
    int startRow = before ? getSelectionModel().getMinSelectionIndex()
            : getSelectionModel().getMaxSelectionIndex();
    if (startRow < 0) {
        return 0;
    }
    if (startRow == 0) {
        before = false;
    }

    String trstring = null;
    try {
        Clipboard system = Toolkit.getDefaultToolkit().getSystemClipboard();
        trstring = (String) (system.getContents(this)
                .getTransferData(DataFlavor.stringFlavor));
    } catch (Exception e) {
        return 0;
    }
    ;

    return insertRowsAt(trstring, startRow, before);
}
项目:incubator-netbeans    文件:OutlineView.java   
private void doCopy(ExplorerManager em) {
    Node[] sel = em.getSelectedNodes();
    Transferable trans = ExplorerActionsImpl.getTransferableOwner(sel, true);

    Transferable ot = new OutlineTransferHandler().createOutlineTransferable();
    if (trans != null) {
        if (ot != null) {
            trans = new TextAddedTransferable(trans, ot);
        }
    } else {
        trans = ot;
    }

    if (trans != null) {
        Clipboard clipboard = ExplorerActionsImpl.getClipboard();
        if (clipboard != null) {
            clipboard.setContents(trans, new StringSelection("")); // NOI18N
        }
    }                        
}
项目:Logisim    文件:Clip.java   
public void copy() {
    Caret caret = editor.getCaret();
    long p0 = caret.getMark();
    long p1 = caret.getDot();
    if (p0 < 0 || p1 < 0)
        return;
    if (p0 > p1) {
        long t = p0;
        p0 = p1;
        p1 = t;
    }
    p1++;

    int[] data = new int[(int) (p1 - p0)];
    HexModel model = editor.getModel();
    for (long i = p0; i < p1; i++) {
        data[(int) (i - p0)] = model.get(i);
    }

    Clipboard clip = editor.getToolkit().getSystemClipboard();
    clip.setContents(new Data(data), this);
}
项目:incubator-netbeans    文件:CopyPathToClipboardAction.java   
/**
 * Sets the clipboard context in textual-format.
 *
 * @param content
 */
@Messages({
    "# {0} - copied file path",
    "CTL_Status_CopyToClipboardSingle=Copy to Clipboard: {0}",
    "# {0} - number of copied paths",
    "CTL_Status_CopyToClipboardMulti={0} paths were copied to clipboard"
})
private void setClipboardContents(String content, int items) {
    Clipboard clipboard = Lookup.getDefault().lookup(ExClipboard.class);
    if (clipboard == null) {
        clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    }
    if (clipboard != null) {
        String statusText = items > 1
                ? Bundle.CTL_Status_CopyToClipboardMulti(items)
                : Bundle.CTL_Status_CopyToClipboardSingle(content);
        StatusDisplayer.getDefault().setStatusText(statusText);
        clipboard.setContents(new StringSelection(content), null);
    }
}
项目:vexillo    文件:CopySVGMenuItem.java   
public CopySVGMenuItem(final FlagFrame frame) {
    setText("Copy SVG");
    if (!OSUtils.isMacOS()) setMnemonic(KeyEvent.VK_S);
    setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputUtils.META_SHIFT_MASK));
    if (frame == null) {
        setEnabled(false);
    } else {
        addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                SVGExporter s = new SVGExporter(frame.getFlagFile(), frame.getFlag());
                String svg = s.exportToString(frame.getViewerWidth(), frame.getViewerHeight(), frame.getGlaze());
                StringSelection ss = new StringSelection(svg);
                Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
                cb.setContents(ss, ss);
            }
        });
    }
}
项目:Neukoelln_SER316    文件:HTMLEditor.java   
private void doPaste() {
    Clipboard clip =
        java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
    try {
        Transferable content = clip.getContents(this);
        if (content == null)
            return;
        String txt =
            content
                .getTransferData(new DataFlavor(String.class, "String"))
                .toString();
        document.replace(
            editor.getSelectionStart(),
            editor.getSelectionEnd() - editor.getSelectionStart(),
            txt,
            editorKit.getInputAttributes());
        //editor.replaceSelection(content.getTransferData(new
        // DataFlavor(String.class, "String")).toString());
        //editor.paste();
        //insertHTML(content.getTransferData(new DataFlavor(String.class,
        // "String")).toString(), editor.getCaretPosition());
        /*
         * Element el =
         * document.getParagraphElement(editor.getCaretPosition());
         * insertTextInElement(el, content.getTransferData(new
         * DataFlavor(String.class, "String")).toString(),
         */

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
项目:incubator-netbeans    文件:NbClipboard.java   
NbClipboard( Clipboard systemClipboard ) {
    super("NBClipboard");   // NOI18N
    this.systemClipboard = systemClipboard;

    result = Lookup.getDefault().lookupResult(ExClipboard.Convertor.class);
    result.addLookupListener(this);

    systemClipboard.addFlavorListener(this);

    resultChanged(null);

    if (System.getProperty("netbeans.slow.system.clipboard.hack") != null) {
        slowSystemClipboard = Boolean.getBoolean("netbeans.slow.system.clipboard.hack"); // NOI18N
    } else if (Utilities.isMac()) {
        slowSystemClipboard = false;
    }
    else {
        slowSystemClipboard = true;
    }




    if (System.getProperty("sun.awt.datatransfer.timeout") == null) { // NOI18N
        System.setProperty("sun.awt.datatransfer.timeout", "1000"); // NOI18N
    }
    if (slowSystemClipboard) {
        Toolkit.getDefaultToolkit().addAWTEventListener(
            this, AWTEvent.WINDOW_EVENT_MASK);
    }
}
项目:openjdk-jdk10    文件:XToolkit.java   
@Override
public Clipboard getSystemSelection() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
    }
    synchronized (this) {
        if (selection == null) {
            selection = new XClipboard("Selection", "PRIMARY");
        }
    }
    return selection;
}
项目:SER316-Munich    文件:HTMLEditor.java   
private void doCopy() {
    /*
     * java.awt.datatransfer.Clipboard clip =
     * java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); try {
     * String text = editor.getSelectedText();
     * //.getText(editor.getSelectionStart(),
     * editor.getSelectionEnd()-editor.getSelectionStart());
     * clip.setContents(new java.awt.datatransfer.StringSelection(text),
     * null); } catch (Exception e) { e.printStackTrace();
     */
    Element el = document.getParagraphElement(editor.getSelectionStart());
    if (el.getName().toUpperCase().equals("P-IMPLIED"))
        el = el.getParentElement();
    String elName = el.getName();
    StringWriter sw = new StringWriter();
    String copy;
    java.awt.datatransfer.Clipboard clip =
        java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
    try {
        editorKit.write(
            sw,
            document,
            editor.getSelectionStart(),
            editor.getSelectionEnd() - editor.getSelectionStart());
        copy = sw.toString();
        copy = copy.split("<" + elName + "(.*?)>")[1];
        copy = copy.split("</" + elName + ">")[0];
        clip.setContents(
            new java.awt.datatransfer.StringSelection(copy.trim()),
            null);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
项目:incubator-netbeans    文件:DebuggingActionsProvider.java   
static Clipboard getClipboard() {
    Clipboard clipboard = org.openide.util.Lookup.getDefault().lookup(Clipboard.class);
    if (clipboard == null) {
        clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    }
    return clipboard;
}
项目:incubator-netbeans    文件:CallStackActionsProvider.java   
private void stackToCLBD() {
    JPDAThread t = debugger.getCurrentThread();
    if (t == null) return ;
    StringBuffer frameStr = new StringBuffer(50);
    DebuggingActionsProvider.appendStackInfo(frameStr, t);
    Clipboard systemClipboard = DebuggingActionsProvider.getClipboard();
    Transferable transferableText =
            new StringSelection(frameStr.toString());
    systemClipboard.setContents(
            transferableText,
            null);
}
项目:incubator-netbeans    文件:EditorCaret.java   
private void updateSystemSelection() {
    if(component == null) return;
    Clipboard clip = null;
    try {
        clip = component.getToolkit().getSystemSelection();
    } catch (SecurityException ex) {
        // XXX: ignore for now, there is no ExClipboard for SystemSelection Clipboard
    }
    if(clip != null) {
        StringBuilder builder = new StringBuilder();
        boolean first = true;
        List<CaretInfo> sortedCarets = getSortedCarets();
        for (CaretInfo caret : sortedCarets) {
            CaretItem caretItem = caret.getCaretItem();
            if(caretItem.isSelection()) {
                if(!first) {
                    builder.append("\n");
                } else {
                    first = false;
                }
                builder.append(getSelectedText(caretItem));
            }
        }
        if(builder.length() > 0) {
            clip.setContents(new java.awt.datatransfer.StringSelection(builder.toString()), null);
        }
    }
}
项目:jaer    文件:SpikeSoundSignalHandler.java   
public void do_Copy_trace() {
    if (spikeTimesRecord != null) {
        StringBuilder sb = new StringBuilder();
        sb.append(recordedMinTime+"\t0\n");
        for (int i : spikeTimesRecord) {
            sb.append(i+"\t0\n"+i+"\t100\n"+i+"\t0\n");
        }
        sb.append(recordedMaxTime+"\t0\n");
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Clipboard clipboard = toolkit.getSystemClipboard();
        StringSelection strSel = new StringSelection(sb.toString());
        clipboard.setContents(strSel, null);
    }
}
项目:incubator-netbeans    文件:ExplorerActionsImpl.java   
/** If our clipboard is not found return the default system clipboard. */
public static Clipboard getClipboard() {
    if (GraphicsEnvironment.isHeadless()) {
        return null;
    }
    Clipboard c = Lookup.getDefault().lookup(Clipboard.class);

    if (c == null) {
        c = Toolkit.getDefaultToolkit().getSystemClipboard();
    }

    return c;
}
项目:incubator-netbeans    文件:ExplorerActionsImpl.java   
private void registerListener() {
    if (flavL == null) {
        Clipboard c = getClipboard();
        if (c != null) {
            flavL = WeakListeners.create(FlavorListener.class, this, c);
            c.addFlavorListener(flavL);
        }
    }
}
项目:incubator-netbeans    文件:DragDropUtilities.java   
/** If our clipboard is not found return the default system clipboard. */
private static Clipboard getClipboard() {
    Clipboard c = Lookup.getDefault().lookup(Clipboard.class);

    if (c == null) {
        c = Toolkit.getDefaultToolkit().getSystemClipboard();
    }

    return c;
}
项目:incubator-netbeans    文件:UI.java   
private static Clipboard getClipboard() {
    Clipboard clipboard = Lookup.getDefault().lookup(ExClipboard.class);

    if (clipboard == null) {
        clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    }
    return clipboard;
}
项目:SER316-Ingolstadt    文件:HTMLEditor.java   
private void doCopy() {
    /*
     * java.awt.datatransfer.Clipboard clip =
     * java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); try {
     * String text = editor.getSelectedText();
     * //.getText(editor.getSelectionStart(),
     * editor.getSelectionEnd()-editor.getSelectionStart());
     * clip.setContents(new java.awt.datatransfer.StringSelection(text),
     * null); } catch (Exception e) { e.printStackTrace();
     */
    Element el = document.getParagraphElement(editor.getSelectionStart());
    if (el.getName().toUpperCase().equals("P-IMPLIED"))
        el = el.getParentElement();
    String elName = el.getName();
    StringWriter sw = new StringWriter();
    String copy;
    java.awt.datatransfer.Clipboard clip =
        java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
    try {
        editorKit.write(
            sw,
            document,
            editor.getSelectionStart(),
            editor.getSelectionEnd() - editor.getSelectionStart());
        copy = sw.toString();
        copy = copy.split("<" + elName + "(.*?)>")[1];
        copy = copy.split("</" + elName + ">")[0];
        clip.setContents(
            new java.awt.datatransfer.StringSelection(copy.trim()),
            null);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
项目:OpenJSharp    文件:WToolkit.java   
@Override
public Clipboard getSystemClipboard() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
    }
    synchronized (this) {
        if (clipboard == null) {
            clipboard = new WClipboard();
        }
    }
    return clipboard;
}
项目:incubator-netbeans    文件:Terminal.java   
private ActiveTerm createActiveTerminal() {
Clipboard aSystemClipboard = Lookup.getDefault().lookup(Clipboard.class);
if (aSystemClipboard == null) {
    aSystemClipboard = getToolkit().getSystemClipboard();
}
return new MyActiveTerm(aSystemClipboard);
   }
项目:komodoGUI    文件:AddressBookPanel.java   
public void actionPerformed(ActionEvent e) {
    int row = table.getSelectedRow();
    if (row < 0)
        return;
    AddressBookEntry entry = entries.get(row);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(new StringSelection(entry.address), null);
}
项目:Sikulix2tesseract    文件:ImageHelper.java   
/**
 * Gets an image from Clipboard.
 *
 * @return image
 */
public static Image getClipboardImage() {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    try {
        return (Image) clipboard.getData(DataFlavor.imageFlavor);
    } catch (Exception e) {
        return null;
    }
}
项目:SER316-Aachen    文件:HTMLEditor.java   
private void doPaste() {
    Clipboard clip =
        java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
    try {
        Transferable content = clip.getContents(this);
        if (content == null)
        {
            return;
        }
        String txt =
            content
                .getTransferData(new DataFlavor(String.class, "String"))
                .toString();
        document.replace(
            editor.getSelectionStart(),
            editor.getSelectionEnd() - editor.getSelectionStart(),
            txt,
            editorKit.getInputAttributes());
        //editor.replaceSelection(content.getTransferData(new
        // DataFlavor(String.class, "String")).toString());
        //editor.paste();
        //insertHTML(content.getTransferData(new DataFlavor(String.class,
        // "String")).toString(), editor.getCaretPosition());
        /*
         * Element el =
         * document.getParagraphElement(editor.getCaretPosition());
         * insertTextInElement(el, content.getTransferData(new
         * DataFlavor(String.class, "String")).toString(),
         */

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
项目:jdk8u-jdk    文件:XToolkit.java   
public Clipboard getSystemSelection() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
    }
    synchronized (this) {
        if (selection == null) {
            selection = new XClipboard("Selection", "PRIMARY");
        }
    }
    return selection;
}
项目:geomapapp    文件:XMImage.java   
public void copy() {
    StringBuffer sb = new StringBuffer();
    sb.append(tempInfo);
    Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
    String tempString = sb.toString();
    tempString = tempString.replaceAll("zoom.+","");
    tempString = tempString.replaceAll("[\\(\\)=,\\w&&[^WESN\\d]]+","");
    String [] result = tempString.split("\\s+");
    tempString = "";
    for ( int i =0; i < result.length; i++ ) {
        if ( result[i].indexOf("\u00B0") != -1 && result[i].indexOf("\u00B4") == -1 ) {
            result[i] = result[i].replaceAll("\\u00B0","");
        }
        if ( i == 2 ) {
            if ( result[i].indexOf("W") != -1 ) {
                result[i] = "-" + result[i];
            }
            result[i] = result[i].replaceAll("[WE]","");
        }
        else if ( i == 3 ) {
            if ( result[i].indexOf("S") != -1 ) {
                result[i] = "-" + result[i];
            }
            result[i] = result[i].replaceAll("[NS]","");
        }
        tempString += result[i] + "\t";
    }
    tempString = tempString.trim();
    tempString = line.getCruiseID().trim() + "\t" + line.getID().trim() + "\t" + currentTime/1000.0 + "\t" + currentCDP + "\t" + tempString;
    StringSelection ss = new StringSelection(tempString + "\n");
    c.setContents(ss, ss);
}
项目:freecol    文件:DropListener.java   
/**
 * Gets called when the mouse was released on a Swing component
 * that has this object as a MouseListener.
 *
 * @param e The event that holds the information about the mouse click.
 */
@Override
public void mouseReleased(MouseEvent e) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable clipData = clipboard.getContents(clipboard);
    if (clipData != null) {
        if (clipData.isDataFlavorSupported(DefaultTransferHandler.flavor)) {
            JComponent comp = (JComponent)e.getSource();
            TransferHandler handler = comp.getTransferHandler();
            handler.importData(comp, clipData);
        }
    }
}
项目:incubator-netbeans    文件:PasteAction.java   
/** If our clipboard is not found return the default system clipboard. */
private static Clipboard getClipboard() {
    Clipboard c = Lookup.getDefault().lookup(Clipboard.class);

    if (c == null) {
        c = Toolkit.getDefaultToolkit().getSystemClipboard();
    }

    return c;
}
项目:AgentWorkbench    文件:DBConnection.java   
/**
 * This method puts the value of 'toClipboard' to the clipboard
 * In case of an SQL-Error, the SQL-Statement will be placed in
 * such a way and can be used in an external application as well.
 * @param toClipboard String which will be placed in the clipboard
 */
public void put2Clipboard(String toClipboard) {
    if (Application.isOperatingHeadless()==false) {
        // --- Only in case that Agent.GUI is operated with graphical representation ------
        StringSelection data = new StringSelection(toClipboard);
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(data, data);  
    }
}
项目:rapidminer    文件:AbstractChartPanel.java   
/**
 * Copies the current chart to the system clipboard.
 * 
 * @since 1.0.13
 */

@Override
public void doCopy() {
    Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Insets insets = getInsets();
    int w = getWidth() - insets.left - insets.right;
    int h = getHeight() - insets.top - insets.bottom;
    ChartTransferable selection = new ChartTransferable(this.chart, w, h);
    systemClipboard.setContents(selection, null);
}
项目:rapidminer    文件:CopyChartAction.java   
/**
 * Copies the current chart to the system clipboard.
 */
public static synchronized void copyChart(final JFreeChartPlotEngine engine) {
    Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Insets insets = engine.getChartPanel().getInsets();
    int w = engine.getChartPanel().getWidth() - insets.left - insets.right;
    int h = engine.getChartPanel().getHeight() - insets.top - insets.bottom;
    BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = img.createGraphics();
    engine.getChartPanel().print(g2);
    g2.dispose();
    systemClipboard.setContents(new TransferableImage(img), null);
}
项目:FreeCol    文件:DropListener.java   
/**
 * Gets called when the mouse was released on a Swing component
 * that has this object as a MouseListener.
 *
 * @param e The event that holds the information about the mouse click.
 */
@Override
public void mouseReleased(MouseEvent e) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable clipData = clipboard.getContents(clipboard);
    if (clipData != null) {
        if (clipData.isDataFlavorSupported(DefaultTransferHandler.flavor)) {
            JComponent comp = (JComponent)e.getSource();
            TransferHandler handler = comp.getTransferHandler();
            handler.importData(comp, clipData);
        }
    }
}
项目:SER316-Ingolstadt    文件:HTMLEditor.java   
private void doPaste() {
    Clipboard clip =
        java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
    try {
        Transferable content = 

                clip.getContents(this);
        if (content == null)
            return;
        String txt =
            content
                .getTransferData(new DataFlavor(String.class, "String"))
                .toString();
        document.replace(
            editor.getSelectionStart(),
            editor.getSelectionEnd() - editor.getSelectionStart(),
            txt,
            editorKit.getInputAttributes());
        //editor.replaceSelection(content.getTransferData(new
        // DataFlavor(String.class, "String")).toString());
        //editor.paste();
        //insertHTML(content.getTransferData(new DataFlavor(String.class,
        // "String")).toString(), editor.getCaretPosition());
        /*
         * Element el =
         * document.getParagraphElement(editor.getCaretPosition());
         * insertTextInElement(el, content.getTransferData(new
         * DataFlavor(String.class, "String")).toString(),
         */

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
项目:rapidminer    文件:EnterLicenseCard.java   
private String getLicenseKeyFromClipboard() {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

    try {
        String licenseFromClipboard = (String)clipboard.getData(DataFlavor.stringFlavor);
        if(ProductConstraintManager.INSTANCE.isLicenseValid(licenseFromClipboard)) {
            return licenseFromClipboard;
        }
    } catch (Exception var3) {
        ;
    }

    return null;
}
项目:featurea    文件:ModbusLogsToolbarComponent.java   
private void copyLogs() {
    JTextArea textArea = service.docket.execute("featurea.scada.ide.modbusLogs.textArea");
    String text = textArea.getText();
    StringSelection stringSelection = new StringSelection(text);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(stringSelection, null);
}