Class DecoratedTextFactory
- java.lang.Object
-
- ch.sahits.game.openpatrician.javafx.service.DecoratedTextFactory
-
public class DecoratedTextFactory extends java.lang.ObjectFactory method to create a decorated text from a template.- Author:
- Andi Hotz, (c) Sahits GmbH, 2014 Created on Nov 10, 2014
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBALE_ICONstatic java.lang.StringBARREL_ICONstatic java.lang.StringCOIN_ICONstatic java.lang.StringGENERIC_ICONstatic java.lang.StringIMAGEstatic java.lang.StringSEGMENT_IMAGE
-
Constructor Summary
Constructors Constructor Description DecoratedTextFactory(int leftInset, int topInset, int wrappingWidth)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DecoratedTextcreateDecoratedText(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.DecoratedTextcreateDecoratedText(java.lang.String template, java.util.Map<java.lang.String,java.lang.Object> parameters)Create a decorated text from the template string.javafx.scene.control.LabelcreateLabel(java.lang.String template)javafx.scene.layout.VBoxcreateMultiParagraphContainer()DecoratedTextcreateSimpleDecoratedText(java.lang.String template)java.lang.StringreplaceTextParameters(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
-
-
-
Field Detail
-
COIN_ICON
public static final java.lang.String COIN_ICON
- See Also:
- Constant Field Values
-
BARREL_ICON
public static final java.lang.String BARREL_ICON
- See Also:
- Constant Field Values
-
BALE_ICON
public static final java.lang.String BALE_ICON
- See Also:
- Constant Field Values
-
GENERIC_ICON
public static final java.lang.String GENERIC_ICON
- See Also:
- Constant Field Values
-
SEGMENT_IMAGE
public static final java.lang.String SEGMENT_IMAGE
- See Also:
- Constant Field Values
-
IMAGE
public static final java.lang.String IMAGE
- See Also:
- Constant Field Values
-
-
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])
- Parameters:
template- template stringparameters- 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)
-
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])
- Parameters:
template- template stringstyleClass- 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 placeholdersparameters- to replace the parameters- Returns:
- finalized string
-
-