コード例 #1
0
  @FXML
  private void HandleBlocButtonAction(ActionEvent event) {
    String text = "";
    String[] lines = SourceText.getSelectedText().split("\n");
    for (String line : lines) {
      text += "| " + line + "\n";
    }

    List<String> choices = new ArrayList<>();
    choices.add("information");
    choices.add("question");
    choices.add("attention");
    choices.add("erreur");

    ChoiceDialog<String> dialog = new ChoiceDialog<>("information", choices);
    dialog.setTitle("Choix du bloc");
    dialog.setHeaderText("Votre type de bloc");
    dialog.setContentText("Type de bloc: ");

    // Traditional way to get the response value.
    Optional<String> result = dialog.showAndWait();
    if (result.isPresent()) {
      SourceText.replaceText(SourceText.getSelection(), "\n[[" + result.get() + "]]\n" + text);
    }

    SourceText.requestFocus();
  }
コード例 #2
0
  @FXML
  public void HandleSaveButtonAction(ActionEvent event) {
    extract.setMarkdown(SourceText.getText());
    extract.save();
    tab.setText(extract.getTitle());
    this.isSaved = true;

    SourceText.requestFocus();
  }
コード例 #3
0
  @FXML
  private void HandleLinkButtonAction(ActionEvent event) {
    String link = SourceText.getSelectedText();

    // Create the custom dialog.
    Dialog<Pair<String, String>> dialog = new Dialog<>();
    dialog.setTitle("Détail du lien");
    dialog.setHeaderText("");

    // Set the icon (must be included in the project).
    dialog.setGraphic(
        new ImageView(MainApp.class.getResource("assets/static/icons/link.png").toString()));

    dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);

    // Create the username and password labels and fields.
    GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(20, 150, 10, 10));

    TextField tLink = new TextField();
    tLink.setText(link);
    TextField tLabel = new TextField();
    tLabel.setText(link);

    grid.add(new Label("Lien:"), 0, 0);
    grid.add(tLink, 1, 0);
    grid.add(new Label("Titre du lien"), 0, 1);
    grid.add(tLabel, 1, 1);

    dialog.getDialogPane().setContent(grid);

    // Request focus on the username field by default.
    Platform.runLater(tLink::requestFocus);

    // Convert the result to a username-password-pair when the login button
    // is clicked.
    dialog.setResultConverter(
        dialogButton -> {
          if (dialogButton == ButtonType.OK) {
            return new Pair<>(tLink.getText(), tLabel.getText());
          }
          return null;
        });

    Optional<Pair<String, String>> result = dialog.showAndWait();

    result.ifPresent(
        tLinkTLabel ->
            SourceText.replaceText(
                SourceText.getSelection(),
                "[" + tLinkTLabel.getValue() + "](" + tLinkTLabel.getKey() + ")"));

    SourceText.requestFocus();
  }
コード例 #4
0
  @FXML
  private void HandleTableButtonAction(ActionEvent event) throws IOException {
    // Create the custom dialog.
    Dialog<Pair<ObservableList, ObservableList<ZRow>>> dialog = new Dialog<>();
    dialog.setTitle("Editeur de tableau");
    dialog.setHeaderText("");

    // Set the icon (must be included in the project).
    dialog.setGraphic(
        new ImageView(MainApp.class.getResource("assets/static/icons/table.png").toString()));

    // Set the button types.
    dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);

    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(MainApp.class.getResource("fxml/TableEditor.fxml"));
    BorderPane tableEditor = loader.load();
    TableView<ZRow> tbView = (TableView) tableEditor.getCenter();

    TableController controller = loader.getController();
    controller.setEditor(this);

    dialog.getDialogPane().setContent(tableEditor);

    dialog.setResultConverter(
        dialogButton -> {
          if (dialogButton == ButtonType.OK) {
            return new Pair<>(tbView.getColumns(), tbView.getItems());
          }
          return null;
        });

    Optional<Pair<ObservableList, ObservableList<ZRow>>> result = dialog.showAndWait();

    result.ifPresent(
        datas -> {
          String[][] data =
              new String[datas.getValue().size()][datas.getValue().get(0).getRow().size()];
          String[] headers = new String[datas.getKey().size()];
          int cpt = 0;
          for (Object key : datas.getKey()) {
            headers[cpt] = ((TextField) ((TableColumn) key).getGraphic()).getText();
            cpt++;
          }

          for (int i = 0; i < datas.getValue().size(); i++) {
            for (int j = 0; j < datas.getValue().get(i).getRow().size(); j++) {
              data[i][j] = datas.getValue().get(i).getRow().get(j);
            }
          }
          String tablestring = FlipTable.of(headers, data);
          SourceText.replaceText(SourceText.getSelection(), "\n\n" + tablestring + "\n\n");
          SourceText.requestFocus();
        });
  }
