Example usage for java.awt.datatransfer StringSelection StringSelection

List of usage examples for java.awt.datatransfer StringSelection StringSelection

Introduction

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

Prototype

public StringSelection(String data) 

Source Link

Document

Creates a Transferable capable of transferring the specified String .

Usage

From source file:library.Form_Library.java

License:asdf

private void tbSupplierAdminMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbSupplierAdminMouseClicked
    // TODO add your handling code here:
    int donghh = this.tbSupplierAdmin.getSelectedRow();
    Supplier b = SupplierList.getSupplier(donghh);
    this.viewSupplier1(b);
    jMenuItemSup.addActionListener(new ActionListener() {
        @Override//from  w  w w  . ja va  2  s.c  om
        public void actionPerformed(ActionEvent e) {
            StringSelection entry = new StringSelection(tfSupplierID1.getText());
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(entry, entry);
        }
    });
}

From source file:library.Form_Library.java

License:asdf

private void tbBorrowingManagementMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbBorrowingManagementMouseClicked
    int donghh = this.tbBorrowingManagement.getSelectedRow();
    BorrowingManagement b = BorrowingList.getBorrowingManagement(donghh);
    this.viewBorrowing(b);
    //        System.out.println(tbBorrowingManagement.getValueAt(donghh, 4).toString());

    jMenuItemBo.addActionListener(new ActionListener() {
        @Override/*from ww w .j a  v a  2  s  . c o m*/
        public void actionPerformed(ActionEvent e) {
            StringSelection entry = new StringSelection(tfBorrowID.getText());
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(entry, entry);
        }
    });
}

From source file:com.cohort.util.String2.java

/** This method writes a string to the system clipboard.
 * This works in a standalone Java program, not an applet.
 * From Java Developers Almanac./* w w w .  j a v a  2 s  .  co  m*/
 * This won't throw an exception.
 */
public static void setClipboardString(String s) {
    try {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(new StringSelection(s), null);
    } catch (Throwable t) {
        log(ERROR + " while putting the string on the clipboard:\n" + MustBe.throwableToString(t));
    }
}

From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

/**
 * Force handle popup.//from  w ww  .j av a2s. co m
 * 
 * @param robot
 *            the robot
 * @param inputString
 *            the input string
 */
public final void forceHandlePopup(final Robot robot, final String inputString) {
    String[] commandSet = inputString.split("\\|");

    for (String fullCommand : commandSet) {
        sleep(retryInterval);
        int commandIndex = 0;
        int inputIndex = 1;
        String command = fullCommand.split("=")[commandIndex];
        String input = fullCommand.split("=")[inputIndex];
        if ("type".equalsIgnoreCase(command)) {

            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)) {

            super.sleep(Integer.parseInt(input));
        }

    }
}

From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

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

private void fireKeyEvent(final String commands) throws Exception {

    String[] commandSet = commands.split("\\|");
    Robot robot = getRobot();
    for (String fullCommand : commandSet) {
        sleep(retryInterval / 2);
        int commandIndex = 0;
        int inputIndex = 1;
        String command = fullCommand.split("=")[commandIndex];
        String input = fullCommand.split("=")[inputIndex];
        if ("type".equalsIgnoreCase(command)) {

            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)) {

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