Search in sources :

Example 81 with StringSelection

use of java.awt.datatransfer.StringSelection in project azure-tools-for-java by Microsoft.

the class BlobExplorerFileEditor method copyURLSelectedFile.

private void copyURLSelectedFile() {
    BlobFile fileSelection = getFileSelection();
    if (fileSelection != null) {
        StringSelection selection = new StringSelection(fileSelection.getUri());
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(selection, selection);
    }
}
Also used : BlobFile(com.microsoft.tooling.msservices.model.storage.BlobFile) Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 82 with StringSelection

use of java.awt.datatransfer.StringSelection in project azure-tools-for-java by Microsoft.

the class ProjectUtil method createSparkSDKTipsPanel.

public static JPanel createSparkSDKTipsPanel() {
    final JPanel panel = new JPanel();
    GridBagLayout layout = new GridBagLayout();
    JLabel[] labels = new JLabel[] { new JLabel("You can either download Spark library from"), new JLabel("<HTML><FONT color=\"#000099\"><U>here</U></FONT>,</HTML>"), new JLabel("or add Apache Spark packages from Maven repository in the project manually.") };
    for (int i = 0; i < labels.length; ++i) {
        panel.add(labels[i]);
    }
    labels[1].setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    labels[1].setToolTipText(downloadSparkSDKUrl);
    labels[1].addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                StringSelection stringSelection = new StringSelection(downloadSparkSDKUrl);
                Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                clipboard.setContents(stringSelection, null);
                JOptionPane.showMessageDialog(panel, "Already copy Download URL to Clipboard");
            } else if (SwingUtilities.isLeftMouseButton(e)) {
                try {
                    URI uri = new URI(downloadSparkSDKUrl);
                    Desktop.getDesktop().browse(uri);
                } catch (Exception exception) {
                    DefaultLoader.getUIHelper().showError(exception.getMessage(), exception.getClass().getName());
                }
            }
        }
    });
    GridBagConstraints constraints = new GridBagConstraints(GridBagConstraints.RELATIVE, GridBagConstraints.RELATIVE, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0);
    layout.setConstraints(labels[0], constraints);
    layout.setConstraints(labels[1], constraints);
    layout.setConstraints(labels[2], constraints);
    JPanel mainPanel = new JPanel();
    GridBagLayout mainLayout = new GridBagLayout();
    mainPanel.setLayout(mainLayout);
    mainPanel.add(panel, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    //make sure label message on the head of left
    mainPanel.add(new JLabel(), new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    return mainPanel;
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) URI(java.net.URI) StringSelection(java.awt.datatransfer.StringSelection) Clipboard(java.awt.datatransfer.Clipboard)

Example 83 with StringSelection

use of java.awt.datatransfer.StringSelection in project cloudstack by apache.

the class VncServerPacketReceiver method serverCutText.

/**
     * Handle packet with server clip-board.
     */
private void serverCutText(DataInputStream is) throws IOException {
    ServerCutText clipboardContent = new ServerCutText(is);
    StringSelection contents = new StringSelection(clipboardContent.getContent());
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, null);
    s_logger.info("Server clipboard buffer: " + clipboardContent.getContent());
}
Also used : ServerCutText(com.cloud.consoleproxy.vnc.packet.server.ServerCutText) StringSelection(java.awt.datatransfer.StringSelection)

Example 84 with StringSelection

use of java.awt.datatransfer.StringSelection in project adempiere by adempiere.

the class VTableExcelAdapter method actionPerformed.

/**
	 * This method is activated on the Keystrokes we are listening to
	 * in this implementation. Here it listens for Copy and Paste ActionCommands.
	 * 
	 * @param e event 
	 */