コード例 #5
0
  public void HandleGoToLineAction() {
    TextInputDialog dialog = new TextInputDialog();
    dialog.setTitle("Aller à la ligne");
    dialog.setHeaderText(null);
    dialog.setContentText("Numéro de ligne: ");

    Optional<String> result = dialog.showAndWait();
    result.ifPresent(
        line ->
            SourceText.positionCaret(
                SourceText.position(Integer.parseInt(line) - 1, 0).toOffset()));
  }
コード例 #6
0
  private void replaceAction(
      String defaultString, int defaultOffsetCaret, String beforeString, String afterString) {
    if (SourceText.getSelectedText().isEmpty()) {
      SourceText.replaceText(SourceText.getSelection(), defaultString);
      SourceText.moveTo(SourceText.getCaretPosition() - defaultOffsetCaret);
    } else {
      SourceText.replaceText(
          SourceText.getSelection(), beforeString + SourceText.getSelectedText() + afterString);
    }

    SourceText.requestFocus();
  }
コード例 #7
0
  @Override
  public void start(Stage primaryStage) {
    Button red = createColorButton(Color.RED, "red");
    Button green = createColorButton(Color.GREEN, "green");
    Button blue = createColorButton(Color.BLUE, "blue");
    Button bold = createBoldButton("bold");
    HBox panel = new HBox(red, green, blue, bold);

    VirtualizedScrollPane<StyleClassedTextArea> vsPane = new VirtualizedScrollPane<>(area);
    VBox.setVgrow(vsPane, Priority.ALWAYS);
    area.setWrapText(true);
    VBox vbox = new VBox(panel, vsPane);

    Scene scene = new Scene(vbox, 600, 400);
    scene
        .getStylesheets()
        .add(ManualHighlighting.class.getResource("manual-highlighting.css").toExternalForm());
    primaryStage.setScene(scene);
    primaryStage.setTitle("Manual Highlighting Demo");
    primaryStage.show();

    area.requestFocus();
  }
コード例 #8
0
  @FXML
  private void HandleBulletButtonAction(ActionEvent event) {
    if (SourceText.getSelectedText().isEmpty()) {
      SourceText.replaceText(SourceText.getSelection(), "- ");
    } else {
      StringBuilder sb = new StringBuilder();
      String[] lines = SourceText.getSelectedText().split("\n");
      for (String line : lines) {
        sb.append("- ").append(line).append("\n");
      }

      SourceText.replaceText(SourceText.getSelection(), sb.toString());
    }

    SourceText.requestFocus();
  }
コード例 #9
0
 @FXML
 private void HandleValidateButtonAction(ActionEvent event) {
   String s = StringEscapeUtils.unescapeHtml(markdownToHtml(SourceText.getText()));
   if (corrector == null) {
     corrector = new Corrector();
   }
   try {
     String result = corrector.checkHtmlContent(s);
     WebEngine webEngine = renderView.getEngine();
     webEngine.loadContent(
         "<!doctype html><html lang='fr'><head><meta charset='utf-8'><base href='file://"
             + MainApp.class.getResource(".").getPath()
             + "' /></head><body>"
             + result
             + "</body></html>");
     webEngine.setUserStyleSheetLocation(
         MainApp.class.getResource("css/content.css").toExternalForm());
   } catch (DOMException e) {
     logger.error(e.getMessage(), e);
   }
 }
コード例 #10
0
 @FXML
 private void HandleUnbreakableAction(ActionEvent event) {
   SourceText.replaceText(SourceText.getSelection(), SourceText.getSelectedText() + "\u00a0");
   SourceText.requestFocus();
 }
