public String getSelectedValue() { return values.get(getSelectedIndex()); }
public OpenPatricianSlider(int width) { values = new SimpleListProperty<>(this, "options", FXCollections.observableList(new ArrayList<String>())); initialWidth = new SimpleIntegerProperty(this,"initialWidth", width); selectedIndex = new SimpleIntegerProperty(this, "selectedIndex", -1); this.getStyleClass().add(this.getClass().getSimpleName()); }
/** * Snap to the correct angle. Correct angle is angle belonging to the nearest label. */ void snapToNearestAngle() { double currentAngle = currentRotation.doubleValue() + 180; double currentMin = 360; int minIndex = 0; for (int i = 0; i < angles.size(); i++) { double angle = angles.get(i); double diff = Math.abs(angle - currentAngle); if (diff < currentMin) { currentMin = diff; minIndex = i; } } Double destinationAngle = angles.get(minIndex); if (destinationAngle < 180 + 10 || destinationAngle > 360 - 10) { throw new IllegalStateException("Angle is out of range: "+currentRotation.doubleValue()+" -> "+destinationAngle); } control.selectedIndexProperty().set(minIndex); currentRotation.set(destinationAngle - 180); } /**
grid.add(gameSpeedLbl, 0, 2); speed = new OpenPatricianSlider(200); speed.getStyleClass().add("defaultTextSize24"); speed.setValues(gameOptions.getGameSpeedList()); int index = 0; currentSpeed = game.getGameSpeed(); speed.selectedIndexProperty().setValue(index);
/** * Create the labels and add them to the group. * @param g group the labels are added to * @param centerPoint central point around which the labels are placed. */ private void createAndAddLabels(Group g, final Point2D centerPoint) { List<String> values = control.valuesProperty(); angles = new ArrayList<>(values.size()); double angle = currentRotation.doubleValue() + 180; double step = (180.0 - 2 * currentRotation.doubleValue()) / (values.size() - 1); int radius = 120; for (String value : values) { angles.add(angle); Point2D basePoint = calculateBasePoint(centerPoint, radius, angle); Dimension2D dim = sizeing.calculate(value, control.getFont()); Label l = new Label(value); l.setFont(control.getFont()); l.getStyleClass().add("openPatricianSlider"); l.setTranslateX(basePoint.getX() - dim.getWidth() * calculateMoveFactor(angle)); l.setTranslateY(basePoint.getY() - dim.getHeight()); g.getChildren().add(l); angle += step; } double initialAngle = Math.max(INITIAL_ROTATION, control.getSelectedIndex() * step); currentRotation.setValue(initialAngle); } /**
Bounds bounds = control.getBoundsInParent(); Point2D center = control.localToScene(bounds.getWidth() / 2, bounds.getHeight()); if (mouseEvent.getSceneY() < center.getY()) {
public List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData() { return getClassCssMetaData(); }
public OpenPatricianSliderSkin(OpenPatricianSlider slider) { super(slider); control = slider; currentRotation = new SimpleDoubleProperty(this, "currentRotation", INITIAL_ROTATION); sizeing = new TextSizingUtility(); final SteeringWheelGroup background = new SteeringWheelGroup(control.getInitialWidth(), currentRotation.doubleValue()); background.setManaged(false); Group g = new Group(background); final Point2D centerPoint = new Point2D(control.getInitialWidth()/2, control.getInitialWidth()/2); createAndAddLabels(g, centerPoint); background.setTranslateX(centerPoint.getX() - background.getImageWidth()/2); background.setTranslateY(centerPoint.getY() - background.getImageWidth()/2 - yTranslation); getChildren().add(g); } /**
grid.add(difficultyLbl, 0, 4); difficulty = new OpenPatricianSlider(200); difficulty.getStyleClass().addAll("defaultTextSize24"); difficulty.setValues(getDificutlyList()); difficulty.selectedIndexProperty().setValue(0); grid.add(difficulty, 1, 4); GridPane.setHalignment(difficulty, HPos.LEFT); grid.add(gameSpeedLbl, 3, 4); speed = new OpenPatricianSlider(200); speed.getStyleClass().addAll("defaultTextSize24"); speed.setValues(gameOptions.getGameSpeedList()); speed.selectedIndexProperty().setValue(1); grid.add(speed, 4, 4); GridPane.setHalignment(speed, HPos.LEFT);
private EventHandler<MouseEvent> getBackEvent() { return event -> { try { EGameSpeed gameSpeed = EGameSpeed.values()[speed.getSelectedIndex()]; EGameSpeed currentSpeed = game.getGameSpeed(); if (gameSpeed != currentSpeed) { game.setGameSpeed(gameSpeed); } MainGameScene mainGame = uiFactory.getMainGameScene(getRoot().getWidth(), getRoot().getHeight()); getSceneChangeable().changeScene(mainGame); soundPlayer.play(); newSaveGame.setText(""); timerEventBus.post(new ResumeGame()); } catch (RuntimeException e) { logger.error("Failed to go back to game", e); } }; }
if (validInput()) { NewGame newGameDTO = NewGame.builder() .difficulty(Difficulty.fromIndex(difficulty.getSelectedIndex())) .firstName(name.getText()) .lastName(lastName.getText()) .hometown(hometown.getSelectedValue()) .objective(EObjective.values()[objective.getSelectedIndex()]) .speed(EGameSpeed.values()[speed.getSelectedIndex()]) .startYear(Integer.parseInt(startYear.getSelectedValue())) .male(maleRadioButton.isSelected() && !femaleRadioButton.isSelected())