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;
/**
* Encapsulates a change to the {@code enterToSend} setting.<br>
* <br>
* Project: <strong>envoy-client</strong><br>
* File: <strong>EnterToSendEvent.java</strong><br>
* Created: <strong>22 Dec 2019</strong><br>
@ -13,15 +15,13 @@ public class EnterToSendEvent implements Event<Boolean> {
private boolean mode;
/**
* @param mode This is the enter to sent mode when sending messages.
* </br>
* true = Enter to Send Messages </br>
* 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; }
}
}

View File

@ -1,6 +1,8 @@
package envoy.client.event;
/**
* Encapsulates a change to the {@code currentOnCloseMode} setting.<br>
* <br>
* Project: <strong>envoy-client</strong><br>
* File: <strong>OnCloseChangeEvent.java</strong><br>
* Created: <strong>22 Dec 2019</strong><br>
@ -13,16 +15,13 @@ public class OnCloseChangeEvent implements Event<Boolean> {
private boolean closeMode;
/**
* @param closeMode This is the on close mode for the client, that should be
* set.
* </br>
* true = ExitOnClose </br>
* 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; }
}
}

View File

@ -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
* </br>
* </br>
*
* This Component can be used to toggle between two options. e.g. on and
* off.<br>
* <br>
* Project: <strong>envoy-client</strong><br>
* File: <strong>PrimaryToggleSwitch.java</strong><br>
* Created: <strong>21 Dec 2019</strong><br>
@ -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. </br>
* true: off </br>
* 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<Boolean>> 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<Boolean>> 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. </br>
* true: off </br>
* 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;
}
}

View File

@ -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!");
}

View File

@ -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.<br>
* <br>
*
* Project: <strong>envoy-client</strong><br>
* File: <strong>General.java</strong><br>
* Created: <strong>21 Dec 2019</strong><br>
@ -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<Boolean>> 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);
}
};
}
}
}

View File

@ -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()); }
}
}