Class DecoratedTextFactory


  • public class DecoratedTextFactory
    extends java.lang.Object
    Factory method to create a decorated text from a template.
    Author:
    Andi Hotz, (c) Sahits GmbH, 2014 Created on Nov 10, 2014
    • Field Detail

      • leftInset

        private final int leftInset
      • topInset

        private final int topInset
      • wrappingWidth

        private final int wrappingWidth
      • fontLoader

        @Autowired
        private IFontLoader fontLoader
      • context

        @Autowired
        private org.springframework.context.ApplicationContext context
    • Constructor Detail

      • DecoratedTextFactory

        public DecoratedTextFactory​(int leftInset,
                                    int topInset,
                                    int wrappingWidth)
    • Method Detail

      • createMultiParagraphContainer

        public javafx.scene.layout.VBox createMultiParagraphContainer()
      • createDecoratedText

        public DecoratedText createDecoratedText​(java.lang.String template,
                                                 java.util.Map<java.lang.String,​java.lang.Object> parameters)
        Create a decorated text from the template string. The template string can contain placeholders, that are replaced through objects in the parameters Map. The normal replacement uses the toString() method on the map entry's value. There are some special cases where a specific Node is created to represent the placeholder.
        Special placeholders:
        • icon:Coin: Coin icon followed by the amount passed in as parameter ([icon:Coin coinAmount])
        • icon:Barrel: Barrel icon followed by the amount passed in as a parameter ([icon:Barrel amount])
        • icon:Bale: Bale icon followed by the amount passed in as a parameter ([icon:Bale amount])
        • icon:Generic: generic icon that is passed as parameter([icon:Generic icons/64/cannonball_icon]). The icon is scaled so it matches the line hight.
        • image:Segment: segmented image split up in 9 segments and only the specified parts are visible ([image:Segment mapSegment1.png visibleSegments])
        • image: centered image ([image imageName])
        The amounts for Coin Barrel and Bale may also be already provided, e.g replaced as part of the message retrevial. In this case it is important that the amount is an unformatted integer. ([icon:Coin{0, number, #}]).
        Parameters:
        template - template string
        parameters - Map containing the parameters.
        Returns:
        new Decorated instance based on a template and parameters
      • createLabel

        public javafx.scene.control.Label createLabel​(java.lang.String template)
      • createSimpleDecoratedText

        public DecoratedText createSimpleDecoratedText​(java.lang.String template)
      • initializeDecoratedText

        private DecoratedText initializeDecoratedText​(java.lang.String template,
                                                      java.util.Map<java.lang.String,​java.lang.Object> parameters,
                                                      DecoratedText text)
      • createDecoratedText

        public DecoratedText createDecoratedText​(java.lang.String template,
                                                 java.lang.String styleClass,
                                                 java.util.Map<java.lang.String,​java.lang.Object> parameters)
        Create a decorated text from the template string. The template string can contain placeholders, that are replaced through objects in the parameters Map. The normal replacement uses the toString() method on the map entry's value. There are some special cases where a specific Node is created to represent the placeholder.
        Special placeholders:
        • icon:Coin: Coin icon followed by the amount passed in as parameter ([icon:Coin coinAmount])
        • icon:Barrel: Barrel icon followed by the amount passed in as a parameter ([icon:Barrel amount])
        • icon:Bale: Bale icon followed by the amount passed in as a parameter ([icon:Bale amount])
        • image:Segment: segmented image split up in 9 segments and only the specified parts are visible ([image:Segment mapSegment1.png visibleSegments])
        • image: centered image ([image imageName])
        The amounts for Coin Barrel and Bale may also be already provided, e.g replaced as part of the message retrevial. In this case it is important that the amount is an unformatted integer. ([icon:Coin{0, number, #}]).
        Parameters:
        template - template string
        styleClass - style class from the base.css to be applied on the Decorated Text.
        parameters - Map containing the parameters.
        Returns:
        new instance of decorated text based on a template and parameters and styled with the style class.
      • replaceTextParameters

        public java.lang.String replaceTextParameters​(java.lang.String template,
                                                      java.util.Map<java.lang.String,​java.lang.Object> parameters)
        Replace the placeholders in the template with the values from the parameters object
        Parameters:
        template - string containing placeholders
        parameters - to replace the parameters
        Returns:
        finalized string
      • replaceParameters

        private DecoratedText replaceParameters​(DecoratedText text,
                                                java.lang.String template,
                                                java.util.Map<java.lang.String,​java.lang.Object> parameters)
      • replaceSpecialParameter

        private DecoratedText replaceSpecialParameter​(DecoratedText text,
                                                      java.util.Map<java.lang.String,​java.lang.Object> parameters,
                                                      java.lang.String tail,
                                                      java.lang.String key)
      • createSegmentedShape

        private javafx.scene.shape.Shape createSegmentedShape​(double width,
                                                              double heigth,
                                                              java.util.List<java.lang.Integer> visibleSegments)
      • isSpecialKey

        private boolean isSpecialKey​(java.lang.String key)
      • replaceSimpleParameter

        private DecoratedText replaceSimpleParameter​(DecoratedText text,
                                                     java.util.Map<java.lang.String,​java.lang.Object> parameters,
                                                     java.lang.String head,
                                                     java.lang.String tail,
                                                     java.lang.String key)
      • replaceSimpleParameter

        private java.lang.String replaceSimpleParameter​(java.util.Map<java.lang.String,​java.lang.Object> parameters,
                                                        java.lang.String head,
                                                        java.lang.String tail,
                                                        java.lang.String key)