Search in sources :

Example 71 with Transferable

use of java.awt.datatransfer.Transferable in project android by JetBrains.

the class LayoutTestUtilities method createTransferable.

public static Transferable createTransferable(DataFlavor flavor, Object data) throws IOException, UnsupportedFlavorException {
    Transferable transferable = mock(Transferable.class);
    when(transferable.getTransferDataFlavors()).thenReturn(new DataFlavor[] { flavor });
    when(transferable.getTransferData(eq(flavor))).thenReturn(data);
    when(transferable.isDataFlavorSupported(eq(flavor))).thenReturn(true);
    return transferable;
}
Also used : Transferable(java.awt.datatransfer.Transferable)

Example 72 with Transferable

use of java.awt.datatransfer.Transferable in project android by JetBrains.

the class NlComponentTree method performPaste.

@Override
public void performPaste(@NotNull DataContext dataContext) {
    InsertSpecification spec = getInsertSpecification();
    if (spec == null) {
        return;
    }
    Transferable transferable = myCopyPasteManager.getContents();
    if (transferable == null) {
        return;
    }
    DnDTransferItem item = NlModel.getTransferItem(transferable, true);
    if (item == null) {
        return;
    }
    List<NlComponent> components = ApplicationManager.getApplication().runWriteAction((Computable<List<NlComponent>>) () -> myModel.createComponents(myScreenView, item, InsertType.PASTE));
    myModel.addComponents(components, spec.layout, spec.before, InsertType.PASTE);
}
Also used : Transferable(java.awt.datatransfer.Transferable) List(java.util.List) ArrayList(java.util.ArrayList)

Example 73 with Transferable

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

the class EditorGutterComponentImpl method installDnD.

@SuppressWarnings("ConstantConditions")
private void installDnD() {
    DnDSupport.createBuilder(this).setBeanProvider(info -> {
        final GutterMark renderer = getGutterRenderer(info.getPoint());
        if (renderer instanceof GutterIconRenderer && ((GutterIconRenderer) renderer).getDraggableObject() != null && (info.isCopy() || info.isMove())) {
            myDnDInProgress = true;
            return new DnDDragStartBean(renderer);
        }
        return null;
    }).setDropHandler(e -> {
        final Object attachedObject = e.getAttachedObject();
        if (attachedObject instanceof GutterIconRenderer && checkDumbAware(attachedObject)) {
            final GutterDraggableObject draggableObject = ((GutterIconRenderer) attachedObject).getDraggableObject();
            if (draggableObject != null) {
                final int line = convertPointToLineNumber(e.getPoint());
                if (line != -1) {
                    draggableObject.copy(line, myEditor.getVirtualFile());
                }
            }
        } else if (attachedObject instanceof DnDNativeTarget.EventInfo && myEditor.getSettings().isDndEnabled()) {
            Transferable transferable = ((DnDNativeTarget.EventInfo) attachedObject).getTransferable();
            if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                EditorImpl.handleDrop(myEditor, transferable, e.getAction().getActionId());
            }
        }
        myDnDInProgress = false;
    }).setTargetChecker(e -> {
        final Object attachedObject = e.getAttachedObject();
        if (attachedObject instanceof GutterIconRenderer && checkDumbAware(attachedObject)) {
            final GutterDraggableObject draggableObject = ((GutterIconRenderer) attachedObject).getDraggableObject();
            if (draggableObject != null) {
                final int line = convertPointToLineNumber(e.getPoint());
                if (line != -1) {
                    e.setDropPossible(true);
                    e.setCursor(draggableObject.getCursor(line));
                }
            }
        } else if (attachedObject instanceof DnDNativeTarget.EventInfo && myEditor.getSettings().isDndEnabled()) {
            Transferable transferable = ((DnDNativeTarget.EventInfo) attachedObject).getTransferable();
            if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                final int line = convertPointToLineNumber(e.getPoint());
                if (line != -1) {
                    e.setDropPossible(true);
                    myEditor.getCaretModel().moveToOffset(myEditor.getDocument().getLineStartOffset(line));
                }
            }
        }
        return true;
    }).setImageProvider((NullableFunction<DnDActionInfo, DnDImage>) info -> {
        boolean inUserScale = SystemInfo.isWindows ? !UIUtil.isJreHiDPI(myEditor.getComponent()) : true;
        Image image = ImageUtil.toBufferedImage(getDragImage(getGutterRenderer(info.getPoint())), inUserScale);
        return new DnDImage(image, new Point(image.getWidth(null) / 2, image.getHeight(null) / 2));
    }).enableAsNativeTarget().install();
}
Also used : ScalableIcon(com.intellij.openapi.util.ScalableIcon) TIntFunction(gnu.trove.TIntFunction) HashMap(com.intellij.util.containers.HashMap) EditorUtil(com.intellij.openapi.editor.ex.util.EditorUtil) EditorFontType(com.intellij.openapi.editor.colors.EditorFontType) Balloon(com.intellij.openapi.ui.popup.Balloon) EditorMouseEventArea(com.intellij.openapi.editor.event.EditorMouseEventArea) ColorKey(com.intellij.openapi.editor.colors.ColorKey) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) Logger(com.intellij.openapi.diagnostic.Logger) IterationState(com.intellij.openapi.editor.impl.view.IterationState) TIntArrayList(gnu.trove.TIntArrayList) DumbService(com.intellij.openapi.project.DumbService) ComponentUI(javax.swing.plaf.ComponentUI) com.intellij.openapi.editor.markup(com.intellij.openapi.editor.markup) AffineTransform(java.awt.geom.AffineTransform) TooltipController(com.intellij.codeInsight.hint.TooltipController) TIntObjectProcedure(gnu.trove.TIntObjectProcedure) IdeGlassPaneImpl(com.intellij.openapi.wm.impl.IdeGlassPaneImpl) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ApplicationImpl(com.intellij.openapi.application.impl.ApplicationImpl) com.intellij.util.ui(com.intellij.util.ui) java.awt.event(java.awt.event) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Registry(com.intellij.openapi.util.registry.Registry) NonHideableIconGutterMark(com.intellij.codeInsight.daemon.NonHideableIconGutterMark) com.intellij.util(com.intellij.util) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) RelativePoint(com.intellij.ui.awt.RelativePoint) JBColor(com.intellij.ui.JBColor) java.util(java.util) GutterMark(com.intellij.codeInsight.daemon.GutterMark) DataFlavor(java.awt.datatransfer.DataFlavor) ActionUtil(com.intellij.openapi.actionSystem.ex.ActionUtil) com.intellij.openapi.editor(com.intellij.openapi.editor) Transferable(java.awt.datatransfer.Transferable) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) IdeEventQueue(com.intellij.ide.IdeEventQueue) Comparing(com.intellij.openapi.util.Comparing) HintHint(com.intellij.ui.HintHint) Project(com.intellij.openapi.project.Project) com.intellij.openapi.editor.ex(com.intellij.openapi.editor.ex) com.intellij.ide.dnd(com.intellij.ide.dnd) StringUtil(com.intellij.openapi.util.text.StringUtil) JBUIScaleTrackable(com.intellij.util.ui.JBUI.JBUIScaleTrackable) SystemInfo(com.intellij.openapi.util.SystemInfo) TooltipGroup(com.intellij.codeInsight.hint.TooltipGroup) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) EditorUIUtil(com.intellij.openapi.editor.ex.util.EditorUIUtil) VisualLinesIterator(com.intellij.openapi.editor.impl.view.VisualLinesIterator) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) EditorColors(com.intellij.openapi.editor.colors.EditorColors) CustomActionsSchema(com.intellij.ide.ui.customization.CustomActionsSchema) javax.swing(javax.swing) Transferable(java.awt.datatransfer.Transferable) RelativePoint(com.intellij.ui.awt.RelativePoint) NonHideableIconGutterMark(com.intellij.codeInsight.daemon.NonHideableIconGutterMark) GutterMark(com.intellij.codeInsight.daemon.GutterMark) RelativePoint(com.intellij.ui.awt.RelativePoint) HintHint(com.intellij.ui.HintHint)

