Example usage for javafx.scene.input MouseEvent getScreenX

List of usage examples for javafx.scene.input MouseEvent getScreenX

Introduction

In this page you can find the example usage for javafx.scene.input MouseEvent getScreenX.

Prototype

public final double getScreenX() 

Source Link

Document

Returns absolute horizontal position of the event.

Usage

From source file:Main.java

public static void addDraggableNode(final Node node) {

    node.setOnMousePressed((MouseEvent me) -> {
        dragInitialX = me.getSceneX();/*from  w ww  . jav  a2s  .  co  m*/
        dragInitialY = me.getSceneY();
    });

    node.setOnMouseDragged((MouseEvent me) -> {
        node.getScene().getWindow().setX(me.getScreenX() - dragInitialX);
        node.getScene().getWindow().setY(me.getScreenY() - dragInitialY);
    });
}

From source file:gov.va.isaac.gui.util.ErrorMarkerUtils.java

/**
 * Setup an 'INFORMATION' info marker on the component. Automatically displays anytime that the initialControl is disabled.
 * Put the initial control in the provided stack pane
 *//*w  ww. ja  v  a 2s  . c  o  m*/
public static Node setupDisabledInfoMarker(Control initialControl, StackPane stackPane,
        ObservableStringValue reasonWhyControlDisabled) {
    ImageView information = Images.INFORMATION.createImageView();

    information.visibleProperty().bind(initialControl.disabledProperty());
    Tooltip tooltip = new Tooltip();
    tooltip.textProperty().bind(reasonWhyControlDisabled);
    Tooltip.install(information, tooltip);
    tooltip.setAutoHide(true);

    information.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            tooltip.show(information, event.getScreenX(), event.getScreenY());

        }

    });

    stackPane.setMaxWidth(Double.MAX_VALUE);
    stackPane.getChildren().add(initialControl);
    StackPane.setAlignment(initialControl, Pos.CENTER_LEFT);
    stackPane.getChildren().add(information);
    if (initialControl instanceof Button) {
        StackPane.setAlignment(information, Pos.CENTER);
    } else if (initialControl instanceof CheckBox) {
        StackPane.setAlignment(information, Pos.CENTER_LEFT);
        StackPane.setMargin(information, new Insets(0, 0, 0, 1));
    } else {
        StackPane.setAlignment(information, Pos.CENTER_RIGHT);
        double insetFromRight = (initialControl instanceof ComboBox ? 30.0 : 5.0);
        StackPane.setMargin(information, new Insets(0.0, insetFromRight, 0.0, 0.0));
    }
    return stackPane;
}

From source file:gov.va.isaac.gui.util.ErrorMarkerUtils.java

/**
 * Setup an 'EXCLAMATION' error marker on the component. Automatically displays anytime that the reasonWhyControlInvalid value
 * is false. Hides when the isControlCurrentlyValid is true.
 * @param stackPane - optional - created if necessary
 *///from   ww  w. ja v a2  s  .  com
public static StackPane setupErrorMarker(Node initialNode, StackPane stackPane,
        ValidBooleanBinding isNodeCurrentlyValid) {
    ImageView exclamation = Images.EXCLAMATION.createImageView();

    if (stackPane == null) {
        stackPane = new StackPane();
    }

    exclamation.visibleProperty().bind(isNodeCurrentlyValid.not());
    Tooltip tooltip = new Tooltip();
    tooltip.textProperty().bind(isNodeCurrentlyValid.getReasonWhyInvalid());
    Tooltip.install(exclamation, tooltip);
    tooltip.setAutoHide(true);

    exclamation.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            tooltip.show(exclamation, event.getScreenX(), event.getScreenY());

        }

    });

    stackPane.setMaxWidth(Double.MAX_VALUE);
    stackPane.getChildren().add(initialNode);
    StackPane.setAlignment(initialNode, Pos.CENTER_LEFT);
    stackPane.getChildren().add(exclamation);
    StackPane.setAlignment(exclamation, Pos.CENTER_RIGHT);
    double insetFromRight;
    if (initialNode instanceof ComboBox) {
        insetFromRight = 30.0;
    } else if (initialNode instanceof ChoiceBox) {
        insetFromRight = 25.0;
    } else {
        insetFromRight = 5.0;
    }
    StackPane.setMargin(exclamation, new Insets(0.0, insetFromRight, 0.0, 0.0));
    return stackPane;
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    BorderPane root = new BorderPane();
    Scene scene = new Scene(root, 300, 250, Color.WHITE);
    MenuBar menuBar = new MenuBar();
    menuBar.getMenus().addAll(fileMenu(), cameraMenu(), alarmMenu());
    root.setTop(menuBar);//  ww  w .j a  va2 s.c o  m
    ContextMenu contextFileMenu = new ContextMenu(exitMenuItem());

    primaryStage.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent me) -> {
        if (me.getButton() == MouseButton.SECONDARY || me.isControlDown()) {
            contextFileMenu.show(root, me.getScreenX(), me.getScreenY());
        } else {
            contextFileMenu.hide();
        }
    });
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:com.sceneControllers.MainWindowSceneController.java

