Java Code Examples for javafx.scene.Cursor#DEFAULT

The following examples show how to use javafx.scene.Cursor#DEFAULT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DragResizerUtil.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
protected static Cursor getCursorForState(DragDirection state) {
    switch (state) {
    case NW_RESIZE:
        return Cursor.NW_RESIZE;
    case SW_RESIZE:
        return Cursor.SW_RESIZE;
    case NE_RESIZE:
        return Cursor.NE_RESIZE;
    case SE_RESIZE:
        return Cursor.SE_RESIZE;
    case E_RESIZE:
        return Cursor.E_RESIZE;
    case W_RESIZE:
        return Cursor.W_RESIZE;
    case N_RESIZE:
        return Cursor.N_RESIZE;
    case S_RESIZE:
        return Cursor.S_RESIZE;
    default:
        return Cursor.DEFAULT;
    }
}
 
Example 2
Source File: PlotCursors.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private static Cursor getCursor(final MouseMode mode)
{
    switch (mode)
    {
    case PAN:
    case PAN_X:
    case PAN_Y:
    case PAN_PLOT:
        return cursor_pan;
    case ZOOM_IN:
    case ZOOM_IN_PLOT:
    case ZOOM_IN_X:
    case ZOOM_IN_Y:
        return cursor_zoom_in;
    case ZOOM_OUT:
        return cursor_zoom_out;
    default:
         return Cursor.DEFAULT;
    }
}
 
Example 3
Source File: ShowSplitPane.java    From oim-fx with MIT License 5 votes vote down vote up
private Cursor getCursor(MouseEvent me, Pane pane) {
	Cursor cursor = Cursor.DEFAULT;

	double grp = 4;
	double width = pane.getWidth();
	double height = pane.getHeight();

	double x = me.getX();
	double y = me.getY();

	if (x < grp && y < grp) {
		// cursor = Cursor.SE_RESIZE;
		type = 1;
	} else if (x > (width - grp) && y < grp) {
		// cursor = Cursor.SW_RESIZE;
		type = 2;
	} else if (x < grp && y > (height - grp)) {
		// cursor = Cursor.SW_RESIZE;
		type = 3;
	} else if (x > (width - grp) && y > (height - grp)) {
		// cursor = Cursor.SE_RESIZE;
		type = 4;
	} else if (x < grp) {
		// cursor = Cursor.H_RESIZE;
		type = 5;
	} else if (x > (width - grp)) {
		// cursor = Cursor.H_RESIZE;
		type = 6;
	} else if (y < grp) {
		cursor = Cursor.V_RESIZE;
		type = 7;
	} else if (y > (height - grp)) {
		// cursor = Cursor.V_RESIZE;
		type = 8;
	} else {
		type = 0;
	}
	return cursor;
}
 
Example 4
Source File: ChatListFrame.java    From oim-fx with MIT License 5 votes vote down vote up
private Cursor getCursor(MouseEvent me, Pane pane) {
	Cursor cursor = Cursor.DEFAULT;

	double grp = 3;
	double width = pane.getWidth();
	double height = pane.getHeight();

	double x = me.getX();
	double y = me.getY();

	if (x < grp && y < grp) {
		// cursor = Cursor.SE_RESIZE;
		type = 1;
	} else if (x > (width - grp) && y < grp) {
		// cursor = Cursor.SW_RESIZE;
		type = 2;
	} else if (x < grp && y > (height - grp)) {
		// cursor = Cursor.SW_RESIZE;
		type = 3;
	} else if (x > (width - grp) && y > (height - grp)) {
		// cursor = Cursor.SE_RESIZE;
		type = 4;
	} else if (x < grp) {
		// cursor = Cursor.H_RESIZE;
		type = 5;
	} else if (x > (width - grp)) {
		cursor = Cursor.H_RESIZE;
		type = 6;
	} else if (y < grp) {
		// cursor = Cursor.V_RESIZE;
		type = 7;
	} else if (y > (height - grp)) {
		// cursor = Cursor.V_RESIZE;
		type = 8;
	} else {
		type = 0;
	}
	return cursor;
}
 