Example 74 with Transferable

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

the class EditorCopyPasteHelperImpl method copySelectionToClipboard.

@Override
public void copySelectionToClipboard(@NotNull Editor editor) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    List<TextBlockTransferableData> extraData = new ArrayList<>();
    String s = editor.getCaretModel().supportsMultipleCarets() ? getSelectedTextForClipboard(editor, extraData) : editor.getSelectionModel().getSelectedText();
    if (s == null)
        return;
    s = TextBlockTransferable.convertLineSeparators(s, "\n", extraData);
    Transferable contents = editor.getCaretModel().supportsMultipleCarets() ? new TextBlockTransferable(s, extraData, null) : new StringSelection(s);
    CopyPasteManager.getInstance().setContents(contents);
}
Also used : TextBlockTransferable(com.intellij.codeInsight.editorActions.TextBlockTransferable) ArrayList(java.util.ArrayList) TextBlockTransferableData(com.intellij.codeInsight.editorActions.TextBlockTransferableData) Transferable(java.awt.datatransfer.Transferable) TextBlockTransferable(com.intellij.codeInsight.editorActions.TextBlockTransferable) StringSelection(java.awt.datatransfer.StringSelection)

Example 75 with Transferable

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

the class RichCopyTest method doTest.

private void doTest(boolean columnMode) throws Exception {
    myFixture.configureByFile(getTestName(false) + ".java");
    if (columnMode) {
        myFixture.performEditorAction("EditorToggleColumnMode");
    }
    myFixture.performEditorAction("EditorCopy");
    Transferable contents = CopyPasteManager.getInstance().getContents();
    assertNotNull(contents);
    assertTrue(contents.isDataFlavorSupported(HtmlTransferableData.FLAVOR));
    String expectedHtml = getFileContents(getTestName(false) + ".html");
    String actualHtml = readFully((Reader) contents.getTransferData(HtmlTransferableData.FLAVOR));
    assertMatches("HTML contents differs", expectedHtml, actualHtml);
    assertTrue(contents.isDataFlavorSupported(RtfTransferableData.FLAVOR));
    String expectedRtf = getFileContents(getTestName(false) + ".rtf" + (SystemInfo.isMac ? ".mac" : ""));
    String actualRtf = readFully((InputStream) contents.getTransferData(RtfTransferableData.FLAVOR));
    assertMatches("RTF contents differs", expectedRtf, actualRtf);
}
Also used : Transferable(java.awt.datatransfer.Transferable)

Aggregations

Transferable (java.awt.datatransfer.Transferable)96 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)30 IOException (java.io.IOException)30 List (java.util.List)18 DataFlavor (java.awt.datatransfer.DataFlavor)14 ArrayList (java.util.ArrayList)14 File (java.io.File)13 Clipboard (java.awt.datatransfer.Clipboard)12 Point (java.awt.Point)9 StringSelection (java.awt.datatransfer.StringSelection)5 Project (com.intellij.openapi.project.Project)4 ClipboardOwner (java.awt.datatransfer.ClipboardOwner)4 TransferHandler (javax.swing.TransferHandler)4 Editor (com.intellij.openapi.editor.Editor)3 ActionEvent (java.awt.event.ActionEvent)3 JComponent (javax.swing.JComponent)3 TreePath (javax.swing.tree.TreePath)3 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 PsiElement (com.intellij.psi.PsiElement)2