Search in sources :

Example 1 with Clipboard

use of java.awt.datatransfer.Clipboard in project jdk8u_jdk by JetBrains.

the class bug8059739 method runTest.

private static void runTest() throws Exception {
    String testString = "my string";
    JTextField tf = new JTextField(testString);
    tf.selectAll();
    Clipboard clipboard = new Clipboard("clip");
    tf.getTransferHandler().exportToClipboard(tf, clipboard, TransferHandler.COPY);
    DataFlavor[] dfs = clipboard.getAvailableDataFlavors();
    for (DataFlavor df : dfs) {
        String charset = df.getParameter("charset");
        if (InputStream.class.isAssignableFrom(df.getRepresentationClass()) && charset != null) {
            BufferedReader br = new BufferedReader(new InputStreamReader((InputStream) clipboard.getData(df), charset));
            String s = br.readLine();
            System.out.println("Content: '" + s + "'");
            passed &= s.contains(testString);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) Clipboard(java.awt.datatransfer.Clipboard) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 2 with Clipboard

use of java.awt.datatransfer.Clipboard in project intellij-community by JetBrains.

the class TreeCopyProvider method performCopy.

public void performCopy(@NotNull DataContext dataContext) {
    try {
        final Clipboard clipboard = myTree.getToolkit().getSystemClipboard();
        myTree.getTransferHandler().exportToClipboard(myTree, clipboard, TransferHandler.COPY);
    } catch (Exception ex) {
        // probably don't have clipboard access or something
        LOG.info(ex);
    }
}
Also used : Clipboard(java.awt.datatransfer.Clipboard)

Example 3 with Clipboard

use of java.awt.datatransfer.Clipboard in project processing by processing.

the class ColorSelector method run.

public void run() {
    if (selector == null) {
        synchronized (ColorSelector.class) {
            if (selector == null) {
                selector = new ColorChooser(base.getActiveEditor(), false, Color.WHITE, Language.text("menu.edit.copy"), new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Clipboard c = Toolkit.getSystemClipboard();
                        c.setContents(new StringSelection(selector.getHexColor()), null);
                    }
                });
            }
        }
    }
    selector.show();
}
Also used : ColorChooser(processing.app.ui.ColorChooser) Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 4 with Clipboard

use of java.awt.datatransfer.Clipboard in project jphp by jphp-compiler.

the class Robot method type.

@Signature
public void type(String characters) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    StringSelection stringSelection = new StringSelection(characters);
    clipboard.setContents(stringSelection, null);
    getWrappedObject().keyPress(KeyEvent.VK_CONTROL);
    getWrappedObject().keyPress(KeyEvent.VK_V);
    getWrappedObject().keyRelease(KeyEvent.VK_V);
    getWrappedObject().keyRelease(KeyEvent.VK_CONTROL);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection) Signature(php.runtime.annotation.Reflection.Signature)

Example 5 with Clipboard

use of java.awt.datatransfer.Clipboard in project JMRI by JMRI.

the class ControlPanelEditor method copyToClipboard.

/*
     * The editor instance is dragged.  When dropped this editor will reference
     * the list of positionables (_clipGroup) for pasting
     */
private void copyToClipboard() {
    if (_selectionGroup != null) {
        ArrayList<Positionable> dragGroup = new ArrayList<Positionable>();
        for (Positionable comp : _selectionGroup) {
            Positionable pos = comp.deepClone();
            dragGroup.add(pos);
            // cloned item gets added to _targetPane during cloning
            removeFromTarget(pos);
        }
        log.debug("copyToClipboard: cloned _selectionGroup, size= {}", _selectionGroup.size());
        _clipGroup = dragGroup;
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(new PositionableListDnD(_clipGroup), this);
        log.debug("copyToClipboard: setContents _selectionGroup, size= {}", _selectionGroup.size());
    } else {
        _clipGroup = null;
    }
}
Also used : ArrayList(java.util.ArrayList) Positionable(jmri.jmrit.display.Positionable) Clipboard(java.awt.datatransfer.Clipboard)

Aggregations

Clipboard (java.awt.datatransfer.Clipboard)172 StringSelection (java.awt.datatransfer.StringSelection)110 Transferable (java.awt.datatransfer.Transferable)43 IOException (java.io.IOException)27 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)15 ActionEvent (java.awt.event.ActionEvent)12 JDialog (javax.swing.JDialog)12 JOptionPane (javax.swing.JOptionPane)12 Flame (org.jwildfire.create.tina.base.Flame)10 ActionListener (java.awt.event.ActionListener)9 JButton (javax.swing.JButton)8 JMenuItem (javax.swing.JMenuItem)8 JScrollPane (javax.swing.JScrollPane)8 JPanel (javax.swing.JPanel)7 JTextArea (javax.swing.JTextArea)7 Foundation (org.concord.energy3d.model.Foundation)7 HousePart (org.concord.energy3d.model.HousePart)7 FlameReader (org.jwildfire.create.tina.io.FlameReader)7 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)7 Point (java.awt.Point)6