javafx.scene.input.InputEvent Java Examples

The following examples show how to use javafx.scene.input.InputEvent. 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: ChartPlugin.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends InputEvent> void addEventHandlers(final Node node) {
    if (node == null) {
        return;
    }
    for (final Pair<EventType<? extends InputEvent>, EventHandler<? extends InputEvent>> pair : mouseEventHandlers) {
        final EventType<T> type = (EventType<T>) pair.getKey();
        final EventHandler<T> handler = (EventHandler<T>) pair.getValue();
        node.addEventHandler(type, handler);
        node.sceneProperty().addListener((ch, o, n) -> {
            if (o == n) {
                return;
            }
            if (o != null) {
                o.removeEventHandler(type, handler);
            }

            if (n != null) {
                n.addEventHandler(type, handler);
            }
        });
    }
}
 
Example #2
Source File: MainController.java    From dev-tools with Apache License 2.0 5 votes vote down vote up
@FXML
private void handleKeyInput(final InputEvent event) {
    if (event instanceof KeyEvent) {
        final KeyEvent keyEvent = (KeyEvent) event;
        if (keyEvent.isControlDown() && keyEvent.getCode() == KeyCode.A) {
            debug("handleKeyInput");
        }
    }
}
 
Example #3
Source File: ChartPlugin.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends InputEvent> void removeEventHandlers(final Node node) {
    if (node == null) {
        return;
    }
    for (final Pair<EventType<? extends InputEvent>, EventHandler<? extends InputEvent>> pair : mouseEventHandlers) {
        final EventType<T> type = (EventType<T>) pair.getKey();
        final EventHandler<T> handler = (EventHandler<T>) pair.getValue();
        node.removeEventHandler(type, handler);
        if (node.getScene() != null) {
            node.getScene().removeEventFilter(type, handler);
        }
    }
}
 
Example #4
Source File: JavaFxRecorderHook.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
protected void setupSceneRoot(Parent root) {
    root.getProperties().put("marathon.fileChooser.eventType", fileChooserEventType);
    root.getProperties().put("marathon.folderChooser.eventType", folderChooserEventType);
    root.addEventFilter(InputEvent.ANY, JavaFxRecorderHook.this);
    root.addEventFilter(fileChooserEventType, JavaFxRecorderHook.this);
    root.addEventFilter(folderChooserEventType, JavaFxRecorderHook.this);
    root.getProperties().put("marathon.menu.handler", menuEvent);
}
 
Example #5
Source File: AllSwtFxEvents.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Scene createScene() {
	Scene scene = new Scene(new Group(), 400, 400);
	scene.addEventFilter(InputEvent.ANY, new EventHandler<InputEvent>() {
		@Override
		public void handle(InputEvent event) {
			System.out.println(event);
		}
	});
	return scene;
}
 
Example #6
Source File: AllFxEvents.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Scene createScene() {
	Scene scene = new Scene(new Group(new Rectangle(50, 50)), 400, 400);
	scene.addEventFilter(InputEvent.ANY, new EventHandler<InputEvent>() {
		@Override
		public void handle(InputEvent event) {
			System.out.println(event);
		}
	});
	return scene;
}
 
Example #7
Source File: TButtonSkin.java    From Enzo with Apache License 2.0 5 votes vote down vote up
private void init() {
    if (Double.compare(getSkinnable().getPrefWidth(), 0.0) <= 0 || Double.compare(getSkinnable().getPrefHeight(), 0.0) <= 0 ||
        Double.compare(getSkinnable().getWidth(), 0.0) <= 0 || Double.compare(getSkinnable().getHeight(), 0.0) <= 0) {
        if (getSkinnable().getPrefWidth() > 0 && getSkinnable().getPrefHeight() > 0) {
            getSkinnable().setPrefSize(getSkinnable().getPrefWidth(), getSkinnable().getPrefHeight());
        } else {
            getSkinnable().setPrefSize(PREFERRED_SIZE, PREFERRED_SIZE);
        }
    }

    if (Double.compare(getSkinnable().getMinWidth(), 0.0) <= 0 || Double.compare(getSkinnable().getMinHeight(), 0.0) <= 0) {
        getSkinnable().setMinSize(MINIMUM_SIZE, MINIMUM_SIZE);
    }

    if (Double.compare(getSkinnable().getMaxWidth(), 0.0) <= 0 || Double.compare(getSkinnable().getMaxHeight(), 0.0) <= 0) {
        getSkinnable().setMaxSize(MAXIMUM_SIZE, MAXIMUM_SIZE);
    }

    inputHandler = new EventHandler<InputEvent>() {
        @Override public void handle(final InputEvent EVENT) {
            final EventType TYPE = EVENT.getEventType();
            final Object    SRC  = EVENT.getSource();
            if (MouseEvent.MOUSE_PRESSED == TYPE) {
                if (SRC.equals(on)) {
                    getSkinnable().setSelected(false);
                } else if (SRC.equals(off)) {
                    getSkinnable().setSelected(true);
                }
                EVENT.consume();
            }
        }
    };
}
 
