Fixed formatting, Javadoc and other cosmetic problems

Also fixed PrimaryToggleSwitches having editable text in their state and
description fields
This commit is contained in:
Kai S. K. Engelbart 2019-12-23 10:56:33 +01:00
parent 5090e81b56
commit 762d7630e3
6 changed files with 85 additions and 127 deletions

View File

@ -1,6 +1,8 @@
package envoy.client.event; package envoy.client.event;
/** /**
* Encapsulates a change to the {@code enterToSend} setting.<br>
* <br>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>EnterToSendEvent.java</strong><br> * File: <strong>EnterToSendEvent.java</strong><br>
* Created: <strong>22 Dec 2019</strong><br> * Created: <strong>22 Dec 2019</strong><br>
@ -13,15 +15,13 @@ public class EnterToSendEvent implements Event<Boolean> {
private boolean mode; private boolean mode;
/** /**
* @param mode This is the enter to sent mode when sending messages. * Initializes an {@link EnterToSendEvent}.
* </br> *
* true = Enter to Send Messages </br> * @param mode the state of the {@code enterToSend} setting
* false = Enter to do a line break
* @since Envoy 0.3-alpha * @since Envoy 0.3-alpha
*/ */
public EnterToSendEvent(boolean mode) { this.mode = mode; } public EnterToSendEvent(boolean mode) { this.mode = mode; }
@Override @Override
public Boolean get() { return mode; } public Boolean get() { return mode; }
} }

View File

@ -1,6 +1,8 @@
package envoy.client.event; package envoy.client.event;
/** /**
* Encapsulates a change to the {@code currentOnCloseMode} setting.<br>
* <br>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>OnCloseChangeEvent.java</strong><br> * File: <strong>OnCloseChangeEvent.java</strong><br>
* Created: <strong>22 Dec 2019</strong><br> * Created: <strong>22 Dec 2019</strong><br>
@ -13,16 +15,13 @@ public class OnCloseChangeEvent implements Event<Boolean> {
private boolean closeMode; private boolean closeMode;
/** /**
* @param closeMode This is the on close mode for the client, that should be * Initializes an {@link OnCloseChangeEvent}.
* set. *
* </br> * @param closeMode the state of the {@code currentOnCloseMode} setting
* true = ExitOnClose </br>
* false = HideOnClose
* @since Envoy 0.3-alpha * @since Envoy 0.3-alpha
*/ */
public OnCloseChangeEvent(boolean closeMode) { this.closeMode = closeMode; } public OnCloseChangeEvent(boolean closeMode) { this.closeMode = closeMode; }
@Override @Override
public Boolean get() { return closeMode; } public Boolean get() { return closeMode; }
} }

View File

