APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.jfx.incubator.scene.control.richtext.util

public final Class RichUtils

extends Object
Class Inheritance
Imports
java.io.BufferedInputStream, .ByteArrayOutputStream, .IOException, .InputStream, .InputStreamReader, java.nio.charset.StandardCharsets, java.text.DecimalFormat, .MessageFormat, java.util.List, .Locale, .Set, java.util.function.Supplier, javax.imageio.ImageIO, javafx.application.ColorScheme, .ConditionalFeature, .Platform, javafx.css.CssMetaData, .Styleable, javafx.geometry.BoundingBox, .Bounds, .HPos, .Insets, .Point2D, .VPos, javafx.scene.Node, .Parent, .Scene, javafx.scene.image.Image, javafx.scene.input.InputMethodEvent, .InputMethodTextRun, javafx.scene.layout.Region, javafx.scene.paint.Color, .Paint, javafx.scene.shape.LineTo, .MoveTo, .PathElement, javafx.scene.text.Font, .Text, .TextAlignment, .TextFlow, com.sun.javafx.scene.text.TextFlowHelper, .TextLayout, .TextLine, jfx.incubator.scene.control.richtext.RichTextArea, .TextPos, jfx.incubator.scene.control.richtext.model.StyleAttribute, .StyleAttributeMap, .StyledTextModel

RichTextArea specific utility methods.

Field Summary

Modifier and TypeField and Description
private static final boolean
CALLER

includes FILE.METHOD:LINE in the debug output

private static final boolean
DEBUG

enables debug output

private static final DecimalFormat

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static TextPos
advancePosition(TextPos start, int offset)

Returns the text positions at a positive offset relative to the 'start' position.

public static boolean
canEdit(RichTextArea rta)

returns true if both control and model are editable

public static StyleAttributeMap

Returns:

the combined attributes, or null
combine
(StyleAttributeMap
the low priority attributes
lowPri
,
StyleAttributeMap
the high priority attributes
hiPri
)

Combines style attributes, returning combined object (or null).

public static List<CssMetaData<? extends Styleable, ?>>

Returns:

the immutable list containing all of the items
combine
(List<CssMetaData<? extends Styleable, ?>>
the CssMetaData items inherited from parent, must not be null
inheritedFromParent
,
CssMetaData<? extends Styleable, ?>...
the additional items
items
)

Utility method which combines CssMetaData items in one immutable list.

public static double

Returns:

the midpoint
computeMidPointY
(PathElement[]
the PathElements
path
)

Computes y midpoint of MoveTo and LineTo path elements.

public static boolean
public static String
dump(PathElement[] elements)

dumps the path element array to a compact human-readable string

private static int
eightBit(double val)

public static boolean
equals(Object a, Object b)

null-tolerant equals()

public static StyleAttributeMap
public static StyleAttributeMap
public static String
public static StyleAttributeMap

Returns:

the StyleAttributeMap instance
fromTextNode
(Text
the text node
textNode
)

Creates an instance of StyleAttributeMap which contains character attributes found in the specified Text node.

public static String
getImeText(InputMethodEvent ev)

Returns composed or committed text.

public static <T extends Node> T
getParentOfClass(Class<T> c, Node node)

returns a parent of the specified type, or null.

public static int
getTextLength(TextFlow f)

Computes text length for the TextFlow embedded into TextCell, ignoring unmanagement Nodes (highlights) and counting non-Text nodes as having length=1.

public static String

Returns:

font style: [ normal | italic | oblique ]
guessFontStyle
(String
font name, must be lowercase'd
lowerCaseName
)

Guesses the font style from the font name, until JDK-8092191 is implemented.

public static String

Returns:

font weight: [ normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 ]
guessFontWeight
(String
font name, must be lowercase'd
lowerCaseName
)

Guesses the font weight from the font name, until JDK-8092191 is implemented.

public static boolean

Returns:

true if the font is bold
isBold
(String
the font name converted to lower case
lowerCaseFontName
)

Returns true if the specified lowercased font name is determined to be bold.

