Removed user id, name and email from Settings

This commit is contained in:
Kai S. K. Engelbart 2019-12-14 09:58:25 +01:00
parent f983b6ffe7
commit 27c420afdc
4 changed files with 20 additions and 130 deletions

View File

@ -38,9 +38,6 @@ public class Client {
this.config = config; this.config = config;
sender = getUser(userName); sender = getUser(userName);
// Update the user ID in the cache
Settings.getInstance().setUserID(sender.getID());
logger.info("Client user ID: " + sender.getID()); logger.info("Client user ID: " + sender.getID());
} }
@ -100,11 +97,7 @@ public class Client {
return sync.getUsers().get(0); return sync.getUsers().get(0);
} else throw new EnvoyException("Unexpected response from Envoy Server"); } else throw new EnvoyException("Unexpected response from Envoy Server");
} catch (Exception e) { } catch (Exception e) {
logger.warning("Could not connect to server, trying offline mode."); throw new EnvoyException("Could not connect to server", e);
if (Settings.getInstance().getUserID() != -1) {
user.setID(Settings.getInstance().getUserID());
return user;
} else throw new EnvoyException("Could not enter offline mode.");
} }
} }

View File

@ -26,9 +26,6 @@ import envoy.client.ui.Theme;
public class Settings { public class Settings {
// Actual settings accessible by the rest of the application // Actual settings accessible by the rest of the application
private String username;
private long userID;
private String email;
private boolean enterToSend = true; private boolean enterToSend = true;
private Map<String, Theme> themes; private Map<String, Theme> themes;
private String currentTheme; private String currentTheme;
@ -66,9 +63,6 @@ public class Settings {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void load() { private void load() {
setUsername(prefs.get("username", ""));
setUserID(prefs.getLong("userID", -1));
setEmail(prefs.get("email", ""));
setEnterToSend(prefs.getBoolean("enterToSend", true)); setEnterToSend(prefs.getBoolean("enterToSend", true));
setCurrentTheme(prefs.get("theme", "dark")); setCurrentTheme(prefs.get("theme", "dark"));
@ -98,9 +92,6 @@ public class Settings {
* @since Envoy v0.2-alpha * @since Envoy v0.2-alpha
*/ */
public void save() throws IOException { public void save() throws IOException {
prefs.put("username", getUsername());
prefs.putLong("userID", getUserID());
prefs.put("email", getEmail());
prefs.put("theme", currentTheme); prefs.put("theme", currentTheme);
prefs.putBoolean("enterToSend", isEnterToSend()); prefs.putBoolean("enterToSend", isEnterToSend());
@ -136,40 +127,6 @@ public class Settings {
*/ */
public void setCurrentTheme(String themeName) { currentTheme = themeName; } public void setCurrentTheme(String themeName) { currentTheme = themeName; }
/**
* @return the user name
* @since Envoy v0.2-alpha
*/
public String getUsername() { return username; }
/**
* @param username the user name to set
* @since Envoy v0.2-alpha
*/
public void setUsername(String username) { this.username = username; }
/**
* @return the userID
*/
public long getUserID() { return userID; }
/**
* @param userID the userID to set
*/
public void setUserID(long userID) { this.userID = userID; }
/**
* @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" * @return true, if "enter" suffices to send a message, else it has to be "ctrl"
* + "enter" * + "enter"

View File

@ -101,8 +101,7 @@ public class SettingsScreen extends JDialog {
createNewThemeButton.setEnabled(false); createNewThemeButton.setEnabled(false);
temporaryTheme = new Theme("temporaryTheme", temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
// Content pane // Content pane
GridBagLayout gbl_contentPanel = new GridBagLayout(); GridBagLayout gbl_contentPanel = new GridBagLayout();
@ -200,20 +199,8 @@ public class SettingsScreen extends JDialog {
colorsPanel.setLayout(new BoxLayout(colorsPanel, BoxLayout.Y_AXIS)); colorsPanel.setLayout(new BoxLayout(colorsPanel, BoxLayout.Y_AXIS));
colorsPanel.setAlignmentX(Component.LEFT_ALIGNMENT); colorsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getBackgroundColor(), "Background", 1);
new JButton(), buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getCellColor(), "Cells", 2);
new JTextPane(),
theme,
theme.getBackgroundColor(),
"Background",
1);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getCellColor(),
"Cells",
2);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
new JTextPane(), new JTextPane(),
@ -228,41 +215,11 @@ public class SettingsScreen extends JDialog {
theme.getInteractableBackgroundColor(), theme.getInteractableBackgroundColor(),
"Interactable Background", "Interactable Background",
4); 4);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getMessageColorChat(), "Messages Chat", 5);
new JButton(), buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getDateColorChat(), "Date Chat", 6);
new JTextPane(), buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getSelectionColor(), "Selection", 7);
theme, buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getTypingMessageColor(), "Typing Message", 8);
theme.getMessageColorChat(), buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getUserNameColor(), "User Names", 9);
"Messages Chat",
5);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getDateColorChat(),
"Date Chat",
6);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getSelectionColor(),
"Selection",
7);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getTypingMessageColor(),
"Typing Message",
8);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getUserNameColor(),
"User Names",
9);
GridBagConstraints gbc_colorsPanel = new GridBagConstraints(); GridBagConstraints gbc_colorsPanel = new GridBagConstraints();
gbc_colorsPanel.fill = GridBagConstraints.HORIZONTAL; gbc_colorsPanel.fill = GridBagConstraints.HORIZONTAL;
@ -283,16 +240,14 @@ public class SettingsScreen extends JDialog {
String s = JOptionPane.showInputDialog("Enter a name for the new theme"); String s = JOptionPane.showInputDialog("Enter a name for the new theme");
System.out.println(s); System.out.println(s);
Settings.getInstance() Settings.getInstance()
.addNewThemeToMap(new Theme(s, temporaryTheme.getBackgroundColor(), .addNewThemeToMap(new Theme(s, temporaryTheme.getBackgroundColor(), temporaryTheme.getCellColor(),
temporaryTheme.getCellColor(), temporaryTheme.getInteractableForegroundColor(), temporaryTheme.getInteractableForegroundColor(), temporaryTheme.getInteractableBackgroundColor(),
temporaryTheme.getInteractableBackgroundColor(), temporaryTheme.getMessageColorChat(), temporaryTheme.getMessageColorChat(), temporaryTheme.getDateColorChat(), temporaryTheme.getSelectionColor(),
temporaryTheme.getDateColorChat(), temporaryTheme.getSelectionColor(),
temporaryTheme.getTypingMessageColor(), temporaryTheme.getUserNameColor())); temporaryTheme.getTypingMessageColor(), temporaryTheme.getUserNameColor()));
themeArray = Arrays.copyOf(themeArray, themeArray.length + 1); themeArray = Arrays.copyOf(themeArray, themeArray.length + 1);
themeArray[themeArray.length - 1] = Settings.getInstance().getThemes().get(s).getThemeName(); themeArray[themeArray.length - 1] = Settings.getInstance().getThemes().get(s).getThemeName();
temporaryTheme = new Theme("temporaryTheme", temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
createNewThemeButton.setEnabled(false); createNewThemeButton.setEnabled(false);
themes.addItem(themeArray[themeArray.length - 1]); themes.addItem(themeArray[themeArray.length - 1]);
@ -348,10 +303,6 @@ public class SettingsScreen extends JDialog {
getRootPane().setDefaultButton(okButton); getRootPane().setDefaultButton(okButton);
okButton.addActionListener((evt) -> { okButton.addActionListener((evt) -> {
try { try {
Settings.getInstance().setUsername(Settings.getInstance().getUsername());// still temporary
Settings.getInstance().setEmail(Settings.getInstance().getEmail());// still temporary value
Settings.getInstance().setEnterToSend(Settings.getInstance().isEnterToSend());// still temporary Settings.getInstance().setEnterToSend(Settings.getInstance().isEnterToSend());// still temporary
Settings.getInstance().setCurrentTheme(selectedTheme.getThemeName()); Settings.getInstance().setCurrentTheme(selectedTheme.getThemeName());
@ -412,21 +363,12 @@ public class SettingsScreen extends JDialog {
temporaryTheme = new Theme("temporaryTheme", temporaryTheme = new Theme("temporaryTheme",
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getBackgroundColor(), Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getBackgroundColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getCellColor(), Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getCellColor(),
Settings.getInstance() Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableForegroundColor(),
.getThemes() Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableBackgroundColor(),
.get(Settings.getInstance().getCurrentTheme())
.getInteractableForegroundColor(),
Settings.getInstance()
.getThemes()
.get(Settings.getInstance().getCurrentTheme())
.getInteractableBackgroundColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat(), Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat(), Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getSelectionColor(), Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getSelectionColor(),
Settings.getInstance() Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getTypingMessageColor(),
.getThemes()
.get(Settings.getInstance().getCurrentTheme())
.getTypingMessageColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor()); Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor());
colorsPanel.removeAll(); colorsPanel.removeAll();
@ -513,8 +455,7 @@ public class SettingsScreen extends JDialog {
private void setContent(JPanel content, GridBagConstraints layout) { contentPanel.add(content, layout); } private void setContent(JPanel content, GridBagConstraints layout) { contentPanel.add(content, layout); }
private void buildCustomizeElement(JPanel panel, JButton button, JTextPane textPane, Theme theme, Color color, private void buildCustomizeElement(JPanel panel, JButton button, JTextPane textPane, Theme theme, Color color, String name, int yIndex) {
String name, int yIndex) {
textPane.setFont(new Font("Arial", Font.PLAIN, 14)); textPane.setFont(new Font("Arial", Font.PLAIN, 14));
textPane.setBackground(theme.getBackgroundColor()); textPane.setBackground(theme.getBackgroundColor());
textPane.setForeground(theme.getUserNameColor()); textPane.setForeground(theme.getUserNameColor());

View File

@ -9,7 +9,6 @@ import javax.swing.JOptionPane;
import envoy.client.Client; import envoy.client.Client;
import envoy.client.Config; import envoy.client.Config;
import envoy.client.LocalDB; import envoy.client.LocalDB;
import envoy.client.Settings;
import envoy.exception.EnvoyException; import envoy.exception.EnvoyException;
/** /**
@ -43,7 +42,8 @@ public class Startup {
// Check if all configuration values have been initialized // Check if all configuration values have been initialized
if (!config.isInitialized()) throw new EnvoyException("Server or port are not defined"); if (!config.isInitialized()) throw new EnvoyException("Server or port are not defined");
} catch (Exception e) { } catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error loading configuration values: \n" + e.toString(), "Configuration error", JOptionPane.ERROR_MESSAGE); JOptionPane
.showMessageDialog(null, "Error loading configuration values: \n" + e.toString(), "Configuration error", JOptionPane.ERROR_MESSAGE);
System.exit(1); System.exit(1);
e.printStackTrace(); e.printStackTrace();
} }
@ -56,7 +56,7 @@ public class Startup {
} }
// Acquire the client user (with ID) either from the server or from the local // Acquire the client user (with ID) either from the server or from the local
// cache (Preferences), which triggers offline mode // database, which triggers offline mode
Client client; Client client;
try { try {
client = new Client(config, userName); client = new Client(config, userName);
@ -79,7 +79,6 @@ public class Startup {
"Local DB error", "Local DB error",
JOptionPane.WARNING_MESSAGE); JOptionPane.WARNING_MESSAGE);
} }
Settings.getInstance().setUsername(userName);
EventQueue.invokeLater(() -> { EventQueue.invokeLater(() -> {
try { try {