use of javafx.geometry.Point2D in project Gargoyle by callakrsos.
the class DockPane method handle.
@Override
public void handle(DockEvent event) {
if (event.getEventType() == DockEvent.DOCK_ENTER) {
if (!dockIndicatorOverlay.isShowing()) {
Point2D topLeft = DockPane.this.localToScreen(0, 0);
dockIndicatorOverlay.show(DockPane.this, topLeft.getX(), topLeft.getY());
}
} else if (event.getEventType() == DockEvent.DOCK_OVER) {
this.receivedEnter = false;
dockPosDrag = null;
dockAreaDrag = dockNodeDrag;
for (DockPosButton dockIndicatorButton : dockPosButtons) {
// if (dockIndicatorButton.contains(dockIndicatorButton.parentToLocal(event.getScreenX(), event.getScreenY()))) {
if (dockIndicatorButton.contains(dockIndicatorButton.screenToLocal(event.getScreenX(), event.getScreenY()))) {
dockPosDrag = dockIndicatorButton.getDockPos();
if (dockIndicatorButton.isDockRoot()) {
dockAreaDrag = root;
}
dockIndicatorButton.pseudoClassStateChanged(PseudoClass.getPseudoClass("focused"), true);
break;
} else {
dockIndicatorButton.pseudoClassStateChanged(PseudoClass.getPseudoClass("focused"), false);
}
}
if (dockPosDrag != null) {
Point2D originToScene = dockAreaDrag.localToScene(0, 0);
dockAreaIndicator.setVisible(true);
dockAreaIndicator.relocate(originToScene.getX(), originToScene.getY());
if (dockPosDrag == DockPos.RIGHT) {
dockAreaIndicator.setTranslateX(dockAreaDrag.getLayoutBounds().getWidth() / 2);
} else {
dockAreaIndicator.setTranslateX(0);
}
if (dockPosDrag == DockPos.BOTTOM) {
dockAreaIndicator.setTranslateY(dockAreaDrag.getLayoutBounds().getHeight() / 2);
} else {
dockAreaIndicator.setTranslateY(0);
}
if (dockPosDrag == DockPos.LEFT || dockPosDrag == DockPos.RIGHT) {
dockAreaIndicator.setWidth(dockAreaDrag.getLayoutBounds().getWidth() / 2);
} else {
dockAreaIndicator.setWidth(dockAreaDrag.getLayoutBounds().getWidth());
}
if (dockPosDrag == DockPos.TOP || dockPosDrag == DockPos.BOTTOM) {
dockAreaIndicator.setHeight(dockAreaDrag.getLayoutBounds().getHeight() / 2);
} else {
dockAreaIndicator.setHeight(dockAreaDrag.getLayoutBounds().getHeight());
}
} else {
dockAreaIndicator.setVisible(false);
}
if (dockNodeDrag != null) {
Point2D originToScreen = dockNodeDrag.localToScreen(0, 0);
double posX = originToScreen.getX() + dockNodeDrag.getLayoutBounds().getWidth() / 2 - dockPosIndicator.getWidth() / 2;
double posY = originToScreen.getY() + dockNodeDrag.getLayoutBounds().getHeight() / 2 - dockPosIndicator.getHeight() / 2;
if (!dockIndicatorPopup.isShowing()) {
dockIndicatorPopup.show(DockPane.this, posX, posY);
} else {
dockIndicatorPopup.setX(posX);
dockIndicatorPopup.setY(posY);
}
// set visible after moving the popup
dockPosIndicator.setVisible(true);
} else {
dockPosIndicator.setVisible(false);
}
}
if (event.getEventType() == DockEvent.DOCK_RELEASED && event.getContents() != null) {
if (dockPosDrag != null && dockIndicatorOverlay.isShowing()) {
DockNode dockNode = (DockNode) event.getContents();
dockNode.dock(this, dockPosDrag, dockAreaDrag);
}
}
if ((event.getEventType() == DockEvent.DOCK_EXIT && !this.receivedEnter) || event.getEventType() == DockEvent.DOCK_RELEASED) {
if (dockIndicatorPopup.isShowing()) {
dockIndicatorOverlay.hide();
dockIndicatorPopup.hide();
}
}
}
use of javafx.geometry.Point2D in project Gargoyle by callakrsos.
the class DockTitleBar method handle.
@Override
public void handle(MouseEvent event) {
//이벤트 관련 코드 추가. 마우스 메인키클릭의 경우에만 적용.
if (MouseButton.PRIMARY != event.getButton())
return;
if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
if (dockNode.isFloating() && event.getClickCount() == 2 && event.getButton() == MouseButton.PRIMARY) {
dockNode.setMaximized(!dockNode.isMaximized());
} else {
// drag detected is used in place of mouse pressed so there is
// some threshold for the
// dragging which is determined by the default drag detection
// threshold
dragStart = new Point2D(event.getX(), event.getY());
}
} else if (event.getEventType() == MouseEvent.DRAG_DETECTED) {
if (!dockNode.isFloating()) {
// the height of this title bar
if (!dockNode.isCustomTitleBar() && dockNode.isDecorated()) {
dockNode.setFloating(true, new Point2D(0, DockTitleBar.this.getHeight()));
} else {
dockNode.setFloating(true);
}
// TODO: Find a better solution.
// Temporary work around for nodes losing the drag event when
// removed from
// the scene graph.
// A possible alternative is to use "ghost" panes in the
// DockPane layout
// while making DockNode simply an overlay stage that is always
// shown.
// However since flickering when popping out was already
// eliminated that would
// be overkill and is not a suitable solution for native
// decorations.
// Bug report open:
// https://bugs.openjdk.java.net/browse/JDK-8133335
DockPane dockPane = this.getDockNode().getDockPane();
if (dockPane != null) {
dockPane.addEventFilter(MouseEvent.MOUSE_DRAGGED, this);
dockPane.addEventFilter(MouseEvent.MOUSE_RELEASED, this);
}
} else if (dockNode.isMaximized()) {
double ratioX = event.getX() / this.getDockNode().getWidth();
double ratioY = event.getY() / this.getDockNode().getHeight();
// Please note that setMaximized is ruined by width and height
// changes occurring on the
// stage and there is currently a bug report filed for this
// though I did not give them an
// accurate test case which I should and wish I would have. This
// was causing issues in the
// original release requiring maximized behavior to be
// implemented manually by saving the
// restored bounds. The problem was that the resize
// functionality in DockNode.java was
// executing at the same time canceling the maximized change.
// https://bugs.openjdk.java.net/browse/JDK-8133334
// restore/minimize the window after we have obtained its
// dimensions
dockNode.setMaximized(false);
// scale the drag start location by our restored dimensions
dragStart = new Point2D(ratioX * dockNode.getWidth(), ratioY * dockNode.getHeight());
}
dragging = true;
event.consume();
} else if (event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
if (dockNode.isFloating() && event.getClickCount() == 2 && event.getButton() == MouseButton.PRIMARY) {
event.setDragDetect(false);
event.consume();
return;
}
if (!dragging)
return;
Stage stage = dockNode.getStage();
Insets insetsDelta = this.getDockNode().getBorderPane().getInsets();
// dragging this way makes the interface more responsive in the
// event
// the system is lagging as is the case with most current JavaFX
// implementations on Linux
stage.setX(event.getScreenX() - dragStart.getX() - insetsDelta.getLeft());
stage.setY(event.getScreenY() - dragStart.getY() - insetsDelta.getTop());
// TODO: change the pick result by adding a copyForPick()
DockEvent dockEnterEvent = new DockEvent(this, DockEvent.NULL_SOURCE_TARGET, DockEvent.DOCK_ENTER, event.getX(), event.getY(), event.getScreenX(), event.getScreenY(), null, this.getDockNode());
DockEvent dockOverEvent = new DockEvent(this, DockEvent.NULL_SOURCE_TARGET, DockEvent.DOCK_OVER, event.getX(), event.getY(), event.getScreenX(), event.getScreenY(), null, this.getDockNode());
DockEvent dockExitEvent = new DockEvent(this, DockEvent.NULL_SOURCE_TARGET, DockEvent.DOCK_EXIT, event.getX(), event.getY(), event.getScreenX(), event.getScreenY(), null, this.getDockNode());
EventTask eventTask = new EventTask() {
@Override
public void run(Node node, Node dragNode) {
executions++;
if (dragNode != node) {
Event.fireEvent(node, dockEnterEvent.copyFor(DockTitleBar.this, node));
if (dragNode != null) {
// fire the dock exit first so listeners
// can actually keep track of the node we
// are currently over and know when we
// aren't over any which DOCK_OVER
// does not provide
Event.fireEvent(dragNode, dockExitEvent.copyFor(DockTitleBar.this, dragNode));
}
dragNodes.put(node.getScene().getWindow(), node);
}
Event.fireEvent(node, dockOverEvent.copyFor(DockTitleBar.this, node));
}
};
this.pickEventTarget(new Point2D(event.getScreenX(), event.getScreenY()), eventTask, dockExitEvent);
} else if (event.getEventType() == MouseEvent.MOUSE_RELEASED) {
dragging = false;
DockEvent dockReleasedEvent = new DockEvent(this, DockEvent.NULL_SOURCE_TARGET, DockEvent.DOCK_RELEASED, event.getX(), event.getY(), event.getScreenX(), event.getScreenY(), null, this.getDockNode());
EventTask eventTask = new EventTask() {
@Override
public void run(Node node, Node dragNode) {
executions++;
// if (dragNode != node) {
// Event.fireEvent(node, dockReleasedEvent.copyFor(DockTitleBar.this, node));
// }
Event.fireEvent(node, dockReleasedEvent.copyFor(DockTitleBar.this, node));
}
};
this.pickEventTarget(new Point2D(event.getScreenX(), event.getScreenY()), eventTask, null);
dragNodes.clear();
// Remove temporary event handler for bug mentioned above.
DockPane dockPane = this.getDockNode().getDockPane();
if (dockPane != null) {
dockPane.removeEventFilter(MouseEvent.MOUSE_DRAGGED, this);
dockPane.removeEventFilter(MouseEvent.MOUSE_RELEASED, this);
}
}
}
use of javafx.geometry.Point2D in project Gargoyle by callakrsos.
the class FxUtil method pick.
/**
* 픽포인트의 노드 리턴
*
* @작성자 : KYJ
* @작성일 : 2016. 1. 20.
* @param node
* @param sceneX
* @param sceneY
* @return
*/
public static Node pick(Node node, double sceneX, double sceneY) {
Point2D p = node.sceneToLocal(sceneX, sceneY, true);
// check if the given node has the point inside it, or else we drop out
if (!node.contains(p))
return null;
// a better child option
if (node instanceof Parent) {
// we iterate through all children in reverse order, and stop when
// we find a match.
// We do this as we know the el ements at the end of the list have a
// higher
// z-order, and are therefore the better match, compared to children
// that
// might also intersect (but that would be underneath the element).
Node bestMatchingChild = null;
List<Node> children = ((Parent) node).getChildrenUnmodifiable();
for (int i = children.size() - 1; i >= 0; i--) {
Node child = children.get(i);
p = child.sceneToLocal(sceneX, sceneY, true);
if (child.isVisible() && !child.isMouseTransparent() && child.contains(p)) {
bestMatchingChild = child;
break;
}
}
if (bestMatchingChild != null) {
return pick(bestMatchingChild, sceneX, sceneY);
}
}
return node;
}
use of javafx.geometry.Point2D in project Gargoyle by callakrsos.
the class FxUtil method getAbsolte2D.
/**
* X, Y축 절대좌표를 구함.
*
* @작성자 : KYJ
* @작성일 : 2016. 2. 22.
* @param longRegion
* 사이즈가 늘어나는 Region객체
* @param target
* 절대좌표를 구할 target객체
* @return
*/
public static Point2D getAbsolte2D(Region longRegion, Parent target) {
Point2D point2d = new Point2D(target.getLayoutX(), target.getLayoutY());
// Point2D point2d = new Point2D(target.getBoundsInLocal().getMaxX(),
// target.getBoundsInLocal().getMaxY());
// Point2D point2d = new Point2D(target.getScene().getX(),
// target.getScene().getY());
Parent parent2 = target.getParent();
if (longRegion == parent2) {
return point2d;
}
return point2d.add(getAbsolte2D(longRegion, parent2));
}
use of javafx.geometry.Point2D in project Gargoyle by callakrsos.
the class FxUtil method getCenter.
public Point2D getCenter(Stage window) {
Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
double centerX = bounds.getMinX() + (bounds.getWidth() - window.getWidth()) * CENTER_ON_SCREEN_X_FRACTION;
double centerY = bounds.getMinY() + (bounds.getHeight() - window.getHeight()) * CENTER_ON_SCREEN_Y_FRACTION;
return new Point2D(centerX, centerY);
}
Aggregations