Merge pull request #52 from informatik-ag-ngl/b/incorrect_color_change
Fixed incorrect color changing
This commit is contained in:
		| @@ -110,7 +110,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(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
|   | |||||||
| @@ -137,11 +137,6 @@ public class SettingsScreen extends JDialog { | |||||||
|  |  | ||||||
| 			Theme theme = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()); | 			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(); | 			GridBagConstraints gbc_optionsList = new GridBagConstraints(); | ||||||
| 			gbc_optionsList.fill	= GridBagConstraints.BOTH; | 			gbc_optionsList.fill	= GridBagConstraints.BOTH; | ||||||
| 			gbc_optionsList.gridx	= 0; | 			gbc_optionsList.gridx	= 0; | ||||||
| @@ -163,9 +158,6 @@ public class SettingsScreen extends JDialog { | |||||||
|  |  | ||||||
| 			GridBagLayout gbl_themeLayout = new GridBagLayout(); | 			GridBagLayout gbl_themeLayout = new GridBagLayout(); | ||||||
|  |  | ||||||
| 			themeContent.setForeground(theme.getUserNameColor()); |  | ||||||
| 			themeContent.setBackground(theme.getCellColor()); |  | ||||||
|  |  | ||||||
| 			gbl_themeLayout.columnWidths	= new int[] { 1, 1 }; | 			gbl_themeLayout.columnWidths	= new int[] { 1, 1 }; | ||||||
| 			gbl_themeLayout.rowHeights		= new int[] { 1, 1 }; | 			gbl_themeLayout.rowHeights		= new int[] { 1, 1 }; | ||||||
| 			gbl_themeLayout.columnWeights	= new double[] { 1.0, 1.0 }; | 			gbl_themeLayout.columnWeights	= new double[] { 1.0, 1.0 }; | ||||||
| @@ -173,8 +165,6 @@ public class SettingsScreen extends JDialog { | |||||||
|  |  | ||||||
| 			themeContent.setLayout(gbl_themeLayout); | 			themeContent.setLayout(gbl_themeLayout); | ||||||
|  |  | ||||||
| 			themes.setBackground(theme.getUserNameColor()); |  | ||||||
| 			themes.setForeground(theme.getBackgroundColor()); |  | ||||||
| 			themes.setSelectedItem(Settings.getInstance().getCurrentTheme()); | 			themes.setSelectedItem(Settings.getInstance().getCurrentTheme()); | ||||||
|  |  | ||||||
| 			themes.addItemListener(new ItemListener() { | 			themes.addItemListener(new ItemListener() { | ||||||
| @@ -199,27 +189,27 @@ public class SettingsScreen extends JDialog { | |||||||
| 			colorsPanel.setLayout(new BoxLayout(colorsPanel, BoxLayout.Y_AXIS)); | 			colorsPanel.setLayout(new BoxLayout(colorsPanel, BoxLayout.Y_AXIS)); | ||||||
| 			colorsPanel.setAlignmentX(Component.LEFT_ALIGNMENT); | 			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.getBackgroundColor(), "Background", 0); | ||||||
| 			buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getCellColor(), "Cells", 2); | 			buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getCellColor(), "Cells", 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(), new JButton(), new JTextPane(), theme, theme.getMessageColorChat(), "Messages Chat", 5); | 			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", 6); | 			buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getDateColorChat(), "Date Chat", 5); | ||||||
| 			buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getSelectionColor(), "Selection", 7); | 			buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getSelectionColor(), "Selection", 6); | ||||||
| 			buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getTypingMessageColor(), "Typing Message", 8); | 			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", 9); | 			buildCustomizeElement(new JPanel(), new JButton(), new JTextPane(), theme, theme.getUserNameColor(), "User Names", 8); | ||||||
|  |  | ||||||
| 			GridBagConstraints gbc_colorsPanel = new GridBagConstraints(); | 			GridBagConstraints gbc_colorsPanel = new GridBagConstraints(); | ||||||
| 			gbc_colorsPanel.fill		= GridBagConstraints.HORIZONTAL; | 			gbc_colorsPanel.fill		= GridBagConstraints.HORIZONTAL; | ||||||
| @@ -255,8 +245,6 @@ public class SettingsScreen extends JDialog { | |||||||
| 					contentPanel.revalidate(); | 					contentPanel.revalidate(); | ||||||
| 					contentPanel.repaint(); | 					contentPanel.repaint(); | ||||||
|  |  | ||||||
| 					// TODO: Create new Theme |  | ||||||
|  |  | ||||||
| 				} catch (Exception e) { | 				} catch (Exception e) { | ||||||
| 					logger.info("New theme couldn't be created! " + e); | 					logger.info("New theme couldn't be created! " + e); | ||||||
| 					e.printStackTrace(); | 					e.printStackTrace(); | ||||||
| @@ -348,8 +336,8 @@ public class SettingsScreen extends JDialog { | |||||||
| 		themeContent.setForeground(theme.getUserNameColor()); | 		themeContent.setForeground(theme.getUserNameColor()); | ||||||
| 		themeContent.setBackground(theme.getCellColor()); | 		themeContent.setBackground(theme.getCellColor()); | ||||||
| 		// themes | 		// themes | ||||||
| 		themes.setBackground(theme.getUserNameColor()); | 		themes.setBackground(theme.getBackgroundColor()); | ||||||
| 		themes.setForeground(theme.getBackgroundColor()); | 		themes.setForeground(getInvertedColor(theme.getBackgroundColor())); | ||||||
|  |  | ||||||
| 		createNewThemeButton.setBackground(theme.getInteractableBackgroundColor()); | 		createNewThemeButton.setBackground(theme.getInteractableBackgroundColor()); | ||||||
| 		createNewThemeButton.setForeground(theme.getInteractableForegroundColor()); | 		createNewThemeButton.setForeground(theme.getInteractableForegroundColor()); | ||||||
| @@ -380,7 +368,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(), | ||||||
| @@ -388,7 +376,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(), | ||||||
| @@ -396,7 +384,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(), | ||||||
| @@ -404,7 +392,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(), | ||||||
| @@ -412,7 +400,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(), | ||||||
| @@ -420,7 +408,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(), | ||||||
| @@ -428,7 +416,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(), | ||||||
| @@ -436,7 +424,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(), | ||||||
| @@ -444,7 +432,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; | ||||||
| @@ -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) { | 	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.setFont(new Font("Arial", Font.PLAIN, 14)); | ||||||
| 		textPane.setBackground(theme.getBackgroundColor()); | 		textPane.setBackground(theme.getBackgroundColor()); | ||||||
| 		textPane.setForeground(theme.getUserNameColor()); | 		textPane.setForeground(getInvertedColor(theme.getBackgroundColor())); | ||||||
| 		textPane.setText(name); | 		textPane.setText(name); | ||||||
| 		textPane.setEditable(false); | 		textPane.setEditable(false); | ||||||
|  |  | ||||||
| @@ -473,18 +461,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++) { | 					colorChanged = true; | ||||||
| 						if (color.getRGB() == colorsArray[i].getRGB()) { | 					createNewThemeButton.setEnabled(true); | ||||||
| 							temporaryTheme.setColor(i, newColor); |  | ||||||
| 							colorChanged = 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); | ||||||
| @@ -500,4 +481,8 @@ public class SettingsScreen extends JDialog { | |||||||
| 		colorsPanel.add(panel); | 		colorsPanel.add(panel); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	private Color getInvertedColor(Color color) { | ||||||
|  | 		return new Color(255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue()); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -43,8 +43,9 @@ 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, other.interactableForegroundColor, | 		this(name, other.backgroundColor, other.cellColor, other.interactableForegroundColor, | ||||||
| 				other.messageColorChat, other.dateColorChat, other.selectionColor, other.typingMessageColor, other.userNameColor); | 				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; } | 	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} | ||||||
| 	 *  | 	 *  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 DieGurke
					DieGurke