Themes & Themes Configuration

Added themes to choose from and provides customization setting for
these.
This commit is contained in:
DieGurke 2019-12-07 10:58:03 +01:00
parent 8f0bf6012a
commit e245a129af
7 changed files with 736 additions and 232 deletions

View File

@ -1,7 +1,11 @@
package envoy.client;
import java.awt.Color;
import java.util.HashMap;
import java.util.Map;
import java.util.prefs.Preferences;
import envoy.client.ui.Theme;
import envoy.schema.User;
/**
@ -10,6 +14,7 @@ import envoy.schema.User;
* Created: <strong>11 Nov 2019</strong><br>
*
* @author Leon Hofmeister
* @author Maximilian K&auml;fer
* @since Envoy v0.2-alpha
*/
public class Settings {
@ -17,7 +22,9 @@ public class Settings {
private String username;
private String email;
private boolean enterToSend = true;
private boolean darkMode = true;
private Map<String, Theme> themes = new HashMap<>();
private String currentTheme;
// private Image profilePic;
private static Settings settings;
private Preferences prefs = Preferences.userNodeForPackage(Settings.class);
@ -47,24 +54,54 @@ public class Settings {
public void load() {
settings.setUsername(prefs.get("username", ""));
settings.setEmail(prefs.get("email", ""));
settings.setDarkMode(prefs.getBoolean("darkMode", true));
settings.setEnterToSend(prefs.getBoolean("enterToSend", true));
// currentTheme = "dark"; Activate once if NullPointerException on currentTheme
// and change theme to dark or white in Settings
settings.setCurrentTheme(prefs.get("theme", "dark"));
}
public void save() {
prefs.put("username", settings.getUsername());
prefs.put("email", settings.getEmail());
prefs.putBoolean("darkMode", settings.isDarkMode());
prefs.put("theme", currentTheme);
System.out.println(currentTheme);
prefs.putBoolean("enterToSend", settings.isEnterToSend());
// TODO: override themes map
}
public void firstSave(User user) {
// TODO: load themes
settings.getThemes()
.put("dark",
new Theme("dark", Color.black, Color.darkGray, Color.white, Color.blue, Color.white, Color.orange,
Color.blue, Color.white, Color.white));
settings.getThemes()
.put("light",
new Theme("light", new Color(235, 235, 235), Color.white, Color.white, Color.darkGray, Color.black,
Color.orange, Color.darkGray, Color.black, Color.black));
prefs.put("username", user.getName());
// prefs.put("email", user.getEmail());
// prefs.putBoolean("darkMode", true);
// prefs.putBoolean("enterToSend", true);
}
public void addNewThemeToMap(Theme theme) {
settings.getThemes().put(theme.getThemeName(), theme);
currentTheme = theme.getThemeName();
}
public String getCurrentTheme() { return currentTheme; }
public void setCurrentTheme(String themeName) { currentTheme = themeName; }
/**
* @return the username
* @since Envoy v0.2-alpha
@ -105,23 +142,9 @@ public class Settings {
*/
public void setEnterToSend(boolean enterToSend) { this.enterToSend = enterToSend; }
/**
* Describes whether the Envoy GUI should be displayed in dark mode or not.
*
* @return true, if dark mode display is currently set, else the light theme
* will be displayed
* @since Envoy v0.2-alpha
*/
public boolean isDarkMode() { return darkMode; }
public Map<String, Theme> getThemes() { return themes; }
/**
* Change display mode of Envoy GUI.
*
* @param darkMode true, if dark mode display is currently set, <br>
* else the light theme will be displayed
* @since Envoy v0.2-alpha
*/
public void setDarkMode(boolean darkMode) { this.darkMode = darkMode; }
public void setThemes(Map<String, Theme> themes) { this.themes = themes; }
// /**
// * @return the profilePic
@ -135,4 +158,5 @@ public class Settings {
// */
// public void setProfilePic(Image profilePic) { this.profilePic = profilePic; }
}

View File

@ -51,8 +51,6 @@ public class ChatWindow extends JFrame {
// user specific objects
private Client client;
private LocalDB localDB;
// used colors in Envoy
private UIColors uiColors = UIColors.getInstance(true);
// GUI components
private JPanel contentPane = new JPanel();
private JTextArea messageEnterTextArea = new JTextArea();
@ -80,12 +78,14 @@ public class ChatWindow extends JFrame {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) { try {
public void windowClosing(WindowEvent e) {
try {
localDB.saveToLocalDB();
} catch (IOException e1) {
e1.printStackTrace();
System.err.println("Could nnot save localDB");
} }
System.err.println("Could not save localDB");
}
}
});
contentPane.setBorder(new EmptyBorder(space, space, space, space));
@ -125,7 +125,8 @@ public class ChatWindow extends JFrame {
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER && ((Settings.getInstance().isEnterToSend() && e.getModifiersEx() == 0)
if (e.getKeyCode() == KeyEvent.VK_ENTER
&& ((Settings.getInstance().isEnterToSend() && e.getModifiersEx() == 0)
|| (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK))) {
postMessage(messageList);
@ -176,7 +177,9 @@ public class ChatWindow extends JFrame {
settingsButton.addActionListener((evt) -> {
try {
SettingsScreen.open();
changeChatWindowColors();
changeChatWindowColors(Settings.getInstance().getCurrentTheme());
} catch (Exception e) {
System.err.println("An error occured while opening the settings screen: " + e);
e.printStackTrace();
@ -232,7 +235,7 @@ public class ChatWindow extends JFrame {
gbc_userList.anchor = GridBagConstraints.PAGE_START;
gbc_userList.insets = new Insets(space, space, space, space);
changeChatWindowColors();
changeChatWindowColors(Settings.getInstance().getCurrentTheme());
contentPane.add(userList, gbc_userList);
contentPane.revalidate();
@ -243,43 +246,44 @@ public class ChatWindow extends JFrame {
contentPane.revalidate();
}
/**
* Used to immediately reload the ChatWindow when settings were changed.
*
* @since Envoy v0.1-alpha
*/
public void changeChatWindowColors() {
uiColors.setDisplayMode(Settings.getInstance().isDarkMode());
public void changeChatWindowColors(String key) {
Theme theme = Settings.getInstance().getThemes().get(key);
// contentPane
contentPane.setBackground(uiColors.getBackgroundColor());
contentPane.setForeground(uiColors.getTextColor());
contentPane.setBackground(theme.getBackgroundColor());
contentPane.setForeground(theme.getUserNameColor());
// messageList
messageList.setSelectionForeground(uiColors.getTextColor());
messageList.setSelectionBackground(uiColors.getSpecialUseColor());
messageList.setForeground(uiColors.getTextColor());
messageList.setBackground(uiColors.getUserInteractionColor());
messageList.setSelectionForeground(theme.getUserNameColor());
messageList.setSelectionBackground(theme.getSelectionColor());
messageList.setForeground(theme.getMessageColorChat());
messageList.setBackground(theme.getCellColor());
// scrollPane
scrollPane.setForeground(uiColors.getBackgroundColor());
scrollPane.setBackground(uiColors.getUserInteractionColor());
scrollPane.setForeground(theme.getBackgroundColor());
scrollPane.setBackground(theme.getCellColor());
// messageEnterTextArea
messageEnterTextArea.setCaretColor(uiColors.getTextColor());
messageEnterTextArea.setForeground(uiColors.getTextColor());
messageEnterTextArea.setBackground(uiColors.getUserInteractionColor());
messageEnterTextArea.setCaretColor(theme.getTypingMessageColor());
messageEnterTextArea.setForeground(theme.getTypingMessageColor());
messageEnterTextArea.setBackground(theme.getCellColor());
// postButton
postButton.setForeground(uiColors.getTextColor());
postButton.setBackground(uiColors.getSpecialUseColor());
postButton.setForeground(theme.getInteractableForegroundColor());
postButton.setBackground(theme.getInteractableBackgroundColor());
// settingsButton
settingsButton.setForeground(uiColors.getTextColor());
settingsButton.setBackground(uiColors.getSpecialUseColor());
settingsButton.setForeground(theme.getInteractableForegroundColor());
settingsButton.setBackground(theme.getInteractableBackgroundColor());
// textPane
textPane.setBackground(uiColors.getBackgroundColor());
textPane.setForeground(uiColors.getTextColor());
textPane.setBackground(theme.getBackgroundColor());
textPane.setForeground(theme.getUserNameColor());
// userList
userList.setSelectionForeground(uiColors.getTextColor());
userList.setSelectionBackground(uiColors.getSpecialUseColor());
userList.setForeground(uiColors.getTextColor());
userList.setBackground(uiColors.getUserInteractionColor());
userList.setSelectionForeground(theme.getUserNameColor());
userList.setSelectionBackground(theme.getSelectionColor());
userList.setForeground(theme.getUserNameColor());
userList.setBackground(theme.getCellColor());
}
@ -294,7 +298,8 @@ public class ChatWindow extends JFrame {
if (!messageEnterTextArea.getText().isEmpty()) try {
// Create and send message object
final Message message = localDB.createMessage(messageEnterTextArea.getText(), currentChat.getRecipient().getID());
final Message message = localDB.createMessage(messageEnterTextArea.getText(),
currentChat.getRecipient().getID());
localDB.addWaitingMessageToLocalDB(message, currentChat);
messageList.setModel(currentChat.getModel());

View File

@ -1,5 +1,6 @@
package envoy.client.ui;
import java.awt.Color;
import java.awt.Component;
import java.text.SimpleDateFormat;
@ -7,6 +8,7 @@ import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import envoy.client.Settings;
import envoy.schema.Message;
/**
@ -44,11 +46,33 @@ public class MessageListRenderer extends JLabel implements ListCellRenderer<Mess
: new SimpleDateFormat("dd.MM.yyyy HH:mm ")
.format(value.getMetadata().getDate().toGregorianCalendar().getTime());
// Getting the MessageColor in the Chat of the current theme
String textColor = null;
textColor = toHex(
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat());
// Getting the DateColor in the Chat of the current theme
String dateColor = null;
dateColor = toHex(
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat());
setText(String.format(
"<html><p style=\"color:#d2d235\"><b><small>%s</b></small><br><p style=\"color:white\">%s :%s</html>",
"<html><p style=\"color:%s\"><b><small>%s</b></small><br><p style=\"color:%s\">%s :%s</html>",
dateColor,
date,
textColor,
text,
state));
return this;
}
public 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

@ -1,15 +1,29 @@
package envoy.client.ui;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Arrays;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextPane;
import javax.swing.ListSelectionModel;
import envoy.client.Settings;
@ -21,15 +35,36 @@ import envoy.client.Settings;
* Created: <strong>31 Oct 2019</strong><br>
*
* @author Leon Hofmeister
* @author Maximilian K&auml;fer
*/
public class SettingsScreen extends JDialog {
private static final long serialVersionUID = -4476913491263077107L;
private final JPanel contentPanel = new JPanel();
private DefaultListModel<String> optionsListModel = new DefaultListModel<>();
private final JList<String> options = new JList<String>();
private JPanel buttonPane = new JPanel();
private JPanel themeContent = new JPanel();
private String[] themeArray = { Settings.getInstance().getThemes().get("dark").getThemeName(),
Settings.getInstance().getThemes().get("light").getThemeName() };
private JComboBox<String> themes = new JComboBox<String>(themeArray);
private GridBagConstraints gbc_themeContent = new GridBagConstraints();
private Theme selectedTheme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
private JButton createNewThemeButton = new JButton("Create New Theme");
private JPanel colorsPanel = new JPanel();
private JButton okButton = new JButton("Save");
private JButton cancelButton = new JButton("Cancel");
private static int space = 5;
private boolean colorChanged = false;
private Theme temporaryTheme;
private static SettingsScreen settingsScreen;
// TODO: Add a JPanel with all the Information necessary:
@ -44,7 +79,7 @@ public class SettingsScreen extends JDialog {
*/
public static void open() {
UIColors.getInstance(Settings.getInstance().isDarkMode());
// UIColors.getInstance(Settings.getInstance().isDarkMode());
settingsScreen = new SettingsScreen();
settingsScreen.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
settingsScreen.setModal(true);
@ -58,21 +93,254 @@ public class SettingsScreen extends JDialog {
*/
private SettingsScreen() {
setBounds(100, 100, 450, 300);
System.out.println(Settings.getInstance().getCurrentTheme());
setBounds(10, 10, 450, 650);
getContentPane().setLayout(new BorderLayout());
contentPanel.setLayout(new FlowLayout());
contentPanel.setBorder(new EmptyBorder(space, space, space, space));
getContentPane().add(contentPanel, BorderLayout.CENTER);
{
getContentPane().add(buttonPane, BorderLayout.SOUTH);
createNewThemeButton.setEnabled(false);
temporaryTheme = new Theme("temporaryTheme",
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
// ContentPane------------------------------------------------------
GridBagLayout gbl_contentPanel = new GridBagLayout();
gbl_contentPanel.columnWidths = new int[] { 1, 1 };
gbl_contentPanel.rowHeights = new int[] { 1 };
gbl_contentPanel.columnWeights = new double[] { 0.05, 1.0 };
gbl_contentPanel.rowWeights = new double[] { 1.0 };
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(gbl_contentPanel);
options.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
options.addListSelectionListener((listSelectionEvent) -> {
if (!listSelectionEvent.getValueIsAdjusting()) {
@SuppressWarnings("unchecked")
final JList<String> selectedOption = (JList<String>) listSelectionEvent.getSource();
final String option = selectedOption.getSelectedValue();
System.out.println(option);
switch (option) {
case "Color Themes":
setContent(themeContent, gbc_themeContent);
getContentPane().repaint();
getContentPane().revalidate();
break;
}
}
});
options.setFont(new Font("Arial", Font.PLAIN, 14));
Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme());
options.setSelectionForeground(theme.getUserNameColor());
options.setSelectionBackground(theme.getSelectionColor());
options.setForeground(theme.getUserNameColor());
options.setBackground(theme.getCellColor());
GridBagConstraints gbc_optionsList = new GridBagConstraints();
gbc_optionsList.fill = GridBagConstraints.BOTH;
gbc_optionsList.gridx = 0;
gbc_optionsList.gridy = 0;
gbc_optionsList.anchor = GridBagConstraints.PAGE_START;
gbc_optionsList.insets = new Insets(space, space, space, space);
optionsListModel.addElement("Color Themes");
options.setModel(optionsListModel);
contentPanel.add(options, gbc_optionsList);
// ThemeContent ---
gbc_themeContent = new GridBagConstraints();
gbc_themeContent.fill = GridBagConstraints.BOTH;
gbc_themeContent.gridx = 1;
gbc_themeContent.gridy = 0;
gbc_themeContent.anchor = GridBagConstraints.PAGE_START;
gbc_themeContent.insets = new Insets(space, space, space, space);
GridBagLayout gbl_themeLayout = new GridBagLayout();
// themeContent.setSelectionForeground(theme.getUserNameColor());
// themeContent.setSelectionBackground(theme.getSelectionColor());
themeContent.setForeground(theme.getUserNameColor());
themeContent.setBackground(theme.getCellColor());
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 };
themeContent.setLayout(gbl_themeLayout);
themes.setBackground(theme.getUserNameColor());
themes.setForeground(theme.getBackgroundColor());
themes.setSelectedItem(Settings.getInstance().getCurrentTheme());
// themes.setBorder(null);
themes.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
String selectedValue = (String) themes.getSelectedItem();
System.out.println(selectedValue);
selectedTheme = Settings.getInstance().getThemes().get(selectedValue);
}
});
GridBagConstraints gbc_themes = new GridBagConstraints();
gbc_themes.fill = GridBagConstraints.HORIZONTAL;
gbc_themes.gridx = 0;
gbc_themes.gridy = 0;
gbc_themes.anchor = GridBagConstraints.NORTHWEST;
gbc_themes.insets = new Insets(space, space, space, space);
themeContent.add(themes, gbc_themes);
colorsPanel.setLayout((LayoutManager) new BoxLayout(colorsPanel, BoxLayout.Y_AXIS));
colorsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getBackgroundColor(),
"Background",
1);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getCellColor(),
"Cells",
2);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getInteractableForegroundColor(),
"Interactable Foreground",
3);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getInteractableBackgroundColor(),
"Interactable Background",
4);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getMessageColorChat(),
"Messages Chat",
5);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getDateColorChat(),
"Date Chat",
6);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getSelectionColor(),
"Selection",
7);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getTypingMessageColor(),
"Typing Message",
8);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getUserNameColor(),
"User Names",
9);
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 = new Insets(space, 0, 0, 0);
themeContent.add(colorsPanel, gbc_colorsPanel);
createNewThemeButton.setBackground(theme.getInteractableBackgroundColor());
createNewThemeButton.setForeground(theme.getInteractableForegroundColor());
colorsPanel.setBackground(theme.getCellColor());
createNewThemeButton.addActionListener((evt) -> {
try {
String s = JOptionPane.showInputDialog("Enter a name for the new theme");
System.out.println(s);
Settings.getInstance()
.addNewThemeToMap(new Theme(s, temporaryTheme.getBackgroundColor(),
temporaryTheme.getCellColor(), temporaryTheme.getInteractableForegroundColor(),
temporaryTheme.getInteractableBackgroundColor(), temporaryTheme.getMessageColorChat(),
temporaryTheme.getDateColorChat(), temporaryTheme.getSelectionColor(),
temporaryTheme.getTypingMessageColor(), temporaryTheme.getUserNameColor()));
themeArray = Arrays.copyOf(themeArray, themeArray.length + 1);
themeArray[themeArray.length - 1] = Settings.getInstance().getThemes().get(s).getThemeName();
temporaryTheme = new Theme("temporaryTheme",
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()));
createNewThemeButton.setEnabled(false);
themes.addItem(themeArray[themeArray.length - 1]);
contentPanel.revalidate();
contentPanel.repaint();
// TODO: Create new Theme
} catch (Exception e) {
System.err.println("New theme couldn't be created! " + e);
e.printStackTrace();
}
});
GridBagConstraints gbc_createNewTheme = new GridBagConstraints();
gbc_createNewTheme.gridx = 0;
gbc_createNewTheme.gridy = 10;
colorsPanel.add(createNewThemeButton, gbc_createNewTheme);
// ButtonPane-------------------------------------------------------
GridBagLayout gbl_buttonPane = new GridBagLayout();
gbl_buttonPane.columnWidths = new int[] { 100, 250, 100, 0 };
gbl_buttonPane.rowHeights = new int[] { 25, 0 };
gbl_buttonPane.columnWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE };
gbl_buttonPane.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
getContentPane().add(buttonPane, BorderLayout.SOUTH);
buttonPane.setLayout(gbl_buttonPane);
{
cancelButton.setActionCommand("Cancel");
cancelButton.setBorderPainted(false);
GridBagConstraints gbc_cancelButton = new GridBagConstraints();
gbc_cancelButton.anchor = GridBagConstraints.NORTHWEST;
gbc_cancelButton.insets = new Insets(space, space, space, space);
@ -84,6 +352,7 @@ public class SettingsScreen extends JDialog {
}
{
okButton.setActionCommand("OK");
okButton.setBorderPainted(false);
GridBagConstraints gbc_okButton = new GridBagConstraints();
gbc_okButton.anchor = GridBagConstraints.NORTHEAST;
gbc_okButton.fill = GridBagConstraints.EAST;
@ -95,16 +364,19 @@ public class SettingsScreen extends JDialog {
okButton.addActionListener((evt) -> {
try {
Settings.getInstance().setUsername(Settings.getInstance().getUsername());// still temporary
// value
Settings.getInstance().setEmail(Settings.getInstance().getEmail());// still temporary value
Settings.getInstance().setDarkMode(!Settings.getInstance().isDarkMode());// TODO temporary
// values while no
// UI is implemented
Settings.getInstance().setEnterToSend(Settings.getInstance().isEnterToSend());// still temporary
// value
Settings.getInstance().setCurrentTheme(selectedTheme.getThemeName());
System.out.println(selectedTheme.getThemeName());
changeSettingsScreenColors(Settings.getInstance().getCurrentTheme());
updateColorVariables(Settings.getInstance().getCurrentTheme());
Settings.getInstance().save();
UIColors.getUIColors().setDisplayMode(Settings.getInstance().isDarkMode());
changeSettingsScreenColors();
revalidate();
repaint();
} catch (Exception e) {
@ -114,23 +386,191 @@ public class SettingsScreen extends JDialog {
});
}
}
changeSettingsScreenColors();
changeSettingsScreenColors(Settings.getInstance().getCurrentTheme());
}
private void changeSettingsScreenColors() {
private void changeSettingsScreenColors(String key) {
Theme theme = Settings.getInstance().getThemes().get(key);
// whole JDialog
setBackground(UIColors.getUIColors().getBackgroundColor());
setBackground(theme.getBackgroundColor());
// contentPanel
contentPanel.setBackground(UIColors.getUIColors().getBackgroundColor());
contentPanel.setBackground(theme.getBackgroundColor());
// buttonPane
buttonPane.setBackground(UIColors.getUIColors().getBackgroundColor());
buttonPane.setBackground(theme.getCellColor());
// cancelButton
cancelButton.setBackground(UIColors.getUIColors().getSpecialUseColor());
cancelButton.setForeground(UIColors.getUIColors().getTextColor());
cancelButton.setBackground(theme.getInteractableBackgroundColor());
cancelButton.setForeground(theme.getInteractableForegroundColor());
// okButton
okButton.setBackground(UIColors.getUIColors().getSpecialUseColor());
okButton.setForeground(UIColors.getUIColors().getTextColor());
okButton.setBackground(theme.getInteractableBackgroundColor());
okButton.setForeground(theme.getInteractableForegroundColor());
// options
options.setSelectionForeground(theme.getUserNameColor());
options.setSelectionBackground(theme.getSelectionColor());
options.setForeground(theme.getUserNameColor());
options.setBackground(theme.getCellColor());
// themeContent
themeContent.setForeground(theme.getUserNameColor());
themeContent.setBackground(theme.getCellColor());
// themes
themes.setBackground(theme.getUserNameColor());
themes.setForeground(theme.getBackgroundColor());
createNewThemeButton.setBackground(theme.getInteractableBackgroundColor());
createNewThemeButton.setForeground(theme.getInteractableForegroundColor());
colorsPanel.setBackground(theme.getCellColor());
}
public void updateColorVariables(String key) {
Theme theme = Settings.getInstance().getThemes().get(key);
temporaryTheme = new Theme("temporaryTheme",
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getBackgroundColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getCellColor(),
Settings.getInstance()
.getThemes()
.get(Settings.getInstance().getCurrentTheme())
.getInteractableForegroundColor(),
Settings.getInstance()
.getThemes()
.get(Settings.getInstance().getCurrentTheme())
.getInteractableBackgroundColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getSelectionColor(),
Settings.getInstance()
.getThemes()
.get(Settings.getInstance().getCurrentTheme())
.getTypingMessageColor(),
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor());
colorsPanel.removeAll();
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getBackgroundColor(),
"Background",
1);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getCellColor(),
"Cells",
2);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getInteractableForegroundColor(),
"Interactable Foreground",
3);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getInteractableBackgroundColor(),
"Interactable Background",
4);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getMessageColorChat(),
"Messages Chat",
5);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getDateColorChat(),
"Date Chat",
6);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getSelectionColor(),
"Selection",
7);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getTypingMessageColor(),
"Typing Message",
8);
buildCustomizeElement(new JPanel(),
new JButton(),
new JTextPane(),
theme,
theme.getUserNameColor(),
"User Names",
9);
GridBagConstraints gbc_createNewTheme = new GridBagConstraints();
gbc_createNewTheme.gridx = 0;
gbc_createNewTheme.gridy = 10;
colorsPanel.add(createNewThemeButton, gbc_createNewTheme);
}
public void setContent(JPanel content, GridBagConstraints layout) { contentPanel.add(content, layout); }
public void buildCustomizeElement(JPanel panel, JButton button, JTextPane textPane, Theme theme, Color color,
String name, int yIndex) {
textPane.setFont(new Font("Arial", Font.PLAIN, 14));
textPane.setBackground(theme.getBackgroundColor());
textPane.setForeground(theme.getUserNameColor());
textPane.setText(name);
textPane.setEditable(false);
button.setBackground(color);
button.setPreferredSize(new Dimension(25, 25));
button.addActionListener((evt) -> {
try {
Color newColor = JColorChooser.showDialog(null, "Choose a color", color);
if (newColor.getRGB() != color.getRGB()) {
System.out.println("New Color");
System.out.println(color.getRGB());
// TODO: When Theme changed in same settings screen, color variable doesnt
// update.
Color[] colorsArray = temporaryTheme.getAllColors();
for (int i = 0; i < colorsArray.length; i++) {
if (color.getRGB() == colorsArray[i].getRGB()) {
temporaryTheme.setColor(i, newColor);
colorChanged = true;
createNewThemeButton.setEnabled(true);
break;
}
}
button.setBackground(newColor);
}
} catch (Exception e) {
System.err.println("An error occured while opening Color Chooser: " + e);
e.printStackTrace();
}
});
panel.add(textPane);
panel.add(button);
panel.setBackground(theme.getCellColor());
panel.setAlignmentX(Component.LEFT_ALIGNMENT);
colorsPanel.add(panel);
}
}

