Added settings object and light theme
Improvements: * settings are implemented via Preferences API * fixed "bug" that made partner name pane editable * light theme is added as new display method
This commit is contained in:
parent
da7f898f1a
commit
8f0bf6012a
@ -2,6 +2,8 @@ package envoy.client;
|
|||||||
|
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
|
import envoy.schema.User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Project: <strong>envoy-client</strong><br>
|
* Project: <strong>envoy-client</strong><br>
|
||||||
* File: <strong>Settings.java</strong><br>
|
* File: <strong>Settings.java</strong><br>
|
||||||
@ -37,8 +39,8 @@ public class Settings {
|
|||||||
public static Settings getInstance() {
|
public static Settings getInstance() {
|
||||||
if (settings == null) {
|
if (settings == null) {
|
||||||
settings = new Settings();
|
settings = new Settings();
|
||||||
|
settings.load();
|
||||||
}
|
}
|
||||||
settings.load();
|
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +57,13 @@ public class Settings {
|
|||||||
prefs.putBoolean("darkMode", settings.isDarkMode());
|
prefs.putBoolean("darkMode", settings.isDarkMode());
|
||||||
prefs.putBoolean("enterToSend", settings.isEnterToSend());
|
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
|
* @return the username
|
||||||
|
@ -51,7 +51,6 @@ public class ChatWindow extends JFrame {
|
|||||||
// user specific objects
|
// user specific objects
|
||||||
private Client client;
|
private Client client;
|
||||||
private LocalDB localDB;
|
private LocalDB localDB;
|
||||||
private Settings settings;
|
|
||||||
// used colors in Envoy
|
// used colors in Envoy
|
||||||
private UIColors uiColors = UIColors.getInstance(true);
|
private UIColors uiColors = UIColors.getInstance(true);
|
||||||
// GUI components
|
// GUI components
|
||||||
@ -63,15 +62,14 @@ public class ChatWindow extends JFrame {
|
|||||||
private JScrollPane scrollPane = new JScrollPane();
|
private JScrollPane scrollPane = new JScrollPane();
|
||||||
private JTextPane textPane = new JTextPane();
|
private JTextPane textPane = new JTextPane();
|
||||||
// private JCheckBox jCbChangeMode;
|
// private JCheckBox jCbChangeMode;
|
||||||
private JButton postButton = new JButton();
|
private JButton postButton = new JButton("Post");
|
||||||
private JButton settingsButton = new JButton();
|
private JButton settingsButton = new JButton("Settings");
|
||||||
|
|
||||||
private static int space = 4;
|
private static int space = 4;
|
||||||
|
|
||||||
public ChatWindow(Client client, LocalDB localDB, Settings setting) {
|
public ChatWindow(Client client, LocalDB localDB) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.localDB = localDB;
|
this.localDB = localDB;
|
||||||
this.settings = setting;
|
|
||||||
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
setBounds(100, 100, 600, 800);
|
setBounds(100, 100, 600, 800);
|
||||||
@ -119,7 +117,6 @@ public class ChatWindow extends JFrame {
|
|||||||
gbc_scrollPane.gridy = 1;
|
gbc_scrollPane.gridy = 1;
|
||||||
|
|
||||||
gbc_scrollPane.insets = new Insets(space, space, space, space);
|
gbc_scrollPane.insets = new Insets(space, space, space, space);
|
||||||
|
|
||||||
contentPane.add(scrollPane, gbc_scrollPane);
|
contentPane.add(scrollPane, gbc_scrollPane);
|
||||||
|
|
||||||
// Message enter field
|
// Message enter field
|
||||||
@ -128,7 +125,7 @@ public class ChatWindow extends JFrame {
|
|||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent e) {
|
public void keyReleased(KeyEvent e) {
|
||||||
|
|
||||||
if (e.getKeyCode() == KeyEvent.VK_ENTER && ((settings.isEnterToSend() && e.getModifiersEx() == 0)
|
if (e.getKeyCode() == KeyEvent.VK_ENTER && ((Settings.getInstance().isEnterToSend() && e.getModifiersEx() == 0)
|
||||||
|| (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK))) {
|
|| (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK))) {
|
||||||
|
|
||||||
postMessage(messageList);
|
postMessage(messageList);
|
||||||
@ -179,6 +176,7 @@ public class ChatWindow extends JFrame {
|
|||||||
settingsButton.addActionListener((evt) -> {
|
settingsButton.addActionListener((evt) -> {
|
||||||
try {
|
try {
|
||||||
SettingsScreen.open();
|
SettingsScreen.open();
|
||||||
|
changeChatWindowColors();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("An error occured while opening the settings screen: " + e);
|
System.err.println("An error occured while opening the settings screen: " + e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -188,6 +186,7 @@ public class ChatWindow extends JFrame {
|
|||||||
|
|
||||||
// Partner name display
|
// Partner name display
|
||||||
textPane.setFont(new Font("Arial", Font.PLAIN, 20));
|
textPane.setFont(new Font("Arial", Font.PLAIN, 20));
|
||||||
|
textPane.setEditable(false);
|
||||||
|
|
||||||
GridBagConstraints gbc_partnerName = new GridBagConstraints();
|
GridBagConstraints gbc_partnerName = new GridBagConstraints();
|
||||||
gbc_partnerName.fill = GridBagConstraints.HORIZONTAL;
|
gbc_partnerName.fill = GridBagConstraints.HORIZONTAL;
|
||||||
@ -216,7 +215,6 @@ public class ChatWindow extends JFrame {
|
|||||||
readCurrentChat();
|
readCurrentChat();
|
||||||
|
|
||||||
client.setRecipient(user);
|
client.setRecipient(user);
|
||||||
|
|
||||||
textPane.setText(currentChat.getRecipient().getName());
|
textPane.setText(currentChat.getRecipient().getName());
|
||||||
|
|
||||||
messageList.setModel(currentChat.getModel());
|
messageList.setModel(currentChat.getModel());
|
||||||
@ -251,7 +249,7 @@ public class ChatWindow extends JFrame {
|
|||||||
* @since Envoy v0.1-alpha
|
* @since Envoy v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public void changeChatWindowColors() {
|
public void changeChatWindowColors() {
|
||||||
uiColors.setDisplayMode(settings.isDarkMode());
|
uiColors.setDisplayMode(Settings.getInstance().isDarkMode());
|
||||||
|
|
||||||
// contentPane
|
// contentPane
|
||||||
contentPane.setBackground(uiColors.getBackgroundColor());
|
contentPane.setBackground(uiColors.getBackgroundColor());
|
||||||
|
@ -8,7 +8,6 @@ import java.awt.Insets;
|
|||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JOptionPane;//TODO: temporary
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
@ -30,8 +29,6 @@ public class SettingsScreen extends JDialog {
|
|||||||
private JPanel buttonPane = new JPanel();
|
private JPanel buttonPane = new JPanel();
|
||||||
private JButton okButton = new JButton("Save");
|
private JButton okButton = new JButton("Save");
|
||||||
private JButton cancelButton = new JButton("Cancel");
|
private JButton cancelButton = new JButton("Cancel");
|
||||||
private static Settings settings;
|
|
||||||
private static UIColors uiColors;
|
|
||||||
private static int space = 5;
|
private static int space = 5;
|
||||||
private static SettingsScreen settingsScreen;
|
private static SettingsScreen settingsScreen;
|
||||||
|
|
||||||
@ -47,8 +44,7 @@ public class SettingsScreen extends JDialog {
|
|||||||
*/
|
*/
|
||||||
public static void open() {
|
public static void open() {
|
||||||
|
|
||||||
settings = Settings.getInstance();
|
UIColors.getInstance(Settings.getInstance().isDarkMode());
|
||||||
uiColors.setDisplayMode(settings.isDarkMode());
|
|
||||||
settingsScreen = new SettingsScreen();
|
settingsScreen = new SettingsScreen();
|
||||||
settingsScreen.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
settingsScreen.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
settingsScreen.setModal(true);
|
settingsScreen.setModal(true);
|
||||||
@ -98,16 +94,23 @@ public class SettingsScreen extends JDialog {
|
|||||||
getRootPane().setDefaultButton(okButton);
|
getRootPane().setDefaultButton(okButton);
|
||||||
okButton.addActionListener((evt) -> {
|
okButton.addActionListener((evt) -> {
|
||||||
try {
|
try {
|
||||||
settings.setUsername(settings.getUsername());// still temporary value
|
Settings.getInstance().setUsername(Settings.getInstance().getUsername());// still temporary
|
||||||
settings.setEmail(settings.getEmail());// still temporary value
|
// value
|
||||||
settings.setDarkMode(false);// TODO temporary values while no UI is implemented
|
Settings.getInstance().setEmail(Settings.getInstance().getEmail());// still temporary value
|
||||||
settings.setEnterToSend(settings.isEnterToSend());// still temporary value
|
Settings.getInstance().setDarkMode(!Settings.getInstance().isDarkMode());// TODO temporary
|
||||||
settings.save();
|
// values while no
|
||||||
|
// UI is implemented
|
||||||
|
Settings.getInstance().setEnterToSend(Settings.getInstance().isEnterToSend());// still temporary
|
||||||
|
// value
|
||||||
|
Settings.getInstance().save();
|
||||||
|
UIColors.getUIColors().setDisplayMode(Settings.getInstance().isDarkMode());
|
||||||
|
changeSettingsScreenColors();
|
||||||
|
revalidate();
|
||||||
|
repaint();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Something went wrong when changing the setting");
|
System.err.println("Something went wrong when changing the setting");
|
||||||
settingsScreen.dispose();
|
settingsScreen.dispose();
|
||||||
}
|
}
|
||||||
JOptionPane.showConfirmDialog(settingsScreen, "Successfully changed settings");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,17 +119,17 @@ public class SettingsScreen extends JDialog {
|
|||||||
|
|
||||||
private void changeSettingsScreenColors() {
|
private void changeSettingsScreenColors() {
|
||||||
// whole JDialog
|
// whole JDialog
|
||||||
setBackground(uiColors.getBackgroundColor());
|
setBackground(UIColors.getUIColors().getBackgroundColor());
|
||||||
// contentPanel
|
// contentPanel
|
||||||
contentPanel.setBackground(uiColors.getBackgroundColor());
|
contentPanel.setBackground(UIColors.getUIColors().getBackgroundColor());
|
||||||
// buttonPane
|
// buttonPane
|
||||||
buttonPane.setBackground(uiColors.getBackgroundColor());
|
buttonPane.setBackground(UIColors.getUIColors().getBackgroundColor());
|
||||||
// cancelButton
|
// cancelButton
|
||||||
cancelButton.setBackground(uiColors.getSpecialUseColor());
|
cancelButton.setBackground(UIColors.getUIColors().getSpecialUseColor());
|
||||||
cancelButton.setForeground(uiColors.getTextColor());
|
cancelButton.setForeground(UIColors.getUIColors().getTextColor());
|
||||||
// okButton
|
// okButton
|
||||||
okButton.setBackground(uiColors.getSpecialUseColor());
|
okButton.setBackground(UIColors.getUIColors().getSpecialUseColor());
|
||||||
okButton.setForeground(uiColors.getTextColor());
|
okButton.setForeground(UIColors.getUIColors().getTextColor());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,11 +61,11 @@ public class Startup {
|
|||||||
"Local DB error",
|
"Local DB error",
|
||||||
JOptionPane.WARNING_MESSAGE);
|
JOptionPane.WARNING_MESSAGE);
|
||||||
}
|
}
|
||||||
Settings settings = Settings.getInstance();//TODO delete line
|
Settings.getInstance().firstSave(client.getSender());
|
||||||
|
|
||||||
EventQueue.invokeLater(() -> {
|
EventQueue.invokeLater(() -> {
|
||||||
try {
|
try {
|
||||||
ChatWindow frame = new ChatWindow(client, localDB, settings);
|
ChatWindow frame = new ChatWindow(client, localDB);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -115,10 +115,9 @@ public class UIColors {
|
|||||||
*/
|
*/
|
||||||
public void setTextColor(Color textColor) { this.textColor = textColor; }
|
public void setTextColor(Color textColor) { this.textColor = textColor; }
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
/**
|
/**
|
||||||
* @return the uiColors object
|
* @return the uiColors object
|
||||||
* @since Envoy v0.2-alpha
|
* @since Envoy v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public static UIColors getEnvoyColors() { return uIColors; }
|
public static UIColors getUIColors() { return uIColors; }
|
||||||
}
|
}
|
Reference in New Issue
Block a user