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 intprotected final Deque<BBCodeHandler.Block> protected final Deque<BBCodeHandler.Tag> protected final BBCodeHandler.Blockprotected int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddStyleIfPresent(Map<String, String> params, String name, String key, Collection<String> c) protected voidaddStyleIfPresent(Map<String, String> params, String key, Collection<String> c, String sep) protected voidprotected voidappendTextToCurrentBranch(BBCodeHandler.Tag tag, int textStart, int textLength) protected voidappendTextToRoot(javafx.scene.Node node) voidcharacters(int start, int length) Notifies about characters data that doesn't belong to any tag, i.e.protected voidprotected @Nullable BBCodeHandler.Tagprotected javafx.scene.NodecreateTextNode(BBCodeHandler.Tag tag, String text) voidNotifies that parsing has finished.voidNotifies about the end of the tag.protected <E extends Enum<E>>
EgetEnumValue(Class<E> c, @Nullable String value, E defaultValue) protected StringgetListItemNumber(javafx.scene.layout.GridPane grid) protected intgetListStartNumber(@Nullable String param) protected Stringprotected StringgetStyle()protected intparseIntOrDefault(@Nullable String s, int defaultValue) voidstartDocument(char[] doc) Notifies that parsing has started.voidNotifies 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:BBCodeHandlerNotifies that parsing has started.- Specified by:
startDocumentin interfaceBBCodeHandler- Parameters:
doc- parser input string
-
endDocument
public void endDocument()Description copied from interface:BBCodeHandlerNotifies that parsing has finished.- Specified by:
endDocumentin interfaceBBCodeHandler
-
startTag
public void startTag(String name, @Nullable @Nullable Map<String, String> params, int start, int length) Description copied from interface:BBCodeHandlerNotifies about the start of the tag. In case of self-closing tag this also notifies about the end of the tag.- Specified by:
startTagin 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:BBCodeHandlerNotifies about the end of the tag. In case of self-closing tag onlyBBCodeHandler.startTag(String, Map, int, int)method is called.- Specified by:
endTagin 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:BBCodeHandlerNotifies about characters data that doesn't belong to any tag, i.e. leading, intermediate or trailing text.- Specified by:
charactersin 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
-