View File

@ -0,0 +1,121 @@
package envoy.client.ui;
import java.awt.Color;
import java.io.Serializable;
/**
*
* Project: <strong>envoy-client</strong><br>
* File: <strong>Theme.java</strong><br>
* Created: <strong>23 Nov 2019</strong><br>
*
* @author Maximilian K&auml;fer
* @since Envoy v0.2-alpha
*/
public class Theme implements Serializable {
private static final long serialVersionUID = 141727847527060352L;
private String themeName;
private Color backgroundColor;
private Color cellColor;
private Color interactableBackgroundColor;
private Color userNameColor;
private Color interactableForegroundColor;
private Color messageColorChat;
private Color dateColorChat;
private Color selectionColor;
private Color typingMessageColor;
public Theme(String themeName, Color backgroundColor, Color cellColor, Color interactableForegroundColor,
Color interactableBackgroundColor, Color messageColorChat, Color dateColorChat, Color selectionColor,
Color typingMessageColor, Color userNameColor) {
this.themeName = themeName;
this.backgroundColor = backgroundColor;
this.cellColor = cellColor;
this.interactableForegroundColor = interactableForegroundColor;
this.interactableBackgroundColor = interactableBackgroundColor;
this.messageColorChat = messageColorChat;
this.dateColorChat = dateColorChat;
this.selectionColor = selectionColor;
this.typingMessageColor = typingMessageColor;
this.userNameColor = userNameColor;
}
public Theme(String name, Theme other) {
this(name, other.backgroundColor, other.cellColor, other.interactableBackgroundColor,
other.interactableForegroundColor, other.messageColorChat, other.dateColorChat, other.selectionColor,
other.typingMessageColor, other.userNameColor);
}
public String getThemeName() { return themeName; }
public Color getInteractableForegroundColor() { return interactableForegroundColor; }
public Color getMessageColorChat() { return messageColorChat; }
public Color getDateColorChat() { return dateColorChat; }
public Color getSelectionColor() { return selectionColor; }
public Color getTypingMessageColor() { return typingMessageColor; }
public Color getBackgroundColor() { return backgroundColor; }
public Color getCellColor() { return cellColor; }
public Color getInteractableBackgroundColor() { return interactableBackgroundColor; }
public Color getUserNameColor() { return userNameColor; }
public Color[] getAllColors() {
Color[] c = new Color[9];
c[0] = backgroundColor;
c[1] = cellColor;
c[2] = interactableForegroundColor;
c[3] = interactableBackgroundColor;
c[4] = messageColorChat;
c[5] = dateColorChat;
c[6] = selectionColor;
c[7] = typingMessageColor;
c[8] = userNameColor;
return c;
}
public void setColor(int index, Color newColor) {
switch (index) {
case 0:
this.backgroundColor = newColor;
break;
case 1:
this.cellColor = newColor;
break;
case 2:
this.interactableForegroundColor = newColor;
break;
case 3:
this.interactableBackgroundColor = newColor;
break;
case 4:
this.messageColorChat = newColor;
break;
case 5:
this.dateColorChat = newColor;
break;
case 6:
this.selectionColor = newColor;
break;
case 7:
this.typingMessageColor = newColor;
break;
case 8:
this.userNameColor = newColor;
break;
}
}
}

