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:Samples.Advanced.GraphEditorDemo.java

/**
* Place a String on the clipboard, and make this class the
* owner of the Clipboard's contents.//from www  . ja v  a2 s.c  om
*/
public void setClipboardContents(String aString) {
    StringSelection stringSelection = new StringSelection(aString);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(stringSelection, this);
}

From source file:net.sf.keystore_explorer.gui.dialogs.DViewCertCsrPem.java

private void copyPressed() {
    String policy = jtaPem.getText();

    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    StringSelection copy = new StringSelection(policy);
    clipboard.setContents(copy, copy);
}

From source file:org.kuali.test.ui.base.BaseTable.java

/**
 *
 * @param config/*from  w  ww .ja va  2s  . c o  m*/
 */
public BaseTable(TableConfiguration config) {
    super(new BaseTableModel(config));

    for (int i = 0; i < config.getHeaders().length; ++i) {
        int cx = getColumnWidth(i);
        getColumnModel().getColumn(i).setWidth(cx);
        getColumnModel().getColumn(i).setPreferredWidth(cx);
    }

    getTableHeader().setReorderingAllowed(false);
    setShowHorizontalLines(true);
    setShowVerticalLines(true);
    setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);

    popupMenu = new JPopupMenu();
    JMenuItem m;
    popupMenu.add(m = new JMenuItem(Constants.COPY_ACTION));
    m.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(new StringSelection(celldata), BaseTable.this);
            celldata = null;
        }
    });

    MouseAdapter ma = new MouseAdapter() {
        private void myPopupEvent(MouseEvent e) {
            int col = BaseTable.this.columnAtPoint(e.getPoint());
            int row = BaseTable.this.rowAtPoint(e.getPoint());
            if ((col > -1) && (row > -1)) {
                if (BaseTable.this.getValueAt(row, col) != null) {
                    celldata = BaseTable.this.getValueAt(row, col).toString();
                    popupMenu.show(BaseTable.this.getComponentAt(e.getX(), e.getY()), e.getX(), e.getY());
                }
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                myPopupEvent(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                myPopupEvent(e);
            }
        }
    };

    addMouseListener(ma);

    initializing = false;
}

From source file:com.igormaznitsa.sciareto.ui.editors.mmeditors.NoteEditor.java

private void buttonCopyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCopyActionPerformed
    StringSelection stringSelection = new StringSelection(this.editorPane.getSelectedText());
    final Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
    clpbrd.setContents(stringSelection, null);
}

From source file:simplesqlformatter.formatter.SQLFormatterEditor.java

private void copyToClipboard(final String copiedSQL) {
    final StringSelection sql = new StringSelection(copiedSQL);
    final Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
    clip.setContents(sql, sql);
}

From source file:clipboardplugin.ClipboardPlugin.java

/**
 * Copy Programs to System-Clipboard//from  w ww.  j  a va 2  s.co m
 *
 * @param programs Programs to Copy
 * @param config The program formating.
 */
public void copyProgramsToSystem(Program[] programs, AbstractPluginProgramFormating config) {
    String param = config.getContentValue();//mSettings.getProperty("ParamToUse", DEFAULT_PARAM);

    StringBuilder result = new StringBuilder();
    ParamParser parser = new ParamParser();

    int i = 0;

    while (!parser.hasErrors() && (i < programs.length)) {
        String prgResult = parser.analyse(param, programs[i]);
        result.append(prgResult);
        i++;
    }

    if (!parser.showErrors(UiUtilities.getLastModalChildOf(getParentFrame()))) {
        Clipboard clip = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
        clip.setContents(new StringSelection(result.toString()), null);
    }
}

From source file:com.igormaznitsa.nbmindmap.nb.swing.PlainTextEditor.java

private void buttonCopyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCopyActionPerformed
    StringSelection stringSelection = new StringSelection(this.lastEditor.getSelectedText());
    final Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
    clpbrd.setContents(stringSelection, null);
}

From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferHandler.java

public void exportToClipboard(JComponent c, Clipboard clip, int action) {
    boolean exportSuccess = false;
    Transferable t = null;/*from w w w . j  a  v a  2  s.c o  m*/

    if (action != NONE) {
        t = createTransferable(c, action);
        if (t != null) {
            clip.setContents(t, null);
            exportSuccess = true;
        }
    }

    if (exportSuccess) {
        exportDone(c, t, action);
    } else {
        exportDone(c, null, NONE);
    }
}

From source file:is.iclt.jcorpald.CorpaldView.java

private void copyToClipboard() {
    try {//from www .  j  a  v a  2s.c om
        File toOpen = model.getResultFile();
        String resultString = FileUtils.readFileToString(toOpen);
        StringSelection stringSelection = new StringSelection(resultString);
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(stringSelection, this);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:balony.summarizeJFrame.java

public void clipboardCopy(int col) {
    String clip = "";

    if (!jTextField1.getText().isEmpty()) {
        clip = jTextField1.getText().concat("\n");
    }//from www  .  ja v  a2  s .c o m

    for (int i = 0; i < tableData.length; i++) {
        int j = jTable1.convertRowIndexToModel(i);
        clip = clip.concat(tableData[j][col].toString().concat("\n"));
    }

    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(new StringSelection(clip), this);
}