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:de.codesourcery.eve.skills.ui.components.impl.planning.ShoppingListComponent.java

private void putSelectedShoppingListOnClipboard() {

    final StringBuffer result = new StringBuffer();

    final ITreeNode selected = getSelectedTreeNode();
    if (selected == null) {
        return;//from ww  w.  j  a  v a 2 s.c  o m
    }

    final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

    ShoppingList list = null;
    if (selected.getValue() instanceof ShoppingList) {
        list = (ShoppingList) selected.getValue();
    } else if (selected.getValue() instanceof ShoppingListEntry) {
        final ShoppingListEntry entry = (ShoppingListEntry) selected.getValue();
        list = entry.getShoppingList();
    }

    if (list == null) {
        return;
    }

    result.append(list.getTitle()).append(Misc.newLine());
    if (!StringUtils.isBlank(list.getDescription())) {
        result.append(Misc.newLine()).append(list.getDescription()).append(Misc.newLine().twice());
    }

    final DecimalFormat quantityFormat = new DecimalFormat("###,###,###,###,##0");

    for (Iterator<ShoppingListEntry> it = list.iterator(); it.hasNext();) {
        final ShoppingListEntry entry = it.next();

        result.append(StringUtils.rightPad(entry.getType().getName(), 30))
                .append(StringUtils.leftPad(quantityFormat.format(entry.getQuantity()), 20));

        if (it.hasNext()) {
            result.append(Misc.newLine());
        }
    }

    clipboard.setContents(new PlainTextTransferable(result.toString()), null);
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

@Override
public void typeUsingRobot(String locator, String value) {
    WebElement we = findElement(locator);
    // try to click otherwise ignore if it fails
    try {/*from w w  w. j  ava  2  s.c om*/
        we.click();
    } catch (Exception e) {
    }
    ClipboardOwner clipboardOwner = new ClipboardOwner() {
        @Override
        public void lostOwnership(Clipboard clipboard, Transferable contents) {
        }
    };
    Robot robot;
    try {
        robot = new Robot();
        try {
            we.sendKeys(value);
        } catch (Exception e) {
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            StringSelection stringSelection = new StringSelection(value);
            clipboard.setContents(stringSelection, clipboardOwner);
            robot.keyPress(KeyEvent.VK_CONTROL);
            robot.keyPress(KeyEvent.VK_V);
            robot.keyRelease(KeyEvent.VK_V);
            robot.keyRelease(KeyEvent.VK_CONTROL);
        }
    } catch (AWTException e1) {
        e1.printStackTrace();
    }
}

From source file:ru.goodfil.catalog.ui.forms.FiltersPanel.java

private void putStringToClipboard(String s) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(new StringSelection(s), this);
}

From source file:com.virtusa.isq.rft.runtime.RFTCommandBase.java

/**
 * Fires a set of java robot key events into the webpage.
 * //from   w w  w  . j a va  2  s.co m
 * @param commands
 *            the commands
 * @throws Exception
 *             the exception
 */

private void fireKeyEvent(final String commands) throws Exception {

    String[] commandSet = commands.split("\\|");
    Robot robot = new Robot();
    for (String fullCommand : commandSet) {
        Utils.pause(retryInterval / 2);
        int commandIndex = 0;
        int inputIndex = 1;
        String command = fullCommand.split("=")[commandIndex];
        String input = fullCommand.split("=")[inputIndex];
        if ("type".equalsIgnoreCase(command)) {
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            StringSelection stringSelection = new StringSelection(input);
            clipboard.setContents(stringSelection, null);

            robot.keyPress(KeyEvent.VK_CONTROL);
            robot.keyPress(KeyEvent.VK_V);
            robot.keyRelease(KeyEvent.VK_V);
            robot.keyRelease(KeyEvent.VK_CONTROL);

        } else if ("Key".equalsIgnoreCase(command)) {

            type(input);
        } else if ("wait".equalsIgnoreCase(command)) {

            Utils.pause(Integer.parseInt(input));
        } else {
            throw new Exception("Command " + command);
        }
    }
}

From source file:cz.muni.fi.pv168.MainForm.java

private void Copy() {
    Clipboard clipboard = getToolkit().getSystemClipboard();
    String data = null;// w w w  . j a va2 s  .c  o m

    switch (jTabbedPane1.getSelectedIndex()) {
    case 0: {
        int column = carTable.getSelectedColumn();
        int row = carTable.getSelectedRow();

        if ((column < 0) || (row < 0)) {
            return;
        }

        CarsTableModel ctm = (CarsTableModel) carTable.getModel();

        data = ctm.getValueAt(row, column).toString();

        break;
    }
    case 1: {
        int column = customerTable.getSelectedColumn();
        int row = customerTable.getSelectedRow();

        if ((column < 0) || (row < 0)) {
            return;
        }

        CustomersTableModel ctm = (CustomersTableModel) customerTable.getModel();

        data = ctm.getValueAt(row, column).toString();

        break;
    }
    case 2: {
        int column = rentTable.getSelectedColumn();
        int row = rentTable.getSelectedRow();

        if ((column < 0) || (row < 0)) {
            return;
        }

        RentsTableModel rtm = (RentsTableModel) rentTable.getModel();

        data = rtm.getValueAt(row, column).toString();

        break;
    }
    default:
        break;
    }

    clipboard.setContents(new StringSelection(data), this);
}

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

/**
 * Copies the current chart to the system clipboard.
 * //from  w  ww  . j  av  a2s. com
 * @since 1.0.13
 */

