本文整理汇总了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));
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
});
}
示例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);
}
示例9: addBackgroundHandler
import javafx.scene.Node; //导入方法依赖的package包/类
public void addBackgroundHandler(Node background) {
background.addEventHandler(MouseEvent.MOUSE_PRESSED, this::onBackgroundPressed);
}
示例10: requestFocusOnPress
import javafx.scene.Node; //导入方法依赖的package包/类
public static void requestFocusOnPress(Node node) {
node.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> node.requestFocus());
}
示例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));
}
示例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));
}
示例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>&, ^, *, \, !, +</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);
});
}