public DecoratedText createSimpleDecoratedText(String template) { DecoratedText text = new DecoratedText(); text.setText(template); return text; }
/** * 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.<br> * Special placeholders: * <ul> * <li>icon:Coin: Coin icon followed by the amount passed in as parameter ([icon:Coin coinAmount])</li> * <li>icon:Barrel: Barrel icon followed by the amount passed in as a parameter ([icon:Barrel amount])</li> * <li>icon:Bale: Bale icon followed by the amount passed in as a parameter ([icon:Bale amount])</li> * <li>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.</li> * <li>image:Segment: segmented image split up in 9 segments and only the specified parts are visible ([image:Segment mapSegment1.png visibleSegments])</li> * <li>image: centered image ([image imageName])</li> * </ul> * 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, #}]). * @param template template string * @param parameters Map containing the parameters. * @return new Decorated instance based on a template and parameters */ public DecoratedText createDecoratedText(String template, Map<String, Object> parameters) { DecoratedText text = new DecoratedText(); return initializeDecoratedText(template, parameters, text); } public Label createLabel(String template) {
/** * 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.<br> * Special placeholders: * <ul> * <li>icon:Coin: Coin icon followed by the amount passed in as parameter ([icon:Coin coinAmount])</li> * <li>icon:Barrel: Barrel icon followed by the amount passed in as a parameter ([icon:Barrel amount])</li> * <li>icon:Bale: Bale icon followed by the amount passed in as a parameter ([icon:Bale amount])</li> * <li>image:Segment: segmented image split up in 9 segments and only the specified parts are visible ([image:Segment mapSegment1.png visibleSegments])</li> * <li>image: centered image ([image imageName])</li> * </ul> * 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, #}]). * @param template template string * @param styleClass style class from the base.css to be applied on the Decorated Text. * @param parameters Map containing the parameters. * @return new instance of decorated text based on a template and parameters and styled with the style class. */ public DecoratedText createDecoratedText(String template, String styleClass, Map<String, Object> parameters) { DecoratedText text = new DecoratedText(styleClass); return initializeDecoratedText(template, parameters, text); }
private ObjectProperty<DecoratedText> createWeaponStrength(IShip currentShip) { int strength = shipService.calculateShipsWeaponsStrength(currentShip); String key = null; if (strength > 0) { if (strength % 2 != 0) { if (strength == 1) { key = "ch.sahits.game.openpatrician.model.ship.impl.Ship.weaponStrengthOne"; } else { key = "ch.sahits.game.openpatrician.model.ship.impl.Ship.weaponStrengthUneven"; } } else { key = "ch.sahits.game.openpatrician.model.ship.impl.Ship.weaponStrengthEven"; } strength /= 2; String template = messageSource.getMessage(key, new Object[]{strength}, locale.getCurrentLocal()); DecoratedText text = textFactory.createDecoratedText(template, new HashMap<>()); text.setId("weaponStrength"); return new SimpleObjectProperty<>(text); } else { return new SimpleObjectProperty<>(new DecoratedText()); } }
@PostConstruct private void initializeDialog() { setTitle(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernFugitiveDialog.title", new Object[]{}, locale.getCurrentLocal())); initializeButtons(); IFugitive fugitive = (IFugitive) currentPerson.get(); DecoratedText text = new DecoratedText(); text.setLayoutX(2 * Dialog.FRAME_BORDER); text.setLayoutY(100); text.setWrappingWidth(Dialog.WRAPPING_WIDTH); String loadedText = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernFugitiveDialog.dialog", new Object[0], locale.getCurrentLocal()); HashMap<String, Object> parameters = new HashMap<>(); parameters.put("destination", fugitive.getDestination().getName()); parameters.put("amount", fugitive.getPremium()); DecoratedText dt = decoratedTextFactory.createDecoratedText(loadedText, parameters); getContent().addAll(dt); }
DecoratedText text = new DecoratedText(); String messageString = ellipsisCalculator.calculateEllipsis(text.getFont(), translatedMessage, maxWidth); text = textFactory.createSimpleDecoratedText(messageString);