public void actionPerformed(ActionEvent e) {
    // Only GridTable model is supported
    if (!(table.getModel() instanceof GridTable)) {
        if (CLogMgt.isLevelFine())
            log.fine("Not supported - " + table.getModel());
        return;
    }
    boolean isCopy = CMD_Copy.equals(e.getActionCommand());
    boolean isCopyWithHeaders = CMD_CopyWithHeaders.equals(e.getActionCommand());
    if (isCopy || isCopyWithHeaders) {
        try {
            int[] selectedRows = table.getSelectedRows();
            if (selectedRows == null || selectedRows.length == 0) {
                return;
            }
            int colscount = table.getColumnCount();
            StringBuffer sb = new StringBuffer();
            GridTable model = (GridTable) table.getModel();
            GridField[] fields = model.getFields();
            // Header
            if (isCopyWithHeaders) {
                for (int col = 0; col < colscount; col++) {
                    String value = "";
                    try {
                        GridField field = fields[col];
                        if (!field.isDisplayed(false)) {
                            continue;
                        }
                        value = field.getHeader();
                    } catch (Exception ex) {
                        log.log(Level.WARNING, "Copy-headers", ex);
                    }
                    value = fixString(value);
                    sb.append(value).append("\t");
                }
                sb.append(Env.NL);
            }
            // Selected rows
            for (int row : selectedRows) {
                for (int col = 0; col < colscount; col++) {
                    Lookup lookup = null;
                    String value = null;
                    Object key = null;
                    GridField field = null;
                    try {
                        key = table.getValueAt(row, col);
                        field = fields[col];
                        if (!field.isDisplayed(false))
                            continue;
                        if (field.isEncryptedColumn() || field.isEncryptedField()) {
                            value = "*";
                        } else if (key instanceof Boolean) {
                            value = Msg.getMsg(Env.getCtx(), ((Boolean) key).booleanValue() ? "Yes" : "No");
                        } else if (key instanceof BigDecimal) {
                            try {
                                value = sysNumberFormat.format(key != null ? key : Env.ZERO);
                            } catch (Exception ex) {
                            }
                        } else if (key instanceof Date) {
                            try {
                                value = sysDateFormat.format(key);
                            } catch (Exception ex) {
                            }
                        } else {
                            lookup = (field != null ? field.getLookup() : null);
                            value = (lookup != null && key != null ? lookup.getDisplay(key) : null);
                            if (value == null && key != null)
                                value = key.toString();
                        }
                    } catch (Exception ex) {
                        log.log(Level.WARNING, "Copy-rows", ex);
                    }
                    value = fixString(value);
                    sb.append(value).append("\t");
                    if (CLogMgt.isLevelFinest())
                        log.finest("col=" + col + ", row=" + row + ": key=" + key + " => value=" + value + ", " + field + ", " + lookup);
                }
                sb.append(Env.NL);
            }
            StringSelection stsel = new StringSelection(sb.toString());
            system = Toolkit.getDefaultToolkit().getSystemClipboard();
            system.setContents(stsel, stsel);
        } catch (Exception ex) {
            log.log(Level.WARNING, "Copy", ex);
        }
    }
}
Also used : GridTable(org.compiere.model.GridTable) GridField(org.compiere.model.GridField) BigDecimal(java.math.BigDecimal) Date(java.util.Date) StringSelection(java.awt.datatransfer.StringSelection) Lookup(org.compiere.model.Lookup)

Example 85 with StringSelection

use of java.awt.datatransfer.StringSelection in project pcgen by PCGen.

the class NameGenPanel method jButton1ActionPerformed.

//GEN-END:initComponents
private void jButton1ActionPerformed(ActionEvent evt) {
    //GEN-FIRST:event_jButton1ActionPerformed
    Clipboard cb = getToolkit().getSystemClipboard();
    StringSelection ss = new StringSelection(name.getText());
    cb.setContents(ss, ss);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Aggregations

StringSelection (java.awt.datatransfer.StringSelection)99 Clipboard (java.awt.datatransfer.Clipboard)28 ActionEvent (java.awt.event.ActionEvent)11 Transferable (java.awt.datatransfer.Transferable)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 JTextArea (javax.swing.JTextArea)7 Test (org.junit.Test)7 JPanel (javax.swing.JPanel)6 ActionListener (java.awt.event.ActionListener)5 JScrollPane (javax.swing.JScrollPane)5 Editor (com.intellij.openapi.editor.Editor)4 Project (com.intellij.openapi.project.Project)4 PsiFile (com.intellij.psi.PsiFile)4 ClipboardOwner (java.awt.datatransfer.ClipboardOwner)4 JMenuItem (javax.swing.JMenuItem)4 BibEntry (org.jabref.model.entry.BibEntry)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 PsiElement (com.intellij.psi.PsiElement)3 BorderLayout (java.awt.BorderLayout)3