-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into 51-integrate-topga…
…iners-and-toplosers-into-view # Conflicts: # millions/src/main/java/no/ntnu/gruppe53/view/FooterBar.java # millions/src/main/java/no/ntnu/gruppe53/view/NavigationBar.java
- Loading branch information
Showing
22 changed files
with
865 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
millions/src/main/java/no/ntnu/gruppe53/service/LanguageManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package no.ntnu.gruppe53.service; | ||
|
|
||
| import javafx.beans.binding.Bindings; | ||
| import javafx.beans.binding.StringBinding; | ||
| import javafx.beans.property.ObjectProperty; | ||
| import javafx.beans.property.SimpleObjectProperty; | ||
|
|
||
| import java.util.Locale; | ||
| import java.util.ResourceBundle; | ||
|
|
||
| /** | ||
| * Manages the language used in the user-interface. | ||
| * <p>The possible languages to be used are set by {@link LanguageRegistry}.</p> | ||
| */ | ||
| public class LanguageManager { | ||
|
|
||
| /** | ||
| * Sets a default language and creates an observable {@link ResourceBundle}. | ||
| */ | ||
| private final ObjectProperty<ResourceBundle> bundleProperty = | ||
| new SimpleObjectProperty<>(); | ||
|
|
||
| private LanguageManager() { | ||
| setLocale(LanguageRegistry.getDefaultLocale()); | ||
| } | ||
|
|
||
| /** | ||
| * Static Inner Class to lazily create the instance | ||
| */ | ||
| private static class LanguageManagerInner { | ||
| private static final LanguageManager INSTANCE = | ||
| new LanguageManager(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the instance of the language manager | ||
| * | ||
| * @return the instance of the language manager | ||
| */ | ||
| public static LanguageManager getInstance() { | ||
| return LanguageManagerInner.INSTANCE; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the observable resource bundle. | ||
| * | ||
| * @return an observable resource bundle | ||
| */ | ||
| public ObjectProperty<ResourceBundle> getBundleProperty() { | ||
| return bundleProperty; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the locale of the instance to a given locale which determines the properties file to load | ||
| * values from. | ||
| * | ||
| * @param locale the locale to change to | ||
| */ | ||
| public void setLocale(Locale locale) { | ||
| ResourceBundle bundle = | ||
| ResourceBundle.getBundle("i18n.lang", locale); | ||
|
|
||
| bundleProperty.set(bundle); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the string value of the given key in a .properties file. | ||
| * | ||
| * @param key the key to look for in the .properties file | ||
| * @return the value of the key | ||
| */ | ||
| public String getString(String key) { | ||
| return bundleProperty.get().getString(key); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the current locale. | ||
| * | ||
| * @return the current locale | ||
| */ | ||
| public Locale getLocale() { | ||
| return bundleProperty.get().getLocale(); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a {@link StringBinding} to a given string and associates it with a given key in a .properties file | ||
| * | ||
| * @param key the key to associate the string binding with | ||
| * @return a string binding observable | ||
| */ | ||
| public StringBinding bindString(String key) { | ||
| return Bindings.createStringBinding( | ||
| () -> getString(key), | ||
| getBundleProperty() | ||
| ); | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
millions/src/main/java/no/ntnu/gruppe53/service/LanguageOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package no.ntnu.gruppe53.service; | ||
|
|
||
| import java.util.Locale; | ||
|
|
||
| /** | ||
| * Acts as a data-carrier representing a language with a string name and a {@link Locale}. | ||
| * | ||
| * @param name the name of the language | ||
| * @param locale the locale of the language | ||
| */ | ||
| public record LanguageOption(String name, Locale locale) {} | ||
|
|
54 changes: 54 additions & 0 deletions
54
millions/src/main/java/no/ntnu/gruppe53/service/LanguageRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package no.ntnu.gruppe53.service; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Locale; | ||
|
|
||
| /** | ||
| * Represents a registry of allowed {@link LanguageOption}s. | ||
| */ | ||
| public class LanguageRegistry { | ||
|
|
||
| /** | ||
| * Sets all possible languages that can be used. | ||
| */ | ||
| private static final List<LanguageOption> languages = List.of( | ||
| new LanguageOption("English", new Locale("en")), | ||
| new LanguageOption("Norsk", new Locale("no")) | ||
| ); | ||
|
|
||
| /** | ||
| * Sets the default language to be used. | ||
| * <p>Searches through the registry to find english and sets it as default.</p> | ||
| */ | ||
| private static final LanguageOption defaultLang = languages.stream() | ||
| .filter(lang -> lang.locale().getLanguage().equals("en")) | ||
| .findFirst() | ||
| .orElse(languages.getFirst()); | ||
|
|
||
| /** | ||
| * Returns all registered languages | ||
| * | ||
| * @return a list of registered languages | ||
| */ | ||
| public static List<LanguageOption> getLanguages() { | ||
| return languages; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the default language. | ||
| * | ||
| * @return the default language | ||
| */ | ||
| public static LanguageOption getDefaultLanguage() { | ||
| return defaultLang; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the default locale of the default language. | ||
| * | ||
| * @return the default locale | ||
| */ | ||
| public static Locale getDefaultLocale() { | ||
| return defaultLang.locale(); | ||
| } | ||
| } |
Oops, something went wrong.