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; }
private String getSaveHash() { return "" + lyricsArea.getText().hashCode() + titleField.getText().hashCode() + authorField.getText().hashCode(); }