Merge pull request #77 from informatik-ag-ngl/f/onCloseToggleSwitch

General Settings screen
This commit is contained in:
DieGurke 2019-12-23 14:20:47 +01:00 committed by GitHub
commit 7ec9e6b13a
12 changed files with 522 additions and 87 deletions

View File

@ -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<String, Theme> 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<String, Theme> 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; }
}

View File

@ -0,0 +1,27 @@
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>
*
* @author Maximilian K&auml;fer
* @since Envoy v0.3-alpha
*/
public class EnterToSendEvent implements Event<Boolean> {
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; }
}

View File

@ -0,0 +1,27 @@
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>
*
* @author Maximilian K&auml;fer
* @since Envoy v0.3-alpha
*/
public class OnCloseChangeEvent implements Event<Boolean> {
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; }
}

View File

@ -0,0 +1,106 @@
package envoy.client.ui;
import java.awt.color.ColorSpace;
/**
* Project: <strong>envoy-clientChess</strong><br>
* File: <strong>Color.javaEvent.java</strong><br>
* Created: <strong>23.12.2019</strong><br>
*
* @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()); }
}

View File

@ -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<Mess
// Getting the MessageColor in the Chat of the current theme
String textColor = null;
textColor = toHex(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat());
textColor = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat().toHex();
// Getting the DateColor in the Chat of the current theme
String dateColor = null;
dateColor = toHex(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat());
dateColor = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat().toHex();
setText(String.format("<html><p style=\"color:%s\"><b><small>%s</b></small><br><p style=\"color:%s\">%s :%s</html>",
dateColor,
@ -60,12 +59,4 @@ public class MessageListRenderer extends JLabel implements ListCellRenderer<Mess
state));
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;
}
}

View File

@ -0,0 +1,114 @@
package envoy.client.ui;
import java.awt.*;
import java.lang.reflect.Constructor;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JPanel;
import envoy.client.Settings;
import envoy.client.event.Event;
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>
* Project: <strong>envoy-client</strong><br>
* File: <strong>PrimaryToggleSwitch.java</strong><br>
* Created: <strong>21 Dec 2019</strong><br>
*
* @author Maximilian K&auml;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. </br>
* true: off </br>
* false: on
* @param eventClass the class of the event dispatched by this toggleSwitch
* @since Envoy v0.3-alpha
*/
public PrimaryToggleSwitch(boolean initialState, Class<? extends Event<Boolean>> 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<? extends Event<Boolean>> 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;
}
}

View File

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

View File

@ -1,6 +1,5 @@
package envoy.client.ui;
import java.awt.Color;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

View File

@ -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<User> {
// 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<User> {
}
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;
}
}

View File

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

View File

@ -39,7 +39,7 @@ public class SettingsScreen extends JDialog {
private final JList<String> 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<String, Class<? extends SettingsPanel>> 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());
}
}
}

View File

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