Example 5
Source File: ChatListStage.java    From oim-fx with MIT License 5 votes vote down vote up
private Cursor getCursor(MouseEvent me, Pane pane) {
	Cursor cursor = Cursor.DEFAULT;

	double grp = 3;
	double width = pane.getWidth();
	double height = pane.getHeight();

	double x = me.getX();
	double y = me.getY();

	if (x < grp && y < grp) {
		// cursor = Cursor.SE_RESIZE;
		type = 1;
	} else if (x > (width - grp) && y < grp) {
		// cursor = Cursor.SW_RESIZE;
		type = 2;
	} else if (x < grp && y > (height - grp)) {
		// cursor = Cursor.SW_RESIZE;
		type = 3;
	} else if (x > (width - grp) && y > (height - grp)) {
		// cursor = Cursor.SE_RESIZE;
		type = 4;
	} else if (x < grp) {
		// cursor = Cursor.H_RESIZE;
		type = 5;
	} else if (x > (width - grp)) {
		cursor = Cursor.H_RESIZE;
		type = 6;
	} else if (y < grp) {
		// cursor = Cursor.V_RESIZE;
		type = 7;
	} else if (y > (height - grp)) {
		// cursor = Cursor.V_RESIZE;
		type = 8;
	} else {
		type = 0;
	}
	return cursor;
}
 
Example 6
Source File: ChatSplitPane.java    From oim-fx with MIT License 5 votes vote down vote up
private Cursor getCursor(MouseEvent me, Pane pane) {
	Cursor cursor = Cursor.DEFAULT;

	double grp = 4;
	double width = pane.getWidth();
	double height = pane.getHeight();

	double x = me.getX();
	double y = me.getY();

	if (x < grp && y < grp) {
		// cursor = Cursor.SE_RESIZE;
		type = 1;
	} else if (x > (width - grp) && y < grp) {
		// cursor = Cursor.SW_RESIZE;
		type = 2;
	} else if (x < grp && y > (height - grp)) {
		// cursor = Cursor.SW_RESIZE;
		type = 3;
	} else if (x > (width - grp) && y > (height - grp)) {
		// cursor = Cursor.SE_RESIZE;
		type = 4;
	} else if (x < grp) {
		// cursor = Cursor.H_RESIZE;
		type = 5;
	} else if (x > (width - grp)) {
		// cursor = Cursor.H_RESIZE;
		type = 6;
	} else if (y < grp) {
		cursor = Cursor.V_RESIZE;
		type = 7;
	} else if (y > (height - grp)) {
		// cursor = Cursor.V_RESIZE;
		type = 8;
	} else {
		type = 0;
	}
	return cursor;
}
 
Example 7
Source File: ResizeListener.java    From Path-of-Leveling with MIT License 5 votes vote down vote up
public ResizeListener(Stage stage) {
    this.stage = stage;
    isPressed = false;
    cursorEvent = Cursor.DEFAULT;
    border = 3;
    stageStartH = 0;
    stageStartW = 0;
    stageStartX = 0;
    stageStartY = 0;
    this.addResizeListener();
}
 
Example 8
Source File: StageFloatable.java    From AnchorFX with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Cursor changeCursor(boolean sizeLeft, boolean sizeRight, boolean sizeTop, boolean sizeBottom) {
    Cursor cursor = Cursor.DEFAULT;
    if (sizeLeft) {
        if (sizeTop) {
            cursor = Cursor.NW_RESIZE;
        }
        else if (sizeBottom) {
            cursor = Cursor.SW_RESIZE;
        }
        else {
            cursor = Cursor.W_RESIZE;
        }
    }
    else if (sizeRight) {
        if (sizeTop) {
            cursor = Cursor.NE_RESIZE;
        }
        else if (sizeBottom) {
            cursor = Cursor.SE_RESIZE;
        }
        else {
            cursor = Cursor.E_RESIZE;
        }
    }
    else if (sizeTop) {
        cursor = Cursor.N_RESIZE;
    }
    else if (sizeBottom) {
        cursor = Cursor.S_RESIZE;
    }

    return cursor;
}
 
