diff --git a/src/main/java/envoy/client/event/EnterToSendEvent.java b/src/main/java/envoy/client/event/EnterToSendEvent.java
index f96d13e..7b26e0a 100644
--- a/src/main/java/envoy/client/event/EnterToSendEvent.java
+++ b/src/main/java/envoy/client/event/EnterToSendEvent.java
@@ -1,6 +1,8 @@
package envoy.client.event;
/**
+ * Encapsulates a change to the {@code enterToSend} setting.
+ *
* Project: envoy-client
* File: EnterToSendEvent.java
* Created: 22 Dec 2019
@@ -13,15 +15,13 @@ public class EnterToSendEvent implements Event {
private boolean mode;
/**
- * @param mode This is the enter to sent mode when sending messages.
- *
- * true = Enter to Send Messages
- * false = Enter to do a line break
+ * Initializes an {@link EnterToSendEvent}.
+ *
+ * @param mode the state of the {@code enterToSend} setting
* @since Envoy 0.3-alpha
*/
public EnterToSendEvent(boolean mode) { this.mode = mode; }
@Override
public Boolean get() { return mode; }
-
-}
+}
\ No newline at end of file
diff --git a/src/main/java/envoy/client/event/OnCloseChangeEvent.java b/src/main/java/envoy/client/event/OnCloseChangeEvent.java
index 717a5da..2d86fb6 100644
--- a/src/main/java/envoy/client/event/OnCloseChangeEvent.java
+++ b/src/main/java/envoy/client/event/OnCloseChangeEvent.java
@@ -1,6 +1,8 @@
package envoy.client.event;
/**
+ * Encapsulates a change to the {@code currentOnCloseMode} setting.
+ *
* Project: envoy-client
* File: OnCloseChangeEvent.java
* Created: 22 Dec 2019
@@ -13,16 +15,13 @@ public class OnCloseChangeEvent implements Event {
private boolean closeMode;
/**
- * @param closeMode This is the on close mode for the client, that should be
- * set.
- *
- * true = ExitOnClose
- * false = HideOnClose
+ * Initializes an {@link OnCloseChangeEvent}.
+ *
+ * @param closeMode the state of the {@code currentOnCloseMode} setting
* @since Envoy 0.3-alpha
*/
public OnCloseChangeEvent(boolean closeMode) { this.closeMode = closeMode; }
@Override
public Boolean get() { return closeMode; }
-
-}
+}
\ No newline at end of file
diff --git a/src/main/java/envoy/client/ui/PrimaryToggleSwitch.java b/src/main/java/envoy/client/ui/PrimaryToggleSwitch.java
index 361db5d..109656a 100644
--- a/src/main/java/envoy/client/ui/PrimaryToggleSwitch.java
+++ b/src/main/java/envoy/client/ui/PrimaryToggleSwitch.java
@@ -4,7 +4,8 @@ import java.awt.*;
import java.lang.reflect.Constructor;
import java.util.logging.Logger;
-import javax.swing.*;
+import javax.swing.JButton;
+import javax.swing.JPanel;
import envoy.client.Settings;
import envoy.client.event.Event;
@@ -12,10 +13,9 @@ import envoy.client.event.EventBus;
import envoy.client.util.EnvoyLog;
/**
- * This Component can be used to toggle between two options. e.g. on and off
- *
- *
- *
+ * This Component can be used to toggle between two options. e.g. on and
+ * off.
+ *
* Project: envoy-client
* File: PrimaryToggleSwitch.java
* Created: 21 Dec 2019
@@ -25,11 +25,12 @@ import envoy.client.util.EnvoyLog;
*/
public class PrimaryToggleSwitch extends JPanel {
- private static final long serialVersionUID = -721155303106833184L;
- JButton b = new JButton("");
- private boolean currentState;
- private boolean variable;
+ private final JButton b = new JButton("");
+ private boolean currentState;
+ private boolean variable;
+
private static final Logger logger = EnvoyLog.getLogger(PrimaryToggleSwitch.class.getSimpleName());
+ private static final long serialVersionUID = -721155303106833184L;
/**
* This is the constructor for the PrimaryToggleSwitch.
@@ -37,12 +38,10 @@ public class PrimaryToggleSwitch extends JPanel {
* @param initialState The state the toggleSwitch is standardly set to.
* true: off
* false: on
- * @param eventName the path of the event class
+ * @param eventClass the class of the event dispatched by this toggleSwitch
* @since Envoy v0.3-alpha
*/
- @SuppressWarnings({ "rawtypes", "unused" })
- public PrimaryToggleSwitch(boolean initialState, String eventName) {
- super();
+ public PrimaryToggleSwitch(boolean initialState, Class extends Event> eventClass) {
setEnabled(true);
setVisible(true);
@@ -68,26 +67,22 @@ public class PrimaryToggleSwitch extends JPanel {
b.addActionListener((evt) -> {
try {
- Class> c = Class.forName(eventName);
- Class[] types = { boolean.class };
- Constructor constructor = c.getConstructor(types);
+ // Dispatch event
+ Constructor extends Event> constructor = eventClass.getConstructor(boolean.class);
+ EventBus.getInstance().dispatch((Event>) constructor.newInstance(variable));
- Object[] parameters = { variable };
- Object instanceOfC = constructor.newInstance(parameters);
-
- EventBus.getInstance().dispatch((Event>) constructor.newInstance(parameters));
setState(!currentState);
- this.revalidate();
- this.repaint();
- } catch (Exception e) {
- logger.info("An error occured while changing the setting: " + e);
- e.printStackTrace();
+ revalidate();
+ repaint();
+ } catch (ReflectiveOperationException | SecurityException e) {
+ logger.warning("An error occured while changing the setting: " + e);
}
});
repaint();
}
+ @Override
public void paintComponent(Graphics g) {
g.setColor(Color.LIGHT_GRAY);
g.fillRect(0, 0, 50, 25);
@@ -96,33 +91,25 @@ public class PrimaryToggleSwitch extends JPanel {
}
/**
- * This method sets the state of the {@link PrimaryToggleSwitch}.
+ * This method sets the state of this {@link PrimaryToggleSwitch}.
*
- * @param state This is the state of the {@link PrimaryToggleSwitch}, that
- * should be set.
- * true: off
- * false: on
+ * @param state {@code true} to enable the switch, {@code false} to disable it
* @since Envoy 0.3-alpha
*/
public void setState(boolean state) {
+ GridBagConstraints gbc_toggleButton = new GridBagConstraints();
+
if (state) {
- GridBagConstraints gbc_toggleButton = new GridBagConstraints();
gbc_toggleButton.anchor = GridBagConstraints.WEST;
gbc_toggleButton.gridx = 0;
- gbc_toggleButton.gridy = 0;
-
- add(b, gbc_toggleButton);
- currentState = true;
- variable = true;
} else {
- GridBagConstraints gbc_toggleButton = new GridBagConstraints();
gbc_toggleButton.anchor = GridBagConstraints.EAST;
gbc_toggleButton.gridx = 1;
- gbc_toggleButton.gridy = 0;
-
- add(b, gbc_toggleButton);
- currentState = false;
- variable = false;
}
+ gbc_toggleButton.gridy = 0;
+ add(b, gbc_toggleButton);
+
+ currentState = state;
+ variable = state;
}
}
diff --git a/src/main/java/envoy/client/ui/Startup.java b/src/main/java/envoy/client/ui/Startup.java
index d2f7125..9cce0dd 100644
--- a/src/main/java/envoy/client/ui/Startup.java
+++ b/src/main/java/envoy/client/ui/Startup.java
@@ -131,13 +131,9 @@ public class Startup {
try {
new StatusTrayIcon(chatWindow).show();
- // If the tray icon is supported, hide the chat window on close
- if (Settings.getInstance().getCurrentOnCloseMode() == true) {
+ // If the tray icon is supported and corresponding settings is set, hide the chat window on close
+ if (Settings.getInstance().getCurrentOnCloseMode())
chatWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
- } else {
- chatWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
-
} catch (EnvoyException e) {
logger.warning("The StatusTrayIcon is not supported on this platform!");
}
diff --git a/src/main/java/envoy/client/ui/settings/General.java b/src/main/java/envoy/client/ui/settings/General.java
index e922359..faa46bc 100644
--- a/src/main/java/envoy/client/ui/settings/General.java
+++ b/src/main/java/envoy/client/ui/settings/General.java
@@ -4,15 +4,14 @@ import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;
+import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTextPane;
import envoy.client.Settings;
-import envoy.client.event.EnterToSendEvent;
-import envoy.client.event.EventBus;
-import envoy.client.event.OnCloseChangeEvent;
+import envoy.client.event.*;
import envoy.client.ui.PrimaryToggleSwitch;
import envoy.client.ui.Theme;
import envoy.client.util.EnvoyLog;
@@ -20,7 +19,6 @@ import envoy.client.util.EnvoyLog;
/**
* Displays GUI components that allow general settings regarding the client.
*
- *
* Project: envoy-client
* File: General.java
* Created: 21 Dec 2019
@@ -30,19 +28,20 @@ import envoy.client.util.EnvoyLog;
*/
public class General extends SettingsPanel {
- private static final long serialVersionUID = -7470848775130754239L;
+ private Theme theme;
+ private boolean onCloseState;
+ private boolean enterToSend;
+
+ private PrimaryToggleSwitch toggleSwitch;
+ private JTextPane onCloseModeTextPane = new JTextPane();
+ private JTextPane onCloseModeStatePane = new JTextPane();
+
+ private PrimaryToggleSwitch toggleSwitchEnterToSend;
+ private JTextPane enterToSendTextPane = new JTextPane();
+ private JTextPane enterToSendStatePane = new JTextPane();
+
private static final Logger logger = EnvoyLog.getLogger(General.class.getSimpleName());
- private Theme theme;
- private boolean onCloseState;
- private boolean enterToSend;
-
- PrimaryToggleSwitch toggleSwitch;
- JTextPane onCloseModeTextPane = new JTextPane();
- JTextPane onCloseModeStatePane = new JTextPane();
-
- PrimaryToggleSwitch toggleSwitchEnterToSend;
- JTextPane enterToSendTextPane = new JTextPane();
- JTextPane enterToSendStatePane = new JTextPane();
+ private static final long serialVersionUID = -7470848775130754239L;
/**
* This is the constructor for the General class. Here the user can set general
@@ -64,7 +63,7 @@ public class General extends SettingsPanel {
setLayout(gbl_general);
createSettingElement(0,
- "envoy.client.event.OnCloseChangeEvent",
+ OnCloseChangeEvent.class,
Settings.getInstance().getCurrentOnCloseMode(),
toggleSwitch,
onCloseModeStatePane,
@@ -73,7 +72,7 @@ public class General extends SettingsPanel {
EventBus.getInstance().register(OnCloseChangeEvent.class, (evt) -> changeOnClose(((OnCloseChangeEvent) evt).get()));
createSettingElement(2,
- "envoy.client.event.EnterToSendEvent",
+ EnterToSendEvent.class,
Settings.getInstance().isEnterToSend(),
toggleSwitchEnterToSend,
enterToSendStatePane,
@@ -92,13 +91,9 @@ public class General extends SettingsPanel {
public void changeOnClose(boolean state) {
this.onCloseState = state;
- if (state == false) {
- onCloseModeStatePane.setText("OFF");
- } else {
- onCloseModeStatePane.setText("ON");
- }
- this.revalidate();
- this.repaint();
+ onCloseModeStatePane.setText(state ? "ON" : "OFF");
+ revalidate();
+ repaint();
}
/**
@@ -111,22 +106,14 @@ public class General extends SettingsPanel {
public void changeEnterToSend(boolean state) {
this.enterToSend = state;
- if (state == false) {
- enterToSendStatePane.setText("OFF");
- } else {
- enterToSendStatePane.setText("ON");
- }
- this.revalidate();
- this.repaint();
+ enterToSendStatePane.setText(state ? "ON" : "OFF");
+ revalidate();
+ repaint();
}
- private void createSettingElement(int gridy, String eventPath, boolean state, PrimaryToggleSwitch toggleSwitch, JTextPane stateText,
- JTextPane descriptionText, String text) {
- if (state == true) {
- toggleSwitch = new PrimaryToggleSwitch(false, eventPath);
- } else {
- toggleSwitch = new PrimaryToggleSwitch(true, eventPath);
- }
+ private void createSettingElement(int gridy, Class extends Event> eventClass, boolean state, PrimaryToggleSwitch toggleSwitch,
+ JTextPane stateText, JTextPane descriptionText, String text) {
+ toggleSwitch = new PrimaryToggleSwitch(state, eventClass);
GridBagConstraints gbc_toggleSwitch = new GridBagConstraints();
gbc_toggleSwitch.gridx = 1;
@@ -134,14 +121,10 @@ public class General extends SettingsPanel {
add(toggleSwitch, gbc_toggleSwitch);
- if (state == false) {
- stateText.setText("OFF");
- } else {
- stateText.setText("ON");
- }
-
+ stateText.setText(state ? "ON" : "OFF");
stateText.setBackground(theme.getCellColor());
stateText.setForeground(theme.getUserNameColor());
+ stateText.setEditable(false);
GridBagConstraints gbc_stateText = new GridBagConstraints();
gbc_stateText.anchor = GridBagConstraints.NORTH;
@@ -154,6 +137,7 @@ public class General extends SettingsPanel {
descriptionText.setBackground(theme.getBackgroundColor());
// TODO: Change to inverted color.
descriptionText.setForeground(theme.getUserNameColor());
+ descriptionText.setEditable(false);
GridBagConstraints gbc_descriptionText = new GridBagConstraints();
gbc_descriptionText.fill = GridBagConstraints.BOTH;
@@ -168,27 +152,19 @@ public class General extends SettingsPanel {
@Override
public ActionListener getOkButtonAction() {
return (evt) -> {
- if (onCloseState != Settings.getInstance().getCurrentOnCloseMode()) {
- try {
- Settings.getInstance().setCurrentOnCloseMode(onCloseState);
- JOptionPane.showMessageDialog(null, "The changes will take effect the next time the program is started.");
- } catch (Exception e) {
- logger.info("Close mode could not be changed! " + e);
- e.printStackTrace();
- }
+ if (onCloseState != Settings.getInstance().getCurrentOnCloseMode()) try {
+ Settings.getInstance().setCurrentOnCloseMode(onCloseState);
+ JOptionPane.showMessageDialog(null, "The changes will take effect the next time the program is started.");
+ } catch (Exception e) {
+ logger.log(Level.WARNING, "Close mode could not be changed! ", e);
}
- if (enterToSend != Settings.getInstance().isEnterToSend()) {
- try {
- Settings.getInstance().setEnterToSend(enterToSend);
- ;
- JOptionPane.showMessageDialog(null, "The changes will take effect the next time the program is started.");
- } catch (Exception e) {
- logger.info("Enter to send mode could not be changed! " + e);
- e.printStackTrace();
- }
+ if (enterToSend != Settings.getInstance().isEnterToSend()) try {
+ Settings.getInstance().setEnterToSend(enterToSend);
+ JOptionPane.showMessageDialog(null, "The changes will take effect the next time the program is started.");
+ } catch (Exception e) {
+ logger.log(Level.WARNING, "Enter to send mode could not be changed! ", e);
}
};
}
-
-}
+}
\ No newline at end of file
diff --git a/src/main/java/envoy/client/ui/settings/ThemeCustomizationPanel.java b/src/main/java/envoy/client/ui/settings/ThemeCustomizationPanel.java
index 959690e..5310a5e 100644
--- a/src/main/java/envoy/client/ui/settings/ThemeCustomizationPanel.java
+++ b/src/main/java/envoy/client/ui/settings/ThemeCustomizationPanel.java
@@ -30,7 +30,6 @@ import envoy.client.util.EnvoyLog;
*/
public class ThemeCustomizationPanel extends SettingsPanel {
- private static final long serialVersionUID = -8697897390666456624L;
private JPanel colorsPanel = new JPanel();
@@ -42,6 +41,7 @@ public class ThemeCustomizationPanel extends SettingsPanel {
private final Insets insets = new Insets(5, 5, 5, 5);
private static final Logger logger = EnvoyLog.getLogger(ThemeCustomizationPanel.class.getSimpleName());
+ private static final long serialVersionUID = -8697897390666456624L;
/**
* Initializes a {@link ThemeCustomizationPanel} that enables the user to change
@@ -230,4 +230,4 @@ public class ThemeCustomizationPanel extends SettingsPanel {
}
private Color getInvertedColor(Color color) { return new Color(255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue()); }
-}
+}
\ No newline at end of file