Пример #1
0
 private void createTextField() {
   textField = new TextField(getString());
   textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
   textField.setOnKeyPressed(
       new EventHandler<KeyEvent>() {
         @Override
         public void handle(KeyEvent t) {
           if (t.getCode() == KeyCode.ENTER) {
             commitEdit(textField.getText());
           } else if (t.getCode() == KeyCode.ESCAPE) {
             cancelEdit();
           } else if (t.getCode() == KeyCode.TAB) {
             commitEdit(textField.getText());
             TableColumn nextColumn = getNextColumn(!t.isShiftDown());
             if (nextColumn != null) {
               getTableView().edit(getTableRow().getIndex(), nextColumn);
             }
           }
         }
       });
   textField
       .focusedProperty()
       .addListener(
           new ChangeListener<Boolean>() {
             @Override
             public void changed(
                 ObservableValue<? extends Boolean> observable,
                 Boolean oldValue,
                 Boolean newValue) {
               if (!newValue && textField != null) {
                 commitEdit(textField.getText());
               }
             }
           });
 }
Пример #2
0
  private void createTextField() {

    textField = new TextField(getString());
    textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);

    // TODO new added
    textField
        .focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {

              @Override
              public void changed(
                  ObservableValue<? extends Boolean> arg0, Boolean arg1, Boolean arg2) {
                if (!arg2) {
                  commitEdit(textField.getText());
                }
              }
            });

    textField.setOnKeyPressed(
        new EventHandler<KeyEvent>() {
          @Override
          public void handle(KeyEvent t) {
            if (t.getCode() == KeyCode.ENTER) {
              commitEdit(textField.getText());
            } else if (t.getCode() == KeyCode.ESCAPE) {
              cancelEdit();
            }
          }
        });
  }
  @FXML
  void initialize() {
    viewModel.setLogger(new LengthConvertorLogger("./LengthConvertorLogger.xml"));

    final ChangeListener<Boolean> focusValueChangeListener =
        new ChangeListener<Boolean>() {
          @Override
          public void changed(
              final ObservableValue<? extends Boolean> observable,
              final Boolean oldValue,
              final Boolean newValue) {
            viewModel.valueChanged(oldValue, newValue);
          }
        };

    final ChangeListener<LengthUnit> focusLengthUnitChangeListener =
        new ChangeListener<LengthUnit>() {
          @Override
          public void changed(
              final ObservableValue<? extends LengthUnit> observable,
              final LengthUnit oldValue,
              final LengthUnit newValue) {
            viewModel.lengthUnitsChanged(oldValue, newValue);
          }
        };

    inputValueTextBox.textProperty().bindBidirectional(viewModel.inputValueProperty());
    inputValueTextBox.focusedProperty().addListener(focusValueChangeListener);

    inputUnitComboBox.valueProperty().bindBidirectional(viewModel.inputUnitProperty());
    inputUnitComboBox.valueProperty().addListener(focusLengthUnitChangeListener);

    outputUnitComboBox.valueProperty().bindBidirectional(viewModel.outputUnitProperty());
    outputUnitComboBox.valueProperty().addListener(focusLengthUnitChangeListener);

    convertButton.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(final ActionEvent event) {
            viewModel.convert();
          }
        });
  }
  private void createTextField() {
    textField = new TextField(getString());
    textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
    textField.setOnKeyPressed(
        new EventHandler<KeyEvent>() {
          @Override
          public void handle(KeyEvent t) {
            if (t.getCode() == KeyCode.ENTER) {
              commitHelper(false);
            } else if (t.getCode() == KeyCode.ESCAPE) {
              cancelEdit();
            } else if (t.getCode() == KeyCode.TAB) {
              commitHelper(false);

              getTableView()
                  .edit(
                      getTableView().getSelectionModel().getSelectedIndex() + 1, getTableColumn());
            }
          }
        });
    textField
        .focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                // This focus listener fires at the end of cell editing when focus is lost
                // and when enter is pressed (because that causes the text field to lose focus).
                // The problem is that if enter is pressed then cancelEdit is called before this
                // listener runs and therefore the text field has been cleaned up. If the
                // text field is null we don't commit the edit. This has the useful side effect
                // of stopping the double commit.
                if (!newValue && textField != null) {
                  commitHelper(true);
                }
              }
            });
  }
