Example usage for javafx.scene.input MouseEvent getEventType

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

Introduction

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

Prototype

@Override
    public EventType<? extends MouseEvent> getEventType() 

Source Link

Usage

From source file:Main.java

public static java.awt.event.MouseEvent toAwt(final MouseEvent event) {
    final EventType type = event.getEventType();
    if (null == type) {
        return null;
    }//from  www  .  j a  va2  s.c om

    final int id;
    if (MouseEvent.MOUSE_MOVED.equals(type)) {
        id = java.awt.event.MouseEvent.MOUSE_MOVED;
    } else if (MouseEvent.MOUSE_DRAGGED.equals(type)) {
        id = java.awt.event.MouseEvent.MOUSE_DRAGGED;
    } else if (MouseEvent.MOUSE_CLICKED.equals(type)) {
        id = java.awt.event.MouseEvent.MOUSE_CLICKED;
    } else if (MouseEvent.MOUSE_PRESSED.equals(type)) {
        id = java.awt.event.MouseEvent.MOUSE_PRESSED;
    } else if (MouseEvent.MOUSE_RELEASED.equals(type)) {
        id = java.awt.event.MouseEvent.MOUSE_RELEASED;
    } else if (MouseEvent.MOUSE_ENTERED.equals(type)) {
        id = java.awt.event.MouseEvent.MOUSE_ENTERED;
    } else if (MouseEvent.MOUSE_EXITED.equals(type)) {
        id = java.awt.event.MouseEvent.MOUSE_EXITED;
    } else {
        return null;
    }

    final int button;
    if (event.isPrimaryButtonDown()) {
        button = java.awt.event.MouseEvent.BUTTON1;
    } else if (event.isMiddleButtonDown()) {
        button = java.awt.event.MouseEvent.BUTTON2;
    } else if (event.isSecondaryButtonDown()) {
        button = java.awt.event.MouseEvent.BUTTON3;
    } else {
        button = java.awt.event.MouseEvent.NOBUTTON;
    }

    final long when = -1;
    final int modifiers = modifiers(event);
    final int x = (int) event.getX();
    final int y = (int) event.getY();
    final int xAbs = Integer.MAX_VALUE;
    final int yAbs = Integer.MAX_VALUE;
    final int count = event.getClickCount();
    boolean popup = event.isPopupTrigger();
    if (MouseEvent.MOUSE_CLICKED.equals(type) && event.isMetaDown()) {
        // mack books use meta flag for right-clicks
        popup = true;
    }
    return new java.awt.event.MouseEvent(empty, id, when, modifiers, x, y, xAbs, yAbs, count, popup, button);
}

From source file:com.panemu.tiwulfx.form.BaseControl.java

public BaseControl(String propertyName, E control) {
    this.inputControl = control;
    this.propertyName = propertyName;
    HBox.setHgrow(control, Priority.ALWAYS);
    setAlignment(Pos.CENTER_LEFT);//from   w  w  w  .j av a  2s.co  m
    control.setMaxWidth(Double.MAX_VALUE);
    control.setMinHeight(USE_PREF_SIZE);
    getChildren().add(control);
    getChildren().add(imagePlaceHolder);

    required.addListener(imageListener);
    valid.addListener(imageListener);

    this.getStyleClass().add("form-control");
    value = new SimpleObjectProperty<>();
    bindValuePropertyWithControl(control);
    bindEditablePropertyWithControl(control);

    addEventHandler(MouseEvent.ANY, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            if (event.getEventType() == MouseEvent.MOUSE_MOVED && !isValid() && !getPopup().isShowing()) {
                Point2D p = BaseControl.this.localToScene(0.0, 0.0);
                getPopup().show(BaseControl.this, p.getX() + getScene().getX() + getScene().getWindow().getX(),
                        p.getY() + getScene().getY() + getScene().getWindow().getY()
                                + getInputComponent().getHeight() - 1);
            } else if (event.getEventType() == MouseEvent.MOUSE_EXITED && getPopup().isShowing()) {
                getPopup().hide();
            }
        }
    });
    getInputComponent().addEventHandler(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent t) {
            if (!isValid() && getPopup().isShowing()) {
                getPopup().hide();
            }
        }
    });
}

From source file:com.panemu.tiwulfx.form.BaseListControl.java

