Example usage for javafx.scene.input MouseEvent getTarget

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

Introduction

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

Prototype

public EventTarget getTarget() 

Source Link

Document

Returns the event target of this event.

Usage

From source file:jasperreports.FXMLDocumentController.java

@FXML
public void handle(MouseEvent event) throws BackingStoreException {
    File directory = directoryChooser.showDialog(((Node) event.getTarget()).getScene().getWindow());
    if (directory != null) {
        if (directory.exists() && directory.canRead()) {
            destination.setText(directory.getPath());
            prefs.put("path", directory.getPath());
            prefs.flush();//from  w w  w  .  j av a 2s  . c o m
        }
    }
}

From source file:com.panemu.tiwulfx.control.skin.LookupFieldSkin.java

private void createPopup() {
    popup = new PopupControl() {
        {//from ww w .  j  a v a 2 s . c  o  m
            setSkin(new Skin() {
                @Override
                public Skinnable getSkinnable() {
                    return LookupFieldSkin.this.lookupField;
                }

                @Override
                public Node getNode() {
                    return listView;
                }

                @Override
                public void dispose() {
                }
            });
        }
    };
    popup.setAutoHide(true);
    popup.setAutoFix(true);
    popup.setHideOnEscape(true);
    popup.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent t) {
            popup.hide();
        }
    });

    listView.setCellFactory(new Callback() {
        @Override
        public Object call(Object p) {
            return new PropertyListCell(lookupField.getPropertyName());
        }
    });

    /**
     * Taken from
     * {@link com.sun.javafx.scene.control.skin.ComboBoxListViewSkin}
     */
    listView.addEventFilter(MouseEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent t) {
            // RT-18672: Without checking if the user is clicking in the 
            // scrollbar area of the ListView, the comboBox will hide. Therefore,
            // we add the check below to prevent this from happening.
            EventTarget target = t.getTarget();
            if (target instanceof Parent) {
                List<String> s = ((Parent) target).getStyleClass();
                if (s.contains("thumb") || s.contains("track") || s.contains("decrement-arrow")
                        || s.contains("increment-arrow")) {
                    return;
                }
            }
            needValidation = false;
            lookupField.setValue(listView.getSelectionModel().getSelectedItem());
            popup.hide();
        }
    });

    listView.setOnKeyPressed(new EventHandler<KeyEvent>() {
        @Override
        public void handle(KeyEvent t) {
            if (t.getCode() == KeyCode.ENTER) {
                needValidation = false;
                lookupField.setValue(listView.getSelectionModel().getSelectedItem());
                popup.hide();
            } else if (t.getCode() == KeyCode.ESCAPE) {
                popup.hide();
            }
        }
    });

}

From source file:view.EditorView.java

@FXML
void scrollPaneOnMouseClicked(MouseEvent event) {
    /*//from   ww w  . j  a  v a  2s.  c om
    event.getTarget() instanceof RoomRectangle is necessary because the event is required twice:
    - once with event.getTarget() instanceof RoomRectangle and
    - once with event.getTarget() instanceof Label (the name label of the room)
    ... and we need to suppress one of the two because we don't want to insert two rooms
     */
    /*
    When the user uses a touch screen and adds a new room by clicking the insertRoom-button and then clicking the
    scrollPane, the event target is an instance of ScrollPaneSkin$4 which is an anonymous inner class in ScrollPane.
    Since we cannot directly check the class type using instanceof against that inner class, we need to use
    event.getTarget().getClass().getName() and do a String comparison for this particular use case.
    Keep in mind that this is an internal api of java and the class name of that class might change at ANY TIME so
    things might break just by upgrading the java version! (But we have no other choice unfortunately :( )
    See https://github.com/vatbub/zorkClone/issues/7 and http://stackoverflow.com/questions/41454202/javafx-instanceof-scrollpaneskin-fails
    for more info
     */
    FOKLogger.finest(EditorView.class.getName(), "scrollPaneOnMouseClicked occurred. event target class is "
            + event.getTarget().getClass().getName());
    if (currentEditMode == EditMode.INSERT_ROOM
            && (event.getTarget() instanceof RoomRectangle || event.getTarget() instanceof ToggleButton
                    || event.getTarget().getClass().getName()
                            .equals("com.sun.javafx.scene.control.skin.ScrollPaneSkin$4"))
            && event.getClickCount() == 1 && tempRoomForRoomInsertion != null) {
        // add tempRoomForRoomInsertion to the game
        FOKLogger.fine(MainWindow.class.getName(),
                "Added room to game: " + tempRoomForRoomInsertion.getRoom().getName());
        tempRoomForRoomInsertion.setTemporary(false);
        tempRoomForRoomInsertion.setSelected(false);
        allRoomsAsList.add(tempRoomForRoomInsertion);
        // this.renderView(false, false, true);
        this.renderView(false, false);

        this.setCurrentEditMode(this.getPreviousEditMode());
    }
}