ConfigurationContext extends GraphicalContext<BorderPane> { MenuButton buildLanguageChooser( Configuration configuration, ConfigurationContext configurationContext ) { String currentCodeLanguage = configuration.getLanguage(); String currentCodeCountry = configuration.getCountry(); Locale currentLocale = new Locale(currentCodeLanguage, currentCodeCountry); LanguageDetails currentLanguageDetails = Languages.getLocale(currentLocale); Image currentFlag = new Image(currentLanguageDetails.getFlags().get(0)); ImageView currentFlagImageView = new ImageView(currentFlag); currentFlagImageView.setPreserveRatio(true); currentFlagImageView.setFitHeight(25); MenuButton languageBox = new MenuButton(currentLanguageDetails.getLabel(), currentFlagImageView); for (LanguageDetails language : Languages.getAllLanguageDetails()) { List<String> flags = language.getFlags(); for (String flag : flags) { Image image = new Image(flag); ImageView imageView = new ImageView(image); imageView.setPreserveRatio(true); imageView.setFitHeight(25); MenuItem languagesItem = new MenuItem(language.getLabel(), imageView); languagesItem.setOnAction(eventMenuLanguages -> { configuration.getLanguageProperty().setValue(language.getLocale().getLanguage()); configuration.getCountryProperty().setValue(language.getLocale().getCountry()); configurationContext.getGazePlay().getTranslator().notifyLanguageChanged(); languageBox.setText(language.getLabel()); ImageView newImage = new ImageView(image); newImage.setPreserveRatio(true); newImage.setFitHeight(25); languageBox.setGraphic(newImage); if (language.isLeftAligned() != currentLanguageAlignmentIsLeftAligned) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Language information"); alert.setHeaderText( "Alignment settings have just changed for your language, please restart GazePlay for the new changes to take effect."); alert.show(); } if (!language.isStableTranslationAvailable()) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Language information"); alert.setHeaderText( "Translation has just been performed for your language. If you think that some words sound odd in the games, it is maybe a problem of translation. \nPlease contact us to propose better ones at www.gazeplay.net and they will be in the next version."); alert.show(); } }); languageBox.getItems().add(languagesItem); } } languageBox.setPrefWidth(PREF_WIDTH); languageBox.setPrefHeight(PREF_HEIGHT); return languageBox; } ConfigurationContext(GazePlay gazePlay); @Override ObservableList<Node> getChildren();  }
@Test void shouldBuildLanguageChooser() throws InterruptedException { Platform.runLater(() -> { ConfigurationContext context = new ConfigurationContext(mockGazePlay); StringProperty languageProperty = new SimpleStringProperty("eng"); StringProperty countryProperty = new SimpleStringProperty("GB"); when(mockConfig.getLanguage()).thenReturn(languageProperty.getValue()); when(mockConfig.getCountry()).thenReturn(countryProperty.getValue()); when(mockConfig.getLanguageProperty()).thenReturn(languageProperty); when(mockConfig.getCountryProperty()).thenReturn(countryProperty); when(mockContext.getGazePlay()).thenReturn(mockGazePlay); MenuButton result = context.buildLanguageChooser(mockConfig, context); assertEquals(23, result.getItems().size()); result.getItems().get(1).fire(); ImageView image = (ImageView) result.getGraphic(); assertTrue(image.getImage().getUrl().contains("Arab")); assertEquals("ara", languageProperty.getValue()); }); TestingUtils.waitForRunLater(); }