Example 9
Source File: ResizeHelper.java    From Path-of-Leveling with MIT License 4 votes vote down vote up
@Override
public void handle(MouseEvent mouseEvent) {
    EventType<? extends MouseEvent> mouseEventType = mouseEvent.getEventType();
    Scene scene = stage.getScene();

    double mouseEventX = mouseEvent.getSceneX();
    double mouseEventY = mouseEvent.getSceneY();
    double sceneWidth = scene.getWidth();
    double sceneHeight = scene.getHeight();

    if (MouseEvent.MOUSE_MOVED.equals(mouseEventType)) {
        if (mouseEventX < border && mouseEventY < border) {
            cursorEvent = Cursor.NW_RESIZE;
        } else if (mouseEventX < border && mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.SW_RESIZE;
        } else if (mouseEventX > sceneWidth - border && mouseEventY < border) {
            cursorEvent = Cursor.NE_RESIZE;
        } else if (mouseEventX > sceneWidth - border && mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.SE_RESIZE;
        } else if (mouseEventX < border) {
            cursorEvent = Cursor.W_RESIZE;
        } else if (mouseEventX > sceneWidth - border) {
            cursorEvent = Cursor.E_RESIZE;
        } else if (mouseEventY < border) {
            cursorEvent = Cursor.N_RESIZE;
        } else if (mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.S_RESIZE;
        } else {
            cursorEvent = Cursor.DEFAULT;
        }
        scene.setCursor(cursorEvent);
    } else if (MouseEvent.MOUSE_EXITED.equals(mouseEventType) || MouseEvent.MOUSE_EXITED_TARGET.equals(mouseEventType)) {
        scene.setCursor(Cursor.DEFAULT);
    } else if (MouseEvent.MOUSE_PRESSED.equals(mouseEventType)) {
        startX = stage.getWidth() - mouseEventX;
        startY = stage.getHeight() - mouseEventY;
    } else if (MouseEvent.MOUSE_DRAGGED.equals(mouseEventType)) {
        if (!Cursor.DEFAULT.equals(cursorEvent)) {
            if (!Cursor.W_RESIZE.equals(cursorEvent) && !Cursor.E_RESIZE.equals(cursorEvent)) {
                double minHeight = stage.getMinHeight() > (border * 2) ? stage.getMinHeight() : (border * 2);
                double maxHeight = stage.getMaxHeight();
                if (Cursor.NW_RESIZE.equals(cursorEvent) || Cursor.N_RESIZE.equals(cursorEvent) || Cursor.NE_RESIZE.equals(cursorEvent)) {
                    double newHeight = stage.getHeight() - (mouseEvent.getScreenY() - stage.getY());
                    if (newHeight >= minHeight && newHeight <= maxHeight) {
                        stage.setHeight(newHeight);
                        stage.setY(mouseEvent.getScreenY());
                    } else {
                        newHeight = Math.min(Math.max(newHeight, minHeight), maxHeight);
                        // y1 + h1 = y2 + h2
                        // y1 = y2 + h2 - h1
                        stage.setY(stage.getY() + stage.getHeight() - newHeight);
                        stage.setHeight(newHeight);
                    }
                } else {
                    stage.setHeight(Math.min(Math.max(mouseEventY + startY, minHeight), maxHeight));
                }
            }

            if (!Cursor.N_RESIZE.equals(cursorEvent) && !Cursor.S_RESIZE.equals(cursorEvent)) {
                double minWidth = stage.getMinWidth() > (border * 2) ? stage.getMinWidth() : (border * 2);
                double maxWidth = stage.getMaxWidth();
                if (Cursor.NW_RESIZE.equals(cursorEvent) || Cursor.W_RESIZE.equals(cursorEvent) || Cursor.SW_RESIZE.equals(cursorEvent)) {
                    double newWidth = stage.getWidth() - (mouseEvent.getScreenX() - stage.getX());
                    if (newWidth >= minWidth && newWidth <= maxWidth) {
                        stage.setWidth(newWidth);
                        stage.setX(mouseEvent.getScreenX());
                    } else {
                        newWidth = Math.min(Math.max(newWidth, minWidth), maxWidth);
                        // x1 + w1 = x2 + w2
                        // x1 = x2 + w2 - w1
                        stage.setX(stage.getX() + stage.getWidth() - newWidth);
                        stage.setWidth(newWidth);
                    }
                } else {
                    stage.setWidth(Math.min(Math.max(mouseEventX + startX, minWidth), maxWidth));
                }
            }
        }
    }

    if (MouseEvent.MOUSE_PRESSED.equals(mouseEventType)) {
        startScreenX = mouseEvent.getScreenX();
        startScreenY = mouseEvent.getScreenY();
    } else if (MouseEvent.MOUSE_DRAGGED.equals(mouseEventType)) {
        if (Cursor.DEFAULT.equals(cursorEvent) && !stage.isMaximized()) {
            stage.setX(stage.getX() + mouseEvent.getScreenX() - startScreenX);
            startScreenX = mouseEvent.getScreenX();
            stage.setY(stage.getY() + mouseEvent.getScreenY() - startScreenY);
            startScreenY = mouseEvent.getScreenY();
        }
    }
}
 
