javafx.scene.input.MouseEvent.getEventType()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(106)

本文整理了Java中javafx.scene.input.MouseEvent.getEventType()方法的一些代码示例,展示了MouseEvent.getEventType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MouseEvent.getEventType()方法的具体详情如下:
包路径:javafx.scene.input.MouseEvent
类名称:MouseEvent
方法名:getEventType

MouseEvent.getEventType介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

@Override
public void initialize(URL location, ResourceBundle resources) {
combobox.setOnMouseEntered(this);
  combobox.setOnMouseExited(this);
  textfield.setOnMouseEntered(this);
  textfield.setOnMouseExited(this);
  button.setOnMouseEntered(this);
  button.setOnMouseExited(this);

}

@Override
public void handle(MouseEvent event) {
  switch (event.getEventType().getName()){
    case "MOUSE_ENTERED":
      label.setCursor(Cursor.HAND);
      label.setText("Hovered!");
      break;
    case "MOUSE_EXITED":
      label.setCursor(Cursor.MOVE);
      label.setText("Bored");
      break;
  }
}

代码示例来源:origin: stackoverflow.com

if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
  dragging = false;
else if (event.getEventType() == MouseEvent.DRAG_DETECTED) {
  dragging = true;
else if (event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
else if (event.getEventType() == MouseEvent.MOUSE_CLICKED) {
  if (!dragging) {
    onClickedEventHandler.handle(event);

代码示例来源:origin: stackoverflow.com

StackPane root = new StackPane();
root.addEventFilter(MouseEvent.MOUSE_PRESSED, 
 new EventHandler<MouseEvent>() {
 @Override
 public void handle(final MouseEvent event) {
 if(event.getEventType() == MouseEvent.MOUSE_PRESSED)
  //do something
 }
});

// or using MouseEvent.ANY in another eventhandler.
// registering an own eventdispatcher.

代码示例来源:origin: us.ihmc/ihmc-path-planning-visualizers

@Override
  public void handle(MouseEvent event)
  {
   if (event.getButton() != MouseButton.PRIMARY)
     return;
   if (event.isStillSincePress() && event.getEventType() == MouseEvent.MOUSE_CLICKED)
     positionValidated.set(true);
  }
};

代码示例来源:origin: stackoverflow.com

EventType<? extends MouseEvent> mouseEventType = mouseEvent.getEventType();
Scene scene = stage.getScene();

代码示例来源:origin: us.ihmc/IHMCJavaFXToolkit

@Override
  public void handle(MouseEvent event)
  {
   if (event.getEventType() == MouseEvent.MOUSE_PRESSED || event.getEventType() == MouseEvent.MOUSE_DRAGGED)
   {
     // Acquire the new mouse coordinates from the recent event
     double mouseNewX = event.getSceneX();
     double mouseNewY = event.getSceneY();

     if (event.getEventType() == MouseEvent.MOUSE_DRAGGED)
     {
      // Calculate the rotation change of the camera pitch
      double pitchRotate = xRotate.getAngle() + (mouseNewY - mouseOldY) / rotateModifier;
      pitchRotate = MathTools.clipToMinMax(pitchRotate, cameraLimitY);

      xRotate.setAngle(pitchRotate);

      double yawRotate = yRotate.getAngle() - (mouseNewX - mouseOldX) / rotateModifier;
      yRotate.setAngle(yawRotate);
     }

     mouseOldX = mouseNewX;
     mouseOldY = mouseNewY;
   }
  }
}

代码示例来源:origin: us.ihmc/ihmc-javafx-toolkit

@Override
  public void handle(MouseEvent event)
  {
   if (event.getEventType() == MouseEvent.MOUSE_PRESSED || event.getEventType() == MouseEvent.MOUSE_DRAGGED)
   {
     // Acquire the new mouse coordinates from the recent event
     double mouseNewX = event.getSceneX();
     double mouseNewY = event.getSceneY();

     if (event.getEventType() == MouseEvent.MOUSE_DRAGGED)
     {
      // Calculate the rotation change of the camera pitch
      double pitchRotate = xRotate.getAngle() + (mouseNewY - mouseOldY) / rotateModifier;
      pitchRotate = MathTools.clamp(pitchRotate, cameraLimitY);

      xRotate.setAngle(pitchRotate);

      double yawRotate = yRotate.getAngle() - (mouseNewX - mouseOldX) / rotateModifier;
      yRotate.setAngle(yawRotate);
     }

     mouseOldX = mouseNewX;
     mouseOldY = mouseNewY;
   }
  }
}

代码示例来源:origin: at.bestsolution.eclipse/org.eclipse.fx.ui.controls

private void cameraRotationHandler(MouseEvent event) {
  if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
    this.dragStartX = event.getSceneX();
    this.dragStartY = event.getSceneY();
    this.dragStartRotateX = this.cameraXRotation.getAngle();
    this.dragStartRotateY = this.cameraYRotation.getAngle();
  } else if (event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
    double xDelta = event.getSceneX() - this.dragStartX;
    double yDelta = event.getSceneY() - this.dragStartY;
    this.cameraXRotation.setAngle(this.dragStartRotateX - (yDelta * 0.7));
    this.cameraYRotation.setAngle(this.dragStartRotateY + (xDelta * 0.7));
  }
}

