Merge pull request #52 from informatik-ag-ngl/b/incorrect_color_change

Fixed incorrect color changing
This commit is contained in:
DieGurke 2019-12-14 14:25:46 +01:00 committed by GitHub
commit 39465c0fd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 66 deletions

View File

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

View File

@ -137,11 +137,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;
@ -163,9 +158,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 };
@ -173,8 +165,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() {
@ -199,27 +189,27 @@ public class SettingsScreen extends JDialog {
colorsPanel.setLayout(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.getBackgroundColor(), "Background", 0);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getCellColor(), "Cells", 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);
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);
3);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getMessageColorChat(), "Messages Chat", 4);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getDateColorChat(), "Date Chat", 5);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getSelectionColor(), "Selection", 6);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getTypingMessageColor(), "Typing Message", 7);
buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getUserNameColor(), "User Names", 8);
GridBagConstraints gbc_colorsPanel = new GridBagConstraints();
gbc_colorsPanel.fill = GridBagConstraints.HORIZONTAL;
@ -255,8 +245,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();
@ -348,8 +336,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());
@ -380,7 +368,7 @@ public class SettingsScreen extends JDialog {
theme,
theme.getBackgroundColor(),
"Background",
1);
0);
buildCustomizeElement(new JPanel(),
new JButton(),
@ -388,7 +376,7 @@ public class SettingsScreen extends JDialog {
theme,
theme.getCellColor(),
"Cells",
2);
1);
buildCustomizeElement(new JPanel(),
new JButton(),
@ -396,7 +384,7 @@ public class SettingsScreen extends JDialog {
theme,
theme.getInteractableForegroundColor(),
"Interactable Foreground",
3);
2);
buildCustomizeElement(new JPanel(),
new JButton(),
@ -404,7 +392,7 @@ public class SettingsScreen extends JDialog {
theme,
theme.getInteractableBackgroundColor(),
"Interactable Background",
4);
3);
buildCustomizeElement(new JPanel(),
new JButton(),
@ -412,7 +400,7 @@ public class SettingsScreen extends JDialog {
theme,
theme.getMessageColorChat(),
"Messages Chat",
5);
4);
buildCustomizeElement(new JPanel(),
new JButton(),
@ -420,7 +408,7 @@ public class SettingsScreen extends JDialog {
theme,
theme.getDateColorChat(),
"Date Chat",
6);
5);
buildCustomizeElement(new JPanel(),
new JButton(),
@ -428,7 +416,7 @@ public class SettingsScreen extends JDialog {
theme,
theme.getSelectionColor(),
"Selection",
7);
6);
buildCustomizeElement(new JPanel(),
new JButton(),
@ -436,7 +424,7 @@ public class SettingsScreen extends JDialog {
theme,
theme.getTypingMessageColor(),
"Typing Message",
8);
7);
buildCustomizeElement(new JPanel(),
new JButton(),
@ -444,7 +432,7 @@ public class SettingsScreen extends JDialog {
theme,
theme.getUserNameColor(),
"User Names",
9);
8);
GridBagConstraints gbc_createNewTheme = new GridBagConstraints();
gbc_createNewTheme.gridx = 0;
@ -458,7 +446,7 @@ public class SettingsScreen extends JDialog {
private 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.setForeground(getInvertedColor(theme.getBackgroundColor()));
textPane.setText(name);
textPane.setEditable(false);
@ -473,18 +461,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;
}
}
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);
@ -500,4 +481,8 @@ public class SettingsScreen extends JDialog {
colorsPanel.add(panel);
}
private Color getInvertedColor(Color color) {
return new Color(255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue());
}
}

View File

@ -43,8 +43,9 @@ 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, other.typingMessageColor, other.userNameColor);
this(name, other.backgroundColor, other.cellColor, other.interactableForegroundColor,
other.interactableBackgroundColor, other.messageColorChat, other.dateColorChat, other.selectionColor,
other.typingMessageColor, other.userNameColor);
}
/**
@ -107,25 +108,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}
*