當前位置: 首頁>>代碼示例>>Java>>正文


Java Node.addEventHandler方法代碼示例

本文整理匯總了Java中javafx.scene.Node.addEventHandler方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.addEventHandler方法的具體用法?Java Node.addEventHandler怎麽用?Java Node.addEventHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javafx.scene.Node的用法示例。


在下文中一共展示了Node.addEventHandler方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setButtonEffect

import javafx.scene.Node; //導入方法依賴的package包/類
private static void setButtonEffect(Node node)
{
	DropShadow rollOverColor = new DropShadow();
	rollOverColor.setColor(Color.ORANGERED);
	DropShadow clickColor = new DropShadow();
	clickColor.setColor(Color.DARKBLUE);
	
	node.addEventHandler(MouseEvent.MOUSE_ENTERED,
			(event) -> node.setEffect(rollOverColor));
	
	// Removing the shadow when the mouse cursor is off
	node.addEventHandler(MouseEvent.MOUSE_EXITED, (event) -> node.setEffect(null));
	
	// Darken shadow on click
	node.addEventHandler(MouseEvent.MOUSE_PRESSED,
			(event) -> node.setEffect(clickColor));
	
	// Restore hover style on click end
	node.addEventHandler(MouseEvent.MOUSE_RELEASED,
			(event) -> node.setEffect(rollOverColor));
}
 
開發者ID:dhawal9035,項目名稱:WebPLP,代碼行數:22,代碼來源:EmulationWindow.java

示例2: addContinuousPressHandler

import javafx.scene.Node; //導入方法依賴的package包/類
/**
 * Add an event handler to a node will trigger continuously trigger at a given interval while the button is
 * being pressed.
 *
 * @param node     the {@link Node}
 * @param holdTime interval time
 * @param handler  the handler
 */
private void addContinuousPressHandler(final Node node, final Duration holdTime,
                                       final EventHandler<MouseEvent> handler) {
    final Wrapper<MouseEvent> eventWrapper = new Wrapper<>();

    final PauseTransition holdTimer = new PauseTransition(holdTime);
    holdTimer.setOnFinished(event -> {
        handler.handle(eventWrapper.content);
        holdTimer.playFromStart();
    });

    node.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> {
        eventWrapper.content = event;
        holdTimer.playFromStart();
    });
    node.addEventHandler(MouseEvent.MOUSE_RELEASED, event -> holdTimer.stop());
    node.addEventHandler(MouseEvent.DRAG_DETECTED, event -> holdTimer.stop());
}
 
開發者ID:ProgrammingLife2017,項目名稱:hygene,代碼行數:26,代碼來源:GraphNavigationController.java

示例3: bind

import javafx.scene.Node; //導入方法依賴的package包/類
public static DragConfig bind(Node node) {
  node.addEventHandler(MouseEvent.MOUSE_PRESSED, press);
  node.addEventHandler(MouseEvent.MOUSE_DRAGGED, drag);
  node.addEventHandler(MouseEvent.MOUSE_RELEASED, release);
  DragHandle dragConfig = new NodeDrag(node);
  map.put(node, dragConfig);
  return dragConfig;
}
 
開發者ID:XDean,項目名稱:JavaFX-EX,代碼行數:9,代碼來源:DragSupport.java

示例4: bind

import javafx.scene.Node; //導入方法依賴的package包/類
public static ResizeConfig bind(Node node, DoubleProperty width, DoubleProperty height) {
  node.addEventHandler(MouseEvent.MOUSE_MOVED, move);
  node.addEventHandler(MouseEvent.MOUSE_PRESSED, press);
  node.addEventHandler(MouseEvent.MOUSE_DRAGGED, drag);
  node.addEventHandler(MouseEvent.MOUSE_RELEASED, release);
  BaseResize resize = new BaseResize(node, width, height);
  map.put(node, resize);
  return resize;
}
 
開發者ID:XDean,項目名稱:JavaFX-EX,代碼行數:10,代碼來源:ResizeSupport.java

示例5: apply

import javafx.scene.Node; //導入方法依賴的package包/類
public void apply(Node node, PanningComponent panningComponent) {
    this.node = node;
    this.panningComponent = panningComponent;
    node.addEventHandler(MouseEvent.MOUSE_PRESSED, onMousePressed);
    node.addEventHandler(MouseEvent.MOUSE_DRAGGED, onMouseDragged);
    node.addEventHandler(MouseEvent.MOUSE_RELEASED, onMouseReleased);
}
 
開發者ID:rmfisher,項目名稱:fx-animation-editor,代碼行數:8,代碼來源:DragBehavior.java

示例6: createCell

import javafx.scene.Node; //導入方法依賴的package包/類
@Override
protected Node createCell(T item) {
    Node cell = super.createCell(item);
    cell.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> onCellPressed(item));
    selection.addListener((v, o, n) -> cell.pseudoClassStateChanged(SELECTED_PSEUDO_CLASS, item != null && item.equals(n)));
    return cell;
}
 
開發者ID:rmfisher,項目名稱:fx-animation-editor,代碼行數:8,代碼來源:SelectionComboButton.java

示例7: makeDraggable