Example #8
Source File: EditDataSet.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
SelectedDataPoint(final Axis xAxis, final Axis yAxis, final EditableDataSet dataSet, final int index) {
    super();
    getStyleClass().add(STYLE_CLASS_SELECT_PATH);
    // this.setPickOnBounds(true);
    // setManaged(false);

    final EditConstraints constraints = dataSet.getEditConstraints();
    if (constraints == null) {
        pseudoClassStateChanged(NOEDIT_PSEUDO_CLASS, false);
    } else {
        final boolean canChange = constraints.canChange(index);
        if (!canChange) {
            pseudoClassStateChanged(NOEDIT_PSEUDO_CLASS, true);
        }
    }

    this.xAxis = xAxis;
    this.yAxis = yAxis;
    this.dataSet = dataSet;
    this.xValue = dataSet.get(DataSet.DIM_X, index);
    this.yValue = dataSet.get(DataSet.DIM_Y, index);
    this.setCenterX(getX()); // NOPMD by rstein on 13/06/19 14:14
    this.setCenterY(getY()); // NOPMD by rstein on 13/06/19 14:14
    this.setRadius(DEFAULT_MARKER_RADIUS);

    final EventHandler<? super InputEvent> dragOver = e -> {
        // finished drag
        isPointDragActive = false;
        setCursor(Cursor.DEFAULT);
    };

    setOnMouseEntered(e -> setCursor(Cursor.OPEN_HAND));
    addEventFilter(MouseDragEvent.MOUSE_DRAG_OVER, dragOver);

    setOnMousePressed(startDragHandler(this));
    // setOnMouseDragged(dragHandler(this));
    setOnMouseReleased(dragOver);
    setOnMouseDragOver(dragOver);
    // this.setOnMouseExited(dragOver);

    xAxis.addListener(evt -> FXUtils.runFX(() -> this.setCenterX(getX())));
    yAxis.addListener(evt -> FXUtils.runFX(() -> this.setCenterY(getY())));
    dataSet.addListener(e -> FXUtils.runFX(this::update));
}
 
Example #9
Source File: JavaFxRecorderHook.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void removeEventFilter(Stage stage) {
    stage.getScene().getRoot().removeEventFilter(InputEvent.ANY, JavaFxRecorderHook.this);
    stage.getScene().getRoot().removeEventFilter(fileChooserEventType, JavaFxRecorderHook.this);
    stage.getScene().getRoot().removeEventFilter(folderChooserEventType, JavaFxRecorderHook.this);
}
 
Example #10
Source File: EditMicroinstructionsController.java    From CPUSim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * initializes the dialog window after its root element has been processed.
 * contains a listener to the combo box, so that the content of the table will
 * change according to the selected type of microinstruction.
 *
 * @param url the location used to resolve relative paths for the root
 *            object, or null if the location is not known.
 * @param rb  the resources used to localize the root object, or null if the root
 *            object was not localized.
 */