Пример #5
0
  private void addTopComponentListeners() {

    //  validate number of children field
    numofChildrenF
        .focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean outFocused,
                  Boolean focused) {

                if (focused) {

                } else if (outFocused) {

                  if (numofChildrenF.getText().matches("\\d+")) {
                    int children = Integer.parseInt(numofChildrenF.getText());
                    if (children > 1) {
                      numofChildrenF.setText(String.valueOf(children));
                      if (!childrenSchlCBox.getItems().contains(ChildrenSchoolCategory.SOME)) {
                        childrenSchlCBox.getItems().add(ChildrenSchoolCategory.SOME);
                      }
                      childrenSchlCBox.setDisable(false);
                    } else if (children == 1) {
                      numofChildrenF.setText(String.valueOf(children));
                      childrenSchlCBox.setDisable(false);
                      childrenSchlCBox.getItems().remove(ChildrenSchoolCategory.SOME);
                    } else {
                      numofChildrenF.setText("0");
                      childrenSchlCBox.setDisable(true);
                      childrenSchlCBox.getSelectionModel().clearSelection();
                    }
                  } else {
                    numofChildrenF.setText("0");
                  }
                }
              }
            });

    // add Change listener to validate number of children field
    agefield
        .focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable, Boolean outFocus, Boolean focus) {

                if (outFocus) {
                  if (agefield.getText().matches("\\d+")) {
                    int age = Integer.parseInt(agefield.getText());
                    agefield.setText(String.valueOf(age));
                  } else {
                    agefield.setText("");
                  }
                }
              }
            });

    maritalCBox.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            String item = (String) maritalCBox.getSelectionModel().getSelectedItem();
            if (item == null) {

            } else if (item.equals("Married") || item.equals("Live-in")) {
              SpouseName.setDisable(false);
            } else {
              SpouseName.getStyleClass().remove("text-field-error");
              SpouseName.setText("");
              SpouseName.setDisable(true);
            }
          }
        });
  }
Пример #6
0
  public static void setJar(final Tile node) {
    node.data.put("type", "Jar");
    List<Node> toRemove = new ArrayList<>();
    for (Node n : node.node.getChildren()) {
      if (!n.getId().equals("delete")) {
        if (n.getId().equals("typeLabel")) {
          Label l = (Label) n;
          l.setText("jar");
          l.setTranslateY(l.getTranslateY() - 1);
        } else {
          toRemove.add(n);
        }
      }
    }

    VBox leftPadding = new VBox();
    leftPadding.setPrefWidth(14);
    VBox buttons = new VBox();
    VBox textBoxes = new VBox();
    VBox extra = new VBox();

    buttons.setSpacing(5);
    textBoxes.setSpacing(5);
    extra.setSpacing(5);

    buttons.setPadding(new Insets(7, 0, 0, 0));
    textBoxes.setPadding(new Insets(7, 0, 0, 0));
    extra.setPadding(new Insets(7, 0, 0, 0));

    textBoxes.setTranslateX(17);
    extra.setTranslateX(32);

    node.node.getChildren().removeAll(toRemove);

    final String name = "Package Name";
    final String name2 = "Jar Name";

    Button findPkg = new Button();
    final TextField pkgText = new TextField();
    final TextField jarName = new TextField();

    findPkg.getStyleClass().add("defaultButton");
    findPkg.setText("Find Package Name");
    findPkg.setPrefHeight(25);
    findPkg.setTranslateX(12);

    findPkg.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            String mainClassName = Util.packageNameFromTile();
            if (mainClassName != null) {
              pkgText.setText(mainClassName);
            }
          }
        });

    pkgText.setText(name);
    pkgText.setPrefSize(150, 27);
    pkgText.setFont(Font.font("Segoe UI"));
    pkgText.setId("textBox");
    pkgText
        .textProperty()
        .addListener(
            new ChangeListener<String>() {
              @Override
              public void changed(
                  ObservableValue<? extends String> observable, String oldValue, String newValue) {
                node.data.put("package", pkgText.getText().trim());
              }
            });
    pkgText
        .focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                if (newValue == true && pkgText.getText().equals(name)) {
                  pkgText.setText("");
                } else if (newValue == false && pkgText.getText().trim().equals("")) {
                  pkgText.setText(name);
                }
              }
            });

    jarName.setText(name2);
    jarName.setPrefSize(150, 27);
    jarName.setFont(Font.font("Segoe UI"));
    jarName.setId("textBox");
    jarName
        .textProperty()
        .addListener(
            new ChangeListener<String>() {
              @Override
              public void changed(
                  ObservableValue<? extends String> observable, String oldValue, String newValue) {
                node.data.put("jarname", jarName.getText().trim());
              }
            });
    jarName
        .focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                if (newValue == true && jarName.getText().equals(name2)) {
                  jarName.setText("");
                } else if (newValue == false && jarName.getText().trim().equals("")) {
                  jarName.setText(name2);
                }
              }
            });

    final String defTxt = "Additional Flags";
    final TextField flags = new TextField();
    flags.setText(defTxt);
    flags.setPrefSize(150, 27);
    flags.setFont(Font.font("Segoe UI"));
    flags.setId("textBox");

    flags
        .focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                if (newValue == true && flags.getText().equals(defTxt)) {
                  flags.setText("");
                } else if (newValue == false && flags.getText().trim().equals("")) {
                  flags.setText(defTxt);
                }
              }
            });
    flags
        .textProperty()
        .addListener(
            new ChangeListener<String>() {
              @Override
              public void changed(
                  ObservableValue<? extends String> observable, String oldValue, String newValue) {
                node.data.put("flags", flags.getText().trim());
              }
            });

    final String defTxt2 = "Output Directory";
    final TextField outputDir = new TextField();
    outputDir.setText(defTxt2);
    outputDir.setPrefSize(150, 27);
    outputDir.setFont(Font.font("Segoe UI"));
    outputDir.setId("textBox");

    outputDir
        .focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                if (newValue == true && outputDir.getText().equals(defTxt2)) {
                  outputDir.setText("");
                } else if (newValue == false && outputDir.getText().trim().equals("")) {
                  outputDir.setText(defTxt2);
                }
              }
            });
    outputDir
        .textProperty()
        .addListener(
            new ChangeListener<String>() {
              @Override
              public void changed(
                  ObservableValue<? extends String> observable, String oldValue, String newValue) {
                node.data.put("output", outputDir.getText().trim());
              }
            });

    buttons.getChildren().addAll(findPkg);
    textBoxes.getChildren().addAll(pkgText, jarName);
    extra.getChildren().addAll(flags, outputDir);
    node.node.getChildren().addAll(leftPadding, buttons, textBoxes, extra);
  }
