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;
}
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);
}
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();
}
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);
}
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);
}
Aggregations