Search in sources :

Example 21 with KeyEvent

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

the class TypeTreeViewControllerProperty 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().isProperty()) {
                    String oldName = new String(type.getType().getName());
                    if (!oldName.equals(textField.getText())) {
                        boolean hasName = false;
                        for (Type propriete : type.getParent().getTypes()) {
                            if (propriete.getName().equals(textField.getText())) {
                                hasName = true;
                                break;
                            }
                        }
                        if (!hasName) {
                            RenamePropertySchemeCommand cmd = new RenamePropertySchemeCommand(type.getRenamePropertyController(), 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("properties_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) RenamePropertySchemeCommand(controller.command.RenamePropertySchemeCommand) Type(model.Type) AlertType(javafx.scene.control.Alert.AlertType) ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener) Alert(javafx.scene.control.Alert)

Example 22 with KeyEvent

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

the class InterviewTreeViewController method renameInter.

public void renameInter() {
    renameInterview.setDisable(true);
    TextField textField = new TextField();
    textField.setText(interview.getName());
    textField.setMaxWidth(100);
    textField.requestFocus();
    textField.focusedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue) {
            if (!newPropertyValue) {
                nomEntretien.setText(textField.getText());
                interview.setName(textField.getText());
                interviewPane.setLeft(nomEntretien);
                renameInterview.setDisable(false);
            }
        }
    });
    textField.setOnKeyPressed(new EventHandler<KeyEvent>() {

        @Override
        public void handle(KeyEvent event) {
            if (event.getCode() == KeyCode.ENTER) {
                nomEntretien.setText(textField.getText());
                interview.setName(textField.getText());
                interviewPane.setLeft(nomEntretien);
                renameInterview.setDisable(true);
            }
            if (event.getCode() == KeyCode.ESCAPE) {
                interviewPane.setLeft(nomEntretien);
                renameInterview.setDisable(true);
            }
        }
    });
    interviewPane.setLeft(textField);
    Platform.runLater(() -> textField.requestFocus());
    Platform.runLater(() -> textField.selectAll());
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) TextField(javafx.scene.control.TextField)

Example 23 with KeyEvent

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

the class TypeTreeViewControllerFolder 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().isFolder()) {
                    String oldName = new String(type.getType().getName());
                    if (!oldName.equals(textField.getText())) {
                        boolean hasName = false;
                        for (Type folder : type.getParent().getTypes()) {
                            if (folder.getName().equals(textField.getText())) {
                                hasName = true;
                                break;
                            }
                        }
                        if (!hasName) {
                            RenameFolderSchemeCommand cmd = new RenameFolderSchemeCommand(ref, type.getType().getName(), 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("folder_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) ChangeListener(javafx.beans.value.ChangeListener) Alert(javafx.scene.control.Alert) RenameFolderSchemeCommand(controller.command.RenameFolderSchemeCommand)

Example 24 with KeyEvent

use of javafx.scene.input.KeyEvent in project Board-Instrumentation-Framework by intel.

the class Prompt_InputBox method SetupDialog.

@Override
protected Pane SetupDialog(Stage dialog) {
    GridPane root = new GridPane();
    root.setHgap(5.0);
    root.setVgap(5.0);
    root.setPadding(new Insets(5, 5, 2, 5));
    Button btn = new Button();
    btn.setText("OK");
    Label lblMessage = new Label(getMessage());
    Label lblSpacer = new Label("  ");
    lblMessage.setWrapText(true);
    TextField objPrompt = new TextField();
    if (null != _PrevVal) {
        objPrompt.setText(_PrevVal);
    }
    root.setAlignment(Pos.CENTER_LEFT);
    GridPane.setColumnSpan(lblMessage, 2);
    GridPane.setHalignment(btn, HPos.CENTER);
    if (getWidth() > 0) {
        objPrompt.setPrefWidth(getWidth());
    }
    if (getHeight() > 0) {
        root.setPrefHeight(getHeight());
    }
    root.add(lblMessage, 0, 0);
    root.add(objPrompt, 0, 2);
    root.add(btn, 0, 3);
    root.add(lblSpacer, 0, 4);
    // place on correct screen and center
    int xPos = (int) (Configuration.getConfig().getPrimaryScreen().getVisualBounds().getMinX());
    int yPos = (int) (Configuration.getConfig().getPrimaryScreen().getVisualBounds().getMinY());
    dialog.setX(xPos);
    dialog.setY(yPos);
    dialog.centerOnScreen();
    objPrompt.setOnKeyPressed(new EventHandler<KeyEvent>() {

        @Override
        public void handle(KeyEvent ke) {
            KeyCode kc = ke.getCode();
            if (kc.equals(KeyCode.ENTER)) {
                SetPromptedValue(objPrompt.getText());
                _PrevVal = objPrompt.getText();
                dialog.close();
            }
        }
    });
    btn.setOnAction((ActionEvent event) -> {
        SetPromptedValue(objPrompt.getText());
        _PrevVal = objPrompt.getText();
        dialog.close();
    });
    return root;
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) Button(javafx.scene.control.Button) ActionEvent(javafx.event.ActionEvent) Label(javafx.scene.control.Label) TextField(javafx.scene.control.TextField) KeyCode(javafx.scene.input.KeyCode)

Example 25 with KeyEvent

use of javafx.scene.input.KeyEvent in project jabref by JabRef.

the class KeyBindingsDialogViewModelTest method testSetSingleKeyBindingToDefault.

@Test
@Ignore
public void testSetSingleKeyBindingToDefault() {
    KeyBindingViewModel viewModel = setKeyBindingViewModel(KeyBinding.ABBREVIATE);
    model.selectedKeyBindingProperty().set(viewModel);
    KeyEvent shortcutKeyEvent = new KeyEvent(KeyEvent.KEY_PRESSED, "C", "C", KeyCode.C, true, true, true, false);
    assertFalse(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.ABBREVIATE, shortcutKeyEvent));
    model.setNewBindingForCurrent(shortcutKeyEvent);
    model.saveKeyBindings();
    assertTrue(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.ABBREVIATE, shortcutKeyEvent));
    viewModel.resetToDefault();
    model.saveKeyBindings();
    assertFalse(keyBindingRepository.checkKeyCombinationEquality(KeyBinding.ABBREVIATE, shortcutKeyEvent));
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) Ignore(org.junit.Ignore) Test(org.junit.Test)

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