public OpenPatricianRadioButtonSkin(final OpenPatricianRadioButton radioButton) { super(radioButton); String text = radioButton.getText(); InputStream is = getClass().getResourceAsStream("radioboxbg.png"); Image rbBG = new Image(is); radioButton.fontProperty().addListener((observable, oldValue, newValue) -> calculateNewDimenstions(radioButton, text, rbBG)); if (radioButton.isSelected()) { selectedLabel = new Label(radioButton.getSelectedLabel()); } else { selectedLabel = new Label(radioButton.getUnselectedLabel()); selectedLabel.translateYProperty().set(32); radioButton.selectedProperty().addListener((observable, oldValue, newValue) -> { if (newValue) { selectedLabel.setText(radioButton.getSelectedLabel()); } else { selectedLabel.setText(radioButton.getUnselectedLabel()); boolean oldValue = radioButton.selectedProperty().get(); if (!oldValue) { radioButton.setSelected(!oldValue);
public OpenPatricianRadioButton(String text) { super(text); selectedLabel = new SimpleStringProperty(this, "selectedLabel", "yes"); unselectedLabel = new SimpleStringProperty(this, "unselectedLabel", "no"); this.getStyleClass().add(this.getClass().getSimpleName()); }
maleRadioButton = new OpenPatricianRadioButton(messageSource.getMessage("ch.sahits.game.openpatrician.display.scene.NewGameScene.male", new Object[]{}, locale.getCurrentLocal())); maleRadioButton.setSelected(true); maleRadioButton.setToggleGroup(toggleGroup); maleRadioButton.setUnselectedLabel(messageSource.getMessage("no", new Object[]{}, locale.getCurrentLocal())); maleRadioButton.setSelectedLabel(messageSource.getMessage("yes", new Object[]{}, locale.getCurrentLocal())); femaleRadioButton = new OpenPatricianRadioButton(messageSource.getMessage("ch.sahits.game.openpatrician.display.scene.NewGameScene.female", new Object[]{}, locale.getCurrentLocal())); femaleRadioButton.setSelected(false); femaleRadioButton.setToggleGroup(toggleGroup); femaleRadioButton.setUnselectedLabel(messageSource.getMessage("no", new Object[]{}, locale.getCurrentLocal())); femaleRadioButton.setSelectedLabel(messageSource.getMessage("yes", new Object[]{}, locale.getCurrentLocal())); grid.add(femaleRadioButton, 3, 1); GridPane.setHalignment(femaleRadioButton, HPos.LEFT);
.speed(EGameSpeed.values()[speed.getSelectedIndex()]) .startYear(Integer.parseInt(startYear.getSelectedValue())) .male(maleRadioButton.isSelected() && !femaleRadioButton.isSelected()) .mapName(map.getSelectedValue()) .singleplayer(true)
private void calculateNewDimenstions(OpenPatricianRadioButton radioButton, String text, Image rbBG) { InputStream is; final int remainWidth = 28; // width that is left from the background final int destHight = 27; final double xStart = rbBG.getWidth(); final int yStart = 0; Dimension2D dim = sizing.calculate(text, radioButton.getFont()); double width = dim.getWidth(); double destWidth = width-remainWidth + 10; String fileName = imageFactory.getFileNameExt(destWidth,destHight,remainWidth); is = getClass().getResourceAsStream(fileName); Image slab = new Image(is, destWidth, destHight, false, true); slabView.setImage(slab); slabView.translateXProperty().set(xStart); slabView.translateYProperty().set(yStart); double posX = destWidth/2+(xStart-remainWidth-10); label.translateXProperty().set(posX); }