diff --git a/src/main/java/envoy/client/Settings.java b/src/main/java/envoy/client/Settings.java index 5e15743..fc60877 100644 --- a/src/main/java/envoy/client/Settings.java +++ b/src/main/java/envoy/client/Settings.java @@ -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 themes; private String currentTheme; - private boolean currentOnCloseMode; + private boolean currentOnCloseMode; /** * Required to save the settings. diff --git a/src/main/java/envoy/client/ui/Color.java b/src/main/java/envoy/client/ui/Color.java new file mode 100644 index 0000000..33be64b --- /dev/null +++ b/src/main/java/envoy/client/ui/Color.java @@ -0,0 +1,106 @@ +package envoy.client.ui; + +import java.awt.color.ColorSpace; + +/** + * Project: envoy-clientChess
+ * File: Color.javaEvent.java
+ * Created: 23.12.2019
+ * + * @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()); } +} \ No newline at end of file diff --git a/src/main/java/envoy/client/ui/MessageListRenderer.java b/src/main/java/envoy/client/ui/MessageListRenderer.java index 5623fb6..ddd2230 100644 --- a/src/main/java/envoy/client/ui/MessageListRenderer.java +++ b/src/main/java/envoy/client/ui/MessageListRenderer.java @@ -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

%s

%s :%s", dateColor, @@ -60,12 +59,4 @@ public class MessageListRenderer extends JLabel implements ListCellRenderer> 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; } } diff --git a/src/main/java/envoy/client/ui/Theme.java b/src/main/java/envoy/client/ui/Theme.java index 3e6c39e..d912988 100644 --- a/src/main/java/envoy/client/ui/Theme.java +++ b/src/main/java/envoy/client/ui/Theme.java @@ -1,6 +1,5 @@ package envoy.client.ui; -import java.awt.Color; import java.io.Serializable; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/envoy/client/ui/UserListRenderer.java b/src/main/java/envoy/client/ui/UserListRenderer.java index d26aa8b..ca7214d 100644 --- a/src/main/java/envoy/client/ui/UserListRenderer.java +++ b/src/main/java/envoy/client/ui/UserListRenderer.java @@ -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 { // 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 { } 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; - } } \ No newline at end of file diff --git a/src/main/java/envoy/client/ui/settings/General.java b/src/main/java/envoy/client/ui/settings/General.java index faa46bc..b128454 100644 --- a/src/main/java/envoy/client/ui/settings/General.java +++ b/src/main/java/envoy/client/ui/settings/General.java @@ -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); diff --git a/src/main/java/envoy/client/ui/settings/SettingsScreen.java b/src/main/java/envoy/client/ui/settings/SettingsScreen.java index d0e4b8f..b971625 100644 --- a/src/main/java/envoy/client/ui/settings/SettingsScreen.java +++ b/src/main/java/envoy/client/ui/settings/SettingsScreen.java @@ -39,7 +39,7 @@ public class SettingsScreen extends JDialog { private final JList 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()); } -} +} \ No newline at end of file diff --git a/src/main/java/envoy/client/ui/settings/ThemeCustomizationPanel.java b/src/main/java/envoy/client/ui/settings/ThemeCustomizationPanel.java index 5310a5e..8c3f9f4 100644 --- a/src/main/java/envoy/client/ui/settings/ThemeCustomizationPanel.java +++ b/src/main/java/envoy/client/ui/settings/ThemeCustomizationPanel.java @@ -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()); } } \ No newline at end of file