Class DecoratedTextFactory
- java.lang.Object
-
- ch.sahits.game.openpatrician.javafx.service.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 Summary
Fields Modifier and Type Field Description static java.lang.String
BALE_ICON
static java.lang.String
BARREL_ICON
static java.lang.String
COIN_ICON
private org.springframework.context.ApplicationContext
context
private IFontLoader
fontLoader
static java.lang.String
GENERIC_ICON
static java.lang.String
IMAGE
private SelectiveCachableXMLImageLoader
imageLoader
private int
leftInset
static java.lang.String
SEGMENT_IMAGE
private int
topInset
private int
wrappingWidth
-
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 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.DecoratedText
createDecoratedText(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.Label
createLabel(java.lang.String template)
javafx.scene.layout.VBox
createMultiParagraphContainer()
private javafx.scene.shape.Shape
createSegmentedShape(double width, double heigth, java.util.List<java.lang.Integer> visibleSegments)
DecoratedText
createSimpleDecoratedText(java.lang.String template)
private DecoratedText
initializeDecoratedText(java.lang.String template, java.util.Map<java.lang.String,java.lang.Object> parameters, DecoratedText text)
private boolean
isSpecialKey(java.lang.String key)
private DecoratedText
replaceParameters(DecoratedText text, java.lang.String template, java.util.Map<java.lang.String,java.lang.Object> parameters)
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)
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)
private DecoratedText
replaceSpecialParameter(DecoratedText text, java.util.Map<java.lang.String,java.lang.Object> parameters, java.lang.String tail, java.lang.String key)
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
-
-
-
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
-
leftInset
private final int leftInset
-
topInset
private final int topInset
-
wrappingWidth
private final int wrappingWidth
-
imageLoader
@Autowired @Qualifier("xmlImageLoader") private SelectiveCachableXMLImageLoader imageLoader
-
fontLoader
@Autowired private IFontLoader fontLoader
-
context
@Autowired private org.springframework.context.ApplicationContext context
-
-
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)
-
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])
- 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
-
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)
-
-