Top Description Inners Fields Constructors Methods
jfx.incubator.scene.control.richtext.model

public Class RichTextFormatHandler

extends DataFormatHandler
Class Inheritance
Imports
java.io.BufferedWriter, .IOException, .OutputStream, .OutputStreamWriter, .StringWriter, .Writer, java.nio.charset.Charset, java.util.ArrayList, .Collections, .Comparator, .HashMap, javafx.scene.input.DataFormat, javafx.scene.paint.Color, javafx.scene.text.TextAlignment, javafx.util.StringConverter, javafx.util.converter.DoubleStringConverter, com.sun.jfx.incubator.scene.control.richtext.Converters, .RichTextFormatHandlerHelper, jfx.incubator.scene.control.richtext.StyleResolver, .TextPos

A DataFormatHandler for use with attribute-based rich text models.

The handler uses a simple text-based format:

(*) denotes an optional element.

PARAGRAPH[]

PARAGRAPH: {
    PARAGRAPH_ATTRIBUTE[]*,
    TEXT_SEGMENT[],
    "\n"
}

PARAGRAPH_ATTRIBUTE: {
    "{!"
    (name)
    ATTRIBUTE_VALUE[]*
    "}"
}

ATTRIBUTE: {
    "{"
    (name)
    ATTRIBUTE_VALUE[]*
    "}"
}

ATTRIBUTE_VALUE: {
    |
    (value)
}

TEXT_SEGMENT: {
    ATTRIBUTE[]*
    (text string with escaped special characters)
}
Attribute sequences are further deduplicated, using a single {number} token which specifies the index into the list of unique sets of attributes. Paragraph attribute sets are treated as separate from the segment attrubite sets.

The following characters are escaped in text segments: {,%,} The escape format is %XX where XX is a hexadecimal value.

Example:

{c|ff00ff}text{b}bold{!rtl}\n
{1}line 2{!0}\n
Since
24

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
RichTextFormatHandler.Handler<T>

attribute handler

private class
private class

Field Summary

Modifier and TypeField and Description
private static final StringConverter<Boolean>
private static final StringConverter<Color>
public static final DataFormat
DATA_FORMAT

The data format identifier

private static final boolean
private static final StringConverter<ParagraphDirection>
private static final DoubleStringConverter
private final HashMap<Object, RichTextFormatHandler.Handler<T>>
private static final RichTextFormatHandler
private static final StringConverter<String>
private static final StringConverter<TextAlignment>

Constructor Summary

AccessConstructor and Description
private
RichTextFormatHandler()

Constructor.

Method Summary

Modifier and TypeMethod and Description
private <T> void
private <T> void
private void
private void
public Object
copy(StyledTextModel
source model
m
,
StyleResolver
view-specific style resolver
r
,
TextPos
start text position
start
,
TextPos
end text position
end
)

Implements abstract jfx.incubator.scene.control.richtext.model.DataFormatHandler.copy.

Creates an object to be put into the Clipboard for the given text range.

public StyledInput
createStyledInput(String
the input string
input
,
StyleAttributeMap
the style attributes (can be null)
attr
)

Implements abstract jfx.incubator.scene.control.richtext.model.DataFormatHandler.createStyledInput.

Creates a StyledInput for the given input string.

private StyledOutput
public static final RichTextFormatHandler

Returns:

the singleton instance of RtfFormatHandler
getInstance
()

Returns the singleton instance of RtfFormatHandler.

private static void
private static boolean
private static void
public void
save(StyledTextModel
source model
m
,
StyleResolver
view-specific style resolver
r
,
TextPos
start text position
start
,
TextPos
end text position
end
,
OutputStream
target OutputStream
out
)

Implements abstract jfx.incubator.scene.control.richtext.model.DataFormatHandler.save.

Save the text range in the handler's format to the output stream (e.g. save to file).

Inherited from jfx.incubator.scene.control.richtext.model.DataFormatHandler:
getDataFormat

Field Detail

BOOLEAN_CONVERTERback to summary
private static final StringConverter<Boolean> BOOLEAN_CONVERTER
COLOR_CONVERTERback to summary
private static final StringConverter<Color> COLOR_CONVERTER
DATA_FORMATback to summary
public static final DataFormat DATA_FORMAT

The data format identifier

DEBUGback to summary
private static final boolean DEBUG
DIRECTION_CONVERTERback to summary
private static final StringConverter<ParagraphDirection> DIRECTION_CONVERTER
DOUBLE_CONVERTERback to summary
private static final DoubleStringConverter DOUBLE_CONVERTER
handlersback to summary
private final HashMap<Object, RichTextFormatHandler.Handler<T>> handlers
instanceback to summary
private static final RichTextFormatHandler instance
STRING_CONVERTERback to summary
private static final StringConverter<String> STRING_CONVERTER
TEXT_ALIGNMENT_CONVERTERback to summary
private static final StringConverter<TextAlignment> TEXT_ALIGNMENT_CONVERTER

