From 89b75b00c88f4390aa8963478114c8497fecd641 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sat, 14 Dec 2019 11:22:37 +0100 Subject: [PATCH 1/2] Fixes bugs with the incorrect applying of the changed colors. Fixes #50 --- src/main/java/envoy/client/Settings.java | 2 +- .../java/envoy/client/ui/SettingsScreen.java | 60 ++++++++----------- src/main/java/envoy/client/ui/Theme.java | 23 +------ 3 files changed, 28 insertions(+), 57 deletions(-) diff --git a/src/main/java/envoy/client/Settings.java b/src/main/java/envoy/client/Settings.java index 91f696f..3bd54f1 100644 --- a/src/main/java/envoy/client/Settings.java +++ b/src/main/java/envoy/client/Settings.java @@ -116,7 +116,7 @@ public class Settings { */ public void addNewThemeToMap(Theme theme) { settings.getThemes().put(theme.getThemeName(), theme); - currentTheme = theme.getThemeName(); + // currentTheme = theme.getThemeName(); } /** diff --git a/src/main/java/envoy/client/ui/SettingsScreen.java b/src/main/java/envoy/client/ui/SettingsScreen.java index bd80c2e..f96eac1 100644 --- a/src/main/java/envoy/client/ui/SettingsScreen.java +++ b/src/main/java/envoy/client/ui/SettingsScreen.java @@ -206,63 +206,63 @@ public class SettingsScreen extends JDialog { theme, theme.getBackgroundColor(), "Background", - 1); + 0); buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getCellColor(), "Cells", - 2); + 1); buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getInteractableForegroundColor(), "Interactable Foreground", - 3); + 2); buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getInteractableBackgroundColor(), "Interactable Background", - 4); + 3); buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getMessageColorChat(), "Messages Chat", - 5); + 4); buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getDateColorChat(), "Date Chat", - 6); + 5); buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getSelectionColor(), "Selection", - 7); + 6); buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getTypingMessageColor(), "Typing Message", - 8); + 7); buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getUserNameColor(), "User Names", - 9); + 8); GridBagConstraints gbc_colorsPanel = new GridBagConstraints(); gbc_colorsPanel.fill = GridBagConstraints.HORIZONTAL; @@ -438,7 +438,7 @@ public class SettingsScreen extends JDialog { theme, theme.getBackgroundColor(), "Background", - 1); + 0); buildCustomizeElement(new JPanel(), new JButton(), @@ -446,7 +446,7 @@ public class SettingsScreen extends JDialog { theme, theme.getCellColor(), "Cells", - 2); + 1); buildCustomizeElement(new JPanel(), new JButton(), @@ -454,7 +454,7 @@ public class SettingsScreen extends JDialog { theme, theme.getInteractableForegroundColor(), "Interactable Foreground", - 3); + 2); buildCustomizeElement(new JPanel(), new JButton(), @@ -462,7 +462,7 @@ public class SettingsScreen extends JDialog { theme, theme.getInteractableBackgroundColor(), "Interactable Background", - 4); + 3); buildCustomizeElement(new JPanel(), new JButton(), @@ -470,7 +470,7 @@ public class SettingsScreen extends JDialog { theme, theme.getMessageColorChat(), "Messages Chat", - 5); + 4); buildCustomizeElement(new JPanel(), new JButton(), @@ -478,7 +478,7 @@ public class SettingsScreen extends JDialog { theme, theme.getDateColorChat(), "Date Chat", - 6); + 5); buildCustomizeElement(new JPanel(), new JButton(), @@ -486,7 +486,7 @@ public class SettingsScreen extends JDialog { theme, theme.getSelectionColor(), "Selection", - 7); + 6); buildCustomizeElement(new JPanel(), new JButton(), @@ -494,7 +494,7 @@ public class SettingsScreen extends JDialog { theme, theme.getTypingMessageColor(), "Typing Message", - 8); + 7); buildCustomizeElement(new JPanel(), new JButton(), @@ -502,7 +502,7 @@ public class SettingsScreen extends JDialog { theme, theme.getUserNameColor(), "User Names", - 9); + 8); GridBagConstraints gbc_createNewTheme = new GridBagConstraints(); gbc_createNewTheme.gridx = 0; @@ -532,18 +532,11 @@ public class SettingsScreen extends JDialog { 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; - } - - } + temporaryTheme.setColor(yIndex, newColor); + colorChanged = true; + createNewThemeButton.setEnabled(true); + } button.setBackground(newColor); - } } catch (Exception e) { logger.info("An error occured while opening Color Chooser: " + e); @@ -551,12 +544,9 @@ public class SettingsScreen extends JDialog { } }); - panel.add(textPane); - panel.add(button); - panel.setBackground(theme.getCellColor()); - panel.setAlignmentX(Component.LEFT_ALIGNMENT); + panel.add(textPane);panel.add(button);panel.setBackground(theme.getCellColor());panel.setAlignmentX(Component.LEFT_ALIGNMENT); - colorsPanel.add(panel); - } + colorsPanel.add(panel); +} } diff --git a/src/main/java/envoy/client/ui/Theme.java b/src/main/java/envoy/client/ui/Theme.java index a0ef259..9dcda1e 100644 --- a/src/main/java/envoy/client/ui/Theme.java +++ b/src/main/java/envoy/client/ui/Theme.java @@ -44,8 +44,8 @@ public class Theme implements Serializable { } public Theme(String name, Theme other) { - this(name, other.backgroundColor, other.cellColor, other.interactableBackgroundColor, - other.interactableForegroundColor, other.messageColorChat, other.dateColorChat, other.selectionColor, + this(name, other.backgroundColor, other.cellColor, other.interactableForegroundColor, + other.interactableBackgroundColor, other.messageColorChat, other.dateColorChat, other.selectionColor, other.typingMessageColor, other.userNameColor); } @@ -109,25 +109,6 @@ public class Theme implements Serializable { */ public Color getUserNameColor() { return userNameColor; } - /** - * @return a color array containing all colors of this theme - * @since Envoy v0.2-alpha - */ - 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; - } - /** * Sets the a specific {@link Color} in this theme to a new {@link Color} * From a0e72a6e5668ccf916c7a11aec9a14baf6716d87 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sat, 14 Dec 2019 12:54:32 +0100 Subject: [PATCH 2/2] Changed colors management in the displaying of the themes settings screen. --- .../java/envoy/client/ui/SettingsScreen.java | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/main/java/envoy/client/ui/SettingsScreen.java b/src/main/java/envoy/client/ui/SettingsScreen.java index f96eac1..ef1dadc 100644 --- a/src/main/java/envoy/client/ui/SettingsScreen.java +++ b/src/main/java/envoy/client/ui/SettingsScreen.java @@ -138,11 +138,6 @@ public class SettingsScreen extends JDialog { 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; @@ -164,9 +159,6 @@ public class SettingsScreen extends JDialog { GridBagLayout gbl_themeLayout = new GridBagLayout(); - 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 }; @@ -174,8 +166,6 @@ public class SettingsScreen extends JDialog { themeContent.setLayout(gbl_themeLayout); - themes.setBackground(theme.getUserNameColor()); - themes.setForeground(theme.getBackgroundColor()); themes.setSelectedItem(Settings.getInstance().getCurrentTheme()); themes.addItemListener(new ItemListener() { @@ -300,8 +290,6 @@ public class SettingsScreen extends JDialog { contentPanel.revalidate(); contentPanel.repaint(); - // TODO: Create new Theme - } catch (Exception e) { logger.info("New theme couldn't be created! " + e); e.printStackTrace(); @@ -397,8 +385,8 @@ public class SettingsScreen extends JDialog { themeContent.setForeground(theme.getUserNameColor()); themeContent.setBackground(theme.getCellColor()); // themes - themes.setBackground(theme.getUserNameColor()); - themes.setForeground(theme.getBackgroundColor()); + themes.setBackground(theme.getBackgroundColor()); + themes.setForeground(getInvertedColor(theme.getBackgroundColor())); createNewThemeButton.setBackground(theme.getInteractableBackgroundColor()); createNewThemeButton.setForeground(theme.getInteractableForegroundColor()); @@ -517,7 +505,7 @@ public class SettingsScreen extends JDialog { String name, int yIndex) { textPane.setFont(new Font("Arial", Font.PLAIN, 14)); textPane.setBackground(theme.getBackgroundColor()); - textPane.setForeground(theme.getUserNameColor()); + textPane.setForeground(getInvertedColor(theme.getBackgroundColor())); textPane.setText(name); textPane.setEditable(false); @@ -532,11 +520,11 @@ public class SettingsScreen extends JDialog { System.out.println(color.getRGB()); // TODO: When Theme changed in same settings screen, color variable doesnt // update. - temporaryTheme.setColor(yIndex, newColor); - colorChanged = true; - createNewThemeButton.setEnabled(true); - } - button.setBackground(newColor); + temporaryTheme.setColor(yIndex, newColor); + colorChanged = true; + createNewThemeButton.setEnabled(true); + } + button.setBackground(newColor); } catch (Exception e) { logger.info("An error occured while opening Color Chooser: " + e); @@ -544,9 +532,16 @@ public class SettingsScreen extends JDialog { } }); - panel.add(textPane);panel.add(button);panel.setBackground(theme.getCellColor());panel.setAlignmentX(Component.LEFT_ALIGNMENT); + panel.add(textPane); + panel.add(button); + panel.setBackground(theme.getCellColor()); + panel.setAlignmentX(Component.LEFT_ALIGNMENT); - colorsPanel.add(panel); -} + colorsPanel.add(panel); + } + + private Color getInvertedColor(Color color) { + return new Color(255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue()); + } }