public BaseListControl(String propertyName, E control) {
    this.inputControl = control;
    this.propertyName = propertyName;
    HBox.setHgrow(control, Priority.ALWAYS);
    setAlignment(Pos.CENTER_LEFT);/*from   www  .  j ava  2  s. co m*/
    control.setMaxWidth(Double.MAX_VALUE);
    control.setMinHeight(USE_PREF_SIZE);
    getChildren().add(control);
    getChildren().add(imagePlaceHolder);

    required.addListener(imageListener);
    valid.addListener(imageListener);

    this.getStyleClass().add("form-control");
    value = new SimpleListProperty<>();
    bindValuePropertyWithControl(control);
    bindEditablePropertyWithControl(control);

    addEventHandler(MouseEvent.ANY, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            if (event.getEventType() == MouseEvent.MOUSE_MOVED && !isValid() && !getPopup().isShowing()) {
                Point2D p = BaseListControl.this.localToScene(0.0, 0.0);
                getPopup().show(BaseListControl.this,
                        p.getX() + getScene().getX() + getScene().getWindow().getX(),
                        p.getY() + getScene().getY() + getScene().getWindow().getY()
                                + getInputComponent().getHeight() - 1);
            } else if (event.getEventType() == MouseEvent.MOUSE_EXITED && getPopup().isShowing()) {
                getPopup().hide();
            }
        }
    });
    getInputComponent().addEventHandler(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent t) {
            if (!isValid() && getPopup().isShowing()) {
                getPopup().hide();
            }
        }
    });
}

From source file:com.bekwam.mavenpomupdater.MainViewController.java

@FXML
public void mouseTest(MouseEvent evt) {
    log.debug("[MOUSE] evt type=" + evt.getEventType());

}

From source file:de.bayern.gdi.gui.Controller.java

/**
 * Handle the service selection./*from w w w .j ava 2 s . c  om*/
 *
 * @param event The mouse click event.
 */
@FXML
protected void handleServiceSelect(MouseEvent event) {
    if (event.getEventType().equals(MouseEvent.MOUSE_CLICKED)) {
        if (event.getClickCount() == 1) {
            clearUserNamePassword();
            ServiceModel serviceModel = (ServiceModel) this.serviceList.getSelectionModel().getSelectedItems()
                    .get(0);
            if (serviceModel != null) {
                serviceSelection.setDisable(true);
                serviceURL.getScene().setCursor(Cursor.WAIT);
                setStatusTextUI(I18n.format("status.checking-auth"));
                Task task = new Task() {
                    protected Integer call() {
                        try {
                            selectService(serviceModel.getItem());
                            return 0;
                        } finally {
                            serviceSelection.setDisable(false);
                            serviceURL.getScene().setCursor(Cursor.DEFAULT);
                        }
                    }
                };
                Thread th = new Thread(task);
                th.setDaemon(true);
                th.start();
            }
        } else if (event.getClickCount() > 1) {
            clearUserNamePassword();
            resetGui();
        }
    }
}

From source file:org.samcrow.frameviewer.trajectory.ui.FrameController.java

/**
 * Called when a mouse event is received. Subclasses should override
 * this method. The default implementation does nothing.
 * <p>//  w  ww  .  j  a  v  a  2s.  com
 * @param event The mouse event
 * @param framePosition The position of the event in frame coordinates
 */
public void handleMouseEvent(MouseEvent event, Point2D framePosition) {
    final EventType<? extends Event> type = event.getEventType();
    if (type == MouseEvent.MOUSE_PRESSED) {
        handleMousePressed(event, framePosition);
    } else if (type == MouseEvent.MOUSE_RELEASED) {
        handleMouseReleased(event, framePosition);
    } else if (type == MouseEvent.MOUSE_CLICKED && event.isStillSincePress()) {
        handleMouseClicked(event, framePosition);
    } else if (type == MouseEvent.MOUSE_MOVED) {
        handleMouseMoved(event, framePosition);
    } else if (type == MouseEvent.MOUSE_DRAGGED) {
        handleMouseDragged(event, framePosition);
    }
}

From source file:view.FXApplicationController.java

