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 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();
 });
 
  • Field Details

  • Constructor Details

    • Default

      public Default(T root)
      Creates a new handler instance.
      Parameters:
      root - root container
  • Method Details

    • startDocument

      public void startDocument(char[] doc)
      Description copied from interface: BBCodeHandler
      Notifies that parsing has started.
      Specified by:
      startDocument in interface BBCodeHandler
      Parameters:
      doc - parser input string
    • endDocument

      public void endDocument()
      Description copied from interface: BBCodeHandler
      Notifies that parsing has finished.
      Specified by:
      endDocument in interface BBCodeHandler
    • 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 interface BBCodeHandler
      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

      public void endTag(String name, int start, int length)
      Description copied from interface: BBCodeHandler
      Notifies about the end of the tag. In case of self-closing tag only BBCodeHandler.startTag(String, Map, int, int) method is called.
      Specified by:
      endTag in interface BBCodeHandler
      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 interface BBCodeHandler
      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

      protected void appendTextToCurrentBranch(BBCodeHandler.Tag tag, int textStart, int textLength)
    • createTextNode

      protected javafx.scene.Node createTextNode(BBCodeHandler.Tag tag, String text)
    • createBranch

      protected void createBranch()
    • appendSelfCloseTag

      protected void appendSelfCloseTag(BBCodeHandler.Tag tag)
    • addStyleIfPresent

      protected void addStyleIfPresent(Map<String,String> params, String name, String key, Collection<String> c)
    • addStyleIfPresent

      protected void addStyleIfPresent(Map<String,String> params, String key, Collection<String> c, String sep)
    • getEnumValue

      protected <E extends Enum<E>> E getEnumValue(Class<E> c, @Nullable @Nullable String value, E defaultValue)
    • getListStartNumber

      protected int getListStartNumber(@Nullable @Nullable String param)
    • parseIntOrDefault

      protected int parseIntOrDefault(@Nullable @Nullable String s, int defaultValue)
    • getParamOrDefault

      protected String getParamOrDefault(Map<String,String> params, String key, String defaultValue)
    • getListItemNumber

      protected String getListItemNumber(javafx.scene.layout.GridPane grid)
    • getStyleClass

      protected Set<String> getStyleClass()
    • getStyle

      protected String getStyle()