@FXML
protected void onRectangleDragged(MouseEvent event) {
    mainstage.setX(event.getScreenX() + X);
    mainstage.setY(event.getScreenY() + Y);
}

From source file:com.sceneControllers.MainWindowSceneController.java

@FXML
protected void onRectanglePressed(MouseEvent event) {
    X = mainstage.getX() - event.getScreenX();
    Y = mainstage.getY() - event.getScreenY();
}

From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.TooltipHandlerFX.java

/**
 * Handles a mouse moved event by updating the tooltip.
 * //from   ww  w  .j ava  2s  . c om
 * @param canvas  the chart canvas (<code>null</code> not permitted).
 * @param e  the mouse event.
 */
@Override
public void handleMouseMoved(ChartCanvas canvas, MouseEvent e) {
    if (!canvas.isTooltipEnabled()) {
        return;
    }
    String text = getTooltipText(canvas, e.getX(), e.getY());
    canvas.setTooltip(text, e.getScreenX(), e.getScreenY());
}

From source file:de.chaosfisch.uploader.gui.GUIUploader.java

private void initApplication(final Stage primaryStage) {

    try {/*from  w w  w .j  a  v  a2  s .  co m*/

        final Parent parent = fxmlLoader
                .load(getClass().getResource("/de/chaosfisch/uploader/view/SimpleJavaYoutubeUploader.fxml"),
                        resources)
                .getRoot();

        final Scene scene = SceneBuilder.create().root(parent).fill(Color.TRANSPARENT).build();

        try (InputStream iconInputStream = getClass()
                .getResourceAsStream("/de/chaosfisch/uploader/resources/images/film.png")) {
            StageBuilder.create().icons(new Image(iconInputStream)).minHeight(MIN_HEIGHT).height(MIN_HEIGHT)
                    .minWidth(MIN_WIDTH).width(MIN_WIDTH).scene(scene).resizable(true)
                    .onCloseRequest(new ApplicationClosePromptDialog()).applyTo(primaryStage);
        }
        parent.setOnMouseDragged(new EventHandler<MouseEvent>() {

            @Override
            public void handle(final MouseEvent me) {
                primaryStage.setX(me.getScreenX() - initX);
                primaryStage.setY(me.getScreenY() - initY);
            }
        });

        parent.setOnMousePressed(new EventHandler<MouseEvent>() {
            @Override
            public void handle(final MouseEvent me) {
                initX = me.getScreenX() - primaryStage.getX();
                initY = me.getScreenY() - primaryStage.getY();
            }
        });

        primaryStage.initStyle(StageStyle.TRANSPARENT);
        primaryStage.show();
    } catch (final IOException e) {
        LOGGER.error("FXML Load error", e);
        throw new RuntimeException(e);
    }
}

From source file:de.pixida.logtest.designer.automaton.Graph.java

private void mouseClickedOnPane(final MouseEvent event) {
    this.contextMenu.hide();
    if (event.getButton() == MouseButton.PRIMARY) {
        if (this.connectorSourceNode != null) {
            Validate.notNull(this.connector);
            this.cancelDrawingConnector();
        } else {/* w  ww . jav  a  2s . co m*/
            this.automatonEditor.showDefaultConfigFrame();
        }
    } else if (event.getButton() == MouseButton.SECONDARY) {
        this.contextMenu.show(this.pane, event.getScreenX(), event.getScreenY());
    }
}

From source file:fr.amap.commons.javafx.chart.ChartViewer.java

public ChartViewer(String title, int width, int height, int maxChartNumberInARow) {

    stage = new Stage();
    stage.setTitle(title);/*from w w w. j a v a2 s  . c o  m*/
    stage.setWidth(width);
    stage.setHeight(height);

    this.maxChartNumberInARow = maxChartNumberInARow;

    this.setContextMenu(createContextMenu());

    vBoxPane = new VBox();
    scrollPane = new ScrollPane();
    scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    scrollPane.setFitToHeight(true);
    scrollPane.setFitToWidth(true);
    scrollPane.setPannable(true);

    scrollPane.setOnMouseClicked(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent event) {
            MouseButton button = event.getButton();
            if (button == MouseButton.SECONDARY) {
                menu.show(stage, event.getScreenX(), event.getScreenY());
            }
        }
    });

    scrollPane.widthProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
            refreshChartPositionAndSize();
        }
    });

    scrollPane.heightProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
            refreshChartPositionAndSize();
        }
    });

    vBoxPane.getChildren().add(new HBox());
    scrollPane.setContent(vBoxPane);

    chartCanvasList = new ArrayList<>();
    stage.setScene(new Scene(scrollPane));

}