This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/src/main/java/envoy/client/Settings.java

139 lines
3.6 KiB
Java
Raw Normal View History

package envoy.client;
import java.util.prefs.Preferences;
import envoy.schema.User;
/**
* Project: <strong>envoy-client</strong><br>
* File: <strong>Settings.java</strong><br>
* Created: <strong>11 Nov 2019</strong><br>
*
* @author Leon Hofmeister
* @since Envoy v0.2-alpha
*/
public class Settings {
private String username;
private String email;
private boolean enterToSend = true;
private boolean darkMode = true;
// 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();
settings.load();
}
return settings;
}
public void load() {
settings.setUsername(prefs.get("username", ""));
settings.setEmail(prefs.get("email", ""));
settings.setDarkMode(prefs.getBoolean("darkMode", true));
settings.setEnterToSend(prefs.getBoolean("enterToSend", true));
}
public void save() {
prefs.put("username", settings.getUsername());
prefs.put("email", settings.getEmail());
prefs.putBoolean("darkMode", settings.isDarkMode());
prefs.putBoolean("enterToSend", settings.isEnterToSend());
}
public void firstSave(User user) {
prefs.put("username", user.getName());
// prefs.put("email", user.getEmail());
// prefs.putBoolean("darkMode", true);
// prefs.putBoolean("enterToSend", true);
}
/**
* @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; }
/**
* Describes whether the Envoy GUI should be displayed in dark mode or not.
*
* @return true, if dark mode display is currently set, else the light theme
* will be displayed
* @since Envoy v0.2-alpha
*/
public boolean isDarkMode() { return darkMode; }
/**
* Change display mode of Envoy GUI.
*
* @param darkMode true, if dark mode display is currently set, <br>
* else the light theme will be displayed
* @since Envoy v0.2-alpha
*/
public void setDarkMode(boolean darkMode) { this.darkMode = darkMode; }
// /**
// * @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; }
}