Package snap.text
Class TextModelX
java.lang.Object
snap.props.PropObject
snap.text.TextModel
snap.text.SourceTextModel
snap.text.TextModelX
- All Implemented Interfaces:
CharSequence
,Cloneable
,PropChange.DoChange
,CharSequenceX
,XMLArchiver.Archivable
This TextModel subclass adds support for advanced features like text wrapping, font scaling, linking multiple
text models and more.
-
Field Summary
FieldsFields inherited from class snap.text.SourceTextModel
_sourceText
Fields inherited from class snap.text.TextModel
_defaultLineStyle, _defaultTextStyle, _length, _lines, _mouseY, _prefW, _propChangeEnabled, Chars_Prop, DefaultLineStyle_Prop, DefaultTextStyle_Prop, LineStyle_Prop, Style_Prop, TextModified_Prop
Fields inherited from class snap.props.PropObject
_pcs, EMPTY_OBJECT
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.TextModelX
(boolean isRichText) Constructor with option for rich text.TextModelX
(TextModel sourceText) Constructor for source text. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addCharsToLineFinished
(TextLine textLine) Override to handle wrap lines.protected void
addCharsWithStyleImpl
(CharSequence theChars, TextStyle theStyle, int anIndex) Adds characters with given style to this text at given index.Returns the bounds path.double
Returns the font scale of the text.protected double
getMaxHitX
(double aY, double aH) Returns the max x value that doesn't hit right border for given y/height.protected double
getMinHitX
(double aY, double aH, double anIndent) Returns the min x value that doesn't hit left border for given y/height and indent.double
Returns the preferred width.int
Returns the start char in source text.protected boolean
isHitRight
(double aX, double aY, double aH) Returns whether given x location and run hit right border.boolean
Returns whether layout tries to hyphenate wrapped words.boolean
isLinked()
Returns whether text is linked to another text (and shouldn't add lines below bottom border).boolean
Returns whether this text couldn't fit all text.boolean
Returns whether to wrap lines that overrun bounds.void
Scales font sizes of all text to fit in bounds by finding/setting FontScale.void
setBoundsPath
(Shape aPath) Sets the bounds path.void
setFontScale
(double aValue) Sets the font scale of the text.void
setHeight
(double aValue) Override to update layout.void
setHyphenate
(boolean aValue) Sets whether layout tries to hyphenate wrapped words.void
setLinked
(boolean aValue) Returns whether text is linked to another text (and shouldn't add lines below bottom border).void
setStartCharIndex
(int charIndex) Sets the start char in source text.void
setWidth
(double aValue) Override to update layout.void
setWrapLines
(boolean aValue) Sets whether to wrap lines that overrun bounds.protected void
wrapLineIfNeeded
(TextLine textLine) Wraps given line if needed by moving chars from last token(s) to next line.Methods inherited from class snap.text.SourceTextModel
addCharsToLine, addCharsWithStyle, copyForRange, createTokensForTextLine, getSourceText, readTextFromSourceFile, reloadTextFromSourceText, removeChars, setDefaultLineStyle, setDefaultTextStyle, setLineStyle, setLineStyleRich, setLineStyleValueRich, setRichText, setSourceText, setTextModified, setTextStyle, syncTextModelToSourceFile, toXML, writeTextToSourceFile
Methods inherited from class snap.text.TextModel
addChars, addChars, addCharsForTextModel, addCharsWithStyle, addLine, charAt, clear, clone, fromXML, getAlignedY, getAlignX, getAlignY, getBounds, getCharIndexForXY, getDefaultFont, getDefaultLineStyle, getDefaultTextColor, getDefaultTextStyle, getEndCharIndex, getFontForCharIndex, getHeight, getLastLine, getLine, getLineCount, getLineForCharIndex, getLineForY, getLineLongest, getLines, getLineStyleForCharIndex, getMaxX, getMaxY, getPathForCharRange, getPrefHeight, getPrefHeight, getPrefWidthForStartCharIndex, getRunForCharIndex, getRunForCharRange, getRunIterForCharRange, getSourceFile, getSourceUrl, getString, getTextStyleForCharIndex, getTextStyleForCharRange, getTokenForCharIndex, getUnderlineRuns, getWidth, getX, getY, indexOf, isPropChangeEnabled, isRichText, isTextModified, isUnderlined, joinLineWithNextLine, length, moveLineCharsToNextLine, paint, paintLine, removeCharsFromLine, removeLine, replaceChars, replaceCharsWithStyle, resetLineYForLinesAfterIndex, scaleFonts, setAlignX, setAlignY, setBounds, setBounds, setDefaultFont, setDefaultTextColor, setDefaultTextStyleString, setLineStyleValue, setPropChangeEnabled, setSourceUrl, setString, setTextStyleValue, setUnderlined, setX, setY, splitLineAtIndex, subSequence, toStringProps, updateLine, updateLines
Methods inherited from class snap.props.PropObject
addDeepChangeListener, addPropChangeListener, addPropChangeListener, batchPropChange, batchPropChange, batchPropChanges, fireBatchPropChanges, firePropChange, firePropChange, firePropChange, getPropDefault, getPropForName, getPropParent, getPropSet, getPropsForArchival, getPropsForArchivalExtra, getPropsString, getPropValue, initProps, isPropDefault, processArchivedNode, processPropChange, processUnarchivedNode, removeDeepChangeListener, removePropChangeListener, removePropChangeListener, setPropsString, setPropValue, setPropValues, toString
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty, toString
Methods inherited from interface snap.util.CharSequenceX
getIndentLength, getIndentString, getLastChar, indexAfterNewline, indexAfterNewlineOrEnd, indexOfNewline, isAfterLineEnd, isLastCharNewline, isLineEnd, isLineEndChar, isWhiteSpace, lastIndexAfterNewline, lastIndexOfNewline, startsWith
-
Field Details
-
_fontScale
protected double _fontScale
-
-
Constructor Details
-
TextModelX
public TextModelX()Constructor. -
TextModelX
public TextModelX(boolean isRichText) Constructor with option for rich text. -
TextModelX
Constructor for source text.
-
-
Method Details
-
addCharsWithStyleImpl
Adds characters with given style to this text at given index.- Overrides:
addCharsWithStyleImpl
in classTextModel
-
addCharsToLineFinished
Override to handle wrap lines.- Overrides:
addCharsToLineFinished
in classTextModel
-
wrapLineIfNeeded
Wraps given line if needed by moving chars from last token(s) to next line. -
isWrapLines
public boolean isWrapLines()Returns whether to wrap lines that overrun bounds.- Overrides:
isWrapLines
in classTextModel
-
setWrapLines
public void setWrapLines(boolean aValue) Sets whether to wrap lines that overrun bounds. -
isHyphenate
public boolean isHyphenate()Returns whether layout tries to hyphenate wrapped words. -
setHyphenate
public void setHyphenate(boolean aValue) Sets whether layout tries to hyphenate wrapped words. -
isLinked
public boolean isLinked()Returns whether text is linked to another text (and shouldn't add lines below bottom border). -
setLinked
public void setLinked(boolean aValue) Returns whether text is linked to another text (and shouldn't add lines below bottom border). -
getStartCharIndex
public int getStartCharIndex()Returns the start char in source text.- Overrides:
getStartCharIndex
in classTextModel
-
setStartCharIndex
public void setStartCharIndex(int charIndex) Sets the start char in source text. -
getFontScale
public double getFontScale()Returns the font scale of the text. -
setFontScale
public void setFontScale(double aValue) Sets the font scale of the text. -
getBoundsPath
Returns the bounds path. -
setBoundsPath
Sets the bounds path. -
isHitRight
protected boolean isHitRight(double aX, double aY, double aH) Returns whether given x location and run hit right border. -
getMinHitX
protected double getMinHitX(double aY, double aH, double anIndent) Returns the min x value that doesn't hit left border for given y/height and indent. -
getMaxHitX
protected double getMaxHitX(double aY, double aH) Returns the max x value that doesn't hit right border for given y/height. -
setWidth
public void setWidth(double aValue) Override to update layout. -
setHeight
public void setHeight(double aValue) Override to update layout. -
getPrefWidth
public double getPrefWidth()Returns the preferred width.- Overrides:
getPrefWidth
in classTextModel
-
scaleTextToFit
public void scaleTextToFit()Scales font sizes of all text to fit in bounds by finding/setting FontScale. -
isTextOutOfBounds
public boolean isTextOutOfBounds()Returns whether this text couldn't fit all text.
-