Search in sources :

Example 36 with StringSelection

use of java.awt.datatransfer.StringSelection 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)

Example 37 with StringSelection

use of java.awt.datatransfer.StringSelection in project jabref by JabRef.

the class CitationStyleToClipboardWorkerTest method processText.

@Test
public void processText() throws Exception {
    String expected = "[1]B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016." + OS.NEWLINE + "[1]B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016." + OS.NEWLINE;
    String citation = "[1]B. Smith, B. Jones, and J. Williams, “Title of the test entry,” BibTeX Journal, vol. 34, no. 3, pp. 45–67, Jul. 2016." + OS.NEWLINE;
    StringSelection textTransferable = CitationStyleToClipboardWorker.processText(Arrays.asList(citation, citation));
    Object actual = textTransferable.getTransferData(DataFlavor.stringFlavor);
    Assert.assertEquals(expected, actual);
}
Also used : StringSelection(java.awt.datatransfer.StringSelection) Test(org.junit.Test)

Example 38 with StringSelection

use of java.awt.datatransfer.StringSelection 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 39 with StringSelection

use of java.awt.datatransfer.StringSelection 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 40 with StringSelection

use of java.awt.datatransfer.StringSelection 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)

Aggregations

StringSelection (java.awt.datatransfer.StringSelection)99 Clipboard (java.awt.datatransfer.Clipboard)28 ActionEvent (java.awt.event.ActionEvent)11 Transferable (java.awt.datatransfer.Transferable)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 JTextArea (javax.swing.JTextArea)7 Test (org.junit.Test)7 JPanel (javax.swing.JPanel)6 ActionListener (java.awt.event.ActionListener)5 JScrollPane (javax.swing.JScrollPane)5 Editor (com.intellij.openapi.editor.Editor)4 Project (com.intellij.openapi.project.Project)4 PsiFile (com.intellij.psi.PsiFile)4 ClipboardOwner (java.awt.datatransfer.ClipboardOwner)4 JMenuItem (javax.swing.JMenuItem)4 BibEntry (org.jabref.model.entry.BibEntry)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 PsiElement (com.intellij.psi.PsiElement)3 BorderLayout (java.awt.BorderLayout)3