Пример #7
0
  /**
   * Verbindet ein Textfeld bidirektional mit einem Slider und sorgt für Validierung der Eingaben.
   *
   * @param textField Textfeld
   * @param slider Slider
   * @param maxValue Maximalwert für das Textfeld
   */
  private void bindTextInputListenersAndSlider(
      final TextField textField, final Slider slider, final long maxValue) {
    final StringProperty textProperty = textField.textProperty();

    // Eingaben auf Zahlen beschränken
    textField.addEventFilter(
        KeyEvent.KEY_TYPED,
        new EventHandler<KeyEvent>() {
          public void handle(final KeyEvent keyEvent) {
            if (!"0123456789".contains(keyEvent.getCharacter())) {
              keyEvent.consume();
            }
          }
        });

    textProperty.addListener(
        new ChangeListener<String>() {
          public void changed(
              final ObservableValue<? extends String> property,
              final String oldValue,
              final String newValue) {
            // Wert auf gültigen Bereich beschränken
            try {
              final long parsedNumber = Long.parseLong(newValue);
              if (parsedNumber < MIN_VALUE) {
                textProperty.setValue(getTwoDigitValue(MIN_VALUE));
              } else if (parsedNumber > maxValue) {
                textProperty.setValue(getTwoDigitValue(maxValue));
              } else if (newValue.length() > 2) {
                textProperty.setValue(getTwoDigitValue(parsedNumber));
              } else {
                textProperty.setValue(newValue);
              }

              // Änderung an Zeit-Property durchstellen
              timeProperty.set(getValue());
            } catch (final NumberFormatException e) {
              // alten Wert wieder setzen (sinnvoll bei Änderung per Copy & Paste)
              textProperty.setValue(oldValue);
            }
          }
        });

    // bei Verlassen des Feldes sicherstellen, dass Wert zweistellig
    textField
        .focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              public void changed(
                  final ObservableValue<? extends Boolean> property,
                  final Boolean oldValue,
                  final Boolean newValue) {
                if (Boolean.FALSE.equals(newValue)) {
                  try {
                    textProperty.setValue(getTwoDigitValue(Long.parseLong(textProperty.get())));
                  } catch (final NumberFormatException e) {
                    textProperty.setValue(getTwoDigitValue(MIN_VALUE));
                  }
                }
              }
            });

    // Textfeld mit Slider koppeln
    if (slider != null) {
      slider.setMax(maxValue);
      textProperty.bindBidirectional(
          slider.valueProperty(),
          new StringConverter<Number>() {
            public String toString(final Number number) {
              return getTwoDigitValue(number.longValue());
            }

            public Number fromString(final String string) {
              return Long.parseLong(string);
            }
          });
    }

    // auf Scroll-Ereignis im Textfeld reagieren
    textField.setOnScroll(
        new EventHandler<ScrollEvent>() {
          public void handle(final ScrollEvent event) {
            // Scrollen über Feld ohne Fokus hat keine Auswirkung
            if (!textField.isFocused()) {
              return;
            }

            final double change = event.getDeltaY() > 0 ? 1 : -1;
            slider.setValue(slider.getValue() + change);

            event.consume();
          }
        });
  }
