Search in sources :

Example 16 with StringSelection

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

the class VcsLogGraphTable method performCopy.

@Override
public void performCopy(@NotNull DataContext dataContext) {
    StringBuilder sb = new StringBuilder();
    int[] selectedRows = getSelectedRows();
    for (int i = 0; i < Math.min(VcsLogUtil.MAX_SELECTED_COMMITS, selectedRows.length); i++) {
        int row = selectedRows[i];
        for (int j = ROOT_COLUMN + 1; j < getModel().getColumnCount(); j++) {
            sb.append(getModel().getValueAt(row, j).toString());
            if (j < getModel().getRowCount() - 1)
                sb.append(" ");
        }
        if (i != selectedRows.length - 1)
            sb.append("\n");
    }
    CopyPasteManager.getInstance().setContents(new StringSelection(sb.toString()));
}
Also used : StringSelection(java.awt.datatransfer.StringSelection)

Example 17 with StringSelection

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

the class IdeGlassPaneImpl method preprocess.

private boolean preprocess(final MouseEvent e, final boolean motion, JRootPane eventRootPane) {
    try {
        if (UIUtil.getWindow(this) != UIUtil.getWindow(e.getComponent()))
            return false;
        final MouseEvent event = MouseEventAdapter.convert(e, eventRootPane);
        if (event.isAltDown() && SwingUtilities.isLeftMouseButton(event) && event.getID() == MouseEvent.MOUSE_PRESSED) {
            Component c = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
            Balloon balloon = JBPopupFactory.getInstance().getParentBalloonFor(c);
            if (balloon instanceof BalloonImpl) {
                JComponent component = ((BalloonImpl) balloon).getComponent();
                component.getToolkit().getSystemClipboard().setContents(new StringSelection(UIUtil.getDebugText(component)), EmptyClipboardOwner.INSTANCE);
            }
        }
        if (!IdeGlassPaneUtil.canBePreprocessed(e)) {
            return false;
        }
        for (EventListener each : mySortedMouseListeners) {
            if (motion && each instanceof MouseMotionListener) {
                fireMouseMotion((MouseMotionListener) each, event);
            } else if (!motion && each instanceof MouseListener) {
                fireMouseEvent((MouseListener) each, event);
            }
            if (event.isConsumed()) {
                e.consume();
                return true;
            }
        }
        return false;
    } finally {
        if (eventRootPane == myRootPane) {
            Cursor cursor;
            if (!myListener2Cursor.isEmpty()) {
                cursor = myListener2Cursor.values().iterator().next();
                final Point point = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), myRootPane.getContentPane());
                Component target = SwingUtilities.getDeepestComponentAt(myRootPane.getContentPane().getParent(), point.x, point.y);
                if (canProcessCursorFor(target)) {
                    target = getCompWithCursor(target);
                    restoreLastComponent(target);
                    if (target != null) {
                        if (myLastCursorComponent != target) {
                            myLastCursorComponent = target;
                            myLastOriginalCursor = target.getCursor();
                        }
                        if (cursor != null && !cursor.equals(target.getCursor())) {
                            if (target instanceof JComponent) {
                                ((JComponent) target).putClientProperty(PREPROCESSED_CURSOR_KEY, Boolean.TRUE);
                            }
                            target.setCursor(cursor);
                        }
                    }
                    getRootPane().setCursor(cursor);
                }
            } else if (!e.isConsumed() && e.getID() != MouseEvent.MOUSE_DRAGGED) {
                cursor = Cursor.getDefaultCursor();
                JRootPane rootPane = getRootPane();
                if (rootPane != null) {
                    rootPane.setCursor(cursor);
                } else {
                    LOG.warn("Root pane is null. Event: " + e);
                }
                restoreLastComponent(null);
                myLastOriginalCursor = null;
                myLastCursorComponent = null;
            }
            myListener2Cursor.clear();
        }
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseListener(java.awt.event.MouseListener) Balloon(com.intellij.openapi.ui.popup.Balloon) BalloonImpl(com.intellij.ui.BalloonImpl) AWTEventListener(java.awt.event.AWTEventListener) MouseMotionListener(java.awt.event.MouseMotionListener) StringSelection(java.awt.datatransfer.StringSelection)