@ -4,7 +4,8 @@ import java.awt.*;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.*; import javax.swing.JButton;
import javax.swing.JPanel;
import envoy.client.Settings; import envoy.client.Settings;
import envoy.client.event.Event; import envoy.client.event.Event;
@ -12,10 +13,9 @@ import envoy.client.event.EventBus;
import envoy.client.util.EnvoyLog; 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
* </br> * off.<br>
* </br> * <br>
*
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>PrimaryToggleSwitch.java</strong><br> * File: <strong>PrimaryToggleSwitch.java</strong><br>
* Created: <strong>21 Dec 2019</strong><br> * Created: <strong>21 Dec 2019</strong><br>
@ -25,11 +25,12 @@ import envoy.client.util.EnvoyLog;
*/ */
public class PrimaryToggleSwitch extends JPanel { public class PrimaryToggleSwitch extends JPanel {
private static final long serialVersionUID = -721155303106833184L; private final JButton b = new JButton("");
JButton b = new JButton(""); private boolean currentState;
private boolean currentState; private boolean variable;
private boolean variable;
private static final Logger logger = EnvoyLog.getLogger(PrimaryToggleSwitch.class.getSimpleName()); private static final Logger logger = EnvoyLog.getLogger(PrimaryToggleSwitch.class.getSimpleName());
private static final long serialVersionUID = -721155303106833184L;
/** /**
* This is the constructor for the PrimaryToggleSwitch. * 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. </br> * @param initialState The state the toggleSwitch is standardly set to. </br>
* true: off </br> * true: off </br>
* false: on * 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 * @since Envoy v0.3-alpha
*/ */
@SuppressWarnings({ "rawtypes", "unused" }) public PrimaryToggleSwitch(boolean initialState, Class<? extends Event<Boolean>> eventClass) {
public PrimaryToggleSwitch(boolean initialState, String eventName) {
super();
setEnabled(true); setEnabled(true);
setVisible(true); setVisible(true);
@ -68,26 +67,22 @@ public class PrimaryToggleSwitch extends JPanel {
b.addActionListener((evt) -> { b.addActionListener((evt) -> {
try { try {
Class<?> c = Class.forName(eventName); // Dispatch event
Class[] types = { boolean.class }; Constructor<? extends Event<Boolean>> constructor = eventClass.getConstructor(boolean.class);
Constructor constructor = c.getConstructor(types); EventBus.getInstance().dispatch((Event<?>) constructor.newInstance(variable));
Object[] parameters = { variable };
Object instanceOfC = constructor.newInstance(parameters);
EventBus.getInstance().dispatch((Event<?>) constructor.newInstance(parameters));
setState(!currentState); setState(!currentState);
this.revalidate(); revalidate();
this.repaint(); repaint();
} catch (Exception e) { } catch (ReflectiveOperationException | SecurityException e) {
logger.info("An error occured while changing the setting: " + e); logger.warning("An error occured while changing the setting: " + e);
e.printStackTrace();
} }
}); });
repaint(); repaint();
} }
@Override
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
g.setColor(Color.LIGHT_GRAY); g.setColor(Color.LIGHT_GRAY);
g.fillRect(0, 0, 50, 25); 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 * @param state {@code true} to enable the switch, {@code false} to disable it
* should be set. </br>
* true: off </br>
* false: on
* @since Envoy 0.3-alpha * @since Envoy 0.3-alpha
*/ */
public void setState(boolean state) { public void setState(boolean state) {
GridBagConstraints gbc_toggleButton = new GridBagConstraints();
if (state) { if (state) {
GridBagConstraints gbc_toggleButton = new GridBagConstraints();
gbc_toggleButton.anchor = GridBagConstraints.WEST; gbc_toggleButton.anchor = GridBagConstraints.WEST;
gbc_toggleButton.gridx = 0; gbc_toggleButton.gridx = 0;
gbc_toggleButton.gridy = 0;
add(b, gbc_toggleButton);
currentState = true;
variable = true;
} else { } else {
GridBagConstraints gbc_toggleButton = new GridBagConstraints();
gbc_toggleButton.anchor = GridBagConstraints.EAST; gbc_toggleButton.anchor = GridBagConstraints.EAST;
gbc_toggleButton.gridx = 1; 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;
} }
} }

View File

@ -131,13 +131,9 @@ public class Startup {
try { try {
new StatusTrayIcon(chatWindow).show(); new StatusTrayIcon(chatWindow).show();
// If the tray icon is supported, hide the chat window on close // If the tray icon is supported and corresponding settings is set, hide the chat window on close
if (Settings.getInstance().getCurrentOnCloseMode() == true) { if (Settings.getInstance().getCurrentOnCloseMode())
chatWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); chatWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
} else {
chatWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} catch (EnvoyException e) { } catch (EnvoyException e) {
logger.warning("The StatusTrayIcon is not supported on this platform!"); logger.warning("The StatusTrayIcon is not supported on this platform!");
} }

View File

@ -4,15 +4,14 @@ import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
import java.awt.Insets; import java.awt.Insets;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JTextPane; import javax.swing.JTextPane;
import envoy.client.Settings; import envoy.client.Settings;
import envoy.client.event.EnterToSendEvent; import envoy.client.event.*;
import envoy.client.event.EventBus;
import envoy.client.event.OnCloseChangeEvent;
import envoy.client.ui.PrimaryToggleSwitch; import envoy.client.ui.PrimaryToggleSwitch;
import envoy.client.ui.Theme; import envoy.client.ui.Theme;
import envoy.client.util.EnvoyLog; import envoy.client.util.EnvoyLog;
@ -20,7 +19,6 @@ import envoy.client.util.EnvoyLog;
/** /**
* Displays GUI components that allow general settings regarding the client.<br> * Displays GUI components that allow general settings regarding the client.<br>
* <br> * <br>
*
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>General.java</strong><br> * File: <strong>General.java</strong><br>
* Created: <strong>21 Dec 2019</strong><br> * Created: <strong>21 Dec 2019</strong><br>
@ -30,19 +28,20 @@ import envoy.client.util.EnvoyLog;
*/ */
public class General extends SettingsPanel { 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 static final Logger logger = EnvoyLog.getLogger(General.class.getSimpleName());
private Theme theme; private static final long serialVersionUID = -7470848775130754239L;
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();
/** /**
* This is the constructor for the General class. Here the user can set general * 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); setLayout(gbl_general);
createSettingElement(0, createSettingElement(0,
"envoy.client.event.OnCloseChangeEvent", OnCloseChangeEvent.class,
Settings.getInstance().getCurrentOnCloseMode(), Settings.getInstance().getCurrentOnCloseMode(),
toggleSwitch, toggleSwitch,
onCloseModeStatePane, onCloseModeStatePane,
@ -73,7 +72,7 @@ public class General extends SettingsPanel {
EventBus.getInstance().register(OnCloseChangeEvent.class, (evt) -> changeOnClose(((OnCloseChangeEvent) evt).get())); EventBus.getInstance().register(OnCloseChangeEvent.class, (evt) -> changeOnClose(((OnCloseChangeEvent) evt).get()));
createSettingElement(2, createSettingElement(2,
"envoy.client.event.EnterToSendEvent", EnterToSendEvent.class,
Settings.getInstance().isEnterToSend(), Settings.getInstance().isEnterToSend(),
toggleSwitchEnterToSend, toggleSwitchEnterToSend,
enterToSendStatePane, enterToSendStatePane,
@ -92,13 +91,9 @@ public class General extends SettingsPanel {
public void changeOnClose(boolean state) { public void changeOnClose(boolean state) {
this.onCloseState = state; this.onCloseState = state;
if (state == false) { onCloseModeStatePane.setText(state ? "ON" : "OFF");
onCloseModeStatePane.setText("OFF"); revalidate();
} else { repaint();
onCloseModeStatePane.setText("ON");
}
this.revalidate();
this.repaint();
} }
/** /**
@ -111,22 +106,14 @@ public class General extends SettingsPanel {
public void changeEnterToSend(boolean state) { public void changeEnterToSend(boolean state) {
this.enterToSend = state; this.enterToSend = state;
if (state == false) { enterToSendStatePane.setText(state ? "ON" : "OFF");
enterToSendStatePane.setText("OFF"); revalidate();
} else { repaint();
enterToSendStatePane.setText("ON");
}
this.revalidate();
this.repaint();
} }
private void createSettingElement(int gridy, String eventPath, boolean state, PrimaryToggleSwitch toggleSwitch, JTextPane stateText, private void createSettingElement(int gridy, Class<? extends Event<Boolean>> eventClass, boolean state, PrimaryToggleSwitch toggleSwitch,
JTextPane descriptionText, String text) { JTextPane stateText, JTextPane descriptionText, String text) {
if (state == true) { toggleSwitch = new PrimaryToggleSwitch(state, eventClass);
toggleSwitch = new PrimaryToggleSwitch(false, eventPath);
} else {
toggleSwitch = new PrimaryToggleSwitch(true, eventPath);
}
GridBagConstraints gbc_toggleSwitch = new GridBagConstraints(); GridBagConstraints gbc_toggleSwitch = new GridBagConstraints();
gbc_toggleSwitch.gridx = 1; gbc_toggleSwitch.gridx = 1;
@ -134,14 +121,10 @@ public class General extends SettingsPanel {
add(toggleSwitch, gbc_toggleSwitch); add(toggleSwitch, gbc_toggleSwitch);
if (state == false) { stateText.setText(state ? "ON" : "OFF");
stateText.setText("OFF");
} else {
stateText.setText("ON");
}
stateText.setBackground(theme.getCellColor()); stateText.setBackground(theme.getCellColor());
stateText.setForeground(theme.getUserNameColor()); stateText.setForeground(theme.getUserNameColor());
stateText.setEditable(false);
GridBagConstraints gbc_stateText = new GridBagConstraints(); GridBagConstraints gbc_stateText = new GridBagConstraints();
gbc_stateText.anchor = GridBagConstraints.NORTH; gbc_stateText.anchor = GridBagConstraints.NORTH;
@ -154,6 +137,7 @@ public class General extends SettingsPanel {
descriptionText.setBackground(theme.getBackgroundColor()); descriptionText.setBackground(theme.getBackgroundColor());
// TODO: Change to inverted color. // TODO: Change to inverted color.
descriptionText.setForeground(theme.getUserNameColor()); descriptionText.setForeground(theme.getUserNameColor());
descriptionText.setEditable(false);
GridBagConstraints gbc_descriptionText = new GridBagConstraints(); GridBagConstraints gbc_descriptionText = new GridBagConstraints();
gbc_descriptionText.fill = GridBagConstraints.BOTH; gbc_descriptionText.fill = GridBagConstraints.BOTH;
@ -168,27 +152,19 @@ public class General extends SettingsPanel {
@Override @Override
public ActionListener getOkButtonAction() { public ActionListener getOkButtonAction() {
return (evt) -> { return (evt) -> {
if (onCloseState != Settings.getInstance().getCurrentOnCloseMode()) { if (onCloseState != Settings.getInstance().getCurrentOnCloseMode()) try {
try { Settings.getInstance().setCurrentOnCloseMode(onCloseState);
Settings.getInstance().setCurrentOnCloseMode(onCloseState); JOptionPane.showMessageDialog(null, "The changes will take effect the next time the program is started.");
JOptionPane.showMessageDialog(null, "The changes will take effect the next time the program is started."); } catch (Exception e) {
} catch (Exception e) { logger.log(Level.WARNING, "Close mode could not be changed! ", e);
logger.info("Close mode could not be changed! " + e);
e.printStackTrace();
}
} }
if (enterToSend != Settings.getInstance().isEnterToSend()) { if (enterToSend != Settings.getInstance().isEnterToSend()) try {
try { Settings.getInstance().setEnterToSend(enterToSend);
Settings.getInstance().setEnterToSend(enterToSend); JOptionPane.showMessageDialog(null, "The changes will take effect the next time the program is started.");
; } catch (Exception e) {
JOptionPane.showMessageDialog(null, "The changes will take effect the next time the program is started."); logger.log(Level.WARNING, "Enter to send mode could not be changed! ", e);
} catch (Exception e) {
logger.info("Enter to send mode could not be changed! " + e);
e.printStackTrace();
}
} }
}; };
} }
} }

View File

@ -30,7 +30,6 @@ import envoy.client.util.EnvoyLog;
*/ */
public class ThemeCustomizationPanel extends SettingsPanel { public class ThemeCustomizationPanel extends SettingsPanel {
private static final long serialVersionUID = -8697897390666456624L;
private JPanel colorsPanel = new JPanel(); 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 final Insets insets = new Insets(5, 5, 5, 5);
private static final Logger logger = EnvoyLog.getLogger(ThemeCustomizationPanel.class.getSimpleName()); 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 * Initializes a {@link ThemeCustomizationPanel} that enables the user to change