public static boolean
isDarkScheme(Node n)

Returns true if the color scheme is DARK, checking first the node's scene, then platform preferences.

public static boolean

Returns:

true if the font is italic
isItalic
(String
the font name converted to lower case
lowerCaseFontName
)

Returns true if the specified lowercased font name is determined to be italic or oblique.

public static boolean

Returns:

true if the code point at the specified offset is a letter or a digit
isLetterOrDigit
(String
the text
text
,
int
the character offset
offset
)

Returns true if code point at the specified offset is a letter or a digit, returns false otherwise or if the offset is outside of the valid range.

public static boolean

Returns:

true if logical, false otherwise
isLogicalFont
(String
the font family
family
)

Returns true if the font family corresponds to a logical font as defined in OpenJFX Font Setup wiki.

public static boolean
public static void
layoutInArea(Node
the node to lay out
n
,
double
the horizontal offset of the layout area
x
,
double
the vertical offset of the layout area
y
,
double
the width of the layout area
w
,
double
the height of the layout area
h
)

Convenience method for laying out the node within its parent, filling the available area.

public static Integer

Returns:

the line offset
lineEnd
(TextFlow f, int
the line index
line
)

Returns the line end offset of the given line index.

public static int

Returns:

the line index
lineForOffset
(TextFlow f, int
the character offset
offset
)

Returns the line index of the given character offset.

public static Integer

Returns:

the line start offset
lineStart
(TextFlow f, int
the line index
line
)

Returns the line start offset of the given line index.

public static void
public static void
public static void
log(String format, Object... items)

public static void
public static int

Returns:

the offset of the next code point, or the end of the text string
nextCodePoint
(String
the text
text
,
int
the offset to start from
offset
)

Returns the offset of the next code point, or the end of the text string.

public static boolean
notEquals(Object a, Object b)

null-tolerant !equals()

private static void
private static int
public static Bounds[]
pathToBoundsArray(Node owner, PathElement[] elements)

Converts PathElement[] in the owner's coordinates to a Bounds[] in screen coordinates.

private static int
r(double x)

public static String

Returns:

the string
readString
(InputStream
the input stream
in
)

Reads a UTF8 string from the input stream.

public static String

Returns:

a non-null substring
substring
(String
source text or null
text
,
int
start offset, must be >= 0
start
,
int
end offset
end
)

A safe substring method which is tolerant to null text, and offsets being outside of the text boundaries.

public static String
public static String
toCssColor(Color c)

Converts Color to "#rrggbb" or "rgba(r,g,b,a)" string

public static String
public static PathElement[]

Returns:

translated path array, or null
translatePath
(Region
the target Region
tgt
,
Region
the source Region
src
,
PathElement[]
the path elements
elements
)

Translates path (which must contain only LineTo and MoveTo elements) from src frame of reference to the target frame of reference.

public static byte[]

Returns:

byte array containing PNG image
writePNG
(Image
source image
im
)

Writes an Image to a byte array in PNG format.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CALLERback to summary
private static final boolean CALLER

includes FILE.METHOD:LINE in the debug output

DEBUGback to summary
private static final boolean DEBUG

enables debug output

formatback to summary
private static final DecimalFormat format

Constructor Detail

RichUtilsback to summary
private RichUtils()

Method Detail

advancePositionback to summary
public static TextPos advancePosition(TextPos start, int offset)

Returns the text positions at a positive offset relative to the 'start' position.

canEditback to summary
public static boolean canEdit(RichTextArea rta)

returns true if both control and model are editable

combineback to summary
public static StyleAttributeMap combine(StyleAttributeMap lowPri, StyleAttributeMap hiPri)

Combines style attributes, returning combined object (or null).

Parameters
lowPri:StyleAttributeMap

the low priority attributes

hiPri:StyleAttributeMap

the high priority attributes

Returns:StyleAttributeMap

the combined attributes, or null

combineback to summary
public static List<CssMetaData<? extends Styleable, ?>> combine(List<CssMetaData<? extends Styleable, ?>> inheritedFromParent, CssMetaData<? extends Styleable, ?>... items)

