Example usage for java.awt.datatransfer Clipboard setContents

List of usage examples for java.awt.datatransfer Clipboard setContents

Introduction

In this page you can find the example usage for java.awt.datatransfer Clipboard setContents.

Prototype

public synchronized void setContents(Transferable contents, ClipboardOwner owner) 

Source Link

Document

Sets the current contents of the clipboard to the specified transferable object and registers the specified clipboard owner as the owner of the new contents.

Usage

From source file:org.ut.biolab.medsavant.client.view.component.KeyValuePairPanel.java

public static Component getCopyButton(final String key, final KeyValuePairPanel p) {
    JButton button = ViewUtil//from  w  w  w . ja  va2 s  . c om
            .getTexturedButton(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.COPY));
    button.setToolTipText("Copy " + key);
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            String selection = p.getValue(key);
            StringSelection data = new StringSelection(selection);
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(data, data);
            DialogUtils.displayMessage("Copied \"" + selection + "\" to clipboard.");
        }
    });
    return button;
}

From source file:ec.util.chart.swing.Charts.java

public static void copyChart(@Nonnull ChartPanel chartPanel) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Insets insets = chartPanel.getInsets();
    int w = chartPanel.getWidth() - insets.left - insets.right;
    int h = chartPanel.getHeight() - insets.top - insets.bottom;
    Transferable selection = new ChartTransferable2(chartPanel.getChart(), w, h,
            chartPanel.getMinimumDrawWidth(), chartPanel.getMinimumDrawHeight(),
            chartPanel.getMaximumDrawWidth(), chartPanel.getMaximumDrawHeight(), true);
    clipboard.setContents(selection, null);
}

From source file:org.gitools.ui.app.actions.data.CopyToClipboardSelectedLabelHeaderAction.java

@Override
public void actionPerformed(ActionEvent e) {

    if (header == null) {
        return;/*from   w  w w  .  jav a2s . c o  m*/
    }

    StringBuilder content = new StringBuilder();

    HeatmapDimension dimension = header.getHeatmapDimension();
    for (String label : transform(filter(dimension, in(dimension.getSelected())),
            header.getIdentifierTransform())) {
        if (!isEmpty(label)) {
            content.append(label).append('\n');
        }
    }

    Clipboard clipBoard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipBoard.setContents(new StringSelection(content.toString()), null);

}

From source file:storybook.ui.dialog.ExceptionDialog.java

private AbstractAction getCopyTextAction() {
    return new AbstractAction() {
        @Override//w  ww .  j  av  a2  s  .com
        public void actionPerformed(ActionEvent evt) {
            HtmlSelection selection = new HtmlSelection(ta.getText());
            Clipboard clbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
            clbrd.setContents(selection, selection);
        }
    };
}

From source file:ImageTransferTest.java

/**
 * Copies the current image to the system clipboard.
 *//*w  ww  .j a v  a  2  s  . c o  m*/
private void copy() {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    ImageTransferable selection = new ImageTransferable(image);
    clipboard.setContents(selection, null);
}

From source file:passwordencrypter.PasswordEncrypter.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    StringSelection stringSelection = new StringSelection(jTextField2.getText());
    Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
    clpbrd.setContents(stringSelection, null);
}

From source file:com.photon.phresco.framework.actions.FrameworkBaseAction.java

public void copyToClipboard() {
    S_LOGGER.debug("Entered FrameworkBaseAction.copyToClipboard");
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(
            new StringSelection(copyToClipboard.replaceAll(" ", "").replaceAll("(?m)^[ \t]*\r?\n", "")), null);

}

From source file:SerialTransferTest.java

/**
 * Copies the chooser's color into the system clipboard.
 *///  w  w  w .j a  v  a2  s  . c  o  m
private void copy() {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Color color = chooser.getColor();
    SerialTransferable selection = new SerialTransferable(color);
    clipboard.setContents(selection, null);
}

From source file:TextTransferTest.java

/**
 * Copies the selected text to the system clipboard.
 *///from w  w  w .j  a v a 2  s .c o  m
private void copy() {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    String text = textArea.getSelectedText();
    if (text == null)
        text = textArea.getText();
    StringSelection selection = new StringSelection(text);
    clipboard.setContents(selection, null);
}

From source file:ColorSource.java

/** This method copies the color to the clipboard. */
public void copy() {
    // Get system clipboard
    Clipboard c = this.getToolkit().getSystemClipboard();

    // Put our TransferableColor object on the clipboard.
    // Also, we'll get notification when we no longer own the clipboard
    c.setContents(tcolor, this);

    // Set a special border on ourselves that indicates that we're the
    // current color available for pasting.
    this.setBorder(highlightBorder);
}