javafx.event.EventTarget Java Examples

The following examples show how to use javafx.event.EventTarget. 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: 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 #2
Source File: DockEvent.java    From DockFX with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: LabelSourceStateMergeDetachHandler.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public EventHandler<Event> viewerHandler(
		final PainteraBaseView paintera,
		final KeyAndMouseBindings bindings,
		final KeyTracker keyTracker,
		final String bindingKeyMergeAllSelected) {
	return event -> {
		final EventTarget target = event.getTarget();
		if (!(target instanceof Node))
			return;
		Node node = (Node) target;
		LOG.trace("Handling event {} in target {}", event, target);
		// kind of hacky way to accomplish this:
		while (node != null) {
			if (node instanceof ViewerPanelFX) {
				handlers.computeIfAbsent((ViewerPanelFX) node, k -> this.makeHandler(paintera, bindings, keyTracker, k, bindingKeyMergeAllSelected)).handle(event);
				return;
			}
			node = node.getParent();
		}
	};
}
 
Example #4
Source File: LabelSourceStatePaintHandler.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public EventHandler<Event> viewerHandler(final PainteraBaseView paintera, final KeyTracker keyTracker) {
	return event -> {
		final EventTarget target = event.getTarget();
		if (!(target instanceof Node))
			return;
		Node node = (Node) target;
		LOG.trace("Handling event {} in target {}", event, target);
		// kind of hacky way to accomplish this:
		while (node != null) {
			if (node instanceof ViewerPanelFX) {
				handlers.computeIfAbsent((ViewerPanelFX) node, k -> this.makeHandler(paintera, keyTracker, k)).handle(event);
				return;
			}
			node = node.getParent();
		}
	};
}
 
Example #5
Source File: UiUtils.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * @param event the event.
 * @return true if the event is not hotkey.
 */
@FxThread
public static boolean isNotHotKey(@Nullable final KeyEvent event) {
    if (event == null) return false;

    final String text = event.getText();
    if (text.isEmpty()) return false;

    final KeyCode code = event.getCode();
    final EventTarget target = event.getTarget();

    if (code == KeyCode.TAB && !(target instanceof TextInputControl)) {
        return false;
    }

    if (event.isControlDown()) {
        return false;
    } else return !event.isShiftDown();
}
 
Example #6
Source File: EventRedirector.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
private void redirect(@NotNull final GestureEvent event) {

        final EventTarget target = event.getTarget();
        if (target == destination) return;

        final FileEditor currentEditor = editorAreaComponent.getCurrentEditor();
        if (currentEditor == null || !currentEditor.isInside(event.getSceneX(), event.getSceneY(), event.getClass())) {
            return;
        }

        Event.fireEvent(destination, event.copyFor(event.getSource(), destination));
    }
 
Example #7
Source File: DragDropGesture.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void handle(final DragEvent event) {
	final EventTarget target = event.getTarget();
	if (event.getGestureSource() != target
			&& (target instanceof Node)) {
		final Node targetNode = (Node) target;
		dragOver(targetNode, event);
	}
}
 
Example #8
Source File: ScrollGesture.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Callback method that is invoked for the first {@link ScrollEvent} of a
 * scroll gesture.
 *
 * @param viewer
 *            The {@link IViewer}.
 * @param event
 *            The corresponding {@link ScrollEvent}.
 */
protected void scrollStarted(IViewer viewer, ScrollEvent event) {
	EventTarget eventTarget = event.getTarget();
	getDomain().openExecutionTransaction(ScrollGesture.this);
	setActiveHandlers(viewer,
			getHandlerResolver().resolve(ScrollGesture.this,
					eventTarget instanceof Node ? (Node) eventTarget : null,
					viewer, ON_SCROLL_POLICY_KEY));
	for (IOnScrollHandler policy : getActiveHandlers(viewer)) {
		policy.startScroll(event);
	}
}
 
Example #9
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 #10
Source File: AbstractHandler.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns <code>true</code> if the given {@link EventTarget} is registered
 * in the visual-part-map. Otherwise returns <code>false</code>.
 *
 * @param eventTarget
 *            The {@link EventTarget} that is tested.
 * @return <code>true</code> if the given {@link EventTarget} is registered
 *         in the visual-part-map, otherwise <code>false</code>.
 */
protected boolean isRegistered(EventTarget eventTarget) {
	IVisualPart<? extends Node> host = getHost();
	if (host.getRoot() == null || host.getRoot().getViewer() == null) {
		// host is not in visual-part-hierarchy or not in viewer
		return false;
	}
	IViewer viewer = host.getRoot().getViewer();
	if (eventTarget instanceof Node) {
		return PartUtils.retrieveVisualPart(viewer,
				(Node) eventTarget) != viewer.getRootPart();
	}
	// eventTarget is a Scene
	return false;
}
 
