public DecoratedText createSimpleDecoratedText(String template) { DecoratedText text = new DecoratedText(); text.setText(template); return text; }
private DecoratedText initializeDecoratedText(final String template, Map<String, Object> parameters, DecoratedText text) { text.getStylesheets().add(DecoratedText.class.getResource(DecoratedText.class.getSimpleName() + ".css").toExternalForm()); text.getStyleClass().add("decoratedText"); text.setLayoutY(topInset); text.setLayoutX(leftInset); text.setWrappingWidth(wrappingWidth); String[] lines = template.split("\n"); for (int i = 0; i < lines.length; i++) { String curTemplate = lines[i]; if (i == lines.length -1 && template.endsWith("\n") || i < lines.length -1){ curTemplate += "\n"; } text = replaceParameters(text, curTemplate, parameters); } return text; }
private DecoratedText replaceSimpleParameter(DecoratedText text, Map<String, Object> parameters, String head, String tail, String key) { if (tail.startsWith("\n")) { text.append(head + parameters.get(key) + "\n"); tail = tail.substring(1); if (tail.length() > 0) { return replaceParameters(text, tail, parameters); } else { return text; } } else { text.append(head + parameters.get(key)); if (tail.length() > 0) { return replaceParameters(text, tail, parameters); } else { return text; } } } private String replaceSimpleParameter(Map<String, Object> parameters, String head, String tail, String key) {
/** * Constructor using the base.css style sheet and the supplied style class to define the font. */ public DecoratedText(String styleClass) { super(Orientation.HORIZONTAL); wrappingWidth = new SimpleIntegerProperty(this, "wrappingWidth", 0); getStylesheets().add(getClass().getResource(getClass().getSimpleName()+".css").toExternalForm()); getStylesheets().add(this.getClass().getResource("/styles/base.css").toExternalForm()); getStyleClass().add(styleClass); prefWidthProperty().bindBidirectional(wrappingWidth); } /**
@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); }
String template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernCaptainDialog.noShip", new Object[]{}, locale.getCurrentLocal()); DecoratedText noShip = decoratedTextFactory.createDecoratedText(template, parameters); noShip.setLayoutX(2*FRAME_BORDER); noShip.setLayoutY(300); getContent().add(noShip); } else { String template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.TavernPirateDialog.shipSelection", new Object[]{}, locale.getCurrentLocal()); DecoratedText selectedShip = decoratedTextFactory.createDecoratedText(template, parameters); selectedShip.setLayoutX(2*FRAME_BORDER); selectedShip.setLayoutY(300); getContent().add(selectedShip); GridPane shipSelectionPane = dialogUtil.createShipSelection3LinesForShips(city.getPlayersShips(), currentShip);
DecoratedText text = textFactory.createDecoratedText(template, new HashMap<>()); text.getStyleClass().add("dialogText"); text.setLayoutX(50); text.setLayoutY(250); getContent().addAll(text);
DecoratedText text = new DecoratedText(); String messageString = ellipsisCalculator.calculateEllipsis(text.getFont(), translatedMessage, maxWidth); text = textFactory.createSimpleDecoratedText(messageString); EventHandler<MouseEvent> onMouseFocus = getDisplaMessageMouseEnterFocusEventHandler(text, translatedMessage); EventHandler<MouseEvent> onMouseExitFocus = getDisplayMessageMouseExitFocusEventHandler(text); text.setOnMouseEntered(onMouseFocus); text.setOnMouseExited(onMouseExitFocus); NoticeBoardMenuEntry entry = new NoticeBoardMenuEntry(null); entry.setLabel(text);
new Object[]{modelTranslator.getLocalDisplayName(opponent.getCareerLevel()), modelTranslator.getLocalDisplayName(opponent.getRank()), opponent.getName(), opponent.getLastName(), opponent.getHometown().getName()}, locale.getCurrentLocal()); DecoratedText text = textFactory.createDecoratedText(sb, new HashMap<>()); text.setUserData(opponent); text.setStyle(DEFAULT_NON_SELECTED_STYLE); box.getChildren().add(text); opponents.add(text); opponent.setOnMouseReleased(mouseEvent -> { selectedOponent.set((IPlayer) opponent.getUserData()); disableAcceptButton().invalidate(); resetStyles(opponents); opponent.setStyle(SELECTED_STYLE); });
box.setLayoutY(text.getLayoutY()); box.setLayoutX(text.getLayoutX()); text.setId("noPunishment"); text.setOnMouseReleased((evt) -> { office.setViolation(Optional.empty()); taskFactory.getPostponedDisplayMessage(violation.getDate(), "ch.sahits.game.openpatrician.display.dialog.cityhall.AldermanOfficeDialog.displeasure", violation.getCity().getName()); template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.cityhall.AldermanOfficeDialog.smallFine", new Object[]{fine}, locale.getCurrentLocal()); text = textFactory.createDecoratedText(template, new HashMap<>()); text.setId("smallFine"); text.setOnMouseReleased((evt) -> { ((CityViolation) violation).setPunishment(ECityViolationPunishment.SMALL_FINE); LocalDateTime when = date.getCurrentDate().plusMonths(2); template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.cityhall.AldermanOfficeDialog.mediumFine", new Object[]{fine}, locale.getCurrentLocal()); text = textFactory.createDecoratedText(template, new HashMap<>()); text.setId("mediumFine"); text.setOnMouseReleased((evt) -> { ((CityViolation) violation).setPunishment(ECityViolationPunishment.MEDIUM_FINE); LocalDateTime when = date.getCurrentDate().plusMonths(2); template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.cityhall.AldermanOfficeDialog.largeFine", new Object[]{fine}, locale.getCurrentLocal()); text = textFactory.createDecoratedText(template, new HashMap<>()); text.setId("largeFine"); text.setOnMouseReleased((evt) -> { ((CityViolation) violation).setPunishment(ECityViolationPunishment.LARGE_FINE); LocalDateTime when = date.getCurrentDate().plusMonths(2);
@PostConstruct private void initializeDialog() { loaner = (LoanerState) loanerService.findLoaner(city.getCity()); setTitle(messageSource.getMessage("ch.sahits.game.openpatrician.display.notice.NoticeBoardFactory.takeLoan", new Object[]{}, locale.getCurrentLocal())); addDecoratedText("ch.sahits.game.openpatrician.display.dialog.LoanerTakeLoanDialog.dialogSubheading", "introText"); for (final ILoanProposal proposal : loaner.getLoanProposals()) { int amount = proposal.getAmount(); int payback = (int) (amount * proposal.getInterest()); int duration = proposal.getDurationInWeeks(); String interest = String.format("%.1f", (proposal.getInterest() - 1) * 100); final DecoratedText entry = addDecoratedText("ch.sahits.game.openpatrician.display.dialog.LoanerTakeLoanDialog.loanProposal", "proposal", amount, duration, payback, interest); loans.add(entry); entry.setOnMouseReleased(mouseEvent -> { selectedProposal.setValue(proposal); deactivateAll(); entry.applyStyle(SELECTED_STYLE); }); entry.applyStyle(DEFAULT_NON_SELECTED_STYLE); } final OpenPatricianLargeWaxButton acceptBtn = addActionButton("ch.sahits.game.openpatrician.display.dialog.LoanerTakeLoanDialog.btnLabel", "actionBtn"); acceptBtn.setDisable(true); selectedProposal.addListener((observableValue, oldProposal, newProposal) -> { if (newProposal != null) { acceptBtn.setDisable(false); } }); acceptBtn.setOnAction(createAcceptHandler()); } private void deactivateAll() {
public void setLabel(DecoratedText label) { this.label = label; this.label.setLayoutX(inset); label.setOnMouseReleased(evt -> { if (!getDisabled()) { menu.deselctAll(); selected.setValue(true); if (onMouseSelect != null) { // There might be simple messages that have no handle defined. onMouseSelect.handle(evt); } } }); } }
template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.cityhall.OutriggerNoticeDialog.outriggerOwner", args, locale.getCurrentLocal()); text = textFactory.createDecoratedText(template, new HashMap<>()); text.layoutYProperty().bind(prevText.heightProperty().add(prevText.layoutYProperty()).add(24)); getContent().add(text); GridPane grid = dialogUtil.createShipSelection3LinesForShips(capableShips, currentShip); template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.cityhall.OutriggerNoticeDialog.weeklyRefund", new Object[]{ship.getName(), contract.getWeeklyRefund()}, locale.getCurrentLocal()); text = textFactory.createDecoratedText(template, new HashMap<>()); text.setLayoutY(CLOSE_BTN_Y_POS - 200); getContent().add(text); template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.cityhall.OutriggerNoticeDialog.noShip", new Object[]{}, locale.getCurrentLocal()); text = textFactory.createDecoratedText(template, new HashMap<>()); text.setLayoutY(CLOSE_BTN_Y_POS - 400); getContent().add(text); } else {
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()); } }
private void addConvoyList(VBox box, List<IConvoy> presentConvoys, IShip ship) { VBox innerBox = new VBox(); int i = 0; for (IConvoy convoy : presentConvoys) { final String key = "ch.sahits.game.javafx.service.NoticeBoardShipSelectionMenuProvider.ship"; String loadedText = messageSource.getMessage(key, new Object[]{convoy.getName(), convoy.getCapacity()}, locale.getCurrentLocal()); DecoratedText dt = textFactory.createDecoratedText(loadedText, new HashMap<>()); dt.setId("convoy"+i); innerBox.getChildren().add(dt); dt.setOnMouseReleased(evt -> { convoy.addShip(ship); ship.parentShipProperty().setValue(convoy.getOrlegShip()); final ICityPlayerProxyJFX proxy = viewState.getCurrentCityProxy().get(); proxy.leave(ship); proxy.getPlayer().removeSelectableVessel(ship); executeOnCloseButtonClicked(); }); i++; } innerBox.setLayoutX(50); box.getChildren().add(innerBox); }
/** * 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); }
final String s = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.ShipyardConstructionListDialogV2.noShipsBuilding", new Object[]{}, locale.getCurrentLocal()); DecoratedText text = textFactory.createDecoratedText(s, new HashMap<>()); text.setLayoutY(100); getContent().addAll(text); } else {
private void setDisabledStyle(DecoratedText label, Boolean newValue) { if (newValue) { label.getStyleClass().add(DISABLED_LABEL_STYLE); label.getStyleClass().remove(ACTIVE_LABEL_STYLE); label.getStyleClass().remove(DEFAULT_LABEL_STYLE); } else { label.getStyleClass().add(DEFAULT_LABEL_STYLE); label.getStyleClass().remove(ACTIVE_LABEL_STYLE); label.getStyleClass().remove(DISABLED_LABEL_STYLE); } } }
/** * Append a control. * @param control that is to be appended. */ public void append(Node control) { getChildren().add(control); }
private NoticeBoardMenuEntry createMenuEntry(ICityPlayerProxyJFX proxy, INavigableVessel vessel, String loadedText, boolean disabled, int wrappingWidth) { DecoratedText dt = textFactory.createDecoratedText(loadedText, new HashMap<>()); dt.setWrappingWidth(210); NoticeBoardMenuEntry entry = new NoticeBoardMenuEntry(null); entry.setLabel(dt); entry.setDisabled(disabled); entry.setSelected(vessel.equals(proxy.getActiveShip())); return entry; }