Example 18 with StringSelection

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

the class FocusTracesDialog method getCopyStackTraceAction.

private Action getCopyStackTraceAction() {
    return new AbstractAction("&Copy stacktrace") {

        @Override
        public void actionPerformed(ActionEvent e) {
            String text = ExceptionUtil.getThrowableText(myRequests.get(myRequestsTable.getSelectedRow()).trace);
            CopyPasteManager.getInstance().setContents(new StringSelection(text));
        }
    };
}
Also used : ActionEvent(java.awt.event.ActionEvent) StringSelection(java.awt.datatransfer.StringSelection)

Example 19 with StringSelection

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

the class MultiplePasteAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    Component focusedComponent = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    if (!(focusedComponent instanceof JComponent))
        return;
    final CopyPasteManagerEx copyPasteManager = CopyPasteManagerEx.getInstanceEx();
    final ContentChooser<Transferable> chooser = new ContentChooser<Transferable>(project, UIBundle.message("choose.content.to.paste.dialog.title"), true, true) {

        @Override
        protected String getStringRepresentationFor(final Transferable content) {
            try {
                return (String) content.getTransferData(DataFlavor.stringFlavor);
            } catch (UnsupportedFlavorException | IOException e1) {
                return "";
            }
        }

        @Override
        protected List<Transferable> getContents() {
            return Arrays.asList(CopyPasteManager.getInstance().getAllContents());
        }

        @Override
        protected void removeContentAt(final Transferable content) {
            copyPasteManager.removeContent(content);
        }
    };
    if (!chooser.getAllContents().isEmpty()) {
        chooser.show();
    } else {
        chooser.close(DialogWrapper.CANCEL_EXIT_CODE);
    }
    if (chooser.isOK()) {
        List<Transferable> selectedContents = chooser.getSelectedContents();
        if (selectedContents.size() == 1) {
            copyPasteManager.moveContentToStackTop(selectedContents.get(0));
        } else {
            copyPasteManager.setContents(new StringSelection(chooser.getSelectedText()));
        }
        if (editor != null) {
            if (editor.isViewer())
                return;
            final AnAction pasteAction = ActionManager.getInstance().getAction(IdeActions.ACTION_PASTE);
            AnActionEvent newEvent = new AnActionEvent(e.getInputEvent(), DataManager.getInstance().getDataContext(focusedComponent), e.getPlace(), e.getPresentation(), ActionManager.getInstance(), e.getModifiers());
            pasteAction.actionPerformed(newEvent);
        } else {
            final Action pasteAction = ((JComponent) focusedComponent).getActionMap().get(DefaultEditorKit.pasteAction);
            if (pasteAction != null) {
                pasteAction.actionPerformed(new ActionEvent(focusedComponent, ActionEvent.ACTION_PERFORMED, ""));
            }
        }
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) CopyPasteManagerEx(com.intellij.ide.CopyPasteManagerEx) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) StringSelection(java.awt.datatransfer.StringSelection) Project(com.intellij.openapi.project.Project) Editor(com.intellij.openapi.editor.Editor)

Example 20 with StringSelection

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

the class DartProblemsViewPanel method performCopy.

@Override
public void performCopy(@NotNull DataContext dataContext) {
    final List<DartProblem> selectedObjects = myTable.getSelectedObjects();
    final String s = StringUtil.join(selectedObjects, problem -> problem.getSeverity().toLowerCase(Locale.US) + ": " + problem.getErrorMessage() + " (" + problem.getCode() + " at " + problem.getPresentableLocation() + ")", "\n");
    if (!s.isEmpty()) {
        CopyPasteManager.getInstance().setContents(new StringSelection(s));
    }
}
Also used : 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