Module atlantafx.base
Package atlantafx.base.util
Class BBCodeHandler.Default<T extends javafx.scene.layout.Pane>
java.lang.Object
atlantafx.base.util.BBCodeHandler.Default<T>
- All Implemented Interfaces:
BBCodeHandler
- Enclosing interface:
BBCodeHandler
public static class BBCodeHandler.Default<T extends javafx.scene.layout.Pane>
extends Object
implements BBCodeHandler
A basic
Some nodes, e.g.
BBCodeHandler
implementation.While parsing all created nodes will be added to the given root container.
The container choice depends on the actual markup. Default constructor accepts any
Pane
or its descendant. Using theTextFlow
for text-only markup
(no block nodes) and VBox
otherwise, is recommended.
Supported tags
Bold Text : text : [b]{text}[/b] Italic Text : text : [i]{text}[/i] Underlined Text : text : [u]{text}[/u] Strikethrough Text : text : [s]{text}[/s] Font Color : text : [color={color}]{text}[/color] Font Family : text : [font={monospace}]{text}[/font] Font Size : text : [size={size}]{text}[/size] Link : text : [url={url}]{text}[/url] [url url={url} class={class}]{text}[/url] Email : text : [email]{text}[/email] [email email={url} class={class}]{text}[/email] Style : text : [style={style}]{text}[/style] Subscript : text : [sub]{text}[/sub] Superscript : text : [sup]{text}[/sup] Heading : text : [heading]{text}[/heading] [heading={level}]{text}[/heading] Code : text : [code]{text}[/code] [code={class}]{text}[/code] Span : text : [span]{text}[/span] [span={class}]{text}[/span] [span style={style} class={class}]{text}[/span] Label : text : [label]{text}[/label] [label={class}]{text}[/label] [label style={style} class={class}]{text}[/label] Caption Text : text : [caption]{text}[/caption] Small Text : text : [small]{text}[/small] Abbreviation : text : [abbr="tooltip text"]{text}[/abbr] Unordered List : block : [ul] [li]Entry 1[/li] [li]Entry 2[/li] [/ul] [ul={bullet character}] [li]Entry 1[/li] [li]Entry 2[/li] [/ul] Ordered List : block : [ol] [li]Entry 1[/li] [li]Entry 2[/li] [/ol] [ol={start number or letter}] [li]Entry 1[/li] [li]Entry 2[/li] [/ol] Alignment : block : [left]{content}[/left] [center]{content}[/center] [right]{content}[/right] [align={javafx.geometry.Pos}]{content}[/align] Indentation : block : [indent]{content}[/indent] [indent=level]{content}[/indent] Horizontal Rule : block : [hr/] [hr=thickness/]
- If a tag param contains whitespaces or trailing slash is must be enclosed in double or single quotes.
- If a tag only has a single param, it can be shortened to the
[name=value]{text}[/name]
. In this case the tag param name considered to be equal to the tag name. - Unknown tag params will be ignored.
Action Events
Some nodes, e.g.
Hyperlink
require action handlers. To avoid traversing
the root container's node graph you can add an event filter.
var input = "Visit the [url=https://example.com]website[/url].";
var textFlow = BBCodeParser.createLayout(input);
textFlow.addEventFilter(ActionEvent.ACTION, e-> {
if (e.getTarget() instanceof Hyperlink link) {
openURL(link.getUserData());
}
e.consume();
});
-
Nested Class Summary
Nested classes/interfaces inherited from interface atlantafx.base.util.BBCodeHandler
BBCodeHandler.Block, BBCodeHandler.Default<T extends javafx.scene.layout.Pane>, BBCodeHandler.Tag
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected char[]
protected static final int
protected final Deque
<BBCodeHandler.Block> protected final Deque
<BBCodeHandler.Tag> protected final BBCodeHandler.Block
protected int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addStyleIfPresent
(Map<String, String> params, String name, String key, Collection<String> c) protected void
addStyleIfPresent
(Map<String, String> params, String key, Collection<String> c, String sep) protected void
protected void
appendTextToCurrentBranch
(BBCodeHandler.Tag tag, int textStart, int textLength) protected void
appendTextToRoot
(javafx.scene.Node node) void
characters
(int start, int length) Notifies about characters data that doesn't belong to any tag, i.e.protected void
protected @Nullable BBCodeHandler.Tag
protected javafx.scene.Node
createTextNode
(BBCodeHandler.Tag tag, String text) void
Notifies that parsing has finished.void
Notifies about the end of the tag.protected <E extends Enum<E>>
EgetEnumValue
(Class<E> c, @Nullable String value, E defaultValue) protected String
getListItemNumber
(javafx.scene.layout.GridPane grid) protected int
getListStartNumber
(@Nullable String param) protected String
protected String
getStyle()
protected int
parseIntOrDefault
(@Nullable String s, int defaultValue) void
startDocument
(char[] doc) Notifies that parsing has started.void
Notifies about the start of the tag.
-
Field Details
-
OL_LETTER_OFFSET
protected static final int OL_LETTER_OFFSET- See Also:
-
root
-
openTags
-
openBlocks
-
doc
protected char[] doc -
textCursor
protected int textCursor
-
-
Constructor Details
-
Default
-
-
Method Details
-
startDocument
public void startDocument(char[] doc) Description copied from interface:BBCodeHandler
Notifies that parsing has started.- Specified by:
startDocument
in interfaceBBCodeHandler
- Parameters:
doc
- parser input string
-
endDocument
public void endDocument()Description copied from interface:BBCodeHandler
Notifies that parsing has finished.- Specified by:
endDocument
in interfaceBBCodeHandler
-
startTag
public void startTag(String name, @Nullable @Nullable Map<String, String> params, int start, int length) Description copied from interface:BBCodeHandler
Notifies about the start of the tag. In case of self-closing tag this also notifies about the end of the tag.- Specified by:
startTag
in interfaceBBCodeHandler
- Parameters:
name
- The tag name.params
- The tag params.start
- The tag start position, i.e. the position of open square bracket (not the tag name start).length
- The tag length, including closing bracket.
-
endTag
Description copied from interface:BBCodeHandler
Notifies about the end of the tag. In case of self-closing tag onlyBBCodeHandler.startTag(String, Map, int, int)
method is called.- Specified by:
endTag
in interfaceBBCodeHandler
- Parameters:
name
- The tag name.start
- The tag start position, i.e. the position of open square bracket (not the tag name start).length
- The tag length, including closing bracket.
-
characters
public void characters(int start, int length) Description copied from interface:BBCodeHandler
Notifies about characters data that doesn't belong to any tag, i.e. leading, intermediate or trailing text.- Specified by:
characters
in interfaceBBCodeHandler
- Parameters:
start
- The text start position.length
- The text length.
-
createTag
@Nullable protected @Nullable BBCodeHandler.Tag createTag(String name, @Nullable @Nullable Map<String, String> params) -
appendTextToRoot
protected void appendTextToRoot(javafx.scene.Node node) -
appendTextToCurrentBranch
-
createTextNode
-
createBranch
protected void createBranch() -
appendSelfCloseTag
-
addStyleIfPresent
-
addStyleIfPresent
-
getEnumValue
-
getListStartNumber
-
parseIntOrDefault
-
getParamOrDefault
-
getListItemNumber
-
getStyleClass
-
getStyle
-