Constructor Detail

RichTextFormatHandlerback to summary
private RichTextFormatHandler()

Constructor.

Method Detail

addHandlerback to summary
private <T> void addHandler(StyleAttribute<T> a, String id, StringConverter<T> converter)
addHandlerback to summary
private <T> void addHandler(RichTextFormatHandler.Handler<T> h)
addHandlerBooleanback to summary
private void addHandlerBoolean(StyleAttribute<Boolean> a, String id)
addHandlerStringback to summary
private void addHandlerString(StyleAttribute<String> a, String id)
copyback to summary
public Object copy(StyledTextModel m, StyleResolver r, TextPos start, TextPos end) throws IOException

Implements abstract jfx.incubator.scene.control.richtext.model.DataFormatHandler.copy.

Doc from jfx.incubator.scene.control.richtext.model.DataFormatHandler.copy.

Creates an object to be put into the Clipboard for the given text range. The caller must guarantee that the start precedes the end position.

Typically, the implementation creates an instance of StyledOutput and calls StyledTextModel#export(TextPos, TextPos, StyledOutput) method.

Parameters
m:StyledTextModel

source model

r:StyleResolver

view-specific style resolver

start:TextPos

start text position

end:TextPos

end text position

Returns:Object

an object to be placed to the Clipboard

Annotations
@Override
Exceptions
IOException:
when an I/O error occurs
createStyledInputback to summary
public StyledInput createStyledInput(String input, StyleAttributeMap attr)

Implements abstract jfx.incubator.scene.control.richtext.model.DataFormatHandler.createStyledInput.

Doc from jfx.incubator.scene.control.richtext.model.DataFormatHandler.createStyledInput.

Creates a StyledInput for the given input string. When pasting, the caller may pass the style attributes attr at the insertion point. This argument may be used by the implementation if the format contains no styles on its own (for example, in the plain text format case).

Parameters
input:String

the input string

attr:StyleAttributeMap

the style attributes (can be null)

Returns:StyledInput

the StyledInput

Annotations
@Override
createStyledOutputback to summary
private StyledOutput createStyledOutput(StyleResolver r, Writer wr)
getInstanceback to summary
public static final RichTextFormatHandler getInstance()

Returns the singleton instance of RtfFormatHandler.

Returns:RichTextFormatHandler

the singleton instance of RtfFormatHandler

initAccessorback to summary
private static void initAccessor()
isBufferedback to summary
private static boolean isBuffered(Writer x)
logback to summary
private static void log(Object x)
saveback to summary
public void save(StyledTextModel m, StyleResolver r, TextPos start, TextPos end, OutputStream out) throws IOException

Implements abstract jfx.incubator.scene.control.richtext.model.DataFormatHandler.save.

Doc from jfx.incubator.scene.control.richtext.model.DataFormatHandler.save.

Save the text range in the handler's format to the output stream (e.g. save to file). The caller must guarantee that the start precedes the end position. It is the responsibility of the caller to close the OutputStream.

Typically, the implementation creates an instance of StyledOutput and calls StyledTextModel#export(TextPos, TextPos, StyledOutput) method.

Parameters
m:StyledTextModel

source model

r:StyleResolver

view-specific style resolver

start:TextPos

start text position

end:TextPos

end text position

out:OutputStream

target OutputStream

Annotations
@Override
Exceptions
IOException:
when an I/O error occurs
jfx.incubator.scene.control.richtext.model back to summary

pack-priv Class RichTextFormatHandler.Handler<T>

extends Object
Class Inheritance
  • java.lang.Object
  • jfx.incubator.scene.control.richtext.model.RichTextFormatHandler.Handler

attribute handler

Field Summary

Modifier and TypeField and Description
private final StyleAttribute<T>
private final StringConverter<T>
private final String

Constructor Summary

AccessConstructor and Description
public
Handler(StyleAttribute<T> attribute, String id, StringConverter<T> converter)

Method Summary

Modifier and TypeMethod and Description
public String
public StyleAttribute<T>
public boolean
isAllowed(T value)

public T
public String
write(T value)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributeback to summary
private final StyleAttribute<T> attribute
converterback to summary
private final StringConverter<T> converter
idback to summary
private final String id

Constructor Detail

Handlerback to summary
public Handler(StyleAttribute<T> attribute, String id, StringConverter<T> converter)

Method Detail