View File

@ -1,123 +0,0 @@
package envoy.client.ui;
import java.awt.Color;
/**
* This class stores the colors that are used in Envoy.
* <br>
* <br>
* Project: <strong>envoy-client</strong><br>
* File: <strong>EnvoyColors.java</strong><br>
* Created: <strong>16 Nov 2019</strong><br>
*
* @author Leon Hofmeister
* @since Envoy v0.2-alpha
*/
public class UIColors {
private UIColors() {}
private Color backgroundColor;
private Color userInteractionColor;
private Color specialUseColor;
private Color textColor;
private static UIColors uIColors;
/**
* This method is used to ensure that there is only one instance of EnvoyColors.
*
* @param darkMode default value how envoyColors should be displayed
* @return the instance of EnvoyColors
* @since Envoy v0.2-alpha
*/
public static UIColors getInstance(boolean darkMode) {
if (uIColors == null) { uIColors = new UIColors(); }
uIColors.setDisplayMode(darkMode);
return uIColors;
}
/**
* Used to change the appearance of Envoy.
*
* @param darkMode if true, Envoy will be displayed in dark mode else it will
* use bright mode
* @since Envoy v0.2-alpha
*/
public void setDisplayMode(boolean darkMode) {
if (darkMode) {
uIColors.setBackgroundColor(Color.black); // TODO: other color suggestions?
uIColors.setUserInteractionColor(Color.darkGray); // temporary
uIColors.setSpecialUseColor(Color.blue); // temporary
uIColors.setTextColor(Color.white); // temporary
} else {
uIColors.setBackgroundColor(Color.white); // temporary
uIColors.setUserInteractionColor(Color.lightGray); // temporary
uIColors.setSpecialUseColor(Color.green); // temporary
uIColors.setTextColor(Color.black); // temporary
}
}
/**
* @return the general background color where no other element overlaps
* @since Envoy v0.2-alpha
*/
public Color getBackgroundColor() { return backgroundColor; }
/**
* @param backgroundColor the general background where no other element overlaps
* @since Envoy v0.2-alpha
*/
public void setBackgroundColor(Color backgroundColor) { this.backgroundColor = backgroundColor; }
/**
* @return the userInteractionColor:<br>
* This color is used as background for all areas where a user can
* interact with Envoy (i.e. a JTextArea or JList)
* @since Envoy v0.2-alpha
*/
public Color getUserInteractionColor() { return userInteractionColor; }
/**
* @param userInteractionColor This color is used as background for all areas <br>
* where a user can interact with Envoy
* (i.e. a JTextArea or JList)
* @since Envoy v0.2-alpha
*/
public void setUserInteractionColor(Color userInteractionColor) {
this.userInteractionColor = userInteractionColor;
}
/**
* @return specialUseColor: This color is used for any areas that need special attention.<br>
* (i.e. highlighting a selected list column or a button background)
* @since Envoy v0.2-alpha
*/
public Color getSpecialUseColor() { return specialUseColor; }
/**
* @param specialUseColor This color is used for any areas that need special attention.<br>
* (i.e. highlighting a selected list column or a button background)
* @since Envoy v0.2-alpha
*/
public void setSpecialUseColor(Color specialUseColor) { this.specialUseColor = specialUseColor; }
/**
* @return textColor: The color in which text will be displayed
* @since Envoy v0.2-alpha
*/
public Color getTextColor() { return textColor; }
/**
* @param textColor The color in which text will be displayed
* @since Envoy v0.2-alpha
*/
public void setTextColor(Color textColor) { this.textColor = textColor; }
/**
* @return the uiColors object
* @since Envoy v0.2-alpha
*/
public static UIColors getUIColors() { return uIColors; }
}

