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