Search in sources :

Example 6 with Clipboard

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

the class ControlPanelEditor method pasteFromClipboard.

private void pasteFromClipboard() {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    DataFlavor[] flavors = clipboard.getAvailableDataFlavors();
    for (DataFlavor flavor : flavors) {
        if (_positionableListDataFlavor.equals(flavor)) {
            try {
                @SuppressWarnings("unchecked") List<Positionable> clipGroup = (List<Positionable>) clipboard.getData(_positionableListDataFlavor);
                if (clipGroup != null && clipGroup.size() > 0) {
                    Positionable pos = clipGroup.get(0);
                    int minX = pos.getLocation().x;
                    int minY = pos.getLocation().y;
                    // locate group at mouse point
                    for (int i = 1; i < clipGroup.size(); i++) {
                        pos = clipGroup.get(i);
                        minX = Math.min(minX, pos.getLocation().x);
                        minY = Math.min(minY, pos.getLocation().y);
                    }
                    if (_pastePending) {
                        abortPasteItems();
                    }
                    _selectionGroup = new ArrayList<Positionable>();
                    for (int i = 0; i < clipGroup.size(); i++) {
                        pos = clipGroup.get(i);
                        // make positionable belong to this editor
                        pos.setEditor(this);
                        pos.setLocation(pos.getLocation().x + _anchorX - minX, pos.getLocation().y + _anchorY - minY);
                        // now set display level in the pane.
                        pos.setDisplayLevel(pos.getDisplayLevel());
                        putItem(pos);
                        pos.updateSize();
                        pos.setVisible(true);
                        _selectionGroup.add(pos);
                        if (pos instanceof PositionableIcon) {
                            jmri.NamedBean bean = pos.getNamedBean();
                            if (bean != null) {
                                ((PositionableIcon) pos).displayState(bean.getState());
                            }
                        } else if (pos instanceof MemoryIcon) {
                            ((MemoryIcon) pos).displayState();
                        } else if (pos instanceof PositionableJComponent) {
                            ((PositionableJComponent) pos).displayState();
                        }
                        log.debug("Paste Added at ({}, {})", pos.getLocation().x, pos.getLocation().y);
                    }
                }
                return;
            } catch (IOException ioe) {
                log.warn("Editor Paste caught IOException", ioe);
            } catch (UnsupportedFlavorException ufe) {
                log.warn("Editor Paste caught UnsupportedFlavorException", ufe);
            }
        }
    }
}
Also used : MemoryIcon(jmri.jmrit.display.MemoryIcon) PositionableIcon(jmri.jmrit.display.PositionableIcon) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point) DataFlavor(java.awt.datatransfer.DataFlavor) PositionableJComponent(jmri.jmrit.display.PositionableJComponent) List(java.util.List) ArrayList(java.util.ArrayList) Clipboard(java.awt.datatransfer.Clipboard) Positionable(jmri.jmrit.display.Positionable)

Example 7 with Clipboard

use of java.awt.datatransfer.Clipboard in project processdash by dtuma.

the class TabularClipboardDataHelper method getTabularDataFromClipboard.

public static List<List<String>> getTabularDataFromClipboard() {
    Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
    DataFlavor[] flavors = cb.getAvailableDataFlavors();
    if (flavors == null)
        return null;
    DataFlavor html = searchForFlavor(flavors, "text/html", "java.lang.String");
    if (html != null) {
        try {
            String data = (String) cb.getData(html);
            return HtmlTableParser.parseTable(data, true);
        } catch (Exception e) {
            return null;
        }
    }
    DataFlavor text = searchForFlavor(flavors, "text/plain", "java.lang.String");
    if (text != null) {
        try {
            String data = (String) cb.getData(text);
            if (HtmlTableParser.containsHtmlTableData(data))
                return HtmlTableParser.parseTable(data, true);
            else
                return parseTabDelimitedData(data);
        } catch (Exception e) {
            return null;
        }
    }
    return null;
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 8 with Clipboard

use of java.awt.datatransfer.Clipboard in project processdash by dtuma.

the class WBSClipSelection method putNodeListOnClipboard.

/** Interact with the system clipboard, and place a list of WBSNodes there.
     * 
     * @param wbsNodes the list of WBSNodes to share
     * @param o an owner who would like to be notified when the nodes are no
     *   longer on the system clipboard; can be null.
     */
public static void putNodeListOnClipboard(List wbsNodes, ClipboardOwner o) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    WBSClipSelection t = new WBSClipSelection(wbsNodes);
    clipboard.setContents(t, (o == null ? t : o));
}
Also used : Clipboard(java.awt.datatransfer.Clipboard)

Example 9 with Clipboard

use of java.awt.datatransfer.Clipboard in project processdash by dtuma.

the class WBSClipSelection method getNodeListFromClipboard.

/** Interact with the system clipboard to retrieve a list of WBSNodes.
     * 
     * @param prototype if the system clipboard contains plain text, a list
     *   of nodes modeled after this prototype will be returned.
     */
public static List getNodeListFromClipboard(WBSNode prototype) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable t = clipboard.getContents(prototype);
    // on the clipboard).
    try {
        Object d = t.getTransferData(WBS_LIST_FLAVOR);
        List result = ((WBSClipData) d).getWBSNodes(prototype.getWbsModel());
        if (result != null)
            return result;
    } catch (Exception e) {
    }
    // clipboard by some other WBS Editor.
    try {
        Object d = t.getTransferData(WBS_FLAVOR);
        List result = ((WBSClipData) d).getWBSNodes(prototype.getWbsModel());
        if (result != null)
            return result;
    } catch (Exception e) {
    }
    // names, and create some ultra-simple nodes with those names.
    try {
        String plainText = (String) t.getTransferData(DataFlavor.stringFlavor);
        String[] lines = plainText.split("\n");
        int baseIndent = Math.max(1, prototype.getIndentLevel());
        List result = new ArrayList();
        for (int i = 0; i < lines.length; i++) {
            Matcher m = PLAINTEXT_PATTERN.matcher(lines[i]);
            if (!m.find())
                continue;
            String nodeName = scrubName(m.group(2)).trim();
            int indent = baseIndent;
            if (m.group(1) != null && m.group(1).length() > 0) {
                Matcher mi = INDENT_PATTERN.matcher(m.group(1));
                while (mi.find()) indent++;
            }
            WBSNode node = new WBSNode(prototype.getWbsModel(), nodeName, WBSNode.UNKNOWN_TYPE, indent, true);
            result.add(node);
        }
        return result;
    } catch (Exception e) {
    }
    // if all else fails, return null to indicate failure.
    return null;
}
Also used : Matcher(java.util.regex.Matcher) Transferable(java.awt.datatransfer.Transferable) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Clipboard(java.awt.datatransfer.Clipboard) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException)

Example 10 with Clipboard

use of java.awt.datatransfer.Clipboard in project bnd by bndtools.

the class Repository method toClipboard.

void toClipboard(String s) {
    if (s == null)
        return;
    StringSelection stringSelection = new StringSelection(s);
    Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
    clpbrd.setContents(stringSelection, null);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

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