diff --git a/src/main/java/envoy/client/Settings.java b/src/main/java/envoy/client/Settings.java index b1c0b6b..fc60877 100644 --- a/src/main/java/envoy/client/Settings.java +++ b/src/main/java/envoy/client/Settings.java @@ -1,11 +1,11 @@ package envoy.client; -import java.awt.Color; import java.io.*; import java.util.HashMap; import java.util.Map; import java.util.prefs.Preferences; +import envoy.client.ui.Color; import envoy.client.ui.Theme; /** @@ -28,6 +28,7 @@ public class Settings { private boolean enterToSend = true; private Map themes; private String currentTheme; + private boolean currentOnCloseMode; /** * Required to save the settings. @@ -64,6 +65,7 @@ public class Settings { private void load() { setEnterToSend(prefs.getBoolean("enterToSend", true)); setCurrentTheme(prefs.get("theme", "dark")); + setCurrentOnCloseMode(prefs.getBoolean("onCloseMode", true)); // Load themes from theme file try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(themeFile))) { @@ -94,6 +96,7 @@ public class Settings { public void save() throws IOException { prefs.put("theme", currentTheme); prefs.putBoolean("enterToSend", isEnterToSend()); + prefs.putBoolean("onCloseMode", currentOnCloseMode); // Save themes to theme file themeFile.createNewFile(); @@ -155,4 +158,18 @@ public class Settings { * @since Envoy v0.2-alpha */ public void setThemes(Map themes) { this.themes = themes; } + + /** + * @return the current on close mode. + * @since Envoy v0.3-alpha + */ + public boolean getCurrentOnCloseMode() { return currentOnCloseMode; } + + /** + * Sets the current on close mode. + * + * @param currentOnCloseMode the on close mode that should be set. + * @since Envoy v0.3-alpha + */ + public void setCurrentOnCloseMode(boolean currentOnCloseMode) { this.currentOnCloseMode = currentOnCloseMode; } } \ No newline at end of file diff --git a/src/main/java/envoy/client/event/EnterToSendEvent.java b/src/main/java/envoy/client/event/EnterToSendEvent.java new file mode 100644 index 0000000..7b26e0a --- /dev/null +++ b/src/main/java/envoy/client/event/EnterToSendEvent.java @@ -0,0 +1,27 @@ +package envoy.client.event; + +/** + * Encapsulates a change to the {@code enterToSend} setting.
+ *
+ * Project: envoy-client
+ * File: EnterToSendEvent.java
+ * Created: 22 Dec 2019
+ * + * @author Maximilian Käfer + * @since Envoy v0.3-alpha + */ +public class EnterToSendEvent implements Event { + + private boolean mode; + + /** + * 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 new file mode 100644 index 0000000..2d86fb6 --- /dev/null +++ b/src/main/java/envoy/client/event/OnCloseChangeEvent.java @@ -0,0 +1,27 @@ +package envoy.client.event; + +/** + * Encapsulates a change to the {@code currentOnCloseMode} setting.
+ *
+ * Project: envoy-client
+ * File: OnCloseChangeEvent.java
+ * Created: 22 Dec 2019
+ * + * @author Maximilian Käfer + * @since Envoy v0.3-alpha + */ +public class OnCloseChangeEvent implements Event { + + private boolean closeMode; + + /** + * 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/Color.java b/src/main/java/envoy/client/ui/Color.java new file mode 100644 index 0000000..33be64b --- /dev/null +++ b/src/main/java/envoy/client/ui/Color.java @@ -0,0 +1,106 @@ +package envoy.client.ui; + +import java.awt.color.ColorSpace; + +/** + * Project: envoy-clientChess
+ * File: Color.javaEvent.java
+ * Created: 23.12.2019
+ * + * @author Kai S. K. Engelbart + */ +@SuppressWarnings("javadoc") +public class Color extends java.awt.Color { + + /** + * The color white. In the default sRGB space. + */ + public static final Color white = new Color(255, 255, 255); + + /** + * The color light gray. In the default sRGB space. + */ + public static final Color lightGray = new Color(192, 192, 192); + + /** + * The color gray. In the default sRGB space. + */ + public static final Color gray = new Color(128, 128, 128); + + /** + * The color dark gray. In the default sRGB space. + */ + public static final Color darkGray = new Color(64, 64, 64); + + /** + * The color black. In the default sRGB space. + */ + public static final Color black = new Color(0, 0, 0); + + /** + * The color red. In the default sRGB space. + */ + public static final Color red = new Color(255, 0, 0); + + /** + * The color pink. In the default sRGB space. + */ + public static final Color pink = new Color(255, 175, 175); + + /** + * The color orange. In the default sRGB space. + */ + public static final Color orange = new Color(255, 200, 0); + + /** + * The color yellow. In the default sRGB space. + */ + public static final Color yellow = new Color(255, 255, 0); + + /** + * The color green. In the default sRGB space. + */ + public static final Color green = new Color(0, 255, 0); + + /** + * The color magenta. In the default sRGB space. + */ + public static final Color magenta = new Color(255, 0, 255); + + /** + * The color cyan. In the default sRGB space. + */ + public static final Color cyan = new Color(0, 255, 255); + + /** + * The color blue. In the default sRGB space. + */ + public static final Color blue = new Color(0, 0, 255); + + private static final long serialVersionUID = -9166233199998257344L; + + public Color(int rgb) { super(rgb); } + + public Color(int rgba, boolean hasalpha) { super(rgba, hasalpha); } + + public Color(int r, int g, int b) { super(r, g, b); } + + public Color(float r, float g, float b) { super(r, g, b); } + + public Color(ColorSpace cspace, float[] components, float alpha) { super(cspace, components, alpha); } + + public Color(int r, int g, int b, int a) { super(r, g, b, a); } + + public Color(float r, float g, float b, float a) { super(r, g, b, a); } + + /** + * @return the inversion of this {@link Color} by replacing the red, green and + * blue values by subtracting them form 255 + */ + public Color invert() { return new Color(255 - getRed(), 255 - getGreen(), 255 - getBlue()); } + + /** + * @return the hex value of this {@link Color} + */ + public String toHex() { return String.format("#%02x%02x%02x", getRed(), getGreen(), getBlue()); } +} \ No newline at end of file diff --git a/src/main/java/envoy/client/ui/MessageListRenderer.java b/src/main/java/envoy/client/ui/MessageListRenderer.java index 5623fb6..ddd2230 100644 --- a/src/main/java/envoy/client/ui/MessageListRenderer.java +++ b/src/main/java/envoy/client/ui/MessageListRenderer.java @@ -1,6 +1,5 @@ package envoy.client.ui; -import java.awt.Color; import java.awt.Component; import java.text.SimpleDateFormat; @@ -46,11 +45,11 @@ public class MessageListRenderer extends JLabel implements ListCellRenderer

%s

%s :%s", dateColor, @@ -60,12 +59,4 @@ public class MessageListRenderer extends JLabel implements ListCellRenderer + *
+ * Project: envoy-client
+ * File: PrimaryToggleSwitch.java
+ * Created: 21 Dec 2019
+ * + * @author Maximilian Käfer + * @since Envoy v0.3-alpha + */ +public class PrimaryToggleSwitch extends JPanel { + + private final JButton b = new JButton(""); + + private boolean currentState; + + private static final Logger logger = EnvoyLog.getLogger(PrimaryToggleSwitch.class.getSimpleName()); + private static final long serialVersionUID = -721155303106833184L; + + /** + * This is the constructor for the PrimaryToggleSwitch. + * + * @param initialState The state the toggleSwitch is standardly set to.
+ * true: off
+ * false: on + * @param eventClass the class of the event dispatched by this toggleSwitch + * @since Envoy v0.3-alpha + */ + public PrimaryToggleSwitch(boolean initialState, Class> eventClass) { + setEnabled(true); + setVisible(true); + + setPreferredSize(new Dimension(50, 25)); + setMinimumSize(new Dimension(50, 25)); + setMaximumSize(new Dimension(50, 25)); + + b.setPreferredSize(new Dimension(25, 25)); + b.setMinimumSize(new Dimension(25, 25)); + b.setMaximumSize(new Dimension(25, 25)); + + b.setBackground(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableBackgroundColor()); + + GridBagLayout gbl_toggleSwitch = new GridBagLayout(); + gbl_toggleSwitch.columnWidths = new int[] { 1, 1 }; + gbl_toggleSwitch.rowHeights = new int[] { 1 }; + gbl_toggleSwitch.columnWeights = new double[] { 1.0, 1.0 }; + gbl_toggleSwitch.rowWeights = new double[] { 1.0 }; + + setLayout(gbl_toggleSwitch); + + setState(initialState); + + b.addActionListener((evt) -> { + try { + // Dispatch event + Constructor> constructor = eventClass.getConstructor(boolean.class); + EventBus.getInstance().dispatch(constructor.newInstance(currentState)); + + setState(!currentState); + 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); + g.setColor(Color.GREEN); + g.fillRect(0, 0, 25, 25); + } + + /** + * This method sets the state of this {@link PrimaryToggleSwitch}. + * + * @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) { + gbc_toggleButton.anchor = GridBagConstraints.WEST; + gbc_toggleButton.gridx = 0; + } else { + gbc_toggleButton.anchor = GridBagConstraints.EAST; + gbc_toggleButton.gridx = 1; + } + gbc_toggleButton.gridy = 0; + add(b, gbc_toggleButton); + + currentState = state; + } +} diff --git a/src/main/java/envoy/client/ui/Startup.java b/src/main/java/envoy/client/ui/Startup.java index ca68618..5e5bc92 100644 --- a/src/main/java/envoy/client/ui/Startup.java +++ b/src/main/java/envoy/client/ui/Startup.java @@ -142,8 +142,9 @@ public class Startup { try { new StatusTrayIcon(chatWindow).show(); - // If the tray icon is supported, hide the chat window on close - chatWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); + // 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); } catch (EnvoyException e) { logger.warning("The StatusTrayIcon is not supported on this platform!"); } diff --git a/src/main/java/envoy/client/ui/Theme.java b/src/main/java/envoy/client/ui/Theme.java index 3e6c39e..d912988 100644 --- a/src/main/java/envoy/client/ui/Theme.java +++ b/src/main/java/envoy/client/ui/Theme.java @@ -1,6 +1,5 @@ package envoy.client.ui; -import java.awt.Color; import java.io.Serializable; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/envoy/client/ui/UserListRenderer.java b/src/main/java/envoy/client/ui/UserListRenderer.java index d26aa8b..ca7214d 100644 --- a/src/main/java/envoy/client/ui/UserListRenderer.java +++ b/src/main/java/envoy/client/ui/UserListRenderer.java @@ -1,6 +1,5 @@ package envoy.client.ui; -import java.awt.Color; import java.awt.Component; import javax.swing.JLabel; @@ -44,7 +43,7 @@ public class UserListRenderer extends JLabel implements ListCellRenderer { // Getting the UserNameColor of the current theme String textColor = null; - textColor = toHex(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor()); + textColor = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor().toHex(); switch (status) { case ONLINE: setText(String @@ -57,12 +56,4 @@ public class UserListRenderer extends JLabel implements ListCellRenderer { } return this; } - - private String toHex(Color c) { - int r = c.getRed(); - int g = c.getGreen(); - int b = c.getBlue(); - String hex = String.format("#%02x%02x%02x", r, g, b); - return hex; - } } \ No newline at end of file diff --git a/src/main/java/envoy/client/ui/settings/General.java b/src/main/java/envoy/client/ui/settings/General.java new file mode 100644 index 0000000..b128454 --- /dev/null +++ b/src/main/java/envoy/client/ui/settings/General.java @@ -0,0 +1,169 @@ +package envoy.client.ui.settings; + +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.*; +import envoy.client.ui.PrimaryToggleSwitch; +import envoy.client.ui.Theme; +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
+ * + * @author Maximilian Käfer + * @since Envoy v0.3-alpha + */ +public class General extends SettingsPanel { + + 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 long serialVersionUID = -7470848775130754239L; + + /** + * This is the constructor for the General class. Here the user can set general + * settings for the client. + * + * @since Envoy 0.3-alpha + */ + public General() { + theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()); + + setBackground(theme.getCellColor()); + + GridBagLayout gbl_general = new GridBagLayout(); + gbl_general.columnWidths = new int[] { 1, 1 }; + gbl_general.rowHeights = new int[] { 1, 1, 1, 1, 1 }; + gbl_general.columnWeights = new double[] { 1.0, 0.1 }; + gbl_general.rowWeights = new double[] { 0.02, 0.0005, 0.02, 0.0005, 1.0 }; + + setLayout(gbl_general); + + createSettingElement(0, + OnCloseChangeEvent.class, + Settings.getInstance().getCurrentOnCloseMode(), + toggleSwitch, + onCloseModeStatePane, + onCloseModeTextPane, + "Client runs in the background, when window is closed"); + EventBus.getInstance().register(OnCloseChangeEvent.class, (evt) -> changeOnClose(((OnCloseChangeEvent) evt).get())); + + createSettingElement(2, + EnterToSendEvent.class, + Settings.getInstance().isEnterToSend(), + toggleSwitchEnterToSend, + enterToSendStatePane, + enterToSendTextPane, + "Press Enter to send messages"); + EventBus.getInstance().register(EnterToSendEvent.class, (evt) -> changeEnterToSend(((EnterToSendEvent) evt).get())); + } + + /** + * This method changes the on close mode of the client. + * + * @param state This is the integer that defines weather the toggleSwitch is on + * or off. + * @since Envoy v0.3-alpha + */ + public void changeOnClose(boolean state) { + this.onCloseState = state; + + onCloseModeStatePane.setText(state ? "ON" : "OFF"); + revalidate(); + repaint(); + } + + /** + * This method changes the enter to send a message setting. + * + * @param state This is the integer that defines weather the toggleSwitch is on + * or off. + * @since Envoy v0.3-alpha + */ + public void changeEnterToSend(boolean state) { + this.enterToSend = state; + + enterToSendStatePane.setText(state ? "ON" : "OFF"); + revalidate(); + repaint(); + } + + private void createSettingElement(int gridy, Class> 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; + gbc_toggleSwitch.gridy = gridy; + + add(toggleSwitch, gbc_toggleSwitch); + + 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; + gbc_stateText.gridx = 1; + gbc_stateText.gridy = gridy + 1; + + add(stateText, gbc_stateText); + + descriptionText.setText(text); + descriptionText.setBackground(theme.getBackgroundColor().invert()); + descriptionText.setForeground(theme.getUserNameColor()); + descriptionText.setEditable(false); + + GridBagConstraints gbc_descriptionText = new GridBagConstraints(); + gbc_descriptionText.fill = GridBagConstraints.BOTH; + gbc_descriptionText.gridx = 0; + gbc_descriptionText.gridy = gridy; + gbc_descriptionText.gridheight = 2; + gbc_descriptionText.insets = new Insets(5, 5, 5, 5); + + add(descriptionText, gbc_descriptionText); + } + + @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.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.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/SettingsScreen.java b/src/main/java/envoy/client/ui/settings/SettingsScreen.java index 29bbe92..b971625 100644 --- a/src/main/java/envoy/client/ui/settings/SettingsScreen.java +++ b/src/main/java/envoy/client/ui/settings/SettingsScreen.java @@ -39,7 +39,7 @@ public class SettingsScreen extends JDialog { private final JList options = new JList<>(optionsListModel); // OK and cancel buttons - private final JPanel buttonPane = new JPanel(); + private final JPanel buttonPane = new JPanel(); private final PrimaryButton okButton = new PrimaryButton("Save"); private final PrimaryButton cancelButton = new PrimaryButton("Cancel"); @@ -57,6 +57,7 @@ public class SettingsScreen extends JDialog { public SettingsScreen() { // Initialize settings pages Map> panels = new HashMap<>(); + panels.put("General", General.class); panels.put("Color Themes", ThemeCustomizationPanel.class); setBounds(10, 10, 450, 650); @@ -118,10 +119,10 @@ public class SettingsScreen extends JDialog { // ButtonPane GridBagLayout gbl_buttonPane = new GridBagLayout(); - gbl_buttonPane.columnWidths = new int[] { 1, 1}; - gbl_buttonPane.rowHeights = new int[] { 25}; - gbl_buttonPane.columnWeights = new double[] { 1.0, 1.0}; - gbl_buttonPane.rowWeights = new double[] { 0.0}; + gbl_buttonPane.columnWidths = new int[] { 1, 1 }; + gbl_buttonPane.rowHeights = new int[] { 25 }; + gbl_buttonPane.columnWeights = new double[] { 1.0, 1.0 }; + gbl_buttonPane.rowWeights = new double[] { 0.0 }; getContentPane().add(buttonPane, BorderLayout.SOUTH); buttonPane.setLayout(gbl_buttonPane); @@ -188,4 +189,4 @@ public class SettingsScreen extends JDialog { options.setForeground(theme.getUserNameColor()); options.setBackground(theme.getCellColor()); } -} +} \ 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 45663af..8c3f9f4 100644 --- a/src/main/java/envoy/client/ui/settings/ThemeCustomizationPanel.java +++ b/src/main/java/envoy/client/ui/settings/ThemeCustomizationPanel.java @@ -13,6 +13,7 @@ import javax.swing.*; import envoy.client.Settings; import envoy.client.event.EventBus; import envoy.client.event.ThemeChangeEvent; +import envoy.client.ui.Color; import envoy.client.ui.Theme; import envoy.client.util.EnvoyLog; @@ -30,18 +31,17 @@ import envoy.client.util.EnvoyLog; */ public class ThemeCustomizationPanel extends SettingsPanel { - private static final long serialVersionUID = -8697897390666456624L; - private JPanel colorsPanel = new JPanel(); - private String[] themeArray = Settings.getInstance().getThemes().keySet().toArray(new String[0]); - private JComboBox themes = new JComboBox<>(themeArray); - private Theme temporaryTheme, selectedTheme; - private boolean themeChanged = false; + private String[] themeArray = Settings.getInstance().getThemes().keySet().toArray(new String[0]); + private JComboBox themes = new JComboBox<>(themeArray); + private Theme temporaryTheme, selectedTheme; + private boolean themeChanged = false; 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 @@ -51,15 +51,14 @@ public class ThemeCustomizationPanel extends SettingsPanel { * @since Envoy v0.2-alpha */ public ThemeCustomizationPanel() { - temporaryTheme = new Theme("temporaryTheme", - Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme())); + temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme())); GridBagLayout gbl_themeLayout = new GridBagLayout(); - gbl_themeLayout.columnWidths = new int[] { 1, 1 }; - gbl_themeLayout.rowHeights = new int[] { 1, 1 }; - gbl_themeLayout.columnWeights = new double[] { 1.0, 1.0 }; - gbl_themeLayout.rowWeights = new double[] { 0.01, 1.0 }; + gbl_themeLayout.columnWidths = new int[] { 1, 1 }; + gbl_themeLayout.rowHeights = new int[] { 1, 1 }; + gbl_themeLayout.columnWeights = new double[] { 1.0, 1.0 }; + gbl_themeLayout.rowWeights = new double[] { 0.01, 1.0 }; setLayout(gbl_themeLayout); @@ -76,20 +75,20 @@ public class ThemeCustomizationPanel extends SettingsPanel { }); GridBagConstraints gbc_themes = new GridBagConstraints(); - gbc_themes.fill = GridBagConstraints.HORIZONTAL; - gbc_themes.gridwidth = 2; - gbc_themes.gridx = 0; - gbc_themes.gridy = 0; - gbc_themes.anchor = GridBagConstraints.NORTHWEST; - gbc_themes.insets = new Insets(10, 10, 20, 10); + gbc_themes.fill = GridBagConstraints.HORIZONTAL; + gbc_themes.gridwidth = 2; + gbc_themes.gridx = 0; + gbc_themes.gridy = 0; + gbc_themes.anchor = GridBagConstraints.NORTHWEST; + gbc_themes.insets = new Insets(10, 10, 20, 10); add(themes, gbc_themes); GridBagLayout gbl_colorCustomizations = new GridBagLayout(); - gbl_colorCustomizations.columnWidths = new int[] { 1, 1 }; - gbl_colorCustomizations.rowHeights = new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1 }; - gbl_colorCustomizations.columnWeights = new double[] { 1, 1 }; - gbl_colorCustomizations.rowWeights = new double[] { 1, 1, 1, 1, 1, 1, 1, 1 }; + gbl_colorCustomizations.columnWidths = new int[] { 1, 1 }; + gbl_colorCustomizations.rowHeights = new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1 }; + gbl_colorCustomizations.columnWeights = new double[] { 1, 1 }; + gbl_colorCustomizations.rowWeights = new double[] { 1, 1, 1, 1, 1, 1, 1, 1 }; colorsPanel.setLayout(gbl_colorCustomizations); @@ -97,12 +96,12 @@ public class ThemeCustomizationPanel extends SettingsPanel { buildCustomizeElements(theme); GridBagConstraints gbc_colorsPanel = new GridBagConstraints(); - gbc_colorsPanel.fill = GridBagConstraints.HORIZONTAL; - gbc_colorsPanel.gridx = 0; - gbc_colorsPanel.gridy = 1; - gbc_colorsPanel.gridwidth = 2; - gbc_colorsPanel.anchor = GridBagConstraints.NORTHWEST; - gbc_colorsPanel.insets = insets; + gbc_colorsPanel.fill = GridBagConstraints.HORIZONTAL; + gbc_colorsPanel.gridx = 0; + gbc_colorsPanel.gridy = 1; + gbc_colorsPanel.gridwidth = 2; + gbc_colorsPanel.anchor = GridBagConstraints.NORTHWEST; + gbc_colorsPanel.insets = insets; add(colorsPanel, gbc_colorsPanel); colorsPanel.setBackground(theme.getCellColor()); @@ -122,11 +121,10 @@ public class ThemeCustomizationPanel extends SettingsPanel { String name = JOptionPane.showInputDialog("Enter a name for the new theme"); logger.log(Level.FINEST, name); Settings.getInstance().addNewThemeToMap(new Theme(name, temporaryTheme)); - themeArray = Arrays.copyOf(themeArray, themeArray.length + 1); - themeArray[themeArray.length - 1] = Settings.getInstance().getThemes().get(name).getThemeName(); + themeArray = Arrays.copyOf(themeArray, themeArray.length + 1); + themeArray[themeArray.length - 1] = Settings.getInstance().getThemes().get(name).getThemeName(); - temporaryTheme = new Theme("temporaryTheme", - Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme())); + temporaryTheme = new Theme("temporaryTheme", Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme())); themes.addItem(themeArray[themeArray.length - 1]); themes.setSelectedIndex(themeArray.length - 1); @@ -172,10 +170,8 @@ public class ThemeCustomizationPanel extends SettingsPanel { private void buildCustomizeElements(Theme theme) { buildCustomizeElement(theme, theme.getBackgroundColor(), "Background", "backgroundColor", 1); buildCustomizeElement(theme, theme.getCellColor(), "Cells", "cellColor", 2); - buildCustomizeElement(theme, theme.getInteractableForegroundColor(), "Interactable Foreground", - "interactableForegroundColor", 3); - buildCustomizeElement(theme, theme.getInteractableBackgroundColor(), "Interactable Background", - "interactableBackgroundColor", 4); + buildCustomizeElement(theme, theme.getInteractableForegroundColor(), "Interactable Foreground", "interactableForegroundColor", 3); + buildCustomizeElement(theme, theme.getInteractableBackgroundColor(), "Interactable Background", "interactableBackgroundColor", 4); buildCustomizeElement(theme, theme.getMessageColorChat(), "Messages Chat", "messageColorChat", 5); buildCustomizeElement(theme, theme.getDateColorChat(), "Date Chat", "dateColorCat", 6); buildCustomizeElement(theme, theme.getSelectionColor(), "Selection", "selectionColor", 7); @@ -184,12 +180,12 @@ public class ThemeCustomizationPanel extends SettingsPanel { } private void buildCustomizeElement(Theme theme, Color color, String name, String colorName, int gridy) { - JButton button = new JButton(); - JTextPane textPane = new JTextPane(); + JButton button = new JButton(); + JTextPane textPane = new JTextPane(); textPane.setFont(new Font("Arial", Font.PLAIN, 14)); textPane.setBackground(theme.getBackgroundColor()); - textPane.setForeground(getInvertedColor(theme.getBackgroundColor())); + textPane.setForeground(theme.getBackgroundColor().invert()); textPane.setText(name); textPane.setEditable(false); @@ -198,7 +194,7 @@ public class ThemeCustomizationPanel extends SettingsPanel { button.addActionListener((evt) -> { try { - Color newColor = JColorChooser.showDialog(null, "Choose a color", color); + Color newColor = (Color) JColorChooser.showDialog(null, "Choose a color", color); if (newColor.getRGB() != color.getRGB()) { logger.log(Level.FINEST, "New Color: " + String.valueOf(color.getRGB())); // TODO: When Theme changed in same settings screen, color variable doesn't @@ -215,25 +211,21 @@ public class ThemeCustomizationPanel extends SettingsPanel { }); GridBagConstraints gbc_textPane = new GridBagConstraints(); - gbc_textPane.fill = GridBagConstraints.BOTH; - gbc_textPane.gridx = 0; - gbc_textPane.gridy = gridy; - gbc_textPane.anchor = GridBagConstraints.CENTER; - gbc_textPane.insets = insets; + gbc_textPane.fill = GridBagConstraints.BOTH; + gbc_textPane.gridx = 0; + gbc_textPane.gridy = gridy; + gbc_textPane.anchor = GridBagConstraints.CENTER; + gbc_textPane.insets = insets; colorsPanel.add(textPane, gbc_textPane); GridBagConstraints gbc_button = new GridBagConstraints(); - gbc_button.fill = GridBagConstraints.BOTH; - gbc_button.gridx = 1; - gbc_button.gridy = gridy; - gbc_button.anchor = GridBagConstraints.CENTER; - gbc_button.insets = insets; + gbc_button.fill = GridBagConstraints.BOTH; + gbc_button.gridx = 1; + gbc_button.gridy = gridy; + gbc_button.anchor = GridBagConstraints.CENTER; + gbc_button.insets = insets; colorsPanel.add(button, gbc_button); } - - private Color getInvertedColor(Color color) { - return new Color(255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue()); - } -} +} \ No newline at end of file