/** Create a new ZionWorx import dialog. */
 public ZionWorxImportDialog() {
   super(
       new String[] {
         LabelGrabber.INSTANCE.getLabel("zw.import.line1"),
         LabelGrabber.INSTANCE.getLabel("zw.import.line2")
       },
       FileFilters.MAINTABLE_DAT,
       new ZionWorxParser(),
       false,
       false);
 }
 public SongSelectImportDialog() {
   super(
       new String[] {LabelGrabber.INSTANCE.getLabel("songselect.import.line1")},
       FileFilters.USR_SS,
       new SongSelectParser(),
       false,
       true);
 }
  private Button getNonBreakingLineButton() {
    Button ret =
        new Button(
            "", new ImageView(new Image("file:icons/nonbreakline.png", 24, 24, false, true)));
    Utils.setToolbarButtonStyle(ret);
    ret.setTooltip(new Tooltip(LabelGrabber.INSTANCE.getLabel("nonbreak.tooltip")));
    ret.setOnAction(
        (event) -> {
          int caretPos = lyricsArea.getArea().getCaretPosition();
          String[] parts = lyricsArea.getText().split("\n");
          int lineIndex = lineFromPos(lyricsArea.getText(), caretPos);
          String line = parts[lineIndex];
          if (line.trim().isEmpty()) {
            Platform.runLater(
                new Runnable() {

                  @Override
                  public void run() {
                    lyricsArea.getArea().replaceText(caretPos, caretPos, "<>");
                    lyricsArea.getArea().refreshStyle();
                  }
                });
          } else {
            int nextLinePos = nextLinePos(lyricsArea.getText(), caretPos);
            if (nextLinePos >= lyricsArea.getText().length()) {
              Platform.runLater(
                  new Runnable() {

                    @Override
                    public void run() {
                      lyricsArea.getArea().replaceText(nextLinePos, nextLinePos, "\n<>\n");
                      lyricsArea.getArea().refreshStyle();
                    }
                  });
            } else {
              Platform.runLater(
                  new Runnable() {

                    @Override
                    public void run() {
                      lyricsArea.getArea().replaceText(nextLinePos, nextLinePos, "<>\n");
                      lyricsArea.getArea().refreshStyle();
                    }
                  });
            }
          }
        });
    return ret;
  }
  /**
   * Get the button used for transposing the chords.
   *
   * <p>
   *
   * @return the button used for transposing the chords.
   */
  private Button getTransposeButton() {
    Button ret =
        new Button("", new ImageView(new Image("file:icons/transpose.png", 24, 24, false, true)));
    ret.setTooltip(new Tooltip(LabelGrabber.INSTANCE.getLabel("transpose.tooltip")));
    ret.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(javafx.event.ActionEvent t) {
            String originalKey = getKey(0);
            if (originalKey == null) {
              Dialog.showInfo(
                  LabelGrabber.INSTANCE.getLabel("no.chords.title"),
                  LabelGrabber.INSTANCE.getLabel("no.chords.message"));
              return;
            }
            transposeDialog.setKey(originalKey);
            transposeDialog.showAndWait();
            int semitones = transposeDialog.getSemitones();

            TextField keyField =
                QueleaApp.get()
                    .getMainWindow()
                    .getSongEntryWindow()
                    .getDetailedSongPanel()
                    .getKeyField();
            if (!keyField.getText().isEmpty()) {
              keyField.setText(new ChordTransposer(keyField.getText()).transpose(semitones, null));
            }

            String key = getKey(semitones);

            StringBuilder newText = new StringBuilder(getLyricsField().getText().length());
            for (String line : getLyricsField().getText().split("\n")) {
              if (new LineTypeChecker(line).getLineType() == LineTypeChecker.Type.CHORDS) {
                newText.append(new ChordLineTransposer(line).transpose(semitones, key));
              } else {
                newText.append(line);
              }
              newText.append('\n');
            }
            int pos = getLyricsField().getCaretPosition();
            getLyricsField().replaceText(newText.toString());
            getLyricsField().positionCaret(pos);
          }
        });
    Utils.setToolbarButtonStyle(ret);
    return ret;
  }
 /**
  * Get the spell checker button.
  *
  * <p>
  *
  * @return the spell checker button.
  */
 private Button getDictButton() {
   Button button =
       new Button("", new ImageView(new Image("file:icons/dictionary.png", 24, 24, false, true)));
   button.setTooltip(
       new Tooltip(LabelGrabber.INSTANCE.getLabel("run.spellcheck.label") + " (F7)"));
   button.setOnAction(
       new EventHandler<javafx.event.ActionEvent>() {
         @Override
         public void handle(javafx.event.ActionEvent t) {
           lyricsArea.runSpellCheck();
         }
       });
   button.disableProperty().bind(lyricsArea.spellingOkProperty());
   Utils.setToolbarButtonStyle(button);
   return button;
 }
  /**
   * Remove the selected song from the database.
   *
   * <p>
   *
   * @param t the action event.
   */
  @Override
  public void handle(ActionEvent t) {
    MainWindow mainWindow = QueleaApp.get().getMainWindow();
    final LibrarySongList songList =
        mainWindow.getMainPanel().getLibraryPanel().getLibrarySongPanel().getSongList();
    int index = songList.getListView().getSelectionModel().getSelectedIndex();
    if (index == -1) {
      return;
    }
    final SongDisplayable song = songList.getListView().itemsProperty().get().get(index);
    if (song == null) {
      return;
    }
    yes = false;
    Dialog.buildConfirmation(
            LabelGrabber.INSTANCE.getLabel("confirm.remove.text"),
            LabelGrabber.INSTANCE
                .getLabel("confirm.remove.question")
                .replace("$1", song.getTitle()))
        .addYesButton(
            new EventHandler<ActionEvent>() {
              @Override
              public void handle(ActionEvent t) {
                yes = true;
              }
            })
        .addNoButton(
            new EventHandler<ActionEvent>() {
              @Override
              public void handle(ActionEvent t) {}
            })
        .build()
        .showAndWait();
    if (yes) {
      songList.setLoading(true);
      new Thread() {
        @Override
        public void run() {
          if (!SongManager.get().removeSong(song)) {
            Platform.runLater(
                new Runnable() {
                  @Override
                  public void run() {
                    Dialog.showError(
                        LabelGrabber.INSTANCE.getLabel("error.text"),
                        LabelGrabber.INSTANCE.getLabel("error.removing.song.db"));
                  }
                });
          } else {
            song.setID(-1);
            Platform.runLater(
                new Runnable() {

                  @Override
                  public void run() {
                    songList.getListView().itemsProperty().get().remove(song);
                    songList.setLoading(false);
                  }
                });
          }
        }
      }.start();
    }
  }
  /** Create and initialise the song panel. */
  public BasicSongPanel() {
    final VBox centrePanel = new VBox();
    transposeDialog = new TransposeDialog();
    GridPane topPanel = new GridPane();

    titleField = new TextField();
    GridPane.setHgrow(titleField, Priority.ALWAYS);
    Label titleLabel = new Label(LabelGrabber.INSTANCE.getLabel("title.label"));
    GridPane.setConstraints(titleLabel, 1, 1);
    topPanel.getChildren().add(titleLabel);
    titleLabel.setLabelFor(titleField);
    GridPane.setConstraints(titleField, 2, 1);
    topPanel.getChildren().add(titleField);

    authorField = new TextField();
    GridPane.setHgrow(authorField, Priority.ALWAYS);
    Label authorLabel = new Label(LabelGrabber.INSTANCE.getLabel("author.label"));
    GridPane.setConstraints(authorLabel, 1, 2);
    topPanel.getChildren().add(authorLabel);
    authorLabel.setLabelFor(authorField);
    GridPane.setConstraints(authorField, 2, 2);
    topPanel.getChildren().add(authorField);

    centrePanel.getChildren().add(topPanel);
    lyricsArea = new SpellTextArea();
    lyricsArea.setMaxHeight(Double.MAX_VALUE);

    final VBox mainPanel = new VBox();
    ToolBar lyricsToolbar = new ToolBar();
    transposeButton = getTransposeButton();
    nonBreakingLineButton = getNonBreakingLineButton();
    lyricsToolbar.getItems().add(transposeButton);
    lyricsToolbar.getItems().add(nonBreakingLineButton);
    lyricsToolbar.getItems().add(new Separator());
    Region spacer = new Region();
    HBox.setHgrow(spacer, Priority.ALWAYS);
    lyricsToolbar.getItems().add(spacer);
    dictSelector = new ComboBox<>();
    Tooltip.install(
        dictSelector, new Tooltip(LabelGrabber.INSTANCE.getLabel("dictionary.language.text")));
    for (Dictionary dict : DictionaryManager.INSTANCE.getDictionaries()) {
      dictSelector.getItems().add(dict);
    }
    dictSelector
        .selectionModelProperty()
        .get()
        .selectedItemProperty()
        .addListener(
            new ChangeListener<Dictionary>() {

              @Override
              public void changed(
                  ObservableValue<? extends Dictionary> ov, Dictionary t, Dictionary t1) {
                lyricsArea.setDictionary(dictSelector.getValue());
              }
            });

    dictSelector.getSelectionModel().select(QueleaProperties.get().getDictionary());
    lyricsToolbar.getItems().add(dictSelector);
    lyricsToolbar.getItems().add(getDictButton());
    VBox.setVgrow(mainPanel, Priority.ALWAYS);
    mainPanel.getChildren().add(lyricsToolbar);
    VBox.setVgrow(lyricsArea, Priority.ALWAYS);
    mainPanel.getChildren().add(lyricsArea);
    centrePanel.getChildren().add(mainPanel);
    setCenter(centrePanel);
  }