View File

@ -1,11 +1,13 @@
package envoy.client.ui;
import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import envoy.client.Settings;
import envoy.schema.User;
import envoy.schema.User.UserStatus;
@ -24,6 +26,7 @@ public class UserListRenderer extends JLabel implements ListCellRenderer<User> {
private static final long serialVersionUID = 5164417379767181198L;
@SuppressWarnings("incomplete-switch")
@Override
public Component getListCellRendererComponent(JList<? extends User> list, User value, int index, boolean isSelected,
boolean cellHasFocus) {
@ -42,30 +45,40 @@ public class UserListRenderer extends JLabel implements ListCellRenderer<User> {
final String name = value.getName();
final UserStatus status = value.getStatus();
// Getting the UserNameColor of the current theme
String textColor = null;
textColor = toHex(
Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor());
switch (status) {
case ONLINE:
setText(String.format(
"<html><p style=\"color:#03fc20\"><b><small>%s</b></small><br><p style=\"color:white\">%s</html>",
"<html><p style=\"color:#03fc20\"><b><small>%s</b></small><br><p style=\"color:%s\">%s</html>",
status,
textColor,
name));
break;
case OFFLINE:
setText(String.format(
"<html><p style=\"color:#fc0303\"><b><small>%s</b></small><br><p style=\"color:white\">%s</html>",
"<html><p style=\"color:#fc0303\"><b><small>%s</b></small><br><p style=\"color:%s\">%s</html>",
status,
textColor,
name));
break;
case AFK:
break;
case DO_NOT_DISTURB:
break;
default:
break;
}
return this;
}
public 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;
}
}