@Override
public void initialize(URL url, ResourceBundle rb) {

    microinstructionCombo.setVisibleRowCount(14); // show all micros at once

    tableMap.setParents(tablePane);
    tablePane.getChildren().clear();
    activeTable = tableMap.getMap().get("TransferRtoR");
    tablePane.getChildren().add(activeTable);

    activeTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

    newButton.setDisable(!((MicroController)activeTable).newMicrosAreAllowed());

    activeTable.getSelectionModel().selectedItemProperty().addListener(listener);

    // resizes the width and height of the table to match the dialog
    tablePane.widthProperty().addListener((observableValue, oldValue, newValue) ->
                activeTable.setPrefWidth((Double) newValue)
    );
    tablePane.heightProperty().addListener((observableValue, oldValue, newValue) ->
                activeTable.setPrefHeight((Double)newValue)
    );

    // listen for changes to the instruction combo box selection and update
    // the displayed micro instruction table accordingly.
    microinstructionCombo.getSelectionModel().selectedItemProperty().addListener(
            (selected, oldType, newType) -> {
                activeTable.getSelectionModel().selectedItemProperty().
                        removeListener(listener);
                tableMap.getMap().get(oldType).getSelectionModel().clearSelection();
                tablePane.getChildren().clear();
                tablePane.getChildren().add(
                        tableMap.getMap().get(newType));

                activeTable = tableMap.getMap().get(newType);
                activeTable.setPrefWidth(tablePane.getWidth());
                activeTable.setPrefHeight(tablePane.getHeight());
                activeTable.setColumnResizePolicy(TableView
                        .CONSTRAINED_RESIZE_POLICY);


                newButton.setDisable(!((MicroController) activeTable).newMicrosAreAllowed());

                selectedSet = null;
                deleteButton.setDisable(true);
                duplicateButton.setDisable(true);

                activeTable.getSelectionModel().selectedItemProperty().
                        addListener(listener);
            });

    // Define an event filter for the ComboBox for Mouse_released events
    EventHandler validityFilter = new EventHandler<InputEvent>() {
        public void handle(InputEvent event) {
            try{
                ((MicroController)activeTable).checkValidity(activeTable.getItems());

            } catch (ValidationException ex){
                Dialogs.createErrorDialog(tablePane.getScene().getWindow(),
                        "Microinstruction Error", ex.getMessage()).showAndWait();

                event.consume();
            }
        }
    };
    microinstructionCombo.addEventFilter(MouseEvent.MOUSE_RELEASED, validityFilter);
}
 
Example #11
Source File: EditModulesController.java    From CPUSim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * initializes the dialog window after its root element has been processed.
 * contains a listener to the combo box, so that the content of the table will
 * change according to the selected type of microinstruction.
 *
 * @param url the location used to resolve relative paths for the root
 *            object, or null if the location is not known.
 * @param rb  the resources used to localize the root object, or null if the root
 *            object was not localized.
 */
@Override
public void initialize(URL url, ResourceBundle rb) {

    moduleCombo.setVisibleRowCount(4); // show all modules at once

    tableMap.setParents(tablePane);
    tablePane.getChildren().clear();
    activeTable = tableMap.getMap().get("Register");
    tablePane.getChildren().add(activeTable);

    activeTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    activeTable.getSelectionModel().selectedItemProperty().addListener
            (contentChangeListener);

    // resizes the width and height of the content panes
    tablePane.widthProperty().addListener((observableValue, oldValue, newValue) ->
                    activeTable.setPrefWidth((Double) newValue)
    );
    tablePane.heightProperty().addListener((observableValue, oldValue, newValue) ->
                    activeTable.setPrefHeight((Double) newValue)
    );

    // listen for changes to the instruction combo box selection and update
    // the displayed micro instruction table accordingly.
    moduleCombo.getSelectionModel().selectedItemProperty().addListener(
            (selected, oldType, newType) -> {
                ((ModuleController) activeTable).setClones(activeTable.getItems());

                activeTable.getSelectionModel().selectedItemProperty().
                        removeListener(contentChangeListener);
                tableMap.getMap().get(oldType).getSelectionModel().clearSelection();
                tablePane.getChildren().clear();
                tablePane.getChildren().add(
                        tableMap.getMap().get(newType));

                activeTable = tableMap.getMap().get(newType);
                activeTable.setPrefWidth(tablePane.getWidth());
                activeTable.setPrefHeight(tablePane.getHeight());
                activeTable.setColumnResizePolicy(TableView
                        .CONSTRAINED_RESIZE_POLICY);

                newButton.setDisable(!((ModuleController) activeTable)
                        .newModulesAreAllowed());

                if (oldType.equals("Register") || oldType.equals("RegisterArray")) {
                    ((ConditionBitTableController) tableMap.getMap().get
                            ("ConditionBit")).updateRegisters();
                }

                propertiesButton.setDisable(!newType.equals("RegisterArray") ||
                                            activeTable.getItems().size() == 0);

                selectedSet = null;
                deleteButton.setDisable(true);
                duplicateButton.setDisable(true);

                //listen for changes to the table selection and update the
                // status of buttons.
                activeTable.getSelectionModel().selectedItemProperty().
                        addListener(contentChangeListener);
            });

    // Define an event filter for the ComboBox for Mouse_released events
    EventHandler validityFilter = new EventHandler<InputEvent>() {
        public void handle(InputEvent event) {
            try {
                ((ModuleController) activeTable).checkValidity();

            } catch (ValidationException ex) {
                Dialogs.createErrorDialog(tablePane.getScene().getWindow(),
                        "Modules Error", ex.getMessage()).showAndWait();
                event.consume();
            }
        }
    };
    moduleCombo.addEventFilter(MouseEvent.MOUSE_RELEASED, validityFilter);
}
 