Utility method which combines CssMetaData items in one immutable list.

The intended usage is to combine the parent and the child CssMetaData for the purposes of getClassCssMetaData() method, see for example Node#getClassCssMetaData().

Example:

private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES = CssMetaData.combine(
     <Parent>.getClassCssMetaData(),
     STYLEABLE1,
     STYLEABLE2
 );
This method returns an instance of a List that implements java.util.RandomAccess interface.
Parameters
inheritedFromParent:List<CssMetaData<? extends Styleable, ?>>

the CssMetaData items inherited from parent, must not be null

items:CssMetaData<? extends Styleable, ?>[]

the additional items

Returns:List<CssMetaData<? extends Styleable, ?>>

the immutable list containing all of the items

computeMidPointYback to summary
public static double computeMidPointY(PathElement[] path)

Computes y midpoint of MoveTo and LineTo path elements.

Parameters
path:PathElement[]

the PathElements

Returns:double

the midpoint

containsInlineNodesback to summary
public static boolean containsInlineNodes(StyleAttributeMap map)
dumpback to summary
public static String dump(PathElement[] elements)

dumps the path element array to a compact human-readable string

eightBitback to summary
private static int eightBit(double val)
equalsback to summary
public static boolean equals(Object a, Object b)

null-tolerant equals()

filterOutNodeAttributesback to summary
public static StyleAttributeMap filterOutNodeAttributes(StyleAttributeMap map)
filterUnsupportedAttributesback to summary
public static StyleAttributeMap filterUnsupportedAttributes(StyleAttributeMap map, Set<StyleAttribute<?>> supported)
formatDoubleback to summary
public static String formatDouble(Double value)
fromTextNodeback to summary
public static StyleAttributeMap fromTextNode(Text textNode)

Creates an instance of StyleAttributeMap which contains character attributes found in the specified Text node. The following attributes will be set:

Parameters
textNode:Text

the text node

Returns:StyleAttributeMap

the StyleAttributeMap instance

getImeTextback to summary
public static String getImeText(InputMethodEvent ev)

Returns composed or committed text.

getParentOfClassback to summary
public static <T extends Node> T getParentOfClass(Class<T> c, Node node)

returns a parent of the specified type, or null. if node is an instance of the specified class, returns node

getTextLengthback to summary
public static int getTextLength(TextFlow f)

Computes text length for the TextFlow embedded into TextCell, ignoring unmanagement Nodes (highlights) and counting non-Text nodes as having length=1.

guessFontStyleback to summary
public static String guessFontStyle(String lowerCaseName)

Guesses the font style from the font name, until JDK-8092191 is implemented.

Parameters
lowerCaseName:String

font name, must be lowercase'd

Returns:String

font style: [ normal | italic | oblique ]

guessFontWeightback to summary
public static String guessFontWeight(String lowerCaseName)

Guesses the font weight from the font name, until JDK-8092191 is implemented.

Parameters
lowerCaseName:String

font name, must be lowercase'd

Returns:String

font weight: [ normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 ]

isBoldback to summary
public static boolean isBold(String lowerCaseFontName)

Returns true if the specified lowercased font name is determined to be bold. This method is not guaranteed to work in any circumstances, see JDK-8092191

Parameters
lowerCaseFontName:String

the font name converted to lower case

Returns:boolean

true if the font is bold

isDarkSchemeback to summary
public static boolean isDarkScheme(Node n)

Returns true if the color scheme is DARK, checking first the node's scene, then platform preferences.

isItalicback to summary
public static boolean isItalic(String lowerCaseFontName)

Returns true if the specified lowercased font name is determined to be italic or oblique. This method is not guaranteed to work in any circumstances, see JDK-8092191

Parameters
lowerCaseFontName:String

the font name converted to lower case

Returns:boolean

true if the font is italic

isLetterOrDigitback to summary
public static boolean isLetterOrDigit(String text, int offset)

Returns true if code point at the specified offset is a letter or a digit, returns false otherwise or if the offset is outside of the valid range.

Parameters
text:String

the text

