2019-11-22 06:37:59 +01:00
|
|
|
package envoy.client;
|
|
|
|
|
2019-12-07 10:58:03 +01:00
|
|
|
import java.awt.Color;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2019-11-22 06:37:59 +01:00
|
|
|
import java.util.prefs.Preferences;
|
|
|
|
|
2019-12-07 10:58:03 +01:00
|
|
|
import envoy.client.ui.Theme;
|
2019-11-23 13:25:12 +01:00
|
|
|
import envoy.schema.User;
|
|
|
|
|
2019-11-22 06:37:59 +01:00
|
|
|
/**
|
|
|
|
* Project: <strong>envoy-client</strong><br>
|
|
|
|
* File: <strong>Settings.java</strong><br>
|
|
|
|
* Created: <strong>11 Nov 2019</strong><br>
|
|
|
|
*
|
|
|
|
* @author Leon Hofmeister
|
2019-12-07 10:58:03 +01:00
|
|
|
* @author Maximilian Käfer
|
2019-11-22 06:37:59 +01:00
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
|
|
|
public class Settings {
|
|
|
|
|
2019-12-07 10:58:03 +01:00
|
|
|
private String username;
|
|
|
|
private String email;
|
|
|
|
private boolean enterToSend = true;
|
|
|
|
private Map<String, Theme> themes = new HashMap<>();
|
|
|
|
|
|
|
|
private String currentTheme;
|
2019-11-22 06:37:59 +01:00
|
|
|
// private Image profilePic;
|
|
|
|
private static Settings settings;
|
|
|
|
private Preferences prefs = Preferences.userNodeForPackage(Settings.class);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The way to instantiate the settings.
|
|
|
|
* Is set to private to deny other instances of that object.
|
|
|
|
*
|
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
|
|
|
private Settings() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is used to ensure that there is only one instance of Settings.
|
|
|
|
*
|
|
|
|
* @return the instance of Settings
|
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
|
|
|
public static Settings getInstance() {
|
|
|
|
if (settings == null) {
|
|
|
|
settings = new Settings();
|
2019-11-23 13:25:12 +01:00
|
|
|
settings.load();
|
2019-11-22 06:37:59 +01:00
|
|
|
}
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void load() {
|
|
|
|
settings.setUsername(prefs.get("username", ""));
|
|
|
|
settings.setEmail(prefs.get("email", ""));
|
|
|
|
settings.setEnterToSend(prefs.getBoolean("enterToSend", true));
|
2019-12-07 10:58:03 +01:00
|
|
|
// currentTheme = "dark"; Activate once if NullPointerException on currentTheme
|
|
|
|
// and change theme to dark or white in Settings
|
|
|
|
settings.setCurrentTheme(prefs.get("theme", "dark"));
|
2019-11-22 06:37:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void save() {
|
|
|
|
prefs.put("username", settings.getUsername());
|
|
|
|
prefs.put("email", settings.getEmail());
|
2019-12-07 10:58:03 +01:00
|
|
|
prefs.put("theme", currentTheme);
|
|
|
|
System.out.println(currentTheme);
|
2019-11-22 06:37:59 +01:00
|
|
|
prefs.putBoolean("enterToSend", settings.isEnterToSend());
|
2019-12-07 10:58:03 +01:00
|
|
|
// TODO: override themes map
|
|
|
|
|
2019-11-22 06:37:59 +01:00
|
|
|
}
|
2019-12-07 10:58:03 +01:00
|
|
|
|
2019-11-23 13:25:12 +01:00
|
|
|
public void firstSave(User user) {
|
2019-12-07 10:58:03 +01:00
|
|
|
|
|
|
|
// TODO: load themes
|
|
|
|
|
|
|
|
settings.getThemes()
|
|
|
|
.put("dark",
|
|
|
|
new Theme("dark", Color.black, Color.darkGray, Color.white, Color.blue, Color.white, Color.orange,
|
|
|
|
Color.blue, Color.white, Color.white));
|
|
|
|
settings.getThemes()
|
|
|
|
.put("light",
|
|
|
|
new Theme("light", new Color(235, 235, 235), Color.white, Color.white, Color.darkGray, Color.black,
|
|
|
|
Color.orange, Color.darkGray, Color.black, Color.black));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-11-23 13:25:12 +01:00
|
|
|
prefs.put("username", user.getName());
|
2019-12-07 10:58:03 +01:00
|
|
|
// prefs.put("email", user.getEmail());
|
|
|
|
// prefs.putBoolean("darkMode", true);
|
|
|
|
// prefs.putBoolean("enterToSend", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addNewThemeToMap(Theme theme) {
|
|
|
|
settings.getThemes().put(theme.getThemeName(), theme);
|
|
|
|
currentTheme = theme.getThemeName();
|
2019-11-23 13:25:12 +01:00
|
|
|
}
|
2019-11-22 06:37:59 +01:00
|
|
|
|
2019-12-07 10:58:03 +01:00
|
|
|
public String getCurrentTheme() { return currentTheme; }
|
|
|
|
|
|
|
|
public void setCurrentTheme(String themeName) { currentTheme = themeName; }
|
|
|
|
|
2019-11-22 06:37:59 +01:00
|
|
|
/**
|
|
|
|
* @return the username
|
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
|
|
|
public String getUsername() { return username; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param username the username to set
|
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
|
|
|
public void setUsername(String username) { this.username = username; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the email associated with that user.
|
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
|
|
|
public String getEmail() { return email; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param email the email to set
|
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
|
|
|
public void setEmail(String email) { this.email = email; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true, if "enter" suffices to send a message, else it has to be "ctrl"
|
|
|
|
* + "enter"
|
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
|
|
|
public boolean isEnterToSend() { return enterToSend; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change mode of posting a message via Keystroke.
|
|
|
|
*
|
|
|
|
* @param enterToSend if true, "enter" suffices to send a message, <br>
|
|
|
|
* else it has to be "ctrl" + "enter"
|
|
|
|
* @since Envoy v0.2-alpha
|
|
|
|
*/
|
|
|
|
public void setEnterToSend(boolean enterToSend) { this.enterToSend = enterToSend; }
|
|
|
|
|
2019-12-07 10:58:03 +01:00
|
|
|
public Map<String, Theme> getThemes() { return themes; }
|
2019-11-22 06:37:59 +01:00
|
|
|
|
2019-12-07 10:58:03 +01:00
|
|
|
public void setThemes(Map<String, Theme> themes) { this.themes = themes; }
|
2019-11-22 06:37:59 +01:00
|
|
|
|
|
|
|
// /**
|
|
|
|
// * @return the profilePic
|
|
|
|
// * @since Envoy v0.2-alpha
|
|
|
|
// */
|
|
|
|
// public Image getProfilePic() { return profilePic; }
|
|
|
|
//
|
|
|
|
// /**
|
|
|
|
// * @param profilePic the profilePic to set
|
|
|
|
// * @since Envoy v0.1-alpha
|
|
|
|
// */
|
|
|
|
// public void setProfilePic(Image profilePic) { this.profilePic = profilePic; }
|
|
|
|
|
2019-12-07 10:58:03 +01:00
|
|
|
|
2019-11-22 06:37:59 +01:00
|
|
|
}
|