Java examples for JavaFX:Action
is JavaFX MouseEvent in Corner
//package com.java2s; import javafx.geometry.Bounds; import javafx.geometry.Point2D; import javafx.scene.input.MouseEvent; import javafx.scene.layout.Region; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.shape.Rectangle; public class Main { static double SLOP = 8; static public boolean inCorner(MouseEvent ev) { if (ev == null) return false; if (ev.getTarget() instanceof Rectangle) return inCorner(ev.getX(), ev.getY(), (Rectangle) ev.getTarget()); if (ev.getTarget() instanceof StackPane) return inCorner(ev.getX(), ev.getY(), (StackPane) ev.getTarget()); if (ev.getTarget() instanceof VBox) return inCorner(ev.getX(), ev.getY(), (VBox) ev.getTarget()); return false; }//from ww w .j a v a 2 s.com static public boolean inCorner(MouseEvent ev, Rectangle r) { return inCorner(ev.getX(), ev.getY(), r); } static public boolean inCorner(Point2D pt, Rectangle r) { if (pt == null || r == null) return false; return inCorner(pt.getX(), pt.getY(), r); } static public boolean inCorner(Point2D pt, StackPane r) { return inCorner(pt.getX(), pt.getY(), r.getBoundsInLocal()); } static public boolean inCorner(double inX, double inY, StackPane r) { return inCorner(inX, inY, r.getBoundsInLocal()); } static public boolean inCorner(double inX, double inY, VBox r) { return inCorner(inX, inY, r.getBoundsInLocal()); } static public boolean inCorner(Point2D pt, Region r) { if (pt == null || r == null) return false; return inCorner(pt.getX(), pt.getY(), r.getBoundsInLocal()); } static public boolean inCorner(double inX, double inY, Rectangle r) { double x = inX; double y = inY; double left = r.getX(); double right = left + r.getWidth(); double top = r.getY(); double bottom = top + r.getHeight(); if (Math.abs(x - left) < SLOP || Math.abs(x - right) < SLOP) if (Math.abs(y - top) < SLOP || Math.abs(y - bottom) < SLOP) return true; return false; } public static boolean inCorner(Point2D curPoint, Bounds bounds) { return inCorner(curPoint.getX(), curPoint.getY(), bounds); } public static boolean inCorner(double inX, double inY, Bounds bounds) { double left = bounds.getMinX(); double right = left + bounds.getWidth(); double top = bounds.getMinY(); double bottom = top + bounds.getHeight(); if (Math.abs(inX - left) < SLOP || Math.abs(inX - right) < SLOP) if (Math.abs(inY - top) < SLOP || Math.abs(inY - bottom) < SLOP) return true; return false; } }