@Override
public void doCopy() {
    Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Insets insets = getInsets();
    int w = getWidth() - insets.left - insets.right;
    int h = getHeight() - insets.top - insets.bottom;
    ChartTransferable selection = new ChartTransferable(this.chart, w, h);
    systemClipboard.setContents(selection, null);
}

From source file:cz.muni.fi.pv168.MainForm.java

private void Cut() {
    Clipboard clipboard = getToolkit().getSystemClipboard();
    String data = null;/*from   w w  w.  ja va  2 s . co m*/

    switch (jTabbedPane1.getSelectedIndex()) {
    case 0: {
        int column = carTable.getSelectedColumn();
        int row = carTable.getSelectedRow();

        CarsTableModel ctm = (CarsTableModel) carTable.getModel();

        if ((column < 0) || (row < 0) || !ctm.isCellEditable(row, column)) {
            return;
        }

        data = ctm.getValueAt(row, column).toString();
        ctm.setValueAt("", row, column);

        break;
    }
    case 1: {
        int column = customerTable.getSelectedColumn();
        int row = customerTable.getSelectedRow();

        CustomersTableModel ctm = (CustomersTableModel) customerTable.getModel();

        if ((column < 0) || (row < 0) || !ctm.isCellEditable(row, column)) {
            return;
        }

        data = ctm.getValueAt(row, column).toString();
        ctm.setValueAt("", row, column);

        break;
    }
    case 2: {
        int column = rentTable.getSelectedColumn();
        int row = rentTable.getSelectedRow();

        RentsTableModel rtm = (RentsTableModel) rentTable.getModel();

        if ((column < 0) || (row < 0) || !rtm.isCellEditable(row, column)) {
            return;
        }

        data = rtm.getValueAt(row, column).toString();
        rtm.setValueAt("", row, column);

        break;
    }
    default:
        break;
    }

    clipboard.setContents(new StringSelection(data), this);
}

From source file:de.huxhorn.lilith.swing.MainFrame.java

public void copyHtml(String html) {
    Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable transferableText = new HtmlTransferable(html);
    systemClipboard.setContents(transferableText, null);
}

From source file:Tcpbw100.java

public void actionPerformed(ActionEvent event) {
    Object source = event.getSource();
    // System.err.println("Processing WINDOW event #" +event.getID());
    // System.err.println("Processing event " + source);

    if ((source == startTest) || (source == startTest2)) {
        if (f != null) {
            f.toBack();// w w w  . j  a v  a 2s .  c o m
            f.dispose();
            f = null;
        }

        if (ff != null) {
            ff.toBack();
            ff.dispose();
            ff = null;
        }

        pub_errmsg = "Test in progress.";
        runtest();
    }

    else if (source == deTails) {
        deTails.setEnabled(false);
        f.setResizable(true);
        f.setVisible(true);
        deTails.setEnabled(true);
    }

    else if (source == disMiss) {
        f.toBack();
        f.dispose();
    }

    else if (source == disMiss2) {
        ff.toBack();
        ff.dispose();
    }

    else if (source == copy) {
        try {
            Clipboard clipbd = getToolkit().getSystemClipboard();
            cancopy = true;
            String s = diagnosis.getText();
            StringSelection ss = new StringSelection(s);
            clipbd.setContents(ss, ss);
            diagnosis.selectAll();
        } catch (SecurityException e) {
            cancopy = false;
        }
    }

    else if (source == copy2) {
        Clipboard clipbd = getToolkit().getSystemClipboard();
        String s = statistics.getText();
        StringSelection ss = new StringSelection(s);
        clipbd.setContents(ss, ss);
        statistics.selectAll();
    }

    else if (source == sTatistics) {
        sTatistics.setEnabled(false);
        ff.setResizable(true);
        ff.setVisible(true);
        sTatistics.setEnabled(true);
    }

    else if (source == mailTo) {
        int i;
        char key;
        String to[], from[], comments[];
        String Name, Host;

        mailTo.setEnabled(false);
        // envoke mailto: function
        showStatus(messages.getString("invokingMailtoFunction") + "...");

        results.append(messages.getString("generatingReport") + "\n");
        try {
            if ((Name = getParameter(TARGET1)) == null) {
                throw new IllegalArgumentException("U parameter Required:");
            }
            if ((Host = getParameter(TARGET2)) == null) {
                throw new IllegalArgumentException("H parameter Required:");
            }

            String theURL = "mailto:" + Name + "@" + Host;
            String subject = getParameter("subject");

            if (subject == null) {
                subject = messages.getString("troubleReportFrom") + " " + getCodeBase().getHost();
            }
            theURL += "?subject=" + subject;
            theURL += "&body=" + messages.getString("comments") + ":%0A%0A" + emailText + " "
                    + messages.getString("endOfEmail") + "\n%0A";
            // System.out.println("Message body is '" + emailText + "'\n");
            targetURL = new URL(theURL);

        } catch (MalformedURLException rsi) {
            throw new IllegalArgumentException("Can't create mailto: URL" + rsi.getMessage());
        }

        getAppletContext().showDocument(targetURL);
    }
}

From source file:library.Form_Library.java

License:asdf

private void tbcategoryMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbcategoryMouseClicked
    int donghh = this.tbcategory.getSelectedRow();
    Category t = CategoryList.getCategory(donghh);
    this.viewCategory(t);
    jMenuItemCate.addActionListener(new ActionListener() {
        @Override/* w  w w  .  j  a  va 2  s. c o m*/
        public void actionPerformed(ActionEvent e) {
            StringSelection entry = new StringSelection(tfcategoryid.getText());
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(entry, entry);
        }
    });
}