Example #11
Source File: AbstractHandler.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns <code>true</code> if the given {@link EventTarget} is registered
 * in the visual-part-map for the {@link #getHost() host} of this
 * {@link AbstractHandler}. Otherwise returns <code>false</code>.
 *
 * @param eventTarget
 *            The {@link EventTarget} that is tested.
 * @return <code>true</code> if the given {@link EventTarget} is registered
 *         in the visual-part-map for the host of this policy, otherwise
 *         <code>false</code>.
 */
protected boolean isRegisteredForHost(EventTarget eventTarget) {
	IVisualPart<? extends Node> host = getHost();
	if (host.getRoot() == null || host.getRoot().getViewer() == null) {
		// host is not in visual-part-hierarchy or not in viewer
		return false;
	}
	IViewer viewer = host.getRoot().getViewer();
	if (eventTarget instanceof Node) {
		return PartUtils.retrieveVisualPart(viewer,
				(Node) eventTarget) == host;
	}
	// eventTarget is a Scene
	return false;
}
 
Example #12
Source File: CreateCurveOnDragHandler.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
protected CircleSegmentHandlePart findBendTargetPart(GeometricCurvePart curvePart, EventTarget eventTarget) {
	// find last segment handle part
	Multiset<IVisualPart<? extends Node>> anchoreds = curvePart.getAnchoredsUnmodifiable();
	for (IVisualPart<? extends Node> anchored : anchoreds) {
		if (anchored instanceof CircleSegmentHandlePart) {
			CircleSegmentHandlePart circleSegmentHandlePart = (CircleSegmentHandlePart) anchored;
			if (circleSegmentHandlePart.getSegmentParameter() == 1.0) {
				return circleSegmentHandlePart;
			}
		}
	}
	throw new IllegalStateException("Cannot find bend target part.");
}
 
Example #13
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 #14
Source File: EventRedirector.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
private void redirect(@NotNull final InputEvent event) {

        final EventTarget target = event.getTarget();
        if (target == destination) {
            return;
        } else if (target instanceof TextInputControl) {
            if (event instanceof KeyEvent && UiUtils.isNotHotKey((KeyEvent) event)) {
                if (Config.DEV_DEBUG_JFX_KEY_INPUT) {
                    LOGGER.debug(this, target, ev -> "Key event was skipped because it was from " + ev);
                }
                return;
            }
        }

        final EventType<? extends InputEvent> eventType = event.getEventType();
        final FileEditor currentEditor = editorAreaComponent.getCurrentEditor();

        if (Config.DEV_DEBUG_JFX_KEY_INPUT) {
            LOGGER.debug(this, event, notNull(currentEditor), (red, ev, editor) -> "Key event " + ev.getEventType() +
                    " is inside " + editor.isInside(red.getSceneX(), red.getSceneY(), ev.getClass()));
        }

        if (currentEditor == null || eventType != KeyEvent.KEY_RELEASED && !currentEditor.isInside(getSceneX(), getSceneY(), event.getClass())) {
            return;
        }

        if (Config.DEV_DEBUG_JFX_KEY_INPUT) {
            LOGGER.debug(this, event, ev -> "Redirect event " + ev);
        }

        Event.fireEvent(destination, event.copyFor(event.getSource(), destination));
    }
 
Example #15
Source File: DragDropGesture.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void handle(final DragEvent event) {
	final EventTarget target = event.getTarget();
	if (target instanceof Node) {
		dragExited((Node) target, event);
	}
}
 
Example #16
Source File: LabelSourceStatePaintHandler.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public EventHandler<Event> viewerFilter(final PainteraBaseView paintera, final KeyTracker keyTracker) {
	return event -> {
		final EventTarget target = event.getTarget();
		if (MouseEvent.MOUSE_EXITED.equals(event.getEventType()) && target instanceof ViewerPanelFX)
			Optional.ofNullable(painters.get(target)).ifPresent(p -> p.setBrushOverlayVisible(false));
	};
}
 
Example #17
Source File: LabelSourceStateIdSelectorHandler.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public EventHandler<Event> viewerHandler(
		final PainteraBaseView paintera,
		final KeyAndMouseBindings labelSourceStateBindings,
		final KeyTracker keyTracker,
		final String bindingKeySelectAll,
		final String bindingKeySelectAllInCurrentView,
		final String bindingKeyLockSegment,
		final String bindingKeyNextId) {
	return event -> {
		final EventTarget target = event.getTarget();
		if (!(target instanceof Node))
			return;
		Node node = (Node) target;
		LOG.trace("Handling event {} in target {}", event, target);
		// kind of hacky way to accomplish this:
		while (node != null) {
			if (node instanceof ViewerPanelFX) {
				handlers.computeIfAbsent((ViewerPanelFX) node, k -> this.makeHandler(
						paintera,
						labelSourceStateBindings,
						keyTracker,
						k,
						bindingKeySelectAll,
						bindingKeySelectAllInCurrentView,
						bindingKeyLockSegment,
						bindingKeyNextId)).handle(event);
				return;
			}
			node = node.getParent();
		}
	};
}
 
Example #18
Source File: DragDropGesture.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void handle(final DragEvent event) {
	final EventTarget target = event.getTarget();
	if (target instanceof Node) {
		dragEntered((Node) target, event);
	}
}
 
Example #19
Source File: ValueEvent.java    From Enzo with Apache License 2.0 4 votes vote down vote up
public ValueEvent(final Object SOURCE, final EventTarget TARGET, EventType<ValueEvent> TYPE) {
    super(SOURCE, TARGET, TYPE);
}
 
Example #20
Source File: MouseStationaryEvent.java    From RichTextFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Begin(Object source, EventTarget target, Point2D screenPos) {
    super(source, target, MOUSE_STATIONARY_BEGIN);
    this.screenPos = screenPos;
}
 
Example #21
Source File: Marker.java    From Enzo with Apache License 2.0 4 votes vote down vote up
public MarkerEvent(final Object SOURCE, final EventTarget TARGET, EventType<MarkerEvent> TYPE) {
    super(SOURCE, TARGET, TYPE);
}
 
Example #22
Source File: Section.java    From Enzo with Apache License 2.0 4 votes vote down vote up
public SectionEvent(final Object SOURCE, final EventTarget TARGET, EventType<SectionEvent> TYPE) {
    super(SOURCE, TARGET, TYPE);
}
 
Example #23
Source File: AlarmEvent.java    From Enzo with Apache License 2.0 4 votes vote down vote up
public AlarmEvent(final Object SOURCE, final EventTarget TARGET, EventType<AlarmEvent> TYPE) {
    super(SOURCE, TARGET, TYPE);
}
 
Example #24
Source File: PushButton.java    From Enzo with Apache License 2.0 4 votes vote down vote up
public SelectionEvent(final Status STATUS, final Object SOURCE, final EventTarget TARGET, final EventType<SelectionEvent> EVENT_TYPE) {
    super(SOURCE, TARGET, EVENT_TYPE);
    status = STATUS;
}
 
Example #25
Source File: Alarm.java    From Enzo with Apache License 2.0 4 votes vote down vote up
public AlarmEvent(final Alarm ALARM, final Object SOURCE, final EventTarget TARGET, EventType<AlarmEvent> TYPE) {
    super(SOURCE, TARGET, TYPE);
    alarm = ALARM;
}
 
Example #26
Source File: SelectionEvent.java    From Enzo with Apache License 2.0 4 votes vote down vote up
public SelectionEvent(final Object SOURCE, final EventTarget TARGET, final EventType<SelectionEvent> EVENT_TYPE) {
    super(SOURCE, TARGET, EVENT_TYPE);
}
 
Example #27
Source File: RadialMenu.java    From Enzo with Apache License 2.0 4 votes vote down vote up
public ItemEvent(final MenuItem ITEM, final Object SOURCE, final EventTarget TARGET, final EventType<ItemEvent> EVENT_TYPE) {
    super(SOURCE, TARGET, EVENT_TYPE);
    item = ITEM;
}
 
Example #28
Source File: RadialMenu.java    From Enzo with Apache License 2.0 4 votes vote down vote up
public MenuEvent(final Object SOURCE, final EventTarget TARGET, final EventType<MenuEvent> EVENT_TYPE) {
    super(SOURCE, TARGET, EVENT_TYPE);
}
 
Example #29
Source File: AcceleratorsTests.java    From RichTextFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public AcceleratorsTestsHelper(EventTarget source, String character, KeyCode key, boolean controlDown, boolean altDown, boolean expected) {
	keyEvent = new KeyEvent(source, source, KeyEvent.KEY_TYPED, character, key.getName(), key,
			false, controlDown, altDown, false);
	expectedConsumeResult = expected;
}
 
Example #30
Source File: MouseStationaryEvent.java    From RichTextFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public Begin copyFor(Object newSource, EventTarget newTarget) {
    return new Begin(newSource, newTarget, screenPos);
}