Example 10
Source File: ResizeHelper.java    From CustomStage with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(MouseEvent mouseEvent) {
    EventType<? extends MouseEvent> mouseEventType = mouseEvent.getEventType();
    Scene scene = stage.getScene();

    double mouseEventX = mouseEvent.getSceneX(),
            mouseEventY = mouseEvent.getSceneY(),
            sceneWidth = scene.getWidth(),
            sceneHeight = scene.getHeight();

    if (MouseEvent.MOUSE_MOVED.equals(mouseEventType)) {
        if (mouseEventX < border && mouseEventY < border) {
            cursorEvent = Cursor.NW_RESIZE;
        } else if (mouseEventX < border && mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.SW_RESIZE;
        } else if (mouseEventX > sceneWidth - border && mouseEventY < border) {
            cursorEvent = Cursor.NE_RESIZE;
        } else if (mouseEventX > sceneWidth - border && mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.SE_RESIZE;
        } else if (mouseEventX < border) {
            cursorEvent = Cursor.W_RESIZE;
        } else if (mouseEventX > sceneWidth - border) {
            cursorEvent = Cursor.E_RESIZE;
        } else if (mouseEventY < border) {
            cursorEvent = Cursor.N_RESIZE;
        } else if (mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.S_RESIZE;
        } else {
            cursorEvent = Cursor.DEFAULT;
        }
        scene.setCursor(cursorEvent);
    } else if (MouseEvent.MOUSE_EXITED.equals(mouseEventType) || MouseEvent.MOUSE_EXITED_TARGET.equals(mouseEventType)) {
        scene.setCursor(Cursor.DEFAULT);
    } else if (MouseEvent.MOUSE_PRESSED.equals(mouseEventType)) {
        startX = stage.getWidth() - mouseEventX;
        startY = stage.getHeight() - mouseEventY;
    } else if (MouseEvent.MOUSE_DRAGGED.equals(mouseEventType)) {
        if (!Cursor.DEFAULT.equals(cursorEvent)) {
            if (!Cursor.W_RESIZE.equals(cursorEvent) && !Cursor.E_RESIZE.equals(cursorEvent)) {
                double minHeight = stage.getMinHeight() > (border * 2) ? stage.getMinHeight() : (border * 2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) || Cursor.N_RESIZE.equals(cursorEvent)
                        || Cursor.NE_RESIZE.equals(cursorEvent)) {
                    if (stage.getHeight() > minHeight || mouseEventY < 0) {
                        setStageHeight(stage.getY() - mouseEvent.getScreenY() + stage.getHeight());
                        stage.setY(mouseEvent.getScreenY());
                    }
                } else {
                    if (stage.getHeight() > minHeight || mouseEventY + startY - stage.getHeight() > 0) {
                        setStageHeight(mouseEventY + startY);
                    }
                }
            }

            if (!Cursor.N_RESIZE.equals(cursorEvent) && !Cursor.S_RESIZE.equals(cursorEvent)) {
                double minWidth = stage.getMinWidth() > (border * 2) ? stage.getMinWidth() : (border * 2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) || Cursor.W_RESIZE.equals(cursorEvent)
                        || Cursor.SW_RESIZE.equals(cursorEvent)) {
                    if (stage.getWidth() > minWidth || mouseEventX < 0) {
                        setStageWidth(stage.getX() - mouseEvent.getScreenX() + stage.getWidth());
                        stage.setX(mouseEvent.getScreenX());
                    }
                } else {
                    if (stage.getWidth() > minWidth || mouseEventX + startX - stage.getWidth() > 0) {
                        setStageWidth(mouseEventX + startX);
                    }
                }
            }
        }

    }
}
 
