Fixes bugs with the incorrect applying of the changed colors.

Fixes #50
This commit is contained in:
DieGurke 2019-12-14 11:22:37 +01:00
parent 3c8a4c445f
commit 6ab38e1e1a
3 changed files with 28 additions and 57 deletions

View File

@ -116,7 +116,7 @@ public class Settings {
*/ */
public void addNewThemeToMap(Theme theme) { public void addNewThemeToMap(Theme theme) {
settings.getThemes().put(theme.getThemeName(), theme); settings.getThemes().put(theme.getThemeName(), theme);
currentTheme = theme.getThemeName(); // currentTheme = theme.getThemeName();
} }
/** /**

View File

@ -206,63 +206,63 @@ public class SettingsScreen extends JDialog {
theme, theme,
theme.getBackgroundColor(), theme.getBackgroundColor(),
"Background", "Background",
1); 0);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
new JTextPane(), new JTextPane(),
theme, theme,
theme.getCellColor(), theme.getCellColor(),
"Cells", "Cells",
2); 1);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
new JTextPane(), new JTextPane(),
theme, theme,
theme.getInteractableForegroundColor(), theme.getInteractableForegroundColor(),
"Interactable Foreground", "Interactable Foreground",
3); 2);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
new JTextPane(), new JTextPane(),
theme, theme,
theme.getInteractableBackgroundColor(), theme.getInteractableBackgroundColor(),
"Interactable Background", "Interactable Background",
4); 3);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
new JTextPane(), new JTextPane(),
theme, theme,
theme.getMessageColorChat(), theme.getMessageColorChat(),
"Messages Chat", "Messages Chat",
5); 4);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
new JTextPane(), new JTextPane(),
theme, theme,
theme.getDateColorChat(), theme.getDateColorChat(),
"Date Chat", "Date Chat",
6); 5);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
new JTextPane(), new JTextPane(),
theme, theme,
theme.getSelectionColor(), theme.getSelectionColor(),
"Selection", "Selection",
7); 6);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
new JTextPane(), new JTextPane(),
theme, theme,
theme.getTypingMessageColor(), theme.getTypingMessageColor(),
"Typing Message", "Typing Message",
8); 7);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
new JTextPane(), new JTextPane(),
theme, theme,
theme.getUserNameColor(), theme.getUserNameColor(),
"User Names", "User Names",
9); 8);
GridBagConstraints gbc_colorsPanel = new GridBagConstraints(); GridBagConstraints gbc_colorsPanel = new GridBagConstraints();
gbc_colorsPanel.fill = GridBagConstraints.HORIZONTAL; gbc_colorsPanel.fill = GridBagConstraints.HORIZONTAL;
@ -438,7 +438,7 @@ public class SettingsScreen extends JDialog {
theme, theme,
theme.getBackgroundColor(), theme.getBackgroundColor(),
"Background", "Background",
1); 0);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
@ -446,7 +446,7 @@ public class SettingsScreen extends JDialog {
theme, theme,
theme.getCellColor(), theme.getCellColor(),
"Cells", "Cells",
2); 1);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
@ -454,7 +454,7 @@ public class SettingsScreen extends JDialog {
theme, theme,
theme.getInteractableForegroundColor(), theme.getInteractableForegroundColor(),
"Interactable Foreground", "Interactable Foreground",
3); 2);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
@ -462,7 +462,7 @@ public class SettingsScreen extends JDialog {
theme, theme,
theme.getInteractableBackgroundColor(), theme.getInteractableBackgroundColor(),
"Interactable Background", "Interactable Background",
4); 3);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
@ -470,7 +470,7 @@ public class SettingsScreen extends JDialog {
theme, theme,
theme.getMessageColorChat(), theme.getMessageColorChat(),
"Messages Chat", "Messages Chat",
5); 4);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
@ -478,7 +478,7 @@ public class SettingsScreen extends JDialog {
theme, theme,
theme.getDateColorChat(), theme.getDateColorChat(),
"Date Chat", "Date Chat",
6); 5);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
@ -486,7 +486,7 @@ public class SettingsScreen extends JDialog {
theme, theme,
theme.getSelectionColor(), theme.getSelectionColor(),
"Selection", "Selection",
7); 6);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
@ -494,7 +494,7 @@ public class SettingsScreen extends JDialog {
theme, theme,
theme.getTypingMessageColor(), theme.getTypingMessageColor(),
"Typing Message", "Typing Message",
8); 7);
buildCustomizeElement(new JPanel(), buildCustomizeElement(new JPanel(),
new JButton(), new JButton(),
@ -502,7 +502,7 @@ public class SettingsScreen extends JDialog {
theme, theme,
theme.getUserNameColor(), theme.getUserNameColor(),
"User Names", "User Names",
9); 8);
GridBagConstraints gbc_createNewTheme = new GridBagConstraints(); GridBagConstraints gbc_createNewTheme = new GridBagConstraints();
gbc_createNewTheme.gridx = 0; gbc_createNewTheme.gridx = 0;
@ -532,18 +532,11 @@ public class SettingsScreen extends JDialog {
System.out.println(color.getRGB()); System.out.println(color.getRGB());
// TODO: When Theme changed in same settings screen, color variable doesnt // TODO: When Theme changed in same settings screen, color variable doesnt
// update. // update.
Color[] colorsArray = temporaryTheme.getAllColors(); temporaryTheme.setColor(yIndex, newColor);
for (int i = 0; i < colorsArray.length; i++) {
if (color.getRGB() == colorsArray[i].getRGB()) {
temporaryTheme.setColor(i, newColor);
colorChanged = true; colorChanged = true;
createNewThemeButton.setEnabled(true); createNewThemeButton.setEnabled(true);
break;
}
} }
button.setBackground(newColor); button.setBackground(newColor);
}
} catch (Exception e) { } catch (Exception e) {
logger.info("An error occured while opening Color Chooser: " + e); logger.info("An error occured while opening Color Chooser: " + e);
@ -551,10 +544,7 @@ public class SettingsScreen extends JDialog {
} }
}); });
panel.add(textPane); panel.add(textPane);panel.add(button);panel.setBackground(theme.getCellColor());panel.setAlignmentX(Component.LEFT_ALIGNMENT);
panel.add(button);
panel.setBackground(theme.getCellColor());
panel.setAlignmentX(Component.LEFT_ALIGNMENT);
colorsPanel.add(panel); colorsPanel.add(panel);
} }

View File

@ -44,8 +44,8 @@ public class Theme implements Serializable {
} }
public Theme(String name, Theme other) { public Theme(String name, Theme other) {
this(name, other.backgroundColor, other.cellColor, other.interactableBackgroundColor, this(name, other.backgroundColor, other.cellColor, other.interactableForegroundColor,
other.interactableForegroundColor, other.messageColorChat, other.dateColorChat, other.selectionColor, other.interactableBackgroundColor, other.messageColorChat, other.dateColorChat, other.selectionColor,
other.typingMessageColor, other.userNameColor); other.typingMessageColor, other.userNameColor);
} }
@ -109,25 +109,6 @@ public class Theme implements Serializable {
*/ */
public Color getUserNameColor() { return userNameColor; } 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} * Sets the a specific {@link Color} in this theme to a new {@link Color}
* *