Search in sources :

Example 81 with Clipboard

use of java.awt.datatransfer.Clipboard in project hale by halestudio.

the class MapTipManager method setMapKit.

/**
 * @see MapPainter#setMapKit(BasicMapKit)
 */
@Override
public void setMapKit(BasicMapKit mapKit) {
    this.mapKit = mapKit;
    for (MapTipContainer c : mapTips) {
        c.getMapTip().init(mapKit.getMainMap());
        c.getMapTip().getPainter().setMapKit(mapKit);
    }
    mapKit.getMainMap().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            synchronized (this) {
                if (lastTip != null && e.getKeyChar() == 'c') {
                    String text = lastTip.getLastText();
                    if (text != null) {
                        StringSelection stringSelection = new StringSelection(text);
                        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                        clipboard.setContents(stringSelection, MapTipManager.this);
                    }
                }
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) KeyAdapter(java.awt.event.KeyAdapter) Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 82 with Clipboard

use of java.awt.datatransfer.Clipboard in project GregTech by GregTechCE.

the class ClipboardUtil method copyToClipboard.

public static void copyToClipboard(final String text) {
    if (Desktop.isDesktopSupported()) {
        final StringSelection selection = new StringSelection(text);
        final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(selection, null);
    }
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) PacketClipboard(gregtech.api.net.PacketClipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 83 with Clipboard

use of java.awt.datatransfer.Clipboard in project proxyee-down by monkeyWie.

the class NativeController method copy.

@RequestMapping("copy")
public FullHttpResponse copy(Channel channel, FullHttpRequest request) throws Exception {
    Map<String, Object> map = getJSONParams(request);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable selection = null;
    if ("text".equalsIgnoreCase((String) map.get("type"))) {
        selection = new StringSelection((String) map.get("data"));
    }
    clipboard.setContents(selection, null);
    return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
}
Also used : Transferable(java.awt.datatransfer.Transferable) Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 84 with Clipboard

use of java.awt.datatransfer.Clipboard in project BoofCV by lessthanoptimal.

the class ApplicationLauncherApp method handleContextMenu.

/**
 * Displays a context menu for a class leaf node
 * Allows copying of the name and the path to the source
 */
private void handleContextMenu(JTree tree, int x, int y) {
    TreePath path = tree.getPathForLocation(x, y);
    tree.setSelectionPath(path);
    var node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    if (node == null)
        return;
    if (!node.isLeaf()) {
        tree.setSelectionPath(null);
        return;
    }
    final AppInfo info = (AppInfo) node.getUserObject();
    var copyname = new JMenuItem("Copy Name");
    copyname.addActionListener(e -> {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(new StringSelection(info.app.getSimpleName()), null);
    });
    var copypath = new JMenuItem("Copy Path");
    copypath.addActionListener(e -> {
        String path1 = UtilIO.getSourcePath(info.app.getPackage().getName(), info.app.getSimpleName());
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(new StringSelection(path1), null);
    });
    var github = new JMenuItem("Go to Github");
    github.addActionListener(e -> openInGitHub(info));
    var submenu = new JPopupMenu();
    submenu.add(copyname);
    submenu.add(copypath);
    submenu.add(github);
    submenu.show(tree, x, y);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 85 with Clipboard

use of java.awt.datatransfer.Clipboard in project mzmine2 by mzmine.

the class ResultWindow method copyToClipboard.

/**
 * Method sets value of clipboard to `content`
 *
 * @param content - Formula or SMILES string
 * @param errorMessage - to print in a message if value of `content` is null
 */
private void copyToClipboard(String content, String errorMessage) {
    if (content == null) {
        MZmineCore.getDesktop().displayMessage(this, errorMessage);
        return;
    }
    StringSelection stringSelection = new StringSelection(content);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(stringSelection, null);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Aggregations

Clipboard (java.awt.datatransfer.Clipboard)181 StringSelection (java.awt.datatransfer.StringSelection)117 Transferable (java.awt.datatransfer.Transferable)44 IOException (java.io.IOException)30 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)16 JDialog (javax.swing.JDialog)12 JOptionPane (javax.swing.JOptionPane)12 ActionEvent (java.awt.event.ActionEvent)11 Flame (org.jwildfire.create.tina.base.Flame)10 ActionListener (java.awt.event.ActionListener)8 JButton (javax.swing.JButton)8 JScrollPane (javax.swing.JScrollPane)8 JMenuItem (javax.swing.JMenuItem)7 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