offset:int

the character offset

Returns:boolean

true if the code point at the specified offset is a letter or a digit

isLogicalFontback to summary
public static boolean isLogicalFont(String family)

Returns true if the font family corresponds to a logical font as defined in OpenJFX Font Setup wiki.

Parameters
family:String

the font family

Returns:boolean

true if logical, false otherwise

isTouchSupportedback to summary
public static boolean isTouchSupported()
layoutInAreaback to summary
public static void layoutInArea(Node n, double x, double y, double w, double h)

Convenience method for laying out the node within its parent, filling the available area. This method is equivalent to calling Region.layoutInArea(n, x, y, w, h, 0.0, Insets.EMPTY, true, true, HPos.CENTER, VPos.CENTER, snap);

Parameters
n:Node

the node to lay out

x:double

the horizontal offset of the layout area

y:double

the vertical offset of the layout area

w:double

the width of the layout area

h:double

the height of the layout area

lineEndback to summary
public static Integer lineEnd(TextFlow f, int line)

Returns the line end offset of the given line index.

Parameters
line:int

the line index

Returns:Integer

the line offset

lineForOffsetback to summary
public static int lineForOffset(TextFlow f, int offset)

Returns the line index of the given character offset.

Parameters
offset:int

the character offset

Returns:int

the line index

lineStartback to summary
public static Integer lineStart(TextFlow f, int line)

Returns the line start offset of the given line index.

Parameters
line:int

the line index

Returns:Integer

the line start offset

logback to summary
public static void log(Throwable e)
logback to summary
public static void log(Object x)
logback to summary
public static void log(String format, Object... items)
logback to summary
public static void log(Supplier<Object> x)
nextCodePointback to summary
public static int nextCodePoint(String text, int offset)

Returns the offset of the next code point, or the end of the text string.

Parameters
text:String

the text

offset:int

the offset to start from

Returns:int

the offset of the next code point, or the end of the text string

notEqualsback to summary
public static boolean notEquals(Object a, Object b)

null-tolerant !equals()

outputback to summary
private static void output(Object x)
parseIntback to summary
private static int parseInt(Object x)
pathToBoundsArrayback to summary
public static Bounds[] pathToBoundsArray(Node owner, PathElement[] elements)

Converts PathElement[] in the owner's coordinates to a Bounds[] in screen coordinates. It assumes the input array is a sequence of

MoveTo (top-left)
LineTo (to top-right)
LineTo (bottom-right)
LineTo (bottom-left)
LineTo (back to top-left)
This method will break if the input sequence is different.
rback to summary
private static int r(double x)
readStringback to summary
public static String readString(InputStream in) throws IOException

Reads a UTF8 string from the input stream. This method does not close the input stream.

Parameters
in:InputStream

the input stream

Returns:String

the string

Exceptions
IOException:
if an I/O error occurs
substringback to summary
public static String substring(String text, int start, int end)

A safe substring method which is tolerant to null text, and offsets being outside of the text boundaries.

Parameters
text:String

source text or null

start:int

start offset, must be >= 0

end:int

end offset

Returns:String

a non-null substring

toCssback to summary
public static String toCss(TextAlignment a)
toCssColorback to summary
public static String toCssColor(Color c)

Converts Color to "#rrggbb" or "rgba(r,g,b,a)" string

toWebColorback to summary
public static String toWebColor(Color c)
translatePathback to summary
public static PathElement[] translatePath(Region tgt, Region src, PathElement[] elements)

Translates path (which must contain only LineTo and MoveTo elements) from src frame of reference to the target frame of reference.

Parameters
tgt:Region

the target Region

src:Region

the source Region

elements:PathElement[]

the path elements

Returns:PathElement[]

translated path array, or null

Exceptions
RuntimeException:
if path elements contain something other than LineTo or MoveTo
writePNGback to summary
public static byte[] writePNG(Image im) throws IOException

Writes an Image to a byte array in PNG format.

Parameters
im:Image

source image

Returns:byte[]

byte array containing PNG image

Exceptions
IOException:
if an I/O error occurs