-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make Brazilian Portuguese translation actually work
- Loading branch information
1 parent
a537d48
commit 0ac0e46
Showing
6 changed files
with
150 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
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 |
---|---|---|
@@ -1,108 +1,112 @@ | ||
package net.azib.ipscan.config; | ||
|
||
import java.util.Locale; | ||
import java.util.UUID; | ||
import java.util.prefs.Preferences; | ||
|
||
/** | ||
* This class encapsulates preferences of the program. | ||
* It is a singleton class. | ||
* | ||
* @author Anton Keks | ||
*/ | ||
public final class Config { | ||
|
||
/** Singleton instance */ | ||
private static Config globalConfig; | ||
|
||
private Preferences preferences; | ||
public String language; | ||
public String uuid; | ||
|
||
/** easily accessible scanner configuration */ | ||
private ScannerConfig scannerConfig; | ||
/** various GUI preferences and dimensions are stored here */ | ||
private GUIConfig guiConfig; | ||
/** favorites are stored here */ | ||
private FavoritesConfig favoritesConfig; | ||
/** openers are stored here */ | ||
private OpenersConfig openersConfig; | ||
|
||
Config() { | ||
preferences = Preferences.userRoot().node("ipscan"); | ||
scannerConfig = new ScannerConfig(preferences); | ||
guiConfig = new GUIConfig(preferences); | ||
favoritesConfig = new FavoritesConfig(preferences); | ||
openersConfig = new OpenersConfig(preferences); | ||
language = preferences.get("language", "system"); | ||
uuid = preferences.get("uuid", null); | ||
if (uuid == null) { | ||
uuid = UUID.randomUUID().toString(); | ||
preferences.put("uuid", uuid); | ||
} | ||
} | ||
|
||
/** | ||
* Initializes the singleton instance | ||
*/ | ||
public static Config getConfig() { | ||
if (globalConfig == null) { | ||
globalConfig = new Config(); | ||
} | ||
return globalConfig; | ||
} | ||
|
||
public void store() { | ||
preferences.put("language", language); | ||
preferences.put("uuid", uuid); | ||
scannerConfig.store(); | ||
guiConfig.store(); | ||
favoritesConfig.store(); | ||
openersConfig.store(); | ||
} | ||
|
||
public Preferences getPreferences() { | ||
return preferences; | ||
} | ||
|
||
/** | ||
* @return ScannerConfig instance (quick access) | ||
*/ | ||
public ScannerConfig forScanner() { | ||
return scannerConfig; | ||
} | ||
|
||
/** | ||
* @return Favorites config (only local access) | ||
*/ | ||
FavoritesConfig forFavorites() { | ||
return favoritesConfig; | ||
} | ||
|
||
/** | ||
* @return Openers config (only local access); | ||
*/ | ||
public OpenersConfig forOpeners() { | ||
return openersConfig; | ||
} | ||
|
||
/** | ||
* @return Dimensions config (quick access); | ||
*/ | ||
public GUIConfig forGUI() { | ||
return guiConfig; | ||
} | ||
|
||
public Locale getLocale() { | ||
if (language == null || "system".equals(language)) { | ||
return System.getProperty("locale") == null ? Locale.getDefault() : new Locale(System.getProperty("locale")); | ||
} | ||
else { | ||
return new Locale(language); | ||
} | ||
} | ||
|
||
public String getUUID() { | ||
return uuid; | ||
} | ||
} | ||
package net.azib.ipscan.config; | ||
|
||
import java.util.Locale; | ||
import java.util.UUID; | ||
import java.util.prefs.Preferences; | ||
|
||
/** | ||
* This class encapsulates preferences of the program. | ||
* It is a singleton class. | ||
* | ||
* @author Anton Keks | ||
*/ | ||
public final class Config { | ||
|
||
/** Singleton instance */ | ||
private static Config globalConfig; | ||
|
||
private Preferences preferences; | ||
public String language; | ||
public String uuid; | ||
|
||
/** easily accessible scanner configuration */ | ||
private ScannerConfig scannerConfig; | ||
/** various GUI preferences and dimensions are stored here */ | ||
private GUIConfig guiConfig; | ||
/** favorites are stored here */ | ||
private FavoritesConfig favoritesConfig; | ||
/** openers are stored here */ | ||
private OpenersConfig openersConfig; | ||
|
||
Config() { | ||
preferences = Preferences.userRoot().node("ipscan"); | ||
scannerConfig = new ScannerConfig(preferences); | ||
guiConfig = new GUIConfig(preferences); | ||
favoritesConfig = new FavoritesConfig(preferences); | ||
openersConfig = new OpenersConfig(preferences); | ||
language = preferences.get("language", "system"); | ||
uuid = preferences.get("uuid", null); | ||
if (uuid == null) { | ||
uuid = UUID.randomUUID().toString(); | ||
preferences.put("uuid", uuid); | ||
} | ||
} | ||
|
||
/** | ||
* Initializes the singleton instance | ||
*/ | ||
public static Config getConfig() { | ||
if (globalConfig == null) { | ||
globalConfig = new Config(); | ||
} | ||
return globalConfig; | ||
} | ||
|
||
public void store() { | ||
preferences.put("language", language); | ||
preferences.put("uuid", uuid); | ||
scannerConfig.store(); | ||
guiConfig.store(); | ||
favoritesConfig.store(); | ||
openersConfig.store(); | ||
} | ||
|
||
public Preferences getPreferences() { | ||
return preferences; | ||
} | ||
|
||
/** | ||
* @return ScannerConfig instance (quick access) | ||
*/ | ||
public ScannerConfig forScanner() { | ||
return scannerConfig; | ||
} | ||
|
||
/** | ||
* @return Favorites config (only local access) | ||
*/ | ||
FavoritesConfig forFavorites() { | ||
return favoritesConfig; | ||
} | ||
|
||
/** | ||
* @return Openers config (only local access); | ||
*/ | ||
public OpenersConfig forOpeners() { | ||
return openersConfig; | ||
} | ||
|
||
/** | ||
* @return Dimensions config (quick access); | ||
*/ | ||
public GUIConfig forGUI() { | ||
return guiConfig; | ||
} | ||
|
||
public Locale getLocale() { | ||
if (language == null || "system".equals(language)) { | ||
return System.getProperty("locale") == null ? Locale.getDefault() : createLocale(System.getProperty("locale")); | ||
} | ||
else { | ||
return createLocale(language); | ||
} | ||
} | ||
|
||
private Locale createLocale(String locale) { | ||
return Locale.forLanguageTag(locale.replace('_', '-')); | ||
} | ||
|
||
public String getUUID() { | ||
return uuid; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,34 @@ | ||
package net.azib.ipscan.config; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
/** | ||
* @author Anton Keks | ||
*/ | ||
public class ConfigTest { | ||
|
||
@Test | ||
public void testGetters() { | ||
Config config = Config.getConfig(); | ||
assertNotNull(config.getPreferences()); | ||
assertNotNull(config.forScanner()); | ||
assertNotNull(config.forGUI()); | ||
assertNotNull(config.forFavorites()); | ||
assertNotNull(config.forOpeners()); | ||
} | ||
} | ||
package net.azib.ipscan.config; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
/** | ||
* @author Anton Keks | ||
*/ | ||
public class ConfigTest { | ||
Config config = Config.getConfig(); | ||
|
||
@Test | ||
public void locale() { | ||
config.language = "et"; | ||
assertEquals(config.getLocale().toString(), "et"); | ||
} | ||
|
||
@Test | ||
public void localeWithRegion() { | ||
config.language = "pt_BR"; | ||
assertEquals(config.getLocale().toString(), "pt_BR"); | ||
} | ||
|
||
@Test | ||
public void testGetters() { | ||
assertNotNull(config.getPreferences()); | ||
assertNotNull(config.forScanner()); | ||
assertNotNull(config.forGUI()); | ||
assertNotNull(config.forFavorites()); | ||
assertNotNull(config.forOpeners()); | ||
} | ||
} |