Java源码示例:javafx.scene.input.PickResult

示例1
@Test
public void click() {
    Button button = (Button) getPrimaryStage().getScene().getRoot().lookup(".button");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            RFXButtonBase rfxButtonBase = new RFXButtonBase(button, null, null, lr);
            Point2D sceneXY = button.localToScene(new Point2D(3, 3));
            PickResult pickResult = new PickResult(button, sceneXY.getX(), sceneXY.getY());
            Point2D screenXY = button.localToScreen(new Point2D(3, 3));
            MouseEvent me = new MouseEvent(button, button, MouseEvent.MOUSE_PRESSED, 3, 3, sceneXY.getX(), screenXY.getY(),
                    MouseButton.PRIMARY, 1, false, false, false, false, true, false, false, false, false, false, pickResult);
            rfxButtonBase.mouseButton1Pressed(me);
        }
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording select = recordings.get(0);
    AssertJUnit.assertEquals("click", select.getCall());
    AssertJUnit.assertEquals("", select.getParameters()[0]);
}
 
示例2
@Test
public void click() {
    Hyperlink button = (Hyperlink) getPrimaryStage().getScene().getRoot().lookup(".hyperlink");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            RFXButtonBase rfxButtonBase = new RFXButtonBase(button, null, null, lr);
            Point2D sceneXY = button.localToScene(new Point2D(3, 3));
            PickResult pickResult = new PickResult(button, sceneXY.getX(), sceneXY.getY());
            Point2D screenXY = button.localToScreen(new Point2D(3, 3));
            MouseEvent me = new MouseEvent(button, button, MouseEvent.MOUSE_PRESSED, 3, 3, sceneXY.getX(), screenXY.getY(),
                    MouseButton.PRIMARY, 1, false, false, false, false, true, false, false, false, false, false, pickResult);
            rfxButtonBase.mouseButton1Pressed(me);
        }
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording select = recordings.get(0);
    AssertJUnit.assertEquals("click", select.getCall());
    AssertJUnit.assertEquals("", select.getParameters()[0]);
}
 
示例3
@Test
public void getText() {
    Button button = (Button) getPrimaryStage().getScene().getRoot().lookup(".button");
    LoggingRecorder lr = new LoggingRecorder();
    List<String> text = new ArrayList<>();
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            RFXButtonBase rfxButtonBase = new RFXButtonBase(button, null, null, lr);
            Point2D sceneXY = button.localToScene(new Point2D(3, 3));
            PickResult pickResult = new PickResult(button, sceneXY.getX(), sceneXY.getY());
            Point2D screenXY = button.localToScreen(new Point2D(3, 3));
            MouseEvent me = new MouseEvent(button, button, MouseEvent.MOUSE_PRESSED, 3, 3, sceneXY.getX(), screenXY.getY(),
                    MouseButton.PRIMARY, 1, false, false, false, false, true, false, false, false, false, false, pickResult);
            rfxButtonBase.mouseButton1Pressed(me);
            text.add(rfxButtonBase.getAttribute("text"));
        }
    });
    new Wait("Waiting for button text.") {
        @Override
        public boolean until() {
            return text.size() > 0;
        }
    };
    AssertJUnit.assertEquals("Color", text.get(0));
}
 
示例4
/**
 * Fires a newly created {@link MouseEvent} of type
 * {@link MouseEvent#MOUSE_DRAGGED} to the target {@link Node} of the last mouse
 * interaction.
 *
 * @param sceneX
 *            The final x-coordinate (in scene) for the drag.
 * @param sceneY
 *            The final y-coordinate (in scene) for the drag.
 * @param mods
 *            The {@link Modifiers} for the {@link MouseEvent}.
 */
public void mouseDrag(final double sceneX, final double sceneY, final Modifiers mods) {
	waitForIdle();
	// save mouse interaction data
	lastMouseInteraction.sceneX = sceneX;
	lastMouseInteraction.sceneY = sceneY;
	run(() -> {
		Point2D local = lastMouseInteraction.target.sceneToLocal(sceneX, sceneY);
		Point2D screen = lastMouseInteraction.target.localToScreen(local.getX(), local.getY());
		fireEvent(lastMouseInteraction.target,
				new MouseEvent(lastMouseInteraction.target, lastMouseInteraction.target, MouseEvent.MOUSE_DRAGGED,
						local.getX(), local.getY(), screen.getX(), screen.getY(), MouseButton.PRIMARY, 0,
						mods.shift, mods.control, mods.alt, mods.meta, true, false, false, false, false, false,
						new PickResult(lastMouseInteraction.target, sceneX, sceneY)));
	});
	waitForIdle();
}
 