Пример #8
0
  @Override
  public void initialize(URL location, ResourceBundle resources) {
    Circle cuser = new Circle(10, Color.DODGERBLUE);
    Circle cpass = new Circle(10, Color.DODGERBLUE);
    cuser.setOpacity(0);
    cpass.setOpacity(0);
    ButtonSkin users = new ButtonSkin(login);
    users.getChildren().add(0, cuser);
    login.setSkin(users);
    ButtonSkin passs = new ButtonSkin(hify);
    passs.getChildren().add(0, cpass);
    hify.setSkin(passs);
    login.setOnMousePressed(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            // .println("pressed");
            cuser.setOpacity(0.5);
            cuser.setRadius(10);
            cuser.setCenterX(event.getX());
            cuser.setCenterY(event.getY());
            Rectangle r = new Rectangle();
            r.setArcHeight(
                login.getBackground().getFills().get(0).getRadii().getTopLeftVerticalRadius());
            r.setArcWidth(
                login.getBackground().getFills().get(0).getRadii().getTopLeftHorizontalRadius());
            // .println(login.getPrefWidth()+"  "+login.getPrefHeight());
            r.setWidth(login.getPrefWidth());
            r.setHeight(login.getPrefHeight());
            cuser.setClip(r);
            Timeline tl = new Timeline();
            KeyValue kv =
                new KeyValue(
                    cuser.radiusProperty(), 1.5 * login.getPrefWidth(), Interpolator.EASE_OUT);
            KeyFrame kf = new KeyFrame(Duration.millis(1500), kv);
            tl.getKeyFrames().clear();
            tl.getKeyFrames().add(kf);
            tl.play();
            await.countDown();
          }
        });
    login.setOnMouseReleased(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            try {
              await.await();
            } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }

            awaitu.countDown();
            FadeTransition fd = new FadeTransition(Duration.millis(1500), cuser);
            fd.setFromValue(0.5);
            fd.setToValue(0);
            fd.setInterpolator(Interpolator.EASE_OUT);
            fd.play();
          }
        });
    hify.setOnMousePressed(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            // .println("pressed");
            cpass.setOpacity(0.5);
            cpass.setRadius(10);
            cpass.setCenterX(event.getX());
            cpass.setCenterY(event.getY());
            Rectangle r = new Rectangle();
            r.setArcHeight(
                hify.getBackground().getFills().get(0).getRadii().getTopLeftVerticalRadius());
            r.setArcWidth(
                hify.getBackground().getFills().get(0).getRadii().getTopLeftHorizontalRadius());
            r.setWidth(hify.getPrefWidth());
            r.setHeight(hify.getPrefHeight());
            cpass.setClip(r);
            Timeline tl = new Timeline();
            KeyValue kv =
                new KeyValue(
                    cpass.radiusProperty(), 1.5 * hify.getPrefWidth(), Interpolator.EASE_OUT);
            KeyFrame kf = new KeyFrame(Duration.millis(1500), kv);
            tl.getKeyFrames().clear();
            tl.getKeyFrames().add(kf);
            tl.play();
            awaitp.countDown();
          }
        });
    hify.setOnMouseReleased(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            try {
              awaitp.await();
            } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
            awaitpa.countDown();
            FadeTransition fd = new FadeTransition(Duration.millis(1500), cpass);
            fd.setFromValue(0.5);
            fd.setToValue(0);
            fd.setInterpolator(Interpolator.EASE_OUT);
            fd.play();
          }
        });
    user.focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                if (newValue) {
                  TranslateTransition fd = new TranslateTransition(Duration.millis(500), userlabel);
                  FadeTransition ff = new FadeTransition(Duration.millis(500), userlabel);
                  fd.setInterpolator(Interpolator.EASE_BOTH);
                  ff.setInterpolator(Interpolator.EASE_BOTH);
                  ff.setToValue(1.0);
                  ff.setFromValue(0.0);
                  fd.setByY(-3);
                  ParallelTransition pt = new ParallelTransition();
                  pt.getChildren().addAll(fd, ff);
                  pt.play();

                } else {
                  userlabel.setTranslateY(3);
                  userlabel.setOpacity(0);
                }
              }
            });
    pass.focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {

              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                if (newValue) {
                  TranslateTransition fd = new TranslateTransition(Duration.millis(500), passlabel);
                  FadeTransition ff = new FadeTransition(Duration.millis(500), passlabel);
                  fd.setInterpolator(Interpolator.EASE_BOTH);
                  ff.setInterpolator(Interpolator.EASE_BOTH);
                  ff.setToValue(1.0);
                  ff.setFromValue(0.0);
                  fd.setByY(-3);
                  ParallelTransition pt = new ParallelTransition();
                  pt.getChildren().addAll(fd, ff);
                  pt.play();

                } else {
                  passlabel.setTranslateY(3);
                  passlabel.setOpacity(0);
                }
              }
            });
    p1.setEffect(new DropShadow());
  }