Search in sources :

Example 6 with StringSelection

use of java.awt.datatransfer.StringSelection in project vectalign by bonnyfone.

the class Utils method copyToClipboard.

public static void copyToClipboard(String data) {
    Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
    clpbrd.setContents(new StringSelection(data), null);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Example 7 with StringSelection

use of java.awt.datatransfer.StringSelection in project smile by haifengl.

the class TableCopyPasteAdapter method actionPerformed.

/**
     * This method is activated on the Keystrokes we are listening to in this
     * implementation. Here it listens for Copy and Paste ActionCommands.
     * Selections comprising non-adjacent cells result in invalid selection and
     * then copy action cannot be performed. Paste is done by aligning the upper
     * left corner of the selection with the 1st element in the current
     * selection of the JTable.
     */
@Override
public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().compareTo("Copy") == 0) {
        StringBuilder sbf = new StringBuilder();
        // Check to ensure we have selected only a contiguous block of
        // cells
        int numcols = table.getSelectedColumnCount();
        int numrows = table.getSelectedRowCount();
        int[] rowsselected = table.getSelectedRows();
        int[] colsselected = table.getSelectedColumns();
        if (!((numrows - 1 == rowsselected[rowsselected.length - 1] - rowsselected[0] && numrows == rowsselected.length) && (numcols - 1 == colsselected[colsselected.length - 1] - colsselected[0] && numcols == colsselected.length))) {
            JOptionPane.showMessageDialog(null, "Invalid Copy Selection", "Invalid Copy Selection", JOptionPane.ERROR_MESSAGE);
            return;
        }
        for (int i = 0; i < numrows; i++) {
            for (int j = 0; j < numcols; j++) {
                sbf.append(table.getValueAt(rowsselected[i], colsselected[j]));
                if (j < numcols - 1) {
                    sbf.append("\t");
                }
            }
            sbf.append("\n");
        }
        stsel = new StringSelection(sbf.toString());
        system = Toolkit.getDefaultToolkit().getSystemClipboard();
        system.setContents(stsel, stsel);
    }
    if (e.getActionCommand().compareTo("Paste") == 0) {
        LOGGER.log(Level.FINE, "Trying to Paste");
        int startRow = (table.getSelectedRows())[0];
        int startCol = (table.getSelectedColumns())[0];
        try {
            String trstring = (String) (system.getContents(this).getTransferData(DataFlavor.stringFlavor));
            StringTokenizer st1 = new StringTokenizer(trstring, "\n");
            for (int i = 0; st1.hasMoreTokens(); i++) {
                rowstring = st1.nextToken();
                StringTokenizer st2 = new StringTokenizer(rowstring, "\t");
                for (int j = 0; st2.hasMoreTokens(); j++) {
                    value = (String) st2.nextToken();
                    if (startRow + i < table.getRowCount() && startCol + j < table.getColumnCount()) {
                        table.setValueAt(value, startRow + i, startCol + j);
                    }
                }
            }
        } catch (Exception ex) {
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) StringSelection(java.awt.datatransfer.StringSelection)

Example 8 with StringSelection

use of java.awt.datatransfer.StringSelection in project intellij-community by JetBrains.

the class OpenUrlHyperlinkInfo method getPopupMenuGroup.

@Override
public ActionGroup getPopupMenuGroup(@NotNull MouseEvent event) {
    DefaultActionGroup group = new DefaultActionGroup();
    for (final WebBrowser browser : WebBrowserManager.getInstance().getActiveBrowsers()) {
        if (browserCondition.value(browser)) {
            group.add(new AnAction("Open in " + browser.getName(), "Open URL in " + browser.getName(), browser.getIcon()) {

                @Override
                public void actionPerformed(AnActionEvent e) {
                    BrowserLauncher.getInstance().browse(url, browser, e.getProject());
                }
            });
        }
    }
    group.add(new AnAction("Copy URL", "Copy URL to clipboard", PlatformIcons.COPY_ICON) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            CopyPasteManager.getInstance().setContents(new StringSelection(url));
        }
    });
    return group;
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) AnAction(com.intellij.openapi.actionSystem.AnAction) StringSelection(java.awt.datatransfer.StringSelection)

Example 9 with StringSelection

use of java.awt.datatransfer.StringSelection in project intellij-community by JetBrains.

the class HgCachingCommittedChangesProvider method createActions.

public VcsCommittedViewAuxiliary createActions(DecoratorManager decoratorManager, RepositoryLocation repositoryLocation) {
    AnAction copyHashAction = new AnAction("Copy &Hash", "Copy hash to clipboard", PlatformIcons.COPY_ICON) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            ChangeList[] changeLists = e.getData(VcsDataKeys.CHANGE_LISTS);
            if (changeLists != null && changeLists[0] instanceof HgCommittedChangeList) {
                HgRevisionNumber revisionNumber = ((HgCommittedChangeList) changeLists[0]).getRevisionNumber();
                CopyPasteManager.getInstance().setContents(new StringSelection(revisionNumber.getChangeset()));
            }
        }
    };
    return new VcsCommittedViewAuxiliary(Collections.singletonList(copyHashAction), new Runnable() {

        public void run() {
        }
    }, Collections.singletonList(copyHashAction));
}
Also used : CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) ChangeList(com.intellij.openapi.vcs.changes.ChangeList) VcsCommittedViewAuxiliary(com.intellij.openapi.vcs.changes.committed.VcsCommittedViewAuxiliary) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) StringSelection(java.awt.datatransfer.StringSelection)

Example 10 with StringSelection

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

the class PopupMenuCopyUrls method performHistoryReferenceActions.

@Override
protected void performHistoryReferenceActions(List<HistoryReference> hrefs) {
    StringBuilder sb = new StringBuilder();
    for (HistoryReference href : hrefs) {
        sb.append(href.getURI().toString());
        sb.append("\n");
    }
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(new StringSelection(sb.toString()), this);
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) Clipboard(java.awt.datatransfer.Clipboard) StringSelection(java.awt.datatransfer.StringSelection)

Aggregations

StringSelection (java.awt.datatransfer.StringSelection)92 Clipboard (java.awt.datatransfer.Clipboard)23 ActionEvent (java.awt.event.ActionEvent)11 Transferable (java.awt.datatransfer.Transferable)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 JPanel (javax.swing.JPanel)6 JTextArea (javax.swing.JTextArea)6 ActionListener (java.awt.event.ActionListener)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 JScrollPane (javax.swing.JScrollPane)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