示例5
/**
 * Fires a newly created {@link MouseEvent} of type
 * {@link MouseEvent#MOUSE_MOVED} to the given target {@link Node}.
 *
 * @param sceneX
 *            The final x-coordinate (in scene) for the drag.
 * @param sceneY
 *            The final y-coordinate (in scene) for the drag.
 * @param mods
 *            The {@link Modifiers} for the {@link MouseEvent}.
 */
public void mouseMove(final Node target, final double sceneX, final double sceneY, final Modifiers mods) {
	waitForIdle();
	// save mouse interaction data
	lastMouseInteraction = new MouseInteraction();
	lastMouseInteraction.target = target;
	lastMouseInteraction.sceneX = sceneX;
	lastMouseInteraction.sceneY = sceneY;
	run(() -> {
		Point2D local = target.sceneToLocal(sceneX, sceneY);
		Point2D screen = target.localToScreen(local.getX(), local.getY());
		fireEvent(target,
				new MouseEvent(target, target, MouseEvent.MOUSE_MOVED, local.getX(), local.getY(), screen.getX(),
						screen.getY(), MouseButton.NONE, 0, mods.shift, mods.control, mods.alt, mods.meta, false,
						false, false, false, false, false, new PickResult(target, sceneX, sceneY)));
	});
	waitForIdle();
}
 
示例6
/**
 * Fires a newly created {@link MouseEvent} of type
 * {@link MouseEvent#MOUSE_PRESSED} to the target {@link Node} of the last mouse
 * interaction.
 *
 * @param mods
 *            The {@link Modifiers} for the {@link MouseEvent}.
 */
public void mousePress(final Modifiers mods) {
	waitForIdle();
	run(() -> {
		Point2D local = lastMouseInteraction.target.sceneToLocal(lastMouseInteraction.sceneX,
				lastMouseInteraction.sceneY);
		Point2D screen = lastMouseInteraction.target.localToScreen(local.getX(), local.getY());
		fireEvent(lastMouseInteraction.target,
				new MouseEvent(lastMouseInteraction.target, lastMouseInteraction.target, MouseEvent.MOUSE_PRESSED,
						local.getX(), local.getY(), screen.getX(), screen.getY(), MouseButton.PRIMARY, 1,
						mods.shift, mods.control, mods.alt, mods.meta, true, false, false, false, false, false,
						new PickResult(lastMouseInteraction.target, lastMouseInteraction.sceneX,
								lastMouseInteraction.sceneY)));
	});
	waitForIdle();
}
 
示例7
/**
 * Fires a newly created {@link MouseEvent} of type
 * {@link MouseEvent#MOUSE_RELEASED} to the target {@link Node} of the last
 * mouse interaction.
 *
 * @param mods
 *            The {@link Modifiers} for the {@link MouseEvent}.
 */
public void mouseRelease(final Modifiers mods) {
	waitForIdle();
	run(() -> {
		Point2D local = lastMouseInteraction.target.sceneToLocal(lastMouseInteraction.sceneX,
				lastMouseInteraction.sceneY);
		Point2D screen = lastMouseInteraction.target.localToScreen(local.getX(), local.getY());
		fireEvent(lastMouseInteraction.target,
				new MouseEvent(lastMouseInteraction.target, lastMouseInteraction.target, MouseEvent.MOUSE_RELEASED,
						local.getX(), local.getY(), screen.getX(), screen.getY(), MouseButton.PRIMARY, 1,
						mods.shift, mods.control, mods.alt, mods.meta, false, false, false, false, false, false,
						new PickResult(lastMouseInteraction.target, lastMouseInteraction.sceneX,
								lastMouseInteraction.sceneY)));
	});
	waitForIdle();
}
 
示例8
/**
 * Constructs new DockEvent event..
 * 
 * @param source the source of the event. Can be null.
 * @param target the target of the event. Can be null.
 * @param eventType The type of the event.
 * @param x The x with respect to the source. Should be in scene coordinates if source == null or
 *        source is not a Node.
 * @param y The y with respect to the source. Should be in scene coordinates if source == null or
 *        source is not a Node.
 * @param screenX The x coordinate relative to screen.
 * @param screenY The y coordinate relative to screen.
 * @param pickResult pick result. Can be null, in this case a 2D pick result without any further
 *        values is constructed based on the scene coordinates
 * @param contents The contents being dragged during this event.
 */
