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);
}
}
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);
}
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());
}
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;
}
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())));
}
}
}
Aggregations