use of java.awt.datatransfer.StringSelection in project jabref by JabRef.
the class BasePanel method copyKey.
private void copyKey() {
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;
}
StringSelection ss = new StringSelection(String.join(",", keys));
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())));
}
}
}
use of java.awt.datatransfer.StringSelection in project jabref by JabRef.
the class BasePanel method copyTitle.
private void copyTitle() {
List<BibEntry> selectedBibEntries = mainTable.getSelectedEntries();
if (!selectedBibEntries.isEmpty()) {
storeCurrentEdit();
// Collect all non-null titles.
List<String> titles = selectedBibEntries.stream().filter(bibEntry -> bibEntry.getTitle().isPresent()).map(bibEntry -> bibEntry.getTitle().get()).collect(Collectors.toList());
if (titles.isEmpty()) {
output(Localization.lang("None of the selected entries have titles."));
return;
}
StringSelection ss = new StringSelection(String.join("\n", titles));
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, BasePanel.this);
if (titles.size() == selectedBibEntries.size()) {
// All entries had titles.
output((selectedBibEntries.size() > 1 ? Localization.lang("Copied titles") : Localization.lang("Copied title")) + '.');
} else {
output(Localization.lang("Warning: %0 out of %1 entries have undefined title.", Integer.toString(selectedBibEntries.size() - titles.size()), Integer.toString(selectedBibEntries.size())));
}
}
}
use of java.awt.datatransfer.StringSelection in project jabref by JabRef.
the class BasePanel method copy.
private void copy() {
List<BibEntry> bes = mainTable.getSelectedEntries();
if (bes.isEmpty()) {
// The user maybe selected a single cell.
// TODO: Check if this can actually happen
int[] rows = mainTable.getSelectedRows();
int[] cols = mainTable.getSelectedColumns();
if ((cols.length == 1) && (rows.length == 1)) {
// Copy single value.
Object o = mainTable.getValueAt(rows[0], cols[0]);
if (o != null) {
StringSelection ss = new StringSelection(o.toString());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, BasePanel.this);
output(Localization.lang("Copied cell contents") + '.');
}
}
} else {
TransferableBibtexEntry trbe = new TransferableBibtexEntry(bes);
// ! look at ClipBoardManager
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trbe, BasePanel.this);
output(formatOutputMessage(Localization.lang("Copied"), bes.size()));
}
}
use of java.awt.datatransfer.StringSelection in project JMRI by JMRI.
the class DnDTableExportHandler method createTransferable.
@Override
public Transferable createTransferable(JComponent c) {
JTable table = (JTable) c;
int col = table.getSelectedColumn();
int row = table.getSelectedRow();
if (col < 0 || row < 0) {
return null;
}
row = table.convertRowIndexToModel(row);
col = table.convertColumnIndexToModel(col);
if (log.isDebugEnabled()) {
log.debug("TransferHandler.createTransferable: from (" + row + ", " + col + ") for \"" + table.getModel().getValueAt(row, col) + "\"");
}
Object obj = table.getModel().getValueAt(row, col);
if (obj instanceof String) {
return new StringSelection((String) obj);
} else if (obj != null) {
return new StringSelection(obj.getClass().getName());
} else {
return null;
}
}
use of java.awt.datatransfer.StringSelection in project beast-mcmc by beast-dev.
the class MapperFrame method doCopy.
@Override
public void doCopy() {
StringWriter writer = new StringWriter();
PrintWriter pwriter = new PrintWriter(writer);
// for (String tip : treesPanel.getSelectedTips()) {
// pwriter.println(tip);
// }
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection selection = new StringSelection(writer.toString());
clipboard.setContents(selection, selection);
}
Aggregations