Example #12
Source File: EditArrayRegistersController.java    From CPUSim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * initializes the dialog window after its root element has been processed.
 * contains a listener to the combo box, so that the content of the table will
 * change according to the selected type of microinstruction.
 *
 * @param url the location used to resolve relative paths for the root
 *            object, or null if the location is not known.
 * @param rb  the resources used to localize the root object, or null if the root
 *            object was not localized.
 */
@Override
public void initialize(URL url, ResourceBundle rb) {

    arrayCombo.getItems().addAll(registerArrays.stream().map(
            RegisterArray::getName).collect(Collectors.toList()));
    arrayCombo.getSelectionModel().select(selection);

    tableMap = new ChangeTable(registerArrays);
    tableMap.setParents(tablePane);
    tablePane.getChildren().clear();
    tablePane.getChildren().add(tableMap.getMap().get(selection));

    activeTable = tableMap.getMap().get(selection);
    activeTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

    // resizes the width and height of the content panes
    tablePane.widthProperty().addListener((observableValue, oldValue, newValue) ->
                    activeTable.setPrefWidth((Double) newValue)
    );
    tablePane.heightProperty().addListener((observableValue, oldValue, newValue) ->
                    activeTable.setPrefHeight((Double) newValue)
    );

    // listen for changes to the instruction combo box selection and update
    // the displayed micro instruction table accordingly.
    arrayCombo.getSelectionModel().selectedItemProperty().addListener(
            new ChangeListener<String>() {
                @Override
                public void changed(ObservableValue<? extends String> selected,
                                    String oldType, String newType) {
                    ((RegisterArrayTableView) activeTable).setClones(activeTable
                            .getItems());
                    activeTable = tableMap.getMap().get(newType);
                    tableMap.getMap().get(oldType).getSelectionModel()
                            .clearSelection();
                    tablePane.getChildren().clear();
                    tablePane.getChildren().add(
                            tableMap.getMap().get(newType));
                    activeTable.setPrefWidth(tablePane.getWidth());
                    activeTable.setPrefHeight(tablePane.getHeight());
                    activeTable.setColumnResizePolicy(TableView
                            .CONSTRAINED_RESIZE_POLICY);

                }
            });

    // Define an event filter for the ComboBox for Mouse_released events
    EventHandler validityFilter = new EventHandler<InputEvent>() {
        public void handle(InputEvent event) {
            try {
                ObservableList<Register> list = FXCollections.observableArrayList();
                list.addAll(registerController.getItems());
                for (RegisterArrayTableView r : tableMap.getMap().values()) {
                    list.addAll(r.getItems());
                }

                Validate.allNamesAreUnique(list.toArray());
                ((RegisterArrayTableView) activeTable).checkValidity(list);
            } catch (ValidationException ex) {
                Dialogs.createErrorDialog(tablePane.getScene().getWindow(),
                        "Registers Error", ex.getMessage()).showAndWait();
                event.consume();
            }
        }
    };
    arrayCombo.addEventFilter(MouseEvent.MOUSE_RELEASED, validityFilter);
}
 
Example #13
Source File: ChartPlugin.java    From chart-fx with Apache License 2.0 2 votes vote down vote up
/**
 * Registers event handlers that should be added to the {@code XYChartPane} node when the plugin is added to the
 * pane and are removed once the plugin is removed from the pane.
 *
 * @param eventType the event type on which the handler should be called
 * @param handler the event handler to be added to the chart
 */
protected final void registerInputEventHandler(final EventType<? extends InputEvent> eventType,
        final EventHandler<? extends InputEvent> handler) {
    mouseEventHandlers.add(new Pair<>(eventType, handler));
}