use of com.android.tools.idea.uibuilder.model.DnDTransferItem in project android by JetBrains.
the class NlPalettePanelTest method testCopy.
public void testCopy() throws Exception {
myPanel.requestFocus();
DataContext context = mock(DataContext.class);
CopyProvider provider = (CopyProvider) myPanel.getData(PlatformDataKeys.COPY_PROVIDER.getName());
assertThat(provider).isNotNull();
assertThat(provider.isCopyVisible(context)).isTrue();
assertThat(provider.isCopyEnabled(context)).isTrue();
provider.performCopy(context);
ArgumentCaptor<Transferable> captor = ArgumentCaptor.forClass(Transferable.class);
verify(myCopyPasteManager).setContents(captor.capture());
Transferable transferable = captor.getValue();
assertThat(transferable).isNotNull();
assertThat(transferable.isDataFlavorSupported(ItemTransferable.DESIGNER_FLAVOR)).isTrue();
Object item = transferable.getTransferData(ItemTransferable.DESIGNER_FLAVOR);
assertThat(item).isInstanceOf(DnDTransferItem.class);
DnDTransferItem dndItem = (DnDTransferItem) item;
assertThat(dndItem.getComponents().size()).isEqualTo(1);
DnDTransferComponent component = dndItem.getComponents().get(0);
assertThat(component.getRepresentation()).startsWith(("<TextView"));
}
use of com.android.tools.idea.uibuilder.model.DnDTransferItem in project android by JetBrains.
the class ItemTransferHandler method createTransferable.
@Override
@Nullable
protected Transferable createTransferable(@NotNull JComponent component) {
Palette.Item item = myItemSupplier.get();
if (item == null) {
return null;
}
ScreenView screenView = myDesignSurface.getCurrentScreenView();
if (screenView == null) {
return null;
}
@AndroidCoordinate Dimension size;
BufferedImage image = myIconFactory.renderDragImage(item, screenView);
if (image != null) {
size = new Dimension(image.getWidth(), image.getHeight());
double scale = myDesignSurface.getScale();
image = ImageUtils.scale(image, scale);
} else {
Icon icon = item.getIcon();
//noinspection UndesirableClassUsage
image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) image.getGraphics();
icon.paintIcon(component, g2, 0, 0);
g2.dispose();
double scale = myDesignSurface.getScale();
size = new Dimension((int) (image.getWidth() / scale), (int) (image.getHeight() / scale));
}
setDragImage(image);
setDragImageOffset(new Point(-image.getWidth() / 2, -image.getHeight() / 2));
DnDTransferComponent dndComponent = new DnDTransferComponent(item.getTagName(), item.getXml(), size.width, size.height);
return new ItemTransferable(new DnDTransferItem(dndComponent));
}
Aggregations