Search in sources :

Example 16 with Clipboard

use of java.awt.datatransfer.Clipboard in project Terasology by MovingBlocks.

the class BehaviorEditorScreen method onCopyPressed.

private void onCopyPressed() {
    Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    String data = behaviorEditor.save();
    StringSelection contents = new StringSelection(data);
    systemClipboard.setContents(contents, contents);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 17 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);
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    if (node == null)
        return;
    if (!node.isLeaf()) {
        tree.setSelectionPath(null);
        return;
    }
    final AppInfo info = (AppInfo) node.getUserObject();
    JMenuItem copyname = new JMenuItem("Copy Name");
    copyname.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(new StringSelection(info.app.getSimpleName()), null);
        }
    });
    JMenuItem copypath = new JMenuItem("Copy Path");
    copypath.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            String path = UtilIO.getSourcePath(info.app.getPackage().getName(), info.app.getSimpleName());
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(new StringSelection(path), null);
        }
    });
    JMenuItem github = new JMenuItem("Go to Github");
    github.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            openInGitHub(info);
        }
    });
    JPopupMenu 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 18 with Clipboard

use of java.awt.datatransfer.Clipboard in project JWildfire by thargor6.

the class IFlamesController method baseFlameToClipboardButton_clicked.

public void baseFlameToClipboardButton_clicked() {
    try {
        String xml = getIFlamesFunc().getFlameParams(getCurrFlameIndex()).getFlameXML();
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        StringSelection data = new StringSelection(xml);
        clipboard.setContents(data, data);
        messageHelper.showStatusMessage(getFlame(), "flame saved to clipboard");
    } catch (Throwable ex) {
        errorHandler.handleError(ex);
    }
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 19 with Clipboard

use of java.awt.datatransfer.Clipboard in project JWildfire by thargor6.

the class IFlamesController method saveIFlameToClipboardButton_clicked.

public void saveIFlameToClipboardButton_clicked() {
    try {
        if (getFlame() != null) {
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            String xml = new FlameWriter().getFlameXML(getFlame());
            StringSelection data = new StringSelection(xml);
            clipboard.setContents(data, data);
            messageHelper.showStatusMessage(getFlame(), "flame saved to clipboard");
        }
    } catch (Throwable ex) {
        errorHandler.handleError(ex);
    }
}
Also used : FlameWriter(org.jwildfire.create.tina.io.FlameWriter) Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 20 with Clipboard

use of java.awt.datatransfer.Clipboard in project JWildfire by thargor6.

the class DancingFractalsController method loadFlameFromClipboardButton_clicked.

public void loadFlameFromClipboardButton_clicked() {
    List<Flame> newFlames = null;
    try {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable clipData = clipboard.getContents(clipboard);
        if (clipData != null) {
            if (clipData.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                String xml = (String) (clipData.getTransferData(DataFlavor.stringFlavor));
                newFlames = new FlameReader(prefs).readFlamesfromXML(xml);
            }
        }
        if (newFlames == null || newFlames.size() < 1) {
            throw new Exception("There is currently no valid flame in the clipboard");
        } else {
            for (Flame newFlame : newFlames) {
                project.getFlames().add(validateDancingFlame(newFlame));
            }
            refreshProjectFlames();
            enableControls();
        }
    } catch (Throwable ex) {
        errorHandler.handleError(ex);
    }
}
Also used : FlameReader(org.jwildfire.create.tina.io.FlameReader) Transferable(java.awt.datatransfer.Transferable) Clipboard(java.awt.datatransfer.Clipboard) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

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