当前位置: 首页>>代码示例>>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;未经允许,请勿转载。