ConfigurationContext extends GraphicalContext<BorderPane> { static ChoiceBox<BuiltInUiTheme> buildStyleThemeChooser(Configuration configuration, ConfigurationContext configurationContext) { ChoiceBox<BuiltInUiTheme> themesBox = new ChoiceBox<>(); final String cssFile = configuration.getCssFile(); themesBox.getItems().addAll(BuiltInUiTheme.values()); Optional<BuiltInUiTheme> configuredTheme = BuiltInUiTheme.findFromConfigPropertyValue(cssFile); BuiltInUiTheme selected = configuredTheme.orElse(BuiltInUiTheme.DEFAULT_THEME); themesBox.setConverter(new StringConverter<>() { @Override public String toString(BuiltInUiTheme object) { return object.getLabel(); } @Override public BuiltInUiTheme fromString(String string) { return null; } }); themesBox.getSelectionModel().select(selected); themesBox.setPrefWidth(PREF_WIDTH); themesBox.setPrefHeight(PREF_HEIGHT); themesBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { String newPropertyValue = newValue.getPreferredConfigPropertyValue(); configuration.getCssfileProperty().setValue(newPropertyValue); final GazePlay gazePlay = configurationContext.getGazePlay(); CssUtil.setPreferredStylesheets(configuration, gazePlay.getPrimaryScene(), gazePlay.getCurrentScreenDimensionSupplier()); }); return themesBox; } ConfigurationContext(GazePlay gazePlay); @Override ObservableList<Node> getChildren();  }
@Test void shouldCreateThemeChooserNonDefault() { StringProperty cssFileProperty = new SimpleStringProperty("builtin:BLUE"); ObservableList<String> stylesheets = FXCollections.observableArrayList(); Scene mockScene = mock(Scene.class); when(mockConfig.getCssFile()).thenReturn("builtin:BLUE"); when(mockConfig.getCssfileProperty()).thenReturn(cssFileProperty); when(mockContext.getGazePlay()).thenReturn(mockGazePlay); when(mockGazePlay.getPrimaryScene()).thenReturn(mockScene); when(mockScene.getStylesheets()).thenReturn(stylesheets); ChoiceBox<BuiltInUiTheme> result = ConfigurationContext.buildStyleThemeChooser(mockConfig, mockContext); assertEquals(BuiltInUiTheme.values().length, result.getItems().size()); assertEquals(BuiltInUiTheme.BLUE, result.getValue()); assertEquals(cssFileProperty.getValue(), "builtin:BLUE"); result.setValue(BuiltInUiTheme.GREEN); assertEquals(BuiltInUiTheme.GREEN, result.getValue()); assertEquals(cssFileProperty.getValue(), "builtin:GREEN"); }
@Test void shouldCreateThemeChooserDefault() { StringProperty cssFileProperty = new SimpleStringProperty("builtin:WRONG"); ObservableList<String> stylesheets = FXCollections.observableArrayList(); Scene mockScene = mock(Scene.class); when(mockConfig.getCssFile()).thenReturn("builtin:WRONG"); when(mockConfig.getCssfileProperty()).thenReturn(cssFileProperty); when(mockContext.getGazePlay()).thenReturn(mockGazePlay); when(mockGazePlay.getPrimaryScene()).thenReturn(mockScene); when(mockScene.getStylesheets()).thenReturn(stylesheets); ChoiceBox<BuiltInUiTheme> result = ConfigurationContext.buildStyleThemeChooser(mockConfig, mockContext); assertEquals(BuiltInUiTheme.values().length, result.getItems().size()); assertEquals(BuiltInUiTheme.SILVER_AND_GOLD, result.getValue()); result.setValue(BuiltInUiTheme.GREEN); assertEquals(BuiltInUiTheme.GREEN, result.getValue()); assertEquals(cssFileProperty.getValue(), "builtin:GREEN"); }