Search in sources :

Example 31 with KeyEvent

use of javafx.scene.input.KeyEvent in project org.csstudio.display.builder by kasemir.

the class RTImagePlot method showAxisLimitsField.

private void showAxisLimitsField(AxisPart<Double> axis, boolean isHigh, Rectangle area) {
    axisLimitsField.setOnKeyPressed((KeyEvent event) -> {
        if (event.getCode().equals(KeyCode.ENTER)) {
            hideAxisLimitsField();
            if (axisLimitsField.getText().isEmpty())
                return;
            try {
                Double value = Double.parseDouble(axisLimitsField.getText());
                changeAxisLimit(axis, isHigh, value);
            } catch (NumberFormatException e) {
            }
        } else if (event.getCode().equals(KeyCode.ESCAPE)) {
            hideAxisLimitsField();
        }
    });
    String tip = isHigh ? axis.getValueRange().getHigh().toString() : axis.getValueRange().getLow().toString();
    axisLimitsField.setText(tip);
    axisLimitsField.setTooltip(new Tooltip(tip));
    axisLimitsField.setVisible(true);
    axisLimitsField.relocate(area.getX(), area.getY());
    axisLimitsField.resize(area.getWidth(), area.getHeight());
    axisLimitsField.requestFocus();
    // force text to appear in field
    axisLimitsField.layout();
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) Tooltip(javafx.scene.control.Tooltip)

Example 32 with KeyEvent

use of javafx.scene.input.KeyEvent in project org.csstudio.display.builder by kasemir.

the class ZoomPan method createScene.

public static Scene createScene() {
    // Stuff to show as 'widgets'
    final Node[] stuff = new Node[3];
    for (int i = 0; i < stuff.length; ++i) {
        final Rectangle rect = new Rectangle(50 + i * 100, 100, 10 + i * 50, 20 + i * 40);
        rect.setFill(Color.BLUE);
        stuff[i] = rect;
    }
    // With 'Group', stuff would start in top-left (0, 0) corner,
    // not at (50, 100) based on its coordinates
    final Pane widgets = new Pane(stuff);
    widgets.setStyle("-fx-background-color: coral;");
    final ScrollPane scroll;
    if (true) {
        // Additional Group to help ScrollPane get correct bounds
        final Group scroll_content = new Group(widgets);
        scroll = new ScrollPane(scroll_content);
    } else
        scroll = new ScrollPane(widgets);
    final InvalidationListener resized = prop -> handleViewportChanges(scroll);
    scroll.widthProperty().addListener(resized);
    scroll.heightProperty().addListener(resized);
    System.out.println("Press 'space' to change zoom");
    final Scene scene = new Scene(scroll);
    scene.addEventFilter(KeyEvent.KEY_PRESSED, (KeyEvent event) -> {
        if (event.getCode() == KeyCode.SPACE) {
            zoom_in = !zoom_in;
            if (zoom_in)
                widgets.getTransforms().setAll(new Scale(2.5, 2.5));
            else
                widgets.getTransforms().setAll(new Scale(0.5, 0.5));
        }
    });
    return scene;
}
Also used : Scene(javafx.scene.Scene) KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) Node(javafx.scene.Node) Rectangle(javafx.scene.shape.Rectangle) KeyEvent(javafx.scene.input.KeyEvent) Group(javafx.scene.Group) InvalidationListener(javafx.beans.InvalidationListener) Application(javafx.application.Application) ScrollPane(javafx.scene.control.ScrollPane) Stage(javafx.stage.Stage) Scale(javafx.scene.transform.Scale) Pane(javafx.scene.layout.Pane) KeyEvent(javafx.scene.input.KeyEvent) Group(javafx.scene.Group) ScrollPane(javafx.scene.control.ScrollPane) Node(javafx.scene.Node) Rectangle(javafx.scene.shape.Rectangle) InvalidationListener(javafx.beans.InvalidationListener) Scale(javafx.scene.transform.Scale) Scene(javafx.scene.Scene) ScrollPane(javafx.scene.control.ScrollPane) Pane(javafx.scene.layout.Pane)

Example 33 with KeyEvent

use of javafx.scene.input.KeyEvent in project org.csstudio.display.builder by kasemir.

the class ScaledSliderRepresentation method createJFXNode.

@Override
protected GridPane createJFXNode() throws Exception {
    slider.setFocusTraversable(true);
    slider.setOnKeyPressed((final KeyEvent event) -> {
        switch(event.getCode()) {
            case PAGE_UP:
                slider.adjustValue(value + slider.getBlockIncrement());
                event.consume();
                break;
            case PAGE_DOWN:
                slider.adjustValue(value - slider.getBlockIncrement());
                event.consume();
                break;
            default:
                break;
        }
    });
    slider.setValue(value);
    final GridPane pane = new GridPane();
    // pane.setGridLinesVisible(true);
    pane.add(markers, 0, 0);
    pane.getChildren().add(slider);
    return pane;
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) GridPane(javafx.scene.layout.GridPane)

Example 34 with KeyEvent

use of javafx.scene.input.KeyEvent in project uPMT by coco35700.

the class MainViewTransformations method addTypeListener.

public static void addTypeListener(TypeClassRepresentationController boutType, MomentExpVBox m, Type type, Main main) {
    boutType.focusedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue) {
            if (newPropertyValue) {
                boutType.colorFocus();
            } else {
                boutType.resetFocusColor();
            }
        }
    });
    boutType.setOnMouseClicked(new EventHandler<Event>() {

        @Override
        public void handle(Event event) {
            boutType.requestFocus();
        }
    });
    boutType.setOnKeyPressed(new EventHandler<KeyEvent>() {

        @Override
        public void handle(KeyEvent event) {
            if ((event.getCode().equals(KeyCode.DELETE) || event.getCode().equals(KeyCode.BACK_SPACE)) & boutType.isFocused()) {
                RemoveTypeCommand cmd = new RemoveTypeCommand(boutType, m, main);
                cmd.execute();
                UndoCollector.INSTANCE.add(cmd);
            }
        }
    });
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) RemoveTypeCommand(controller.command.RemoveTypeCommand) MouseEvent(javafx.scene.input.MouseEvent) DragEvent(javafx.scene.input.DragEvent) Event(javafx.event.Event) KeyEvent(javafx.scene.input.KeyEvent)

Example 35 with KeyEvent

use of javafx.scene.input.KeyEvent in project uPMT by coco35700.

the class TypeTreeViewControllerClass method rename.

@Override
public void rename() {
    super.rename();
    ChangeListener<Boolean> listener = new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue) {
            if (!newPropertyValue) {
                if (type.getType().isCategory()) {
                    String oldName = new String(type.getType().getName());
                    if (!oldName.equals(textField.getText())) {
                        boolean hasName = false;
                        // System.out.println("Parent: "+type.getParent().getName());
                        for (Type classe : type.getParent().getTypes()) {
                            // System.out.println("Classes: "+classe.getName());
                            if (classe.getName().equals(textField.getText())) {
                                hasName = true;
                                break;
                            }
                        }
                        if (!hasName) {
                            RenameClassSchemeCommand cmd = new RenameClassSchemeCommand(type.getClassNameController(), oldName, textField.getText(), main);
                            cmd.execute();
                            UndoCollector.INSTANCE.add(cmd);
                        } else {
                            Alert alert = new Alert(AlertType.INFORMATION);
                            alert.setTitle(main._langBundle.getString("invalid_name"));
                            alert.setHeaderText(null);
                            alert.setContentText(main._langBundle.getString("class_name_invalid"));
                            alert.show();
                        }
                    }
                }
                typePane.setLeft(nomType);
                rename.setDisable(false);
                textField.focusedProperty().removeListener(this);
            }
        }
    };
    textField.setOnKeyPressed(new EventHandler<KeyEvent>() {

        @Override
        public void handle(KeyEvent event) {
            if (event.getCode() == KeyCode.ENTER) {
                if (type.getType().isProperty()) {
                    textField.setText(textField.getText());
                }
                typePane.setLeft(nomType);
                rename.setDisable(false);
            }
            if (event.getCode() == KeyCode.ESCAPE) {
                typePane.setLeft(nomType);
                rename.setDisable(true);
            }
        }
    });
    textField.focusedProperty().addListener(listener);
    typePane.setLeft(textField);
    Platform.runLater(() -> textField.requestFocus());
    Platform.runLater(() -> textField.selectAll());
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) Type(model.Type) AlertType(javafx.scene.control.Alert.AlertType) ObservableValue(javafx.beans.value.ObservableValue) RenameClassSchemeCommand(controller.command.RenameClassSchemeCommand) ChangeListener(javafx.beans.value.ChangeListener) Alert(javafx.scene.control.Alert)

Aggregations

KeyEvent (javafx.scene.input.KeyEvent)41 KeyCode (javafx.scene.input.KeyCode)10 ObservableValue (javafx.beans.value.ObservableValue)9 Scene (javafx.scene.Scene)8 Test (org.junit.Test)8 TextField (javafx.scene.control.TextField)7 Stage (javafx.stage.Stage)7 Application (javafx.application.Application)6 ChangeListener (javafx.beans.value.ChangeListener)6 EventHandler (javafx.event.EventHandler)6 IOException (java.io.IOException)5 Insets (javafx.geometry.Insets)5 KeyCombination (javafx.scene.input.KeyCombination)5 MouseEvent (javafx.scene.input.MouseEvent)5 Pane (javafx.scene.layout.Pane)5 List (java.util.List)4 Event (javafx.event.Event)4 FXML (javafx.fxml.FXML)4 Label (javafx.scene.control.Label)4 Tooltip (javafx.scene.control.Tooltip)4