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