代码示例来源:origin: stackoverflow.com

final AnimationTimer timer = new AnimationTimer() {
   private long lastUpdate = 0;
   @Override
   public void handle(long time) {
     if (this.lastUpdate > 100) {
       System.out.println("pressed");
     }
     this.lastUpdate = time;
   }
 };
 final Button b = new Button();
 b.addEventFilter(MouseEvent.ANY, new EventHandler<MouseEvent>() {
   @Override
   public void handle(MouseEvent event) {
     if (event.getEventType().equals(MouseEvent.MOUSE_PRESSED)) {
       timer.start();
     } else {
       timer.stop();
     }
   }
 });

代码示例来源:origin: at.bestsolution.efxclipse.rt/org.eclipse.fx.ui.controls

private void cameraRotationHandler(MouseEvent event) {
  if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
    this.dragStartX = event.getSceneX();
    this.dragStartY = event.getSceneY();
    this.dragStartRotateX = this.cameraXRotation.getAngle();
    this.dragStartRotateY = this.cameraYRotation.getAngle();
  } else if (event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
    double xDelta = event.getSceneX() - this.dragStartX;
    double yDelta = event.getSceneY() - this.dragStartY;
    this.cameraXRotation.setAngle(this.dragStartRotateX - (yDelta * 0.7));
    this.cameraYRotation.setAngle(this.dragStartRotateY + (xDelta * 0.7));
  }
}

代码示例来源:origin: org.controlsfx/controlsfx

/**
 * Handles the specified mouse event (possibly by creating/changing/removing a selection) and returns the matching
 * cursor.
 * 
 * @param mouseEvent
 *            the handled {@link MouseEvent}; must not be {@code null}
 * @return the cursor which will be used for this event
 */
public Cursor handleMouseEvent(MouseEvent mouseEvent) {
  Objects.requireNonNull(mouseEvent, "The argument 'mouseEvent' must not be null."); //$NON-NLS-1$
  EventType<? extends MouseEvent> eventType = mouseEvent.getEventType();
  SelectionEvent selectionEvent = createSelectionEvent(mouseEvent);
  if (eventType == MouseEvent.MOUSE_MOVED) {
    return getCursor(selectionEvent);
  }
  if (eventType == MouseEvent.MOUSE_PRESSED) {
    return handleMousePressedEvent(selectionEvent);
  }
  if (eventType == MouseEvent.MOUSE_DRAGGED) {
    return handleMouseDraggedEvent(selectionEvent);
  }
  if (eventType == MouseEvent.MOUSE_RELEASED) {
    return handleMouseReleasedEvent(selectionEvent);
  }
  return Cursor.DEFAULT;
}

代码示例来源:origin: eu.mihosoft.vrl.jcsg/jcsg

@Override
  public void handle(MouseEvent t) {
    if (!btn.equals(t.getButton())) {
      return;
    }

    t.consume();

    if (MouseEvent.MOUSE_PRESSED.equals(t.getEventType())) {
      anchorX = t.getSceneX();
      anchorY = t.getSceneY();
      anchorAngleX = rotateX.getAngle();
      anchorAngleY = rotateZ.getAngle();
      t.consume();
    } else if (MouseEvent.MOUSE_DRAGGED.equals(t.getEventType())) {
      rotateZ.setAngle(anchorAngleY + (anchorX - t.getSceneX()) * 0.7);
      rotateX.setAngle(anchorAngleX - (anchorY - t.getSceneY()) * 0.7);

    }

  }
}

代码示例来源:origin: com.github.wshackle/poseList3DPlot

private void handleFxRootMouseEvent(javafx.scene.input.MouseEvent me) {
//        System.out.println("me = " + me);
    if (me.getEventType() == MouseEvent.MOUSE_RELEASED) {
      setLastMouseEvent(null);
      return;
    }
    if (me.getEventType() == MouseEvent.MOUSE_EXITED) {
      setLastMouseEvent(null);
      return;
    }
    if (null == getLastMouseEvent()) {
      setLastMouseEvent(me);
      return;
    }
    double mouseNewX = getLastMouseEvent().getX();
    double mouseNewY = getLastMouseEvent().getY();
    double mouseOldX = mouseNewX;
    double mouseOldY = mouseNewY;
    mouseNewX = me.getX();
    mouseNewY = me.getY();
    setLastMouseEvent(me);
    final double mouseDeltaX = mouseNewX - mouseOldX;
    final double mouseDeltaY = mouseNewY - mouseOldY;
    Platform.runLater(() -> {
      transformWMouseDelta(mouseDeltaX, mouseDeltaY);
    });

  }

代码示例来源:origin: org.fxmisc.richtext/richtextfx

/**
 * Returns an {@link EventStream} that emits a {@link Point2D} whenever the mouse becomes stationary
 * over the helper's node and emits a {@code null} value whenever the mouse moves after being stationary.
 */