Example 11
Source File: ResizeHelper.java    From ApkToolPlus with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(MouseEvent mouseEvent) {
    EventType<? extends MouseEvent> mouseEventType = mouseEvent.getEventType();
    Scene scene = stage.getScene();

    double mouseEventX = mouseEvent.getSceneX(), 
           mouseEventY = mouseEvent.getSceneY(),
           sceneWidth = scene.getWidth(),
           sceneHeight = scene.getHeight();

    if (MouseEvent.MOUSE_MOVED.equals(mouseEventType) == true) {
        if (mouseEventX < border && mouseEventY < border) {
            cursorEvent = Cursor.NW_RESIZE;
        } else if (mouseEventX < border && mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.SW_RESIZE;
        } else if (mouseEventX > sceneWidth - border && mouseEventY < border) {
            cursorEvent = Cursor.NE_RESIZE;
        } else if (mouseEventX > sceneWidth - border && mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.SE_RESIZE;
        } else if (mouseEventX < border) {
            cursorEvent = Cursor.W_RESIZE;
        } else if (mouseEventX > sceneWidth - border) {
            cursorEvent = Cursor.E_RESIZE;
        } else if (mouseEventY < border) {
            cursorEvent = Cursor.N_RESIZE;
        } else if (mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.S_RESIZE;
        } else {
            cursorEvent = Cursor.DEFAULT;
        }
        scene.setCursor(cursorEvent);
    } else if (MouseEvent.MOUSE_PRESSED.equals(mouseEventType) == true) {
        startX = stage.getWidth() - mouseEventX;
        startY = stage.getHeight() - mouseEventY;
    } else if (MouseEvent.MOUSE_DRAGGED.equals(mouseEventType) == true) {
        if (Cursor.DEFAULT.equals(cursorEvent) == false) {
            if (Cursor.W_RESIZE.equals(cursorEvent) == false && Cursor.E_RESIZE.equals(cursorEvent) == false) {
                double minHeight = stage.getMinHeight() > (border*2) ? stage.getMinHeight() : (border*2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) == true || Cursor.N_RESIZE.equals(cursorEvent) == true || Cursor.NE_RESIZE.equals(cursorEvent) == true) {
                    if (stage.getHeight() > minHeight || mouseEventY < 0) {
                        stage.setHeight(stage.getY() - mouseEvent.getScreenY() + stage.getHeight());
                        stage.setY(mouseEvent.getScreenY());
                    }
                } else {
                    if (stage.getHeight() > minHeight || mouseEventY + startY - stage.getHeight() > 0) {
                        stage.setHeight(mouseEventY + startY);
                    }
                }
            }

            if (Cursor.N_RESIZE.equals(cursorEvent) == false && Cursor.S_RESIZE.equals(cursorEvent) == false) {
                double minWidth = stage.getMinWidth() > (border*2) ? stage.getMinWidth() : (border*2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) == true || Cursor.W_RESIZE.equals(cursorEvent) == true || Cursor.SW_RESIZE.equals(cursorEvent) == true) {
                    if (stage.getWidth() > minWidth || mouseEventX < 0) {
                        stage.setWidth(stage.getX() - mouseEvent.getScreenX() + stage.getWidth());
                        stage.setX(mouseEvent.getScreenX());
                    }
                } else {
                    if (stage.getWidth() > minWidth || mouseEventX + startX - stage.getWidth() > 0) {
                        stage.setWidth(mouseEventX + startX);
                    }
                }
            }
        }

    }
}
 