getIdback to summary
public String getId()
getStyleAttributeback to summary
public StyleAttribute<T> getStyleAttribute()
isAllowedback to summary
public boolean isAllowed(T value)
readback to summary
public T read(String s)
writeback to summary
public String write(T value)
jfx.incubator.scene.control.richtext.model back to summary

private Class RichTextFormatHandler.RichStyledInput

extends Object
implements StyledInput
Class Inheritance
  • java.lang.Object
  • jfx.incubator.scene.control.richtext.model.RichTextFormatHandler.RichStyledInput
All Implemented Interfaces
jfx.incubator.scene.control.richtext.model.StyledInput, java.io.Closeable, java.lang.AutoCloseable

importer

Field Summary

Modifier and TypeField and Description
private int
private int
private StringBuilder
private final ArrayList<StyleAttributeMap>
private final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private int
charAt(int delta)

public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

private static int
decodeHex(int ch)

private int
private String
private String
decodeText(int start, int ix)

private IOException
err(Object text)

public StyledSegment
nextSegment()

Implements jfx.incubator.scene.control.richtext.model.StyledInput.nextSegment.

Returns the next segment, or null if no more segments.

private StyleAttributeMap
parseAttributes(boolean forParagraph)

private int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

indexback to summary
private int index
lineback to summary
private int line
sbback to summary
private StringBuilder sb
stylesback to summary
private final ArrayList<StyleAttributeMap> styles
textback to summary
private final String text

Constructor Detail

RichStyledInputback to summary
public RichStyledInput(String text)

Method Detail

charAtback to summary
private int charAt(int delta)
closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
decodeHexback to summary
private static int decodeHex(int ch) throws IOException
decodeHexByteback to summary
private int decodeHexByte() throws IOException
decodeTextback to summary
private String decodeText() throws IOException
decodeTextback to summary
private String decodeText(int start, int ix) throws IOException
errback to summary
private IOException err(Object text)
nextSegmentback to summary
public StyledSegment nextSegment()

Implements jfx.incubator.scene.control.richtext.model.StyledInput.nextSegment.

Doc from jfx.incubator.scene.control.richtext.model.StyledInput.nextSegment.

Returns the next segment, or null if no more segments.

Returns:StyledSegment

the next segment, or null if no more segments

Annotations
@Override
parseAttributesback to summary
private StyleAttributeMap parseAttributes(boolean forParagraph) throws IOException
parseStyleNumberback to summary
private int parseStyleNumber(String s) throws IOException
jfx.incubator.scene.control.richtext.model back to summary

private Class RichTextFormatHandler.RichStyledOutput

extends Object
implements StyledOutput
Class Inheritance
  • java.lang.Object
  • jfx.incubator.scene.control.richtext.model.RichTextFormatHandler.RichStyledOutput
All Implemented Interfaces
jfx.incubator.scene.control.richtext.model.StyledOutput, java.io.Closeable, java.lang.AutoCloseable

exporter

Field Summary

Modifier and TypeField and Description
private final StyleResolver
private HashMap<StyleAttributeMap, Integer>
private final Writer

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public void
consume(StyledSegment
the segment to output
seg
)

Implements jfx.incubator.scene.control.richtext.model.StyledOutput.consume.

Consumes the next styled segment.

private void
emitAttributes(StyleAttributeMap attrs, boolean forParagraph)

private static String
encode(String text)

public void
private static int
private static boolean
isSpecialChar(char c)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

resolverback to summary
private final StyleResolver resolver
stylesback to summary
private HashMap<StyleAttributeMap, Integer> styles
wrback to summary
private final Writer wr

Constructor Detail

RichStyledOutputback to summary
public RichStyledOutput(StyleResolver r, Writer wr)

Method Detail

closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
consumeback to summary
public void consume(StyledSegment seg) throws IOException

Implements jfx.incubator.scene.control.richtext.model.StyledOutput.consume.

Doc from jfx.incubator.scene.control.richtext.model.StyledOutput.consume.

Consumes the next styled segment.

Parameters
seg:StyledSegment

the segment to output

Annotations
@Override
Exceptions
IOException:
when an I/O error occurs
emitAttributesback to summary
private void emitAttributes(StyleAttributeMap attrs, boolean forParagraph) throws IOException
encodeback to summary
private static String encode(String text)
flushback to summary
public void flush() throws IOException

Implements jfx.incubator.scene.control.richtext.model.StyledOutput.flush.

Doc from jfx.incubator.scene.control.richtext.model.StyledOutput.flush.

Flushes this output stream.

Annotations
@Override
Exceptions
IOException:
when an I/O error occurs
indexOfSpecialCharback to summary
private static int indexOfSpecialChar(String text)
isSpecialCharback to summary
private static boolean isSpecialChar(char c)