@Override
public void initialize(URL arg0, ResourceBundle arg1) {
    System.out.println("initialize called");

    overlay3.addEventHandler(MouseEvent.ANY, new EventHandler<MouseEvent>() {

        @Override//from   w  w  w .  ja va2s  . c  o m
        public void handle(MouseEvent mouse) {
            mouseX.set(mouse.getX());
            mouseY.set(mouse.getY());

            if (kComplexFlag) {

                if (mouse.getEventType() == MouseEvent.MOUSE_PRESSED) {
                    Line line = new Line();
                    line.setStyle("-fx-stroke: red;");

                    overlay3.getChildren().add(line);

                    line.setStartX(0);
                    line.setStartY(0);
                    line.setLayoutX(mouseX.get());
                    line.setLayoutY(mouseY.get());

                    lines.add(line);

                }

                if (mouse.isPrimaryButtonDown() && (!lines.isEmpty())) {
                    Line line = lines.getLast();
                    double endXPos = mouseX.get() - line.getLayoutX();
                    double endYPos = mouseY.get() - line.getLayoutY();

                    line.setEndX(endXPos);
                    line.setEndY(endYPos);

                    calculatePercentageKComplex();

                }

            }

            if (help1Flag) {

                double offsetSize = 1. / (activeChannels.size() + 1.);

                double posOnOverlay = mouse.getY();

                double zoom = 1.0;
                for (int i = 0; i < activeChannels.size(); i++) {

                    double realOffset = (1 - (i + 1.) * offsetSize);

                    double upperBound = yAxis.getDisplayPosition(
                            (realOffset - offsetSize / 2.) * yAxis.getUpperBound()) + yAxis.getLayoutY();

                    double lowerBound = yAxis.getDisplayPosition(
                            (realOffset + offsetSize / 2.) * yAxis.getUpperBound()) + yAxis.getLayoutY();

                    if ((posOnOverlay <= upperBound) && (posOnOverlay > lowerBound)) {

                        zoom = getZoomFromChannel(activeChannels.get(i));
                    }
                }

                space.set(75.0 * zoom / yAxis.getUpperBound() * yAxis.getHeight());

                line1.setVisible(true);
                line2.setVisible(true);
            } else {
                line1.setVisible(false);
                line2.setVisible(false);
            }
        }

    });

    //Key Listener
    lineChart.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {

        @Override
        public void handle(KeyEvent ke) {
            keyAction(ke);
        }

    });

    toolBarGoto.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {

        @Override
        public void handle(KeyEvent ke) {
            if (ke.getCode() == KeyCode.ENTER) {

                int valueTextField = -1;

                try {
                    valueTextField = Integer.parseInt(toolBarGoto.getText());

                } catch (NumberFormatException e) {
                    toolBarGoto.setText((currentEpoch + 1) + "");
                    valueTextField = currentEpoch + 1;

                    Logger.getLogger(this.getClass().getName()).log(Level.INFO,
                            "Error during handling enter key.", e);
                }

                if (valueTextField > dataModel.getNumberOf30sEpochs()) {
                    valueTextField = dataModel.getNumberOf30sEpochs();
                } else if (valueTextField < 1) {
                    valueTextField = 1;
                }

                currentEpoch = valueTextField - 1;

                goToEpoch(currentEpoch);

                if (kComplexFlag) {
                    calculatePercentageKComplex();
                }

            }

        }
    });

    choiceBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {

        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            System.out.println(newValue);
            if (newValue != null) {

                featureModel.setFeatureChannel(Arrays.asList(channelNames).indexOf(newValue));

                System.out.println("########" + Arrays.asList(channelNames).indexOf(newValue));

                System.out.println(featureModel.getFeatureChannel());

                featureModel.setTsneComputed(false);
                featureModel.setFeaturesComputed(false);
                featureModel.setClassificationDone(false);
                featureModel.setReadinDone(false);
                classifyButton.setDisable(false);
                recompute = true;

                if (viewModel.isKcMarkersActive()) {
                    computeKCfeatures();
                } else {
                    overlay4.getChildren().clear();
                }
            }
        }
    });

    choiceBoxModel.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
            classifier = classifierList.get(newValue.intValue());
            System.out.println(classifier);

            featureModel.setClassificationDone(false);
            featureModel.setReadinDone(false);
            classifyButton.setDisable(false);
            recompute = true;
        }

    });

    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent event) {
            System.out.println("RandomAccessFile closed");
            dataModel.getReader().close();
            Platform.exit();
        }
    });

    kComplexOnAction();

    help1OnAction();
}