/** * @return the current char count */ public int getCharCount() { return getContent().getCharCount(); }
/** * Set the selection * * @param offset * the offset * @param length * the length */ public void setSelectionRange(int offset, int length) { setSelection(new TextSelection(offset, length)); }
/** * Get the line index for the caret * * @param caretOffset * the caret offset * @return the line index */ public int getLineAtOffset(int caretOffset) { return getContent().getLineAtOffset(caretOffset); }
/** * navigates to specified line * * @param lineIndex */ public void navigateToLine(int lineIndex) { if (lineIndex >= 0 && lineIndex <= getContent().getLineCount()) { int offset = getContent().getOffsetAtLine(lineIndex); setCaretOffset(offset); } }
/** * Create a new control */ public StyledTextArea() { this.getStyleClass().add("styled-text-area"); //$NON-NLS-1$ this.contentProperty = new ContentProperty(this, "content", new DefaultContent()); //$NON-NLS-1$ setFocusTraversable(true); }
/** * Get the initial offset of the line * * @param lineNumber * the line number * @return the offset */ public int getOffsetAtLine(int lineNumber) { return getContent().getOffsetAtLine(lineNumber); }
/** * Create a new behavior * * @param styledText * the styled text control */ public StyledTextBehavior(StyledTextArea styledText) { this.styledText = styledText; styledText.addEventHandler(KeyEvent.ANY, this::callActionForEvent); }
/** * Create the text set event * * @param source * the source * @return the event */ public static TextChangedEvent textSet(StyledTextContent source) { return new TextChangedEvent(source, 0, 0, 0, null, 0, 0); }
@Override public default CharSequence subSequence(int start, int end) { return getTextRange(start, end - start); } }
@Override public void mapConditional(String conditionId, Supplier<Boolean> condition, char typedChar, TextEditAction action) { x.mapConditional(conditionId, condition, typedChar, action); } });
@Override public void textSet(TextChangedEvent event) { handleTextSet(event); } };
/** * Creates a new DefaultContent and initializes it. A * <code>StyledTextContent</> will always have * at least one empty line. */ DefaultContent() { super(); setText(""); //$NON-NLS-1$ }
private void recalculateOffset(Observable o) { int offset = 0; for (StyledTextNode t : this.textNodes) { t.setStartOffset(offset); offset = t.getEndOffset(); } }
@SuppressWarnings("unchecked") @Override public StyleableProperty<Font> getStyleableProperty(StyledTextArea n) { return (StyleableProperty<Font>) n.fontProperty(); }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + character; return result; }
/** * @return the current char count */ public int getCharCount() { return getContent().getCharCount(); }
/** * Set the selection * * @param offset * the offset * @param length * the length */ public void setSelectionRange(int offset, int length) { setSelection(new TextSelection(offset, length)); }
/** * Get the line index for the caret * * @param caretOffset * the caret offset * @return the line index */ public int getLineAtOffset(int caretOffset) { return getContent().getLineAtOffset(caretOffset); }
/** * Get the initial offset of the line * * @param lineNumber * the line number * @return the offset */ public int getOffsetAtLine(int lineNumber) { return getContent().getOffsetAtLine(lineNumber); }
/** * Create the text set event * * @param source * the source * @return the event */ public static TextChangedEvent textSet(StyledTextContent source) { return new TextChangedEvent(source, 0, 0, 0, null, 0, 0); }