Search in sources :

Example 6 with JBImageIcon

use of com.intellij.util.ui.JBImageIcon in project intellij-community by JetBrains.

the class StripeButton method processDrag.

private void processDrag(final MouseEvent e) {
    if (myDragCancelled || !MouseDragHelper.checkModifiers(e))
        return;
    if (!isDraggingNow()) {
        if (myPressedPoint == null)
            return;
        if (isWithinDeadZone(e))
            return;
        myDragPane = findLayeredPane(e);
        if (myDragPane == null)
            return;
        // -1 because StripeButtonUI.paint will not paint 1 pixel in case (anchor == ToolWindowAnchor.LEFT)
        int width = getWidth() - 1;
        // -1 because StripeButtonUI.paint will not paint 1 pixel in case (anchor.isHorizontal())
        int height = getHeight() - 1;
        BufferedImage image = UIUtil.createImage(e.getComponent(), width, height, BufferedImage.TYPE_INT_RGB);
        Graphics graphics = image.getGraphics();
        graphics.setColor(UIUtil.getBgFillColor(getParent()));
        graphics.fillRect(0, 0, width, height);
        paint(graphics);
        graphics.dispose();
        myDragButtonImage = new JLabel(new JBImageIcon(image)) {

            public String toString() {
                return "Image for: " + StripeButton.this.toString();
            }
        };
        myDragButtonImage.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseReleased(MouseEvent e) {
                finishDragging();
                myPressedPoint = null;
                myDragButtonImage = null;
                super.mouseReleased(e);
            }
        });
        myDragPane.add(myDragButtonImage, JLayeredPane.POPUP_LAYER);
        myDragButtonImage.setSize(myDragButtonImage.getPreferredSize());
        setVisible(false);
        myPane.startDrag();
        myDragKeyEventDispatcher = new DragKeyEventDispatcher();
        KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(myDragKeyEventDispatcher);
    }
    if (!isDraggingNow())
        return;
    Point xy = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), myDragPane);
    if (myPressedPoint != null) {
        xy.x -= myPressedPoint.x;
        xy.y -= myPressedPoint.y;
    }
    myDragButtonImage.setLocation(xy);
    SwingUtilities.convertPointToScreen(xy, myDragPane);
    final Stripe stripe = myPane.getStripeFor(new Rectangle(xy, myDragButtonImage.getSize()), (Stripe) getParent());
    if (stripe == null) {
        if (myLastStripe != null) {
            myLastStripe.resetDrop();
        }
    } else {
        if (myLastStripe != null && myLastStripe != stripe) {
            myLastStripe.resetDrop();
        }
        stripe.processDropButton(this, myDragButtonImage, xy);
    }
    myLastStripe = stripe;
}
Also used : BufferedImage(java.awt.image.BufferedImage) JBImageIcon(com.intellij.util.ui.JBImageIcon)

Aggregations

JBImageIcon (com.intellij.util.ui.JBImageIcon)6 BufferedImage (java.awt.image.BufferedImage)4 NotNull (org.jetbrains.annotations.NotNull)2 DnDTransferItem (com.android.tools.idea.uibuilder.model.DnDTransferItem)1 ActionManager (com.intellij.openapi.actionSystem.ActionManager)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 IdeFrameImpl (com.intellij.openapi.wm.impl.IdeFrameImpl)1 ColoredTreeCellRenderer (com.intellij.ui.ColoredTreeCellRenderer)1 RetrievableIcon (com.intellij.ui.RetrievableIcon)1 File (java.io.File)1 IOException (java.io.IOException)1 Nullable (org.jetbrains.annotations.Nullable)1