Search in sources :

Example 6 with AndroidCoordinate

use of com.android.tools.idea.uibuilder.model.AndroidCoordinate 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));
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) ItemTransferable(com.android.tools.idea.uibuilder.model.ItemTransferable) BufferedImage(java.awt.image.BufferedImage) AndroidCoordinate(com.android.tools.idea.uibuilder.model.AndroidCoordinate) DnDTransferComponent(com.android.tools.idea.uibuilder.model.DnDTransferComponent) DnDTransferItem(com.android.tools.idea.uibuilder.model.DnDTransferItem) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AndroidCoordinate (com.android.tools.idea.uibuilder.model.AndroidCoordinate)6 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)4 Nullable (org.jetbrains.annotations.Nullable)4 NlGraphics (com.android.tools.idea.uibuilder.graphics.NlGraphics)3 NotNull (org.jetbrains.annotations.NotNull)3 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)2 com.android.tools.idea.uibuilder.api (com.android.tools.idea.uibuilder.api)1 DnDTransferComponent (com.android.tools.idea.uibuilder.model.DnDTransferComponent)1 DnDTransferItem (com.android.tools.idea.uibuilder.model.DnDTransferItem)1 Insets (com.android.tools.idea.uibuilder.model.Insets)1 ItemTransferable (com.android.tools.idea.uibuilder.model.ItemTransferable)1 SegmentType (com.android.tools.idea.uibuilder.model.SegmentType)1 TextDirection (com.android.tools.idea.uibuilder.model.TextDirection)1 Lists (com.google.common.collect.Lists)1 java.awt (java.awt)1 BufferedImage (java.awt.image.BufferedImage)1 Field (java.lang.reflect.Field)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1