Example 12
Source File: ResizeHelper.java    From JavaFX-Chat with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void handle(MouseEvent mouseEvent) {
    EventType<? extends MouseEvent> mouseEventType = mouseEvent.getEventType();
    Scene scene = stage.getScene();

    double mouseEventX = mouseEvent.getSceneX(),
            mouseEventY = mouseEvent.getSceneY(),
            sceneWidth = scene.getWidth(),
            sceneHeight = scene.getHeight();

    if (MouseEvent.MOUSE_MOVED.equals(mouseEventType)) {
        if (mouseEventX < border && mouseEventY < border) {
            cursorEvent = Cursor.NW_RESIZE;
        } else if (mouseEventX < border && mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.SW_RESIZE;
        } else if (mouseEventX > sceneWidth - border && mouseEventY < border) {
            cursorEvent = Cursor.NE_RESIZE;
        } else if (mouseEventX > sceneWidth - border && mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.SE_RESIZE;
        } else if (mouseEventX < border) {
            cursorEvent = Cursor.W_RESIZE;
        } else if (mouseEventX > sceneWidth - border) {
            cursorEvent = Cursor.E_RESIZE;
        } else if (mouseEventY < border) {
            cursorEvent = Cursor.N_RESIZE;
        } else if (mouseEventY > sceneHeight - border) {
            cursorEvent = Cursor.S_RESIZE;
        } else {
            cursorEvent = Cursor.DEFAULT;
        }
        scene.setCursor(cursorEvent);
    } else if(MouseEvent.MOUSE_EXITED.equals(mouseEventType) || MouseEvent.MOUSE_EXITED_TARGET.equals(mouseEventType)){
        scene.setCursor(Cursor.DEFAULT);
    } else if (MouseEvent.MOUSE_PRESSED.equals(mouseEventType)) {
        startX = stage.getWidth() - mouseEventX;
        startY = stage.getHeight() - mouseEventY;
    } else if (MouseEvent.MOUSE_DRAGGED.equals(mouseEventType)) {
        if (Cursor.DEFAULT.equals(cursorEvent) == false) {
            if (Cursor.W_RESIZE.equals(cursorEvent) == false && Cursor.E_RESIZE.equals(cursorEvent) == false) {
                double minHeight = stage.getMinHeight() > (border*2) ? stage.getMinHeight() : (border*2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) == true || Cursor.N_RESIZE.equals(cursorEvent) == true || Cursor.NE_RESIZE.equals(cursorEvent) == true) {
                    if (stage.getHeight() > minHeight || mouseEventY < 0) {
                        stage.setHeight(stage.getY() - mouseEvent.getScreenY() + stage.getHeight());
                        stage.setY(mouseEvent.getScreenY());
                    }
                } else {
                    if (stage.getHeight() > minHeight || mouseEventY + startY - stage.getHeight() > 0) {
                        stage.setHeight(mouseEventY + startY);
                    }
                }
            }

            if (Cursor.N_RESIZE.equals(cursorEvent) == false && Cursor.S_RESIZE.equals(cursorEvent) == false) {
                double minWidth = stage.getMinWidth() > (border*2) ? stage.getMinWidth() : (border*2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) == true || Cursor.W_RESIZE.equals(cursorEvent) == true || Cursor.SW_RESIZE.equals(cursorEvent) == true) {
                    if (stage.getWidth() > minWidth || mouseEventX < 0) {
                        stage.setWidth(stage.getX() - mouseEvent.getScreenX() + stage.getWidth());
                        stage.setX(mouseEvent.getScreenX());
                    }
                } else {
                    if (stage.getWidth() > minWidth || mouseEventX + startX - stage.getWidth() > 0) {
                        stage.setWidth(mouseEventX + startX);
                    }
                }
            }
        }

    }
}
 
