Search in sources :

Example 26 with StringSelection

use of java.awt.datatransfer.StringSelection in project intellij-community by JetBrains.

the class JBList method installDefaultCopyAction.

private void installDefaultCopyAction() {
    final Action copy = getActionMap().get("copy");
    if (copy == null || copy instanceof UIResource) {
        Action newCopy = new AbstractAction() {

            @Override
            public boolean isEnabled() {
                return getSelectedIndex() != -1;
            }

            @Override
            public void actionPerformed(ActionEvent e) {
                ArrayList<String> selected = new ArrayList<>();
                JBList list = JBList.this;
                ListCellRenderer renderer = list.getCellRenderer();
                if (renderer != null) {
                    for (int index : getSelectedIndices()) {
                        Object value = list.getModel().getElementAt(index);
                        //noinspection unchecked
                        Component c = renderer.getListCellRendererComponent(list, value, index, true, true);
                        SimpleColoredComponent coloredComponent = null;
                        if (c instanceof JComponent) {
                            coloredComponent = UIUtil.findComponentOfType((JComponent) c, SimpleColoredComponent.class);
                        }
                        if (coloredComponent != null) {
                            selected.add(coloredComponent.toString());
                        } else if (c instanceof JTextComponent) {
                            selected.add(((JTextComponent) c).getText());
                        } else if (value != null) {
                            selected.add(value.toString());
                        }
                    }
                }
                if (selected.size() > 0) {
                    String text = StringUtil.join(selected, " ");
                    CopyPasteManager.getInstance().setContents(new StringSelection(text));
                }
            }
        };
        getActionMap().put("copy", newCopy);
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) JTextComponent(javax.swing.text.JTextComponent) UIResource(javax.swing.plaf.UIResource) StringSelection(java.awt.datatransfer.StringSelection) JTextComponent(javax.swing.text.JTextComponent)

Example 27 with StringSelection

use of java.awt.datatransfer.StringSelection in project cloudstack by apache.

the class AwtClipboardAdapter method handleData.

@Override
public void handleData(ByteBuffer buf, Link link) {
    if (verbose)
        System.out.println("[" + this + "] INFO: Data received: " + buf + ".");
    if (buf == null)
        return;
    String content = (String) buf.getMetadata(CLIPBOARD_CONTENT);
    StringSelection contents = new StringSelection(content);
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, null);
}
Also used : StringSelection(java.awt.datatransfer.StringSelection)

Example 28 with StringSelection

use of java.awt.datatransfer.StringSelection in project limelight by slagyr.

the class TextInputKeyProcessorTest method cmdVPastesAtCursor.

@Test
public void cmdVPastesAtCursor() {
    setupSingleLine("Bob");
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(" Dole"), model);
    processor.processKey(new KeyPressedEvent(CMD, KeyEvent.KEY_V, 0), model);
    assertEquals(model.getEndLocation(), model.getCaretLocation());
    assertEquals("Bob Dole", model.getText());
}
Also used : KeyPressedEvent(limelight.ui.events.panel.KeyPressedEvent) StringSelection(java.awt.datatransfer.StringSelection) Test(org.junit.Test)

Example 29 with StringSelection

use of java.awt.datatransfer.StringSelection in project hid-serial by rayshobby.

the class GClip method copyString.

/**
	 * Copy a string to the clipboard. If the Clipboard has not been created
	 * then create it.
	 * @return true for a successful copy to clipboard
	 */
private boolean copyString(String chars) {
    if (clipboard == null)
        makeClipboardObject();
    if (clipboard != null) {
        StringSelection fieldContent = new StringSelection(chars);
        clipboard.setContents(fieldContent, this);
        return true;
    }
    return false;
}
Also used : StringSelection(java.awt.datatransfer.StringSelection)

Example 30 with StringSelection

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

the class BasePanel method copyCiteKey.

private void copyCiteKey() {
    List<BibEntry> bes = mainTable.getSelectedEntries();
    if (!bes.isEmpty()) {
        storeCurrentEdit();
        List<String> keys = new ArrayList<>(bes.size());
        // Collect all non-null keys.
        for (BibEntry be : bes) {
            be.getCiteKeyOptional().ifPresent(keys::add);
        }
        if (keys.isEmpty()) {
            output(Localization.lang("None of the selected entries have BibTeX keys."));
            return;
        }
        String sb = String.join(",", keys);
        StringSelection ss = new StringSelection("\\cite{" + sb + '}');
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, BasePanel.this);
        if (keys.size() == bes.size()) {
            // All entries had keys.
            output(bes.size() > 1 ? Localization.lang("Copied keys") : Localization.lang("Copied key") + '.');
        } else {
            output(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Integer.toString(bes.size() - keys.size()), Integer.toString(bes.size())));
        }
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) ArrayList(java.util.ArrayList) 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