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:
delvh
2019-11-23 13:25:12 +01:00
parent da7f898f1a
commit 8f0bf6012a
5 changed files with 42 additions and 33 deletions

View File

@ -51,7 +51,6 @@ public class ChatWindow extends JFrame {
// user specific objects
private Client client;
private LocalDB localDB;
private Settings settings;
// used colors in Envoy
private UIColors uiColors = UIColors.getInstance(true);
// GUI components
@ -63,15 +62,14 @@ public class ChatWindow extends JFrame {
private JScrollPane scrollPane = new JScrollPane();
private JTextPane textPane = new JTextPane();
// private JCheckBox jCbChangeMode;
private JButton postButton = new JButton();
private JButton settingsButton = new JButton();
private JButton postButton = new JButton("Post");
private JButton settingsButton = new JButton("Settings");
private static int space = 4;
public ChatWindow(Client client, LocalDB localDB, Settings setting) {
public ChatWindow(Client client, LocalDB localDB) {
this.client = client;
this.localDB = localDB;
this.settings = setting;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 600, 800);
@ -119,7 +117,6 @@ public class ChatWindow extends JFrame {
gbc_scrollPane.gridy = 1;
gbc_scrollPane.insets = new Insets(space, space, space, space);
contentPane.add(scrollPane, gbc_scrollPane);
// Message enter field
@ -128,7 +125,7 @@ public class ChatWindow extends JFrame {
@Override
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))) {
postMessage(messageList);
@ -179,6 +176,7 @@ public class ChatWindow extends JFrame {
settingsButton.addActionListener((evt) -> {
try {
SettingsScreen.open();
changeChatWindowColors();
} catch (Exception e) {
System.err.println("An error occured while opening the settings screen: " + e);
e.printStackTrace();
@ -188,6 +186,7 @@ public class ChatWindow extends JFrame {
// Partner name display
textPane.setFont(new Font("Arial", Font.PLAIN, 20));
textPane.setEditable(false);
GridBagConstraints gbc_partnerName = new GridBagConstraints();
gbc_partnerName.fill = GridBagConstraints.HORIZONTAL;
@ -216,7 +215,6 @@ public class ChatWindow extends JFrame {
readCurrentChat();
client.setRecipient(user);
textPane.setText(currentChat.getRecipient().getName());
messageList.setModel(currentChat.getModel());
@ -251,7 +249,7 @@ public class ChatWindow extends JFrame {
* @since Envoy v0.1-alpha
*/
public void changeChatWindowColors() {
uiColors.setDisplayMode(settings.isDarkMode());
uiColors.setDisplayMode(Settings.getInstance().isDarkMode());
// contentPane
contentPane.setBackground(uiColors.getBackgroundColor());