コード例 #1
0
  @FXML
  private void handleAction(ActionEvent event) {
    TextArea textarea = (TextArea) menuBar.getScene().lookup("#textarea");

    if (event.getSource() == chmiWordWrap) {
      wordWrapOn = chmiWordWrap.isSelected();
      textarea.setWrapText(wordWrapOn);

    } else if (event.getSource() == miChangeCase) {
      try {
        if (changeCaseDialog == null) {
          FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("ChangeCaseDialog.fxml"));
          Parent root = fxmlLoader.load();
          controller = fxmlLoader.getController();
          controller.setSelectedCase(prefs.get(strSelectedCase, "UPPERCASE"));
          changeCaseDialog = new Stage();
          changeCaseDialog.setResizable(false);
          changeCaseDialog.initStyle(StageStyle.UTILITY);
          changeCaseDialog.setAlwaysOnTop(true);
          changeCaseDialog.setX(prefs.getDouble(strChangeCaseX, changeCaseDialog.getX()));
          changeCaseDialog.setY(prefs.getDouble(strChangeCaseY, changeCaseDialog.getY()));
          Scene scene = new Scene(root);
          changeCaseDialog.setScene(scene);
          changeCaseDialog.setTitle("Change Case");
        }

        changeCaseDialog.toFront();
        changeCaseDialog.show();
      } catch (Exception e) {

      }
    } else if (event.getSource() == miRemoveLineBreaks) {
      if (textarea.getSelectedText().length() == 0) {
        textarea.selectAll();

        if (textarea.getSelectedText().length() == 0) {
          return;
        }
      }

      String result = TextUtilities.removeLineBreaks(textarea.getSelectedText());

      int start = textarea.getSelection().getStart();
      textarea.replaceSelection(result);
      textarea.selectRange(start, start + result.length());
    } else if (event.getSource() == miFont) {
      Font font = textarea.getFont();
      FontSelectorDialog dialog = new FontSelectorDialog(font);
      Optional<Font> op = dialog.showAndWait();
      if (op.isPresent()) {
        textarea.setFont(op.get());
      }
    }
  }
コード例 #2
0
  /**
   * Changes letter case.
   *
   * @param typeOfCase The type that the case should be changed to
   */
  public void changeCase(String typeOfCase) {
    if (textarea.selectedTextProperty().length().get() == 0) {
      textarea.selectAll();

      if (textarea.selectedTextProperty().length().get() == 0) {
        return;
      }
    }

    String result = TextUtilities.changeCase(textarea.getSelectedText(), typeOfCase);

    int start = textarea.getSelection().getStart();
    textarea.replaceSelection(result);
    textarea.selectRange(start, start + result.length());
  }