public EventStream<Either<Point2D, Void>> events(Duration delay) {
  EventStream<MouseEvent> mouseEvents = eventsOf(node, MouseEvent.ANY);
  EventStream<Point2D> stationaryPositions = mouseEvents
      .successionEnds(delay)
      .filter(e -> e.getEventType() == MOUSE_MOVED)
      .map(e -> new Point2D(e.getX(), e.getY()));
  EventStream<Void> stoppers = mouseEvents.supply((Void) null);
  return stationaryPositions.or(stoppers).distinct();
}

代码示例来源:origin: us.ihmc/ihmc-javafx-toolkit

@Override
  public void handle(MouseEvent event)
  {
   if (event.getButton() != MouseButton.PRIMARY)
     return;
   if (condition.test(event) && event.isStillSincePress() && event.getEventType() == MouseEvent.MOUSE_CLICKED)
   {
     PickResult pickResult = event.getPickResult();
     Node intersectedNode = pickResult.getIntersectedNode();
     if (intersectedNode == null || intersectedNode instanceof SubScene)
      return;
     javafx.geometry.Point3D localPoint = pickResult.getIntersectedPoint();
     javafx.geometry.Point3D scenePoint = intersectedNode.getLocalToSceneTransform().transform(localPoint);
     focusPointTranslation.setX(scenePoint.getX());
     focusPointTranslation.setY(scenePoint.getY());
     focusPointTranslation.setZ(scenePoint.getZ());
   }
  }
};

代码示例来源:origin: us.ihmc/IHMCJavaFXToolkit

@Override
  public void handle(MouseEvent event)
  {
   if (event.getButton() != MouseButton.PRIMARY)
     return;
   if (condition.test(event) && event.isStillSincePress() && event.getEventType() == MouseEvent.MOUSE_CLICKED)
   {
     PickResult pickResult = event.getPickResult();
     Node intersectedNode = pickResult.getIntersectedNode();
     if (intersectedNode == null || intersectedNode instanceof SubScene)
      return;
     Point3D localPoint = pickResult.getIntersectedPoint();
     Point3D scenePoint = intersectedNode.getLocalToSceneTransform().transform(localPoint);
     focusPointTranslation.setX(scenePoint.getX());
     focusPointTranslation.setY(scenePoint.getY());
     focusPointTranslation.setZ(scenePoint.getZ());
   }
  }
};

代码示例来源:origin: us.ihmc/ihmc-footstep-planning-visualizers

public StartGoalOrientationEditor(Messager messager, SubScene subScene)
{
 this.messager = messager;
 this.subScene = subScene;
 startEditModeEnabled = messager.createInput(FootstepPlannerMessagerAPI.StartOrientationEditModeEnabledTopic, false);
 goalEditModeEnabled = messager.createInput(FootstepPlannerMessagerAPI.GoalOrientationEditModeEnabledTopic, false);
 startPositionReference = messager.createInput(FootstepPlannerMessagerAPI.StartPositionTopic);
 goalPositionReference = messager.createInput(FootstepPlannerMessagerAPI.GoalPositionTopic);
 rayCastInterceptor = (event) ->
 {
   PickResult pickResult = event.getPickResult();
   Node intersectedNode = pickResult.getIntersectedNode();
   if (intersectedNode == null || intersectedNode instanceof SubScene)
    return;
   javafx.geometry.Point3D localPoint = pickResult.getIntersectedPoint();
   javafx.geometry.Point3D scenePoint = intersectedNode.getLocalToSceneTransform().transform(localPoint);
   Point3D interception = new Point3D();
   interception.setX(scenePoint.getX());
   interception.setY(scenePoint.getY());
   interception.setZ(scenePoint.getZ());
   latestInterception.set(interception);
 };
 leftClickInterceptor = (event) ->
 {
   if (event.getButton() != MouseButton.PRIMARY)
    return;
   if (event.isStillSincePress() && event.getEventType() == MouseEvent.MOUSE_CLICKED)
    orientationValidated.set(true);
 };
}

代码示例来源:origin: us.ihmc/ihmc-javafx-toolkit

return;
if (event.getEventType() == MouseEvent.MOUSE_PRESSED)
if (event.getEventType() != MouseEvent.MOUSE_DRAGGED)
  return;

代码示例来源:origin: at.bestsolution.efxclipse.rt/org.eclipse.fx.ui.controls

/**
 * Create a new text position event
 *
 * @param event
 *            the source mouse event
 * @param offset
 *            the offset in the text (might be -1 to indicate no valid
 *            region was found)
 */
public TextPositionEvent(MouseEvent event, int offset) {
  super(convert(event.getEventType()), event.getSceneX(), event.getSceneY(), event.getScreenX(), event.getScreenY(), event.getButton(), event.getClickCount(), event.isShiftDown(), event.isControlDown(), event.isAltDown(), event.isMetaDown(), event.isPrimaryButtonDown(), event.isMiddleButtonDown(),
      event.isSecondaryButtonDown(), event.isSynthesized(), event.isPopupTrigger(), event.isStillSincePress(), event.getPickResult());
  this.offset = offset;
}

代码示例来源:origin: org.jrebirth.af/core

public void handle(final MouseEvent mouseEvent) {
  final EventType<?> type = mouseEvent.getEventType();

相关文章