Added custom Color class to envoy.ui with invert() and toHex() methods.
This commit is contained in:
		| @@ -1,11 +1,11 @@ | ||||
| package envoy.client; | ||||
|  | ||||
| import java.awt.Color; | ||||
| import java.io.*; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| import java.util.prefs.Preferences; | ||||
|  | ||||
| import envoy.client.ui.Color; | ||||
| import envoy.client.ui.Theme; | ||||
|  | ||||
| /** | ||||
| @@ -28,7 +28,7 @@ public class Settings { | ||||
| 	private boolean				enterToSend	= true; | ||||
| 	private Map<String, Theme>	themes; | ||||
| 	private String				currentTheme; | ||||
| 	private boolean					currentOnCloseMode; | ||||
| 	private boolean				currentOnCloseMode; | ||||
|  | ||||
| 	/** | ||||
| 	 * Required to save the settings. | ||||
|   | ||||
							
								
								
									
										106
									
								
								src/main/java/envoy/client/ui/Color.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								src/main/java/envoy/client/ui/Color.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,106 @@ | ||||
| package envoy.client.ui; | ||||
|  | ||||
| import java.awt.color.ColorSpace; | ||||
|  | ||||
| /** | ||||
|  * Project: <strong>envoy-clientChess</strong><br> | ||||
|  * File: <strong>Color.javaEvent.java</strong><br> | ||||
|  * Created: <strong>23.12.2019</strong><br> | ||||
|  *  | ||||
|  * @author Kai S. K. Engelbart | ||||
|  */ | ||||
| @SuppressWarnings("javadoc") | ||||
| public class Color extends java.awt.Color { | ||||
|  | ||||
| 	/** | ||||
| 	 * The color white. In the default sRGB space. | ||||
| 	 */ | ||||
| 	public static final Color white = new Color(255, 255, 255); | ||||
|  | ||||
| 	/** | ||||
| 	 * The color light gray. In the default sRGB space. | ||||
| 	 */ | ||||
| 	public static final Color lightGray = new Color(192, 192, 192); | ||||
|  | ||||
| 	/** | ||||
| 	 * The color gray. In the default sRGB space. | ||||
| 	 */ | ||||
| 	public static final Color gray = new Color(128, 128, 128); | ||||
|  | ||||
| 	/** | ||||
| 	 * The color dark gray. In the default sRGB space. | ||||
| 	 */ | ||||
| 	public static final Color darkGray = new Color(64, 64, 64); | ||||
|  | ||||
| 	/** | ||||
| 	 * The color black. In the default sRGB space. | ||||
| 	 */ | ||||
| 	public static final Color black = new Color(0, 0, 0); | ||||
|  | ||||
| 	/** | ||||
| 	 * The color red. In the default sRGB space. | ||||
| 	 */ | ||||
| 	public static final Color red = new Color(255, 0, 0); | ||||
|  | ||||
| 	/** | ||||
| 	 * The color pink. In the default sRGB space. | ||||
| 	 */ | ||||
| 	public static final Color pink = new Color(255, 175, 175); | ||||
|  | ||||
| 	/** | ||||
| 	 * The color orange. In the default sRGB space. | ||||
| 	 */ | ||||
| 	public static final Color orange = new Color(255, 200, 0); | ||||
|  | ||||
| 	/** | ||||
| 	 * The color yellow. In the default sRGB space. | ||||
| 	 */ | ||||
| 	public static final Color yellow = new Color(255, 255, 0); | ||||
|  | ||||
| 	/** | ||||
| 	 * The color green. In the default sRGB space. | ||||
| 	 */ | ||||
| 	public static final Color green = new Color(0, 255, 0); | ||||
|  | ||||
| 	/** | ||||
| 	 * The color magenta. In the default sRGB space. | ||||
| 	 */ | ||||
| 	public static final Color magenta = new Color(255, 0, 255); | ||||
|  | ||||
| 	/** | ||||
| 	 * The color cyan. In the default sRGB space. | ||||
| 	 */ | ||||
| 	public static final Color cyan = new Color(0, 255, 255); | ||||
|  | ||||
| 	/** | ||||
| 	 * The color blue. In the default sRGB space. | ||||
| 	 */ | ||||
| 	public static final Color blue = new Color(0, 0, 255); | ||||
|  | ||||
| 	private static final long serialVersionUID = -9166233199998257344L; | ||||
|  | ||||
| 	public Color(int rgb) { super(rgb); } | ||||
|  | ||||
| 	public Color(int rgba, boolean hasalpha) { super(rgba, hasalpha); } | ||||
|  | ||||
| 	public Color(int r, int g, int b) { super(r, g, b); } | ||||
|  | ||||
| 	public Color(float r, float g, float b) { super(r, g, b); } | ||||
|  | ||||
| 	public Color(ColorSpace cspace, float[] components, float alpha) { super(cspace, components, alpha); } | ||||
|  | ||||
| 	public Color(int r, int g, int b, int a) { super(r, g, b, a); } | ||||
|  | ||||
| 	public Color(float r, float g, float b, float a) { super(r, g, b, a); } | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the inversion of this {@link Color} by replacing the red, green and | ||||
| 	 *         blue values by subtracting them form 255 | ||||
| 	 */ | ||||
| 	public Color invert() { return new Color(255 - getRed(), 255 - getGreen(), 255 - getBlue()); } | ||||
|  | ||||
| 	/** | ||||
| 	 * @return the hex value of this {@link Color} | ||||
| 	 */ | ||||
| 	public String toHex() { return String.format("#%02x%02x%02x", getRed(), getGreen(), getBlue()); } | ||||
| } | ||||
| @@ -1,6 +1,5 @@ | ||||
| package envoy.client.ui; | ||||
|  | ||||
| import java.awt.Color; | ||||
| import java.awt.Component; | ||||
| import java.text.SimpleDateFormat; | ||||
|  | ||||
| @@ -46,11 +45,11 @@ public class MessageListRenderer extends JLabel implements ListCellRenderer<Mess | ||||
| 		// Getting the MessageColor in the Chat of the current theme | ||||
| 		String textColor = null; | ||||
|  | ||||
| 		textColor = toHex(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat()); | ||||
| 		textColor = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat().toHex(); | ||||
|  | ||||
| 		// Getting the DateColor in the Chat of the current theme | ||||
| 		String dateColor = null; | ||||
| 		dateColor = toHex(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat()); | ||||
| 		dateColor = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat().toHex(); | ||||
|  | ||||
| 		setText(String.format("<html><p style=\"color:%s\"><b><small>%s</b></small><br><p style=\"color:%s\">%s :%s</html>", | ||||
| 				dateColor, | ||||
| @@ -60,12 +59,4 @@ public class MessageListRenderer extends JLabel implements ListCellRenderer<Mess | ||||
| 				state)); | ||||
| 		return this; | ||||
| 	} | ||||
|  | ||||
| 	private 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; | ||||
| 	} | ||||
| } | ||||
| @@ -25,9 +25,9 @@ import envoy.client.util.EnvoyLog; | ||||
|  */ | ||||
| public class PrimaryToggleSwitch extends JPanel { | ||||
|  | ||||
| 	private final JButton	b	= new JButton(""); | ||||
| 	private boolean			currentState; | ||||
| 	private boolean			variable; | ||||
| 	private final JButton b = new JButton(""); | ||||
|  | ||||
| 	private boolean currentState; | ||||
|  | ||||
| 	private static final Logger	logger				= EnvoyLog.getLogger(PrimaryToggleSwitch.class.getSimpleName()); | ||||
| 	private static final long	serialVersionUID	= -721155303106833184L; | ||||
| @@ -69,7 +69,7 @@ public class PrimaryToggleSwitch extends JPanel { | ||||
| 			try { | ||||
| 				// Dispatch event | ||||
| 				Constructor<? extends Event<Boolean>> constructor = eventClass.getConstructor(boolean.class); | ||||
| 				EventBus.getInstance().dispatch((Event<?>) constructor.newInstance(variable)); | ||||
| 				EventBus.getInstance().dispatch(constructor.newInstance(currentState)); | ||||
|  | ||||
| 				setState(!currentState); | ||||
| 				revalidate(); | ||||
| @@ -109,7 +109,6 @@ public class PrimaryToggleSwitch extends JPanel { | ||||
| 		gbc_toggleButton.gridy = 0; | ||||
| 		add(b, gbc_toggleButton); | ||||
|  | ||||
| 		currentState	= state; | ||||
| 		variable		= state; | ||||
| 		currentState = state; | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| package envoy.client.ui; | ||||
|  | ||||
| import java.awt.Color; | ||||
| import java.io.Serializable; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| package envoy.client.ui; | ||||
|  | ||||
| import java.awt.Color; | ||||
| import java.awt.Component; | ||||
|  | ||||
| import javax.swing.JLabel; | ||||
| @@ -44,7 +43,7 @@ public class UserListRenderer extends JLabel implements ListCellRenderer<User> { | ||||
|  | ||||
| 		// Getting the UserNameColor of the current theme | ||||
| 		String textColor = null; | ||||
| 		textColor = toHex(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor()); | ||||
| 		textColor = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getUserNameColor().toHex(); | ||||
| 		switch (status) { | ||||
| 			case ONLINE: | ||||
| 				setText(String | ||||
| @@ -57,12 +56,4 @@ public class UserListRenderer extends JLabel implements ListCellRenderer<User> { | ||||
| 		} | ||||
| 		return this; | ||||
| 	} | ||||
|  | ||||
| 	private 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; | ||||
| 	} | ||||
| } | ||||
| @@ -134,8 +134,7 @@ public class General extends SettingsPanel { | ||||
| 		add(stateText, gbc_stateText); | ||||
|  | ||||
| 		descriptionText.setText(text); | ||||
| 		descriptionText.setBackground(theme.getBackgroundColor()); | ||||
| 		// TODO: Change to inverted color. | ||||
| 		descriptionText.setBackground(theme.getBackgroundColor().invert()); | ||||
| 		descriptionText.setForeground(theme.getUserNameColor()); | ||||
| 		descriptionText.setEditable(false); | ||||
|  | ||||
|   | ||||
| @@ -39,7 +39,7 @@ public class SettingsScreen extends JDialog { | ||||
| 	private final JList<String>				options				= new JList<>(optionsListModel); | ||||
|  | ||||
| 	// OK and cancel buttons | ||||
| 	private final JPanel	buttonPane		= new JPanel(); | ||||
| 	private final JPanel		buttonPane		= new JPanel(); | ||||
| 	private final PrimaryButton	okButton		= new PrimaryButton("Save"); | ||||
| 	private final PrimaryButton	cancelButton	= new PrimaryButton("Cancel"); | ||||
|  | ||||
| @@ -119,10 +119,10 @@ public class SettingsScreen extends JDialog { | ||||
|  | ||||
| 			// ButtonPane | ||||
| 			GridBagLayout gbl_buttonPane = new GridBagLayout(); | ||||
| 			gbl_buttonPane.columnWidths		= new int[] { 1, 1}; | ||||
| 			gbl_buttonPane.rowHeights		= new int[] { 25}; | ||||
| 			gbl_buttonPane.columnWeights	= new double[] { 1.0, 1.0}; | ||||
| 			gbl_buttonPane.rowWeights		= new double[] { 0.0}; | ||||
| 			gbl_buttonPane.columnWidths		= new int[] { 1, 1 }; | ||||
| 			gbl_buttonPane.rowHeights		= new int[] { 25 }; | ||||
| 			gbl_buttonPane.columnWeights	= new double[] { 1.0, 1.0 }; | ||||
| 			gbl_buttonPane.rowWeights		= new double[] { 0.0 }; | ||||
|  | ||||
| 			getContentPane().add(buttonPane, BorderLayout.SOUTH); | ||||
| 			buttonPane.setLayout(gbl_buttonPane); | ||||
| @@ -189,4 +189,4 @@ public class SettingsScreen extends JDialog { | ||||
| 		options.setForeground(theme.getUserNameColor()); | ||||
| 		options.setBackground(theme.getCellColor()); | ||||
| 	} | ||||
| } | ||||
| } | ||||
| @@ -13,6 +13,7 @@ import javax.swing.*; | ||||
| import envoy.client.Settings; | ||||
| import envoy.client.event.EventBus; | ||||
| import envoy.client.event.ThemeChangeEvent; | ||||
| import envoy.client.ui.Color; | ||||
| import envoy.client.ui.Theme; | ||||
| import envoy.client.util.EnvoyLog; | ||||
|  | ||||
| @@ -30,7 +31,6 @@ import envoy.client.util.EnvoyLog; | ||||
|  */ | ||||
| public class ThemeCustomizationPanel extends SettingsPanel { | ||||
|  | ||||
|  | ||||
| 	private JPanel colorsPanel = new JPanel(); | ||||
|  | ||||
| 	private String[]			themeArray		= Settings.getInstance().getThemes().keySet().toArray(new String[0]); | ||||
| @@ -40,7 +40,7 @@ public class ThemeCustomizationPanel extends SettingsPanel { | ||||
|  | ||||
| 	private final Insets insets = new Insets(5, 5, 5, 5); | ||||
|  | ||||
| 	private static final Logger logger = EnvoyLog.getLogger(ThemeCustomizationPanel.class.getSimpleName()); | ||||
| 	private static final Logger	logger				= EnvoyLog.getLogger(ThemeCustomizationPanel.class.getSimpleName()); | ||||
| 	private static final long	serialVersionUID	= -8697897390666456624L; | ||||
|  | ||||
| 	/** | ||||
| @@ -185,7 +185,7 @@ public class ThemeCustomizationPanel extends SettingsPanel { | ||||
|  | ||||
| 		textPane.setFont(new Font("Arial", Font.PLAIN, 14)); | ||||
| 		textPane.setBackground(theme.getBackgroundColor()); | ||||
| 		textPane.setForeground(getInvertedColor(theme.getBackgroundColor())); | ||||
| 		textPane.setForeground(theme.getBackgroundColor().invert()); | ||||
| 		textPane.setText(name); | ||||
| 		textPane.setEditable(false); | ||||
|  | ||||
| @@ -194,7 +194,7 @@ public class ThemeCustomizationPanel extends SettingsPanel { | ||||
|  | ||||
| 		button.addActionListener((evt) -> { | ||||
| 			try { | ||||
| 				Color newColor = JColorChooser.showDialog(null, "Choose a color", color); | ||||
| 				Color newColor = (Color) JColorChooser.showDialog(null, "Choose a color", color); | ||||
| 				if (newColor.getRGB() != color.getRGB()) { | ||||
| 					logger.log(Level.FINEST, "New Color: " + String.valueOf(color.getRGB())); | ||||
| 					// TODO: When Theme changed in same settings screen, color variable doesn't | ||||
| @@ -228,6 +228,4 @@ public class ThemeCustomizationPanel extends SettingsPanel { | ||||
|  | ||||
| 		colorsPanel.add(button, gbc_button); | ||||
| 	} | ||||
|  | ||||
| 	private Color getInvertedColor(Color color) { return new Color(255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue()); } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user