コード例 #11
0
  @FXML
  private void HandleCodeButtonAction(ActionEvent event) {
    String code = SourceText.getSelectedText();
    if (code.trim().startsWith("```") && code.trim().endsWith("```")) {
      int start = code.trim().indexOf('\n') + 1;
      int end = code.trim().lastIndexOf('\n');
      code = code.substring(start, end);
    }

    // Create the custom dialog.
    Dialog<Pair<String, String>> dialog = new Dialog<>();
    dialog.setTitle("Editeur de code");
    dialog.setHeaderText("");

    // Set the icon (must be included in the project).
    dialog.setGraphic(
        new ImageView(MainApp.class.getResource("assets/static/icons/code.png").toString()));

    // Set the button types.
    dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);

    // Create the username and password labels and fields.
    GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(20, 150, 10, 10));

    TextField tLangage = new TextField();
    TextArea tCode = new TextArea();
    tCode.setText(code);

    grid.add(new Label("Langage:"), 0, 0);
    grid.add(tLangage, 1, 0);
    grid.add(new Label("Code"), 0, 1);
    grid.add(tCode, 1, 1);

    dialog.getDialogPane().setContent(grid);

    // Request focus on the username field by default.
    Platform.runLater(tLangage::requestFocus);

    // Convert the result to a username-password-pair when the login button
    // is clicked.
    dialog.setResultConverter(
        dialogButton -> {
          if (dialogButton == ButtonType.OK) {
            return new Pair<>(tLangage.getText(), tCode.getText());
          }
          return null;
        });

    Optional<Pair<String, String>> result = dialog.showAndWait();

    result.ifPresent(
        tLangageTCode ->
            SourceText.replaceText(
                SourceText.getSelection(),
                "\n```" + tLangageTCode.getKey() + "\n" + tLangageTCode.getValue() + "\n```\n"));

    SourceText.requestFocus();
  }
コード例 #12
0
 @FXML
 private void HandleHeaderButtonAction(ActionEvent event) {
   SourceText.replaceText(SourceText.getSelection(), "# " + SourceText.getSelectedText());
   SourceText.requestFocus();
 }
コード例 #13
0
 @FXML
 private void initialize() {
   SourceText.getStyleClass().add("markdown-editor");
   SourceText.getStylesheets().add(MainApp.class.getResource("css/editor.css").toExternalForm());
   SourceText.setParagraphGraphicFactory(LineNumberFactory.get(SourceText));
 }
コード例 #14
0
  public void setMdBox(MdTextController mdBox, Textual extract, Tab tab) throws IOException {
    this.mainApp = mdBox.getMainApp();
    this.config = mainApp.getConfig();
    this.mdBox = mdBox;
    this.tab = tab;
    this.extract = extract;

    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(MainApp.class.getResource("fxml/Editor.fxml"));
    loader.load();

    if (mainApp.getConfig().getEditorToolbarView().equals("no")) {
      BoxEditor.setTop(null);
      BoxRender.setTop(null);
    }

    SourceText.setFont(new Font(config.getEditorFont(), config.getEditorFontsize()));
    SourceText.setStyle("-fx-font-family: \"" + config.getEditorFont() + "\";");
    SourceText.replaceText(extract.getMarkdown());
    SourceText.textProperty()
        .addListener(
            (observableValue, s, s2) -> {
              tab.setText("! " + extract.getTitle());
              this.isSaved = false;
              SourceText.getUndoManager().mark();
              updateRender();
            });
    updateRender();
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(S, SHORTCUT_DOWN), () -> HandleSaveButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(G, SHORTCUT_DOWN), () -> HandleBoldButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(I, SHORTCUT_DOWN), () -> HandleItalicButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(B, SHORTCUT_DOWN), () -> HandleBarredButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(K, SHORTCUT_DOWN), () -> HandleTouchButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(PLUS, SHORTCUT_DOWN), () -> HandleExpButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(EQUALS, SHORTCUT_DOWN), () -> HandleIndButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(E, SHORTCUT_DOWN), () -> HandleCenterButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(
            new KeyCodeCombination(D, SHORTCUT_DOWN, SHIFT_DOWN),
            () -> HandleRightButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(SPACE, SHORTCUT_DOWN), () -> HandleUnbreakableAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(L, SHORTCUT_DOWN), this::HandleGoToLineAction);
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(F, SHORTCUT_DOWN), this::HandleFindReplaceDialog);
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(A, SHORTCUT_DOWN), () -> SourceText.selectAll());

    SourceText.requestFocus();
  }