public DockEvent(Object source, EventTarget target, EventType<? extends DockEvent> eventType,
    double x, double y, double screenX, double screenY, PickResult pickResult, Node contents) {
  super(source, target, eventType);
  this.x = x;
  this.y = y;
  this.screenX = screenX;
  this.screenY = screenY;
  this.sceneX = x;
  this.sceneY = y;
  this.pickResult = pickResult != null ? pickResult : new PickResult(target, x, y);
  final Point3D p = InputEventUtils.recomputeCoordinates(this.pickResult, null);
  this.x = p.getX();
  this.y = p.getY();
  this.z = p.getZ();
  this.contents = contents;
}
 
示例9
@Override
public void click(Node node, Node target, PickResult pickResult, Buttons button, int clickCount, double xoffset,
        double yoffset) {
    MouseButton b = button.getMouseButton();
    dispatchMouseEvent(node, target, pickResult, button == Buttons.RIGHT, clickCount, b, xoffset, yoffset);
    deviceState.setNode(node);
}
 
示例10
private void dispatchMouseEvent(Node node, Node target, PickResult pickResult, boolean popupTrigger, int clickCount,
        MouseButton buttons, double x, double y) {
    ensureVisible(node);
    Point2D screenXY = node.localToScreen(new Point2D(x, y));
    if (node != deviceState.getNode()) {
        if (deviceState.getNode() != null) {
            dispatchEvent(createMouseEvent(MouseEvent.MOUSE_EXITED, target, pickResult, x, y, screenXY.getX(), screenXY.getY(),
                    buttons, clickCount, deviceState.shiftPressed, deviceState.ctrlPressed, deviceState.altPressed,
                    deviceState.metaPressed, false, false, false, false, popupTrigger, false, node));
        }
        dispatchEvent(createMouseEvent(MouseEvent.MOUSE_ENTERED, target, pickResult, x, y, screenXY.getX(), screenXY.getY(),
                buttons, clickCount, deviceState.shiftPressed, deviceState.ctrlPressed, deviceState.altPressed,
                deviceState.metaPressed, false, false, false, false, popupTrigger, false, node));
    }
    for (int n = 1; n <= clickCount; n++) {
        dispatchEvent(createMouseEvent(MouseEvent.MOUSE_PRESSED, target, pickResult, x, y, screenXY.getX(), screenXY.getY(),
                buttons, n, deviceState.shiftPressed, deviceState.ctrlPressed, deviceState.altPressed, deviceState.metaPressed,
                buttons == MouseButton.PRIMARY, buttons == MouseButton.MIDDLE, buttons == MouseButton.SECONDARY, false,
                popupTrigger, false, node));
        dispatchEvent(createMouseEvent(MouseEvent.MOUSE_RELEASED, target, pickResult, x, y, screenXY.getX(), screenXY.getY(),
                buttons, n, deviceState.shiftPressed, deviceState.ctrlPressed, deviceState.altPressed, deviceState.metaPressed,
                buttons == MouseButton.PRIMARY, buttons == MouseButton.MIDDLE, buttons == MouseButton.SECONDARY, false,
                popupTrigger, false, node));
        dispatchEvent(createMouseEvent(MouseEvent.MOUSE_CLICKED, target, pickResult, x, y, screenXY.getX(), screenXY.getY(),
                buttons, n, deviceState.shiftPressed, deviceState.ctrlPressed, deviceState.altPressed, deviceState.metaPressed,
                buttons == MouseButton.PRIMARY, buttons == MouseButton.MIDDLE, buttons == MouseButton.SECONDARY, false,
                popupTrigger, false, node));
    }
}
 
示例11
@Override
public void click(int button, Node target, PickResult pickResult, int clickCount, double xoffset, double yoffset) {
    verifyCanInteractWithElement();

    EventQueueWait.requestFocus(node);
    IDevice mouse = driver.getDevices();
    mouse.click(node, target, pickResult, Buttons.getButtonFor(button), clickCount, xoffset, yoffset);
}
 
示例12
@Override
public void click(int button, Node target, PickResult pickResult, int clickCount, double xoffset, double yoffset) {
    Node cell = getPseudoComponent();
    target = getTextObj((TableCell<?, ?>) cell);
    Point2D targetXY = target.localToParent(xoffset, yoffset);
    targetXY = node.localToScene(targetXY);
    super.click(button, target, new PickResult(target, targetXY.getX(), targetXY.getY()), clickCount, xoffset, yoffset);
}
 
示例13
@Override
public void click(int button, Node target, PickResult pickResult, int clickCount, double xoffset, double yoffset) {
    Node cell = getPseudoComponent();
    target = getTextObj((TreeCell<?>) cell);
    Point2D targetXY = node.localToScene(xoffset, yoffset);
    super.click(button, target, new PickResult(target, targetXY.getX(), targetXY.getY()), clickCount, xoffset, yoffset);
}
 
示例14
@Override
public void click(int button, Node target, PickResult pickResult, int clickCount, double xoffset, double yoffset) {
    Node cell = getPseudoComponent();
    target = getTextObj((ListCell<?>) cell);
    Point2D targetXY = node.localToScene(xoffset, yoffset);
    super.click(button, target, new PickResult(target, targetXY.getX(), targetXY.getY()), clickCount, xoffset, yoffset);
}
 
示例15
@Override
public void click(int button, Node target, PickResult pickResult, int clickCount, double xoffset, double yoffset) {
    Node cell = getPseudoComponent();
    target = getTextObj((TreeTableCell<?, ?>) cell);
    Point2D targetXY = target.localToParent(xoffset, yoffset);
    targetXY = node.localToScene(targetXY);
    super.click(button, target, new PickResult(target, targetXY.getX(), targetXY.getY()), clickCount, xoffset, yoffset);
}
 
示例16
@Override
public void click(int button, Node target, PickResult pickResult, int clickCount, double xoffset, double yoffset) {
    parent.click(selector, frameId);
}
 
示例17
@Override
public void click(int button, Node target, PickResult pickResult, int clickCount, double xoffset, double yoffset) {
    Platform.runLater(() -> ((ChoiceBox<?>) getComponent()).getSelectionModel().select(option));
}
 
示例18
@Override
public void click(int button, Node target, PickResult pickResult, int clickCount, double xoffset, double yoffset) {
    parent.click(selector);
}
 
示例19
@Override
public void click(int button, Node target, PickResult pickResult, int clickCount, double xoffset, double yoffset) {
    Platform.runLater(() -> ((ComboBox<?>) getComponent()).getSelectionModel().select(option));
}
 
示例20
/**
 * Returns information about the pick.
 * 
 * @return new PickResult object that contains information about the pick
 */
public final PickResult getPickResult() {
  return pickResult;
}
 
示例21
/**
 * Constructs new DockEvent event..
 * 
 * @param eventType The type of the event.
 * @param x The x with respect to the source. Should be in scene coordinates if source == null or
 *        source is not a Node.
 * @param y The y with respect to the source. Should be in scene coordinates if source == null or
 *        source is not a Node.
 * @param screenX The x coordinate relative to screen.
 * @param screenY The y coordinate relative to screen.
 * @param pickResult pick result. Can be null, in this case a 2D pick result without any further
 *        values is constructed based on the scene coordinates
 */
public DockEvent(EventType<? extends DockEvent> eventType, double x, double y, double screenX,
    double screenY, PickResult pickResult) {
  this(null, null, eventType, x, y, screenX, screenY, pickResult);
}
 
示例22
/**
 * Constructs new DockEvent event..
 * 
 * @param source the source of the event. Can be null.
 * @param target the target of the event. Can be null.
 * @param eventType The type of the event.
 * @param x The x with respect to the source. Should be in scene coordinates if source == null or
 *        source is not a Node.
 * @param y The y with respect to the source. Should be in scene coordinates if source == null or
 *        source is not a Node.
 * @param screenX The x coordinate relative to screen.
 * @param screenY The y coordinate relative to screen.
 * @param pickResult pick result. Can be null, in this case a 2D pick result without any further
 *        values is constructed based on the scene coordinates
 */
public DockEvent(Object source, EventTarget target, EventType<? extends DockEvent> eventType,
    double x, double y, double screenX, double screenY, PickResult pickResult) {
  this(source, target, eventType, x, y, screenX, screenY, pickResult, null);
}
 
示例23
void click(Node component, Node target, PickResult pickResult, Buttons button, int clickCount, double xoffset, double yoffset); 
示例24
public abstract void click(int button, Node target, PickResult pickResult, int clickCount, double x, double y);