use of com.android.tools.idea.uibuilder.model.ItemTransferable 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