Example 13
Source File: StageFloatable.java    From AnchorFX with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void setupMouseEvents() {
    eventsHandler = event -> {

        if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
            mousePositionStart = new Point2D(event.getScreenX(), event.getScreenY());
            startWidth = getWidth();
            startX = getX();

            startHeight = getHeight();
            startY = getY();
        }

        if (event.getEventType() == MouseEvent.MOUSE_MOVED) {

            boolean sizeRight = valueInRange(event.getX(), stackPanelContainer.getWidth() - stackPanelContainer.getPadding().getLeft(), stackPanelContainer.getWidth());
            boolean sizeLeft = valueInRange(event.getX(), 0, stackPanelContainer.getPadding().getRight());
            boolean sizeTop = valueInRange(event.getY(), 0, stackPanelContainer.getPadding().getTop());
            boolean sizeBottom = valueInRange(event.getY(), stackPanelContainer.getHeight() - stackPanelContainer.getPadding().getBottom(), stackPanelContainer.getHeight());

            Cursor cursor = changeCursor(sizeLeft, sizeRight, sizeTop, sizeBottom);

            getScene().setCursor(cursor);
        }

        if (event.getEventType() == MouseEvent.MOUSE_DRAGGED && (getScene().getCursor() != null && getScene().getCursor() != Cursor.DEFAULT)) {

            if (getScene().getCursor() == Cursor.E_RESIZE || getScene().getCursor() == Cursor.SE_RESIZE || getScene().getCursor() == Cursor.NE_RESIZE) {
                if (event.getScreenX() - getX() + FLOATING_NODE_DROPSHADOW_RADIUS > FLOATING_NODE_MINIMUM_WIDTH) {
                    setWidth(event.getScreenX() - getX() + FLOATING_NODE_DROPSHADOW_RADIUS);
                }
            }
            else if (getScene().getCursor() == Cursor.S_RESIZE || getScene().getCursor() == Cursor.SE_RESIZE || getScene().getCursor() == Cursor.SW_RESIZE) {
                if (event.getScreenY() - getY() + FLOATING_NODE_DROPSHADOW_RADIUS > FLOATING_NODE_MINIMUM_HEIGHT) {
                    setHeight(event.getScreenY() - getY() + FLOATING_NODE_DROPSHADOW_RADIUS);
                }
            }
            else if (getScene().getCursor() == Cursor.W_RESIZE || getScene().getCursor() == Cursor.NW_RESIZE || getScene().getCursor() == Cursor.SW_RESIZE) {

                double newX = event.getScreenX() - FLOATING_NODE_DROPSHADOW_RADIUS;
                double newWidth = startX - newX + startWidth;

                if (newWidth > FLOATING_NODE_MINIMUM_WIDTH) {
                    setX(newX);
                    setWidth(newWidth);
                }

            }
            else if (getScene().getCursor() == Cursor.N_RESIZE || getScene().getCursor() == Cursor.NW_RESIZE || getScene().getCursor() == Cursor.NE_RESIZE) {

                double newY = event.getScreenY() - FLOATING_NODE_DROPSHADOW_RADIUS;
                double newHeight = startY - newY + startHeight;

                if (newHeight > FLOATING_NODE_MINIMUM_HEIGHT) {
                    setY(newY);
                    setHeight(newHeight);
                }

            }

        }
        /*
        else if (event.getEventType() == MouseEvent.MOUSE_RELEASED) {
            // TODO: handle this event?
        }
        */
    };

    stackPanelContainer.addEventFilter(MouseEvent.MOUSE_PRESSED, eventsHandler);
    stackPanelContainer.addEventFilter(MouseEvent.MOUSE_MOVED, eventsHandler);
    stackPanelContainer.addEventFilter(MouseEvent.MOUSE_DRAGGED, eventsHandler);
    stackPanelContainer.addEventFilter(MouseEvent.MOUSE_RELEASED, eventsHandler);
}
 
Example 14
Source File: StageFloatable.java    From AnchorFX with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean inResizing() {
    return (getScene().getCursor() != null && getScene().getCursor() != Cursor.DEFAULT);
}