import javafx.scene.Node; //導入方法依賴的package包/類
public static void makeDraggable(final Node mouseSubject,
                                 final Supplier<DragBounds> getDragBounds) {
    final DoubleProperty previousX = new SimpleDoubleProperty();
    final DoubleProperty previousY = new SimpleDoubleProperty();
    final BooleanProperty wasDragged = new SimpleBooleanProperty();

    final DoubleProperty xDiff = new SimpleDoubleProperty();
    final DoubleProperty yDiff = new SimpleDoubleProperty();

    mouseSubject.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> {
        if(!event.isPrimaryButtonDown()) return;
        
        previousX.set(mouseSubject.getLayoutX());
        previousY.set(mouseSubject.getLayoutY());
        xDiff.set(event.getX());
        yDiff.set(event.getY());
    });

    mouseSubject.addEventHandler(MouseEvent.MOUSE_DRAGGED, event -> {
        if(!event.isPrimaryButtonDown()) return;

        final DragBounds dragBounds = getDragBounds.get();

        final double newX = CanvasPresentation.mouseTracker.getGridX() - CanvasController.getActiveComponent().getX();
        final double newY = CanvasPresentation.mouseTracker.getGridY() - CanvasController.getActiveComponent().getY();

        final double unRoundedX = dragBounds.trimX(newX - xDiff.get());
        final double unRoundedY = dragBounds.trimY(newY - yDiff.get());
        double finalNewX = unRoundedX - unRoundedX % GRID_SIZE;
        double finalNewY = unRoundedY - unRoundedY % GRID_SIZE;
        if (mouseSubject instanceof ComponentPresentation) {
            finalNewX -= 0.5 * GRID_SIZE;
            finalNewY -= 0.5 * GRID_SIZE;
        }
        mouseSubject.setLayoutX(finalNewX);
        mouseSubject.setLayoutY(finalNewY);

        wasDragged.set(true);
    });

    mouseSubject.addEventHandler(MouseEvent.MOUSE_RELEASED, event -> {
        final double currentX = mouseSubject.getLayoutX();
        final double currentY = mouseSubject.getLayoutY
                ();
        final double storePreviousX = previousX.get();
        final double storePreviousY = previousY.get();

        if(currentX != storePreviousX || currentY != storePreviousY) {
            UndoRedoStack.push(
                    () -> {
                        mouseSubject.setLayoutX(currentX);
                        mouseSubject.setLayoutY(currentY);
                    },
                    () -> {
                        mouseSubject.setLayoutX(storePreviousX);
                        mouseSubject.setLayoutY(storePreviousY);
                    },
                    String.format("Moved " + mouseSubject.getClass() + " from (%f,%f) to (%f,%f)", currentX, currentY, storePreviousX, storePreviousY),
                    "pin-drop"
            );
        }

        // Reset the was dragged boolean
        wasDragged.set(false);
    });

}
 
開發者ID:ulriknyman,項目名稱:H-Uppaal,代碼行數:68,代碼來源:ItemDragHelper.java

示例8: addEventHandlers

import javafx.scene.Node; //導入方法依賴的package包/類
private void addEventHandlers(Node resizer) {
    resizer.addEventHandler(MouseEvent.MOUSE_PRESSED, this::onPressed);
    resizer.addEventHandler(MouseEvent.MOUSE_DRAGGED, this::onDragged);
    resizer.addEventHandler(MouseEvent.MOUSE_RELEASED, this::onReleased);
}
 
開發者ID:rmfisher,項目名稱:fx-animation-editor,代碼行數:6,代碼來源:ResizeBehavior.java

示例9: addBackgroundHandler

import javafx.scene.Node; //導入方法依賴的package包/類
public void addBackgroundHandler(Node background) {
    background.addEventHandler(MouseEvent.MOUSE_PRESSED, this::onBackgroundPressed);
}
 
開發者ID:rmfisher,項目名稱:fx-animation-editor,代碼行數:4,代碼來源:SelectionClickBehavior.java

示例10: requestFocusOnPress

import javafx.scene.Node; //導入方法依賴的package包/類
public static void requestFocusOnPress(Node node) {
    node.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> node.requestFocus());
}
 
開發者ID:rmfisher,項目名稱:fx-animation-editor,代碼行數:4,代碼來源:FocusHelper.java

示例11: redirectFocusOnPress

import javafx.scene.Node; //導入方法依賴的package包/類
public static void redirectFocusOnPress(Node node, Node delegate) {
    node.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> Platform.runLater(delegate::requestFocus));
}
 
開發者ID:rmfisher,項目名稱:fx-animation-editor,代碼行數:4,代碼來源:FocusHelper.java

示例12: addHandlers

import javafx.scene.Node; //導入方法依賴的package包/類
public void addHandlers(Node child) {
    child.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> onPressed(child, event));
    child.addEventHandler(MouseEvent.MOUSE_DRAGGED, event -> onDragged(child, event));
    child.addEventHandler(MouseEvent.MOUSE_RELEASED, event -> onReleased(child, event));
}
 
開發者ID:rmfisher,項目名稱:fx-animation-editor,代碼行數:6,代碼來源:KeyFrameDragAnimator.java

示例13: setKeyCombinationShortcut

import javafx.scene.Node; //導入方法依賴的package包/類
/**
 * Convenience method for setting key combination shortcuts.
 * Supports any combination of Ctrl (Command), Alt, Shift plus one of the following:
 * <ul>
 * <li>letter [A-Z], case insensitive</li>
 * <li>digit [0-9]</li>
 * <li>backspace, space</li>
 * <li>&amp;, ^, *, \, !, +</li>
 * </ul>
 * 
 * @param node The node that will respond to the key combination
 * @param keyCombination A string in the format 'modifier[+modifier]+key'
 * @param keyHandler The function called when the key combo is detected
 */
public static void setKeyCombinationShortcut(Node node, String keyCombination, EventHandler<? super KeyEvent> keyHandler) {
	final KeyCombination combo = buildKeyCombination(keyCombination);
	
	node.addEventHandler(KeyEvent.KEY_RELEASED, event -> {
		if(combo.match(event))
			keyHandler.handle(event);
	});
}
 
開發者ID:vibridi,項目名稱:fxutils,代碼行數:23,代碼來源:FXKeyboard.java


注:本文中的javafx.scene.Node.addEventHandler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。