Search in sources :

Example 11 with Clipboard

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

the class ReportContextAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent ev) {
    // JmriJFrame to ensure fits on screen
    final JFrame frame = new JmriJFrame(Bundle.getMessage("TitleContext"));
    final Clipboard clipboard = frame.getToolkit().getSystemClipboard();
    pane = new JTextArea();
    // add a little space at top
    pane.append("\n");
    pane.setEditable(false);
    pane.setLineWrap(true);
    pane.setWrapStyleWord(true);
    pane.setColumns(120);
    JScrollPane scroll = new JScrollPane(pane);
    frame.add(scroll, BorderLayout.CENTER);
    ReportContext r = new ReportContext();
    addString(r.getReport(true));
    // add a little space at bottom
    pane.append("\n");
    // Add button to allow copy to clipboard
    JPanel p = new JPanel();
    JButton copy = new JButton(Bundle.getMessage("ButtonCopyClip"));
    copy.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            StringSelection text = new StringSelection(pane.getText());
            clipboard.setContents(text, text);
        }
    });
    p.add(copy);
    JButton close = new JButton(Bundle.getMessage("ButtonClose"));
    close.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            frame.setVisible(false);
            frame.dispose();
        }
    });
    p.add(close);
    frame.add(p, BorderLayout.SOUTH);
    frame.pack();
    // start scrolled to top
    pane.setCaretPosition(0);
    JScrollBar b = scroll.getVerticalScrollBar();
    b.setValue(b.getMaximum());
    // show
    frame.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) StringSelection(java.awt.datatransfer.StringSelection) JScrollBar(javax.swing.JScrollBar) ActionListener(java.awt.event.ActionListener) JmriJFrame(jmri.util.JmriJFrame) JFrame(javax.swing.JFrame) JmriJFrame(jmri.util.JmriJFrame) Clipboard(java.awt.datatransfer.Clipboard) ReportContext(jmri.jmrit.mailreport.ReportContext)

Example 12 with Clipboard

use of java.awt.datatransfer.Clipboard in project knime-core by knime.

the class CopyAction method actionPerformed.

/**
 * {@inheritDoc}
 */
public void actionPerformed(final ActionEvent e) {
    int[] rows = m_table.getSelectedRows();
    int[] cols = m_table.getSelectedColumns();
    boolean isContiguousBlockSelected = rows.length == rows[rows.length - 1] - rows[0] + 1 && cols.length == cols[cols.length - 1] - cols[0] + 1;
    if (!isContiguousBlockSelected) {
        JOptionPane.showMessageDialog(null, "This function cannot be used for multiple selection", "KNIME", JOptionPane.INFORMATION_MESSAGE);
        return;
    }
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < rows.length; i++) {
        for (int k = 0; k < cols.length; k++) {
            Object value = m_table.getValueAt(rows[i], cols[k]);
            if (value instanceof Cell) {
                builder.append(((Cell) value).getText());
            } else {
                builder.append(value.toString());
            }
            if (k < cols.length - 1) {
                builder.append("\t");
            }
        }
        builder.append("\n");
    }
    StringSelection str = new StringSelection(builder.toString());
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(str, str);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 13 with Clipboard

use of java.awt.datatransfer.Clipboard in project knime-core by knime.

the class CutAction method actionPerformed.

/**
 * {@inheritDoc}
 */
public void actionPerformed(final ActionEvent e) {
    int[] rows = m_table.getSelectedRows();
    int[] cols = m_table.getSelectedColumns();
    boolean isContiguousBlockSelected = rows.length == rows[rows.length - 1] - rows[0] + 1 && cols.length == cols[cols.length - 1] - cols[0] + 1;
    if (!isContiguousBlockSelected) {
        JOptionPane.showMessageDialog(null, "This function cannot be used for multiple selection", "KNIME", JOptionPane.INFORMATION_MESSAGE);
        return;
    }
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < rows.length; i++) {
        for (int k = 0; k < cols.length; k++) {
            Object value = m_table.getValueAt(rows[i], cols[k]);
            if (value instanceof Cell) {
                builder.append(((Cell) value).getText());
            } else {
                builder.append(value.toString());
            }
            m_table.setValueAt("", rows[i], cols[k]);
            if (k < cols.length - 1) {
                builder.append("\t");
            }
        }
        builder.append("\n");
    }
    StringSelection str = new StringSelection(builder.toString());
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(str, str);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 14 with Clipboard

use of java.awt.datatransfer.Clipboard in project megameklab by MegaMek.

the class MenuBarCreator method jMenuExportEntityClipboard_actionPerformed.

public void jMenuExportEntityClipboard_actionPerformed(ActionEvent event) {
    MechView mview = new MechView(parentFrame.getEntity(), true, true, false);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    StringSelection stringSelection = new StringSelection(mview.getMechReadout());
    clipboard.setContents(stringSelection, this);
}
Also used : MechView(megamek.common.MechView) Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 15 with Clipboard

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

the class AbstractEditorScreen method pasteJson.

/**
 * Attempts to serialize the system clipboard's contents - if successful,
 * sets the current state of the editor to the serialized {@link JsonTree}.
 */
protected void pasteJson() {
    // Get the clipboard contents.
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable t = clipboard.getContents(null);
    // Attempt to convert them to a string.
    String clipboardContents = null;
    try {
        if (t != null) {
            clipboardContents = (String) t.getTransferData(DataFlavor.stringFlavor);
        }
    } catch (UnsupportedFlavorException | IOException e) {
        logger.warn("Could not fetch clipboard contents.", e);
    }
    if (clipboardContents != null) {
        try {
            // Attempt to serialize them to a JsonTree and reset the editor state.
            JsonElement json = new JsonParser().parse(clipboardContents);
            JsonTree node = JsonTreeConverter.serialize(json);
            resetState(node);
        } catch (JsonSyntaxException | NullPointerException e) {
            logger.warn("Could not construct a valid tree from clipboard contents.", e);
        }
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonTree(org.terasology.rendering.nui.widgets.treeView.JsonTree) JsonElement(com.google.gson.JsonElement) Transferable(java.awt.datatransfer.Transferable) Clipboard(java.awt.datatransfer.Clipboard) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) JsonParser(com.google.gson.JsonParser)

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