Search in sources :

Example 1 with ChangePropertyValueCommand

use of controller.command.ChangePropertyValueCommand in project uPMT by coco35700.

the class TypePropertyRepresentation method setLabelChangeName.

private void setLabelChangeName(HBox propertyPane2, TypePropertyRepresentation tpr) {
    propertyValue.setOnMouseClicked(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent arg0) {
            if (arg0.getClickCount() == 2) {
                TextField t = new TextField(propertyValue.getText());
                t.setMaxWidth(70);
                t.setMinWidth(10);
                ChangeListener<Boolean> listener = new ChangeListener<Boolean>() {

                    @Override
                    public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue) {
                        if (!newPropertyValue) {
                            ChangePropertyValueCommand cmd = new ChangePropertyValueCommand(tpr, property.getValue(), t.getText(), main);
                            cmd.execute();
                            UndoCollector.INSTANCE.add(cmd);
                            propertyPane2.getChildren().remove(2);
                            propertyPane2.getChildren().add(propertyValue);
                        // propertyPane2.setRight(propertyValue);
                        }
                    }
                };
                t.setOnKeyPressed(new EventHandler<KeyEvent>() {

                    @Override
                    public void handle(KeyEvent event) {
                        if (event.getCode() == KeyCode.ENTER) {
                            t.setText(t.getText());
                            propertyPane2.getChildren().remove(2);
                            propertyPane2.getChildren().add(propertyValue);
                        // propertyPane2.setRight(propertyValue);
                        }
                        if (event.getCode() == KeyCode.ESCAPE) {
                            propertyPane2.getChildren().remove(2);
                            propertyPane2.getChildren().add(propertyValue);
                        // propertyPane2.setRight(propertyValue);
                        }
                    }
                });
                t.focusedProperty().addListener(listener);
                Platform.runLater(() -> t.requestFocus());
                Platform.runLater(() -> t.selectAll());
                propertyPane2.getChildren().remove(2);
                propertyPane2.getChildren().add(t);
            // propertyPane2.setRight(t);
            }
        }
    });
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) ChangePropertyValueCommand(controller.command.ChangePropertyValueCommand) MouseEvent(javafx.scene.input.MouseEvent) TextField(javafx.scene.control.TextField) EventHandler(javafx.event.EventHandler) ChangeListener(javafx.beans.value.ChangeListener)

Aggregations

ChangePropertyValueCommand (controller.command.ChangePropertyValueCommand)1 ChangeListener (javafx.beans.value.ChangeListener)1 EventHandler (javafx.event.EventHandler)1 TextField (javafx.scene.control.TextField)1 KeyEvent (javafx.scene.input.KeyEvent)1 MouseEvent (javafx.scene.input.MouseEvent)1