Java 类com.intellij.ui.MouseDragHelper 实例源码

项目:intellij-ce-playground    文件:DragHelper.java   
protected void processDrag(MouseEvent event, Point targetScreenPoint, Point startPointScreen) {
  if (!myTabs.isTabDraggingEnabled() || !isDragSource(event) || !MouseDragHelper.checkModifiers(event)) return;

  SwingUtilities.convertPointFromScreen(startPointScreen, myTabs);

  if (isDragJustStarted()) {
    if (myPressedTabLabel == null) return;

    final Rectangle labelBounds = myPressedTabLabel.getBounds();

    myHoldDelta = new Dimension(startPointScreen.x - labelBounds.x, startPointScreen.y - labelBounds.y);
    myDragSource = myPressedTabLabel.getInfo();
    myDragRec = new Rectangle(startPointScreen, labelBounds.getSize());
    myDragOriginalRec = (Rectangle)myDragRec.clone();

    myDragOriginalRec.x -= myHoldDelta.width;
    myDragOriginalRec.y -= myHoldDelta.height;
  }
  else {
    if (myDragRec == null) return;

    final Point toPoint = SwingUtilities.convertPoint(event.getComponent(), event.getPoint(), myTabs);

    myDragRec.x = toPoint.x;
    myDragRec.y = toPoint.y;
  }

  myDragRec.x -= myHoldDelta.width;
  myDragRec.y -= myHoldDelta.height;

  final Rectangle headerRec = myTabs.getLastLayoutPass().getHeaderRectangle();
  ScreenUtil.moveToFit(myDragRec, headerRec, null);

  int deadZoneX = 0;
  int deadZoneY = 0;

  final TabLabel top = findLabel(new Point(myDragRec.x + myDragRec.width / 2, myDragRec.y + deadZoneY));
  final TabLabel bottom = findLabel(new Point(myDragRec.x + myDragRec.width / 2, myDragRec.y + myDragRec.height - deadZoneY));
  final TabLabel left = findLabel(new Point(myDragRec.x + deadZoneX, myDragRec.y + myDragRec.height / 2));
  final TabLabel right = findLabel(new Point(myDragRec.x + myDragRec.width - deadZoneX, myDragRec.y + myDragRec.height / 2));


  TabLabel targetLabel;
  if (myTabs.isHorizontalTabs()) {
    targetLabel = findMostOverlapping(Axis.X, left, right);
    if (targetLabel == null) {
      targetLabel = findMostOverlapping(Axis.Y, top, bottom);
    }
  } else {
    targetLabel = findMostOverlapping(Axis.Y, top, bottom);
    if (targetLabel == null) {
      targetLabel = findMostOverlapping(Axis.X, left, right);
    }
  }

  if (targetLabel != null) {
    Rectangle saved = myDragRec;
    myDragRec = null;
    myTabs.reallocate(myDragSource, targetLabel.getInfo());
    myDragOriginalRec = myTabs.myInfo2Label.get(myDragSource).getBounds();
    myDragRec = saved;
    myTabs.moveDraggedTabLabel();
  } else {
    myTabs.moveDraggedTabLabel();
    final int border = myTabs.getTabsBorder().getTabBorderSize();
    headerRec.x -= border;
    headerRec.y -= border;
    headerRec.width += border * 2;
    headerRec.height += border * 2;
    myTabs.repaint(headerRec);
  }
  event.consume();
}
项目:intellij-ce-playground    文件:StripeButton.java   
private boolean isWithinDeadZone(final MouseEvent e) {
  return Math.abs(myPressedPoint.x - e.getPoint().x) < MouseDragHelper.DRAG_START_DEADZONE && Math.abs(myPressedPoint.y - e.getPoint().y) < MouseDragHelper
    .DRAG_START_DEADZONE;
}
项目:intellij-ce-playground    文件:DnDManagerImpl.java   
public void dragGestureRecognized(DragGestureEvent dge) {
  try {
    final DnDSource source = getSource(dge.getComponent());
    if (source == null || !MouseDragHelper.checkModifiers(dge.getTriggerEvent())) return;

    DnDAction action = getDnDActionForPlatformAction(dge.getDragAction());
    if (source.canStartDragging(action, dge.getDragOrigin())) {

      if (myCurrentEvent == null) {
        // Actually, under Linux it is possible to get 2 or more dragGestureRecognized calls for single drag
        // operation. To reproduce:
        // 1. Do D-n-D in Styles tree
        // 2. Make an attempt to do D-n-D in Services tree
        // 3. Do D-n-D in Styles tree again.

        LOG.debug("Starting dragging for " + action);
        hideCurrentHighlighter();
        final DnDDragStartBean dnDDragStartBean = source.startDragging(action, dge.getDragOrigin());
        myCurrentEvent = new DnDEventImpl(DnDManagerImpl.this, action, dnDDragStartBean.getAttachedObject(), dnDDragStartBean.getPoint());
        myCurrentEvent.setOrgPoint(dge.getDragOrigin());

        Pair<Image, Point> pair = dnDDragStartBean.isEmpty() ? null : source.createDraggedImage(action, dge.getDragOrigin());
        if (pair == null) {
          pair = Pair.create(EMPTY_IMAGE, new Point(0, 0));
        }

        if (!DragSource.isDragImageSupported()) {
          // not all of the platforms supports image dragging (mswin doesn't, for example).
          myCurrentEvent.putUserData(DRAGGED_IMAGE_KEY, pair);
        }

        // mac osx fix: it will draw a border with size of the dragged component if there is no image provided.
        dge.startDrag(DragSource.DefaultCopyDrop, pair.first, pair.second, myCurrentEvent, new MyDragSourceListener(source));

        // check if source is also a target
        //        DnDTarget target = getTarget(dge.getComponent());
        //        if( target != null ) {
        //          target.update(myCurrentEvent);
        //        }
      }
    }
  }
  catch (InvalidDnDOperationException e) {
    LOG.info(e);
  }
}
项目:tools-idea    文件:StripeButton.java   
private boolean isWithinDeadZone(final MouseEvent e) {
  return Math.abs(myPressedPoint.x - e.getPoint().x) < MouseDragHelper.DRAG_START_DEADZONE && Math.abs(myPressedPoint.y - e.getPoint().y) < MouseDragHelper
    .DRAG_START_DEADZONE;
}
项目:consulo    文件:DragHelper.java   
protected void processDrag(MouseEvent event, Point targetScreenPoint, Point startPointScreen) {
  if (!myTabs.isTabDraggingEnabled() || !isDragSource(event) || !MouseDragHelper.checkModifiers(event)) return;

  SwingUtilities.convertPointFromScreen(startPointScreen, myTabs);

  if (isDragJustStarted()) {
    if (myPressedTabLabel == null) return;

    final Rectangle labelBounds = myPressedTabLabel.getBounds();

    myHoldDelta = new Dimension(startPointScreen.x - labelBounds.x, startPointScreen.y - labelBounds.y);
    myDragSource = myPressedTabLabel.getInfo();
    myDragRec = new Rectangle(startPointScreen, labelBounds.getSize());
    myDragOriginalRec = (Rectangle)myDragRec.clone();

    myDragOriginalRec.x -= myHoldDelta.width;
    myDragOriginalRec.y -= myHoldDelta.height;
  }
  else {
    if (myDragRec == null) return;

    final Point toPoint = SwingUtilities.convertPoint(event.getComponent(), event.getPoint(), myTabs);

    myDragRec.x = toPoint.x;
    myDragRec.y = toPoint.y;
  }

  myDragRec.x -= myHoldDelta.width;
  myDragRec.y -= myHoldDelta.height;

  final Rectangle headerRec = myTabs.getLastLayoutPass().getHeaderRectangle();
  ScreenUtil.moveToFit(myDragRec, headerRec, null);

  int deadZoneX = 0;
  int deadZoneY = 0;

  final TabLabel top = findLabel(new Point(myDragRec.x + myDragRec.width / 2, myDragRec.y + deadZoneY));
  final TabLabel bottom = findLabel(new Point(myDragRec.x + myDragRec.width / 2, myDragRec.y + myDragRec.height - deadZoneY));
  final TabLabel left = findLabel(new Point(myDragRec.x + deadZoneX, myDragRec.y + myDragRec.height / 2));
  final TabLabel right = findLabel(new Point(myDragRec.x + myDragRec.width - deadZoneX, myDragRec.y + myDragRec.height / 2));


  TabLabel targetLabel;
  if (myTabs.isHorizontalTabs()) {
    targetLabel = findMostOverlapping(Axis.X, left, right);
    if (targetLabel == null) {
      targetLabel = findMostOverlapping(Axis.Y, top, bottom);
    }
  } else {
    targetLabel = findMostOverlapping(Axis.Y, top, bottom);
    if (targetLabel == null) {
      targetLabel = findMostOverlapping(Axis.X, left, right);
    }
  }

  if (targetLabel != null) {
    Rectangle saved = myDragRec;
    myDragRec = null;
    myTabs.reallocate(myDragSource, targetLabel.getInfo());
    myDragOriginalRec = myTabs.myInfo2Label.get(myDragSource).getBounds();
    myDragRec = saved;
    myTabs.moveDraggedTabLabel();
  } else {
    myTabs.moveDraggedTabLabel();
    final int border = myTabs.getTabsBorder().getTabBorderSize();
    headerRec.x -= border;
    headerRec.y -= border;
    headerRec.width += border * 2;
    headerRec.height += border * 2;
    myTabs.repaint(headerRec);
  }
  event.consume();
}
项目:consulo    文件:DnDManagerImpl.java   
public void dragGestureRecognized(DragGestureEvent dge) {
  try {
    final DnDSource source = getSource(dge.getComponent());
    if (source == null || !MouseDragHelper.checkModifiers(dge.getTriggerEvent())) return;

    DnDAction action = getDnDActionForPlatformAction(dge.getDragAction());
    if (source.canStartDragging(action, dge.getDragOrigin())) {

      if (myCurrentEvent == null) {
        // Actually, under Linux it is possible to get 2 or more dragGestureRecognized calls for single drag
        // operation. To reproduce:
        // 1. Do D-n-D in Styles tree
        // 2. Make an attempt to do D-n-D in Services tree
        // 3. Do D-n-D in Styles tree again.

        LOG.debug("Starting dragging for " + action);
        hideCurrentHighlighter();
        final DnDDragStartBean dnDDragStartBean = source.startDragging(action, dge.getDragOrigin());
        myCurrentEvent = new DnDEventImpl(DnDManagerImpl.this, action, dnDDragStartBean.getAttachedObject(), dnDDragStartBean.getPoint());
        myCurrentEvent.setOrgPoint(dge.getDragOrigin());

        Pair<Image, Point> pair = dnDDragStartBean.isEmpty() ? null : source.createDraggedImage(action, dge.getDragOrigin());
        if (pair == null) {
          pair = Pair.create(EMPTY_IMAGE, new Point(0, 0));
        }

        if (!DragSource.isDragImageSupported()) {
          // not all of the platforms supports image dragging (mswin doesn't, for example).
          myCurrentEvent.putUserData(DRAGGED_IMAGE_KEY, pair);
        }

        // mac osx fix: it will draw a border with size of the dragged component if there is no image provided.
        dge.startDrag(DragSource.DefaultCopyDrop, pair.first, pair.second, myCurrentEvent, new MyDragSourceListener(source));

        // check if source is also a target
        //        DnDTarget target = getTarget(dge.getComponent());
        //        if( target != null ) {
        //          target.update(myCurrentEvent);
        //        }
      }
    }
  }
  catch (InvalidDnDOperationException e) {
    LOG.info(e);
  }
}
项目:consulo    文件:DesktopStripeButton.java   
private boolean isWithinDeadZone(final MouseEvent e) {
  return Math.abs(myPressedPoint.x - e.getPoint().x) < MouseDragHelper.DRAG_START_DEADZONE && Math.abs(myPressedPoint.y - e.getPoint().y) < MouseDragHelper
          .DRAG_START_DEADZONE;
}