Java Code Examples for javafx.scene.input.MouseEvent#getTarget()

The following examples show how to use javafx.scene.input.MouseEvent#getTarget() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MouseDragSnippet.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
protected void onMousePress(MouseEvent event) {
	pressed = (Node) event.getTarget();
	System.out.println("press " + pressed);
	startMousePosition = new Point2D(event.getSceneX(), event.getSceneY());
	startLayoutPosition = new Point2D(pressed.getLayoutX(),
			pressed.getLayoutY());

	// add effect
	pressed.setEffect(new Bloom(0));
	IAnchor ifxAnchor = anchors.get(pressed);
	if (ifxAnchor != null) {
		Set<AnchorKey> keys = ifxAnchor.positionsUnmodifiableProperty()
				.keySet();
		for (AnchorKey key : keys) {
			key.getAnchored().setEffect(null);
		}
	}
}
 
Example 2
Source File: HoverGesture.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates an {@link EventHandler} for hover {@link MouseEvent}s. The
 * handler will search for a target part within the given {@link IViewer}
 * and notify all hover policies of that target part about hover changes.
 * <p>
 * If no target part can be identified, then the root part of the given
 * {@link IViewer} is used as the target part.
 *
 * @return The {@link EventHandler} that handles hover changes for the given
 *         {@link IViewer}.
 */
protected EventHandler<MouseEvent> createHoverFilter() {
	return new EventHandler<MouseEvent>() {
		@Override
		public void handle(MouseEvent event) {
			updateHoverIntentPosition(event);
			if (!isHoverEvent(event)) {
				return;
			}
			EventTarget eventTarget = event.getTarget();
			if (eventTarget instanceof Node) {
				IViewer viewer = PartUtils.retrieveViewer(getDomain(),
						(Node) eventTarget);
				if (viewer != null) {
					notifyHover(viewer, event, (Node) eventTarget);
				}
				updateHoverIntent(event, (Node) eventTarget);
			}
		}
	};
}
 
Example 3
Source File: AutoScrollingWindow.java    From graph-editor with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Handles mouse-dragged events.
 *
 * <p>
 * The event object is stored to be re-fired later. When we pan the window, we re-fire the previous drag event on
 * its target so that even if the cursor is no longer moving, the dragged-object will continue to move smoothly
 * along as the window auto-scrolls.
 * </p>
 *
 * @param event the mouse-dragged event object
 */
private void handleMouseDragged(final MouseEvent event) {

    if (event.isPrimaryButtonDown() && event.getTarget() instanceof Node) {

        currentDragEvent = event;
        dragEventTarget = (Node) event.getTarget();

        jumpDistance = getDistanceToJump(event.getX(), event.getY());

        if (jumpDistance == null) {
            jumpsTaken = 0;
        } else if (!isScrolling && isAutoScrollingEnabled()) {
            startScrolling();
        }
    }
}
 
Example 4
Source File: RFXTabPane.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
protected void mousePressed(MouseEvent me) {
    Node target = (Node) me.getTarget();
    if (onCloseButton(target)) {
        recorder.recordSelect(this, getTextForTab((TabPane) node, getTab(target)) + "::close");
    }
}
 
Example 5
Source File: TabToolComponent.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a click to a tab.
 */
private void processMouseClick(@NotNull final MouseEvent event) {
    final EventTarget target = event.getTarget();
    if (!(target instanceof Node)) return;

    final Node node = (Node) target;

    if (!(node instanceof Text) || node.getStyleClass().contains("tab-container")) {
        return;
    }

    final Parent label = node.getParent();

    if (!(label instanceof Label)) {
        return;
    }

    final Parent tabContainer = label.getParent();

    if (!tabContainer.getStyleClass().contains("tab-container")) {
        return;
    }

    if (isChangingTab()) {
        setChangingTab(false);
        return;
    }

    processExpandOrCollapse();
}
 
Example 6
Source File: UICanvas.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
@Override
public void handle(MouseEvent event) {
	MouseButton btn = event.getButton();
	if (!(event.getTarget() instanceof Canvas)) {
		return;
	}

	Canvas c = (Canvas) event.getTarget();
	Point2D p = c.sceneToLocal(event.getSceneX(), event.getSceneY());
	int mousex = (int) p.getX();
	int mousey = (int) p.getY();

	if (event.getEventType() == MouseEvent.MOUSE_MOVED || event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
		canvas.mouseMoved(mousex, mousey);
		canvas.setLastMousePosition(mousex, mousey);
		if (mouseDown) {
			this.canvas.requestPaint();
		}
	} else {
		if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
			mouseDown = true;
			canvas.mousePressed(mousex, mousey, btn);
		} else if (event.getEventType() == MouseEvent.MOUSE_RELEASED) {
			canvas.mouseReleased(mousex, mousey, btn);
			mouseDown = false;
			canvas.requestPaint();
		}
	}

}
 
Example 7
Source File: ClickDragGesture.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void handle(MouseEvent event) {
	if (indicationCursorPolicy[0] != null) {
		indicationCursorPolicy[0].hideIndicationCursor();
		indicationCursorPolicy[0] = null;
	}

	EventTarget eventTarget = event.getTarget();
	if (eventTarget instanceof Node) {
		// determine all drag policies that can be
		// notified about events
		Node target = (Node) eventTarget;
		IViewer viewer = PartUtils.retrieveViewer(getDomain(), target);
		if (viewer != null) {
			possibleDragPolicies[0] = new ArrayList<>(
					getHandlerResolver().resolve(ClickDragGesture.this,
							target, viewer, ON_DRAG_POLICY_KEY));
		} else {
			possibleDragPolicies[0] = new ArrayList<>();
		}

		// search drag policies in reverse order first,
		// so that the policy closest to the target part
		// is the first policy to provide an indication
		// cursor
		ListIterator<? extends IOnDragHandler> dragIterator = possibleDragPolicies[0]
				.listIterator(possibleDragPolicies[0].size());
		while (dragIterator.hasPrevious()) {
			IOnDragHandler policy = dragIterator.previous();
			if (policy.showIndicationCursor(event)) {
				indicationCursorPolicy[0] = policy;
				break;
			}
		}
	}
}
 
Example 8
Source File: Controller.java    From blobsaver with GNU General Public License v3.0 4 votes vote down vote up
public void helpLabelHandler(MouseEvent evt) {
    if (Main.SHOW_BREAKPOINT) {
        return; // remember to put a breakpoint here
    }

    String labelID;
    // if user clicks on question mark instead of padding, evt.getTarget() returns LabeledText instead of Label
    if (evt.getTarget() instanceof LabeledText) {
        labelID = ((LabeledText) evt.getTarget()).getParent().getId();
    } else {
        labelID = ((Label) evt.getTarget()).getId();
    }
    String helpItem = labelID.substring(0, labelID.indexOf("Help"));
    Alert alert;
    ButtonType openLink = new ButtonType("Open link");
    switch (helpItem) {
        case "ecid":
            alert = new Alert(Alert.AlertType.INFORMATION, "Connect your device to your computer and go to iTunes and open the device \"page.\" Then click on the serial number twice and copy and paste it here.", ButtonType.OK);
            alert.setTitle("Help: ECID");
            alert.setHeaderText("Help");
            alert.showAndWait();
            break;
        case "buildID":
            alert = new Alert(Alert.AlertType.INFORMATION, "Get the build ID for the iOS version from theiphonewiki.com/wiki/Beta_Firmware and paste it here.", openLink, ButtonType.OK);
            alert.setTitle("Help: Build ID");
            alert.setHeaderText("Help");
            alert.showAndWait();
            if (openLink.equals(alert.getResult())) {
                openURL("https://www.theiphonewiki.com/wiki/Beta_Firmware");
            }
            break;
        case "ipswURL":
            alert = new Alert(Alert.AlertType.INFORMATION, "Get the IPSW download URL for the iOS version from theiphonewiki.com/wiki/Beta_Firmware and paste it here.", openLink, ButtonType.OK);
            alert.setTitle("Help: IPSW URL");
            alert.setHeaderText("Help");
            alert.showAndWait();
            if (openLink.equals(alert.getResult())) {
                openURL("https://www.theiphonewiki.com/wiki/Beta_Firmware");
            }
            break;
        case "boardConfig":
            openLink = new ButtonType("BMSSM app");
            alert = new Alert(Alert.AlertType.INFORMATION, "Get the board configuration from the BMSSM app from the appstore. Go to the system tab and it'll be called the model. It can be something like \"n69ap\"", openLink, ButtonType.OK);
            alert.setTitle("Help: Board Configuration");
            alert.setHeaderText("Help");
            alert.showAndWait();
            if (openLink.equals(alert.getResult())) {
                openURL("https://itunes.apple.com/us/app/battery-memory-system-status-monitor/id497937231");
            }
            break;
        case "location":
            openLink = new ButtonType("Open link");
            alert = new Alert(Alert.AlertType.INFORMATION, "Click \"Open link\" to see how to automatically upload blobs you save to the cloud.", openLink, ButtonType.OK);
            alert.setTitle("Help: Saving Blobs to the Cloud");
            alert.setHeaderText("Help");
            alert.showAndWait();
            if (openLink.equals(alert.getResult())) {
                openURL("https://github.com/airsquared/blobsaver/wiki/Automatically-saving-blobs-to-the-cloud(Dropbox,-Google-Drive,-iCloud)");
            }
            break;
    }
}
 
Example 9
Source File: CreateCurveOnDragHandler.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void startDrag(MouseEvent event) {
	// create new curve
	GeometricCurve curve = new GeometricCurve(new Point[] { new Point(), new Point() },
			MvcLogoExample.GEF_COLOR_GREEN, MvcLogoExample.GEF_STROKE_WIDTH, MvcLogoExample.GEF_DASH_PATTERN, null);
	curve.addSourceAnchorage(getShapePart().getContent());

	// create using CreationPolicy from root part
	CreationPolicy creationPolicy = getHost().getRoot().getAdapter(CreationPolicy.class);
	init(creationPolicy);
	curvePart = (GeometricCurvePart) creationPolicy.create(curve, getHost().getRoot(),
			HashMultimap.<IContentPart<? extends Node>, String> create());
	commit(creationPolicy);

	// disable refresh visuals for the curvePart
	storeAndDisableRefreshVisuals(curvePart);

	// move curve to pointer location
	curvePart.getVisual().setEndPoint(getLocation(event));

	// build operation to deselect all but the new curve part
	List<IContentPart<? extends Node>> toBeDeselected = new ArrayList<>(
			getHost().getRoot().getViewer().getAdapter(SelectionModel.class).getSelectionUnmodifiable());
	toBeDeselected.remove(curvePart);
	DeselectOperation deselectOperation = new DeselectOperation(getHost().getRoot().getViewer(), toBeDeselected);
	// execute on stack
	try {
		getHost().getRoot().getViewer().getDomain().execute(deselectOperation, new NullProgressMonitor());
	} catch (ExecutionException e) {
		throw new RuntimeException(e);
	}

	// find bend target part
	bendTargetPart = findBendTargetPart(curvePart, event.getTarget());
	if (bendTargetPart != null) {
		dragPolicies = bendTargetPart.getAdapters(ClickDragGesture.ON_DRAG_POLICY_KEY);
	}
	if (dragPolicies != null) {
		MouseEvent dragEvent = new MouseEvent(event.getSource(), event.getTarget(), MouseEvent.MOUSE_DRAGGED,
				event.getX(), event.getY(), 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());
		for (IOnDragHandler dragPolicy : dragPolicies.values()) {
			dragPolicy.startDrag(event);
			// XXX: send initial drag event so that the end position is set
			dragPolicy.drag(dragEvent, new Dimension());
		}
	}
}
 
Example 10
Source File: TargetEditorController.java    From ShootOFF with GNU General Public License v3.0 4 votes vote down vote up
public void regionClicked(MouseEvent event) {
	if (!cursorButton.isSelected()) {
		// We want to drop a new region
		regionDropped(event);
		return;
	}

	// Want to select the current region
	final Node selected = (Node) event.getTarget();
	boolean tagEditorOpen = false;

	if (tagEditor.isPresent()) {
		// Close tag editor
		tagsButton.setSelected(false);
		toggleTagEditor();
		tagEditorOpen = true;
	}

	if (cursorRegion.isPresent()) {
		final Node previous = cursorRegion.get();

		// Unhighlight the old selection
		if (!previous.equals(selected)) {
			unhighlightRegion(previous);
		}
	}

	if (((TargetRegion) selected).getType() != RegionType.IMAGE)
		((Shape) selected).setStroke(TargetRegion.SELECTED_STROKE_COLOR);
	selected.requestFocus();
	toggleShapeControls(true);
	cursorRegion = Optional.of(selected);
	if (((TargetRegion) selected).getType() != RegionType.IMAGE)
		regionColorChoiceBox.getSelectionModel().select(getColorName((Color) ((Shape) selected).getFill()));

	// Re-open editor
	if (tagEditorOpen) {
		tagsButton.setSelected(true);
		toggleTagEditor();
	}
}