diff --git a/src/main/java/envoy/client/data/Settings.java b/src/main/java/envoy/client/data/Settings.java index 9d43bca..fc16c26 100644 --- a/src/main/java/envoy/client/data/Settings.java +++ b/src/main/java/envoy/client/data/Settings.java @@ -25,7 +25,7 @@ import envoy.util.SerializationUtils; public class Settings { // Actual settings accessible by the rest of the application - private Map> items; + private Map> items; /** * Settings are stored in this file. @@ -93,6 +93,15 @@ public class Settings { */ public void setCurrentTheme(String themeName) { ((SettingsItem) items.get("currentTheme")).set(themeName); } + /** + * @return true if the currently used theme is one of the default themes + * @since Envoy Client v0.1-beta + */ + public boolean isUsingDefaultTheme() { + final var theme = getCurrentTheme(); + return theme.equals("dark") || theme.equals("light"); + } + /** * @return {@code true}, if pressing the {@code Enter} key suffices to send a * message. Otherwise it has to be pressed in conjunction with the diff --git a/src/main/java/envoy/client/ui/ClearableTextField.java b/src/main/java/envoy/client/ui/ClearableTextField.java index b8b3a34..fbe6926 100644 --- a/src/main/java/envoy/client/ui/ClearableTextField.java +++ b/src/main/java/envoy/client/ui/ClearableTextField.java @@ -47,7 +47,7 @@ public class ClearableTextField extends GridPane { public ClearableTextField(String text, int size) { // initializing the textField and the button textField = new TextField(text); - clearButton = new Button("", new ImageView(IconUtil.loadDefaultThemeSensitive("clear_button_", size))); + clearButton = new Button("", new ImageView(IconUtil.loadIconThemeSensitive("clear_button", size))); clearButton.setOnAction(e -> textField.clear()); clearButton.setFocusTraversable(false); clearButton.getStyleClass().clear(); diff --git a/src/main/java/envoy/client/ui/IconUtil.java b/src/main/java/envoy/client/ui/IconUtil.java index 337227e..4591f51 100644 --- a/src/main/java/envoy/client/ui/IconUtil.java +++ b/src/main/java/envoy/client/ui/IconUtil.java @@ -66,23 +66,23 @@ public class IconUtil { * folder and scales it to 16px.
* The suffix {@code .png} is automatically appended. * - * @param name the image name without the .png - suffix + * @param name the image name without the .png suffix * @return the loaded image * @since Envoy Client v0.1-beta * @apiNote let's take a sample image {@code abc.png} in the folder * {@code /icons/}. *
* To do that, we only have to call - * {@code IconUtil.loadDefault("abc")} + * {@code IconUtil.loadIcon("abc")} */ - public static Image loadDefault(String name) { return load("/icons/" + name + ".png"); } + public static Image loadIcon(String name) { return load("/icons/" + name + ".png"); } /** * Loads a {@code .png} icon from the sub-folder {@code /icons/} of the resource * folder and scales it to a given size.
* The suffix {@code .png} is automatically appended. * - * @param name the image name without the .png - suffix + * @param name the image name without the .png suffix * @param size the size of the image to scale to * @return the loaded image * @since Envoy Client v0.1-beta @@ -90,9 +90,9 @@ public class IconUtil { * {@code /icons/} and load it in size 16. *
* To do that, we only have to call - * {@code IconUtil.loadDefault("abc", 16)} + * {@code IconUtil.loadIcon("abc", 16)} */ - public static Image loadDefault(String name, int size) { return load("/icons/" + name + ".png", size); } + public static Image loadIcon(String name, int size) { return load("/icons/" + name + ".png", size); } /** * Loads a {@code .png} icon whose design depends on the currently active theme @@ -104,16 +104,16 @@ public class IconUtil { * The suffix {@code .png} is automatically appended. * * @param name the image name without the "black" or "white" suffix and without - * the .png - suffix + * the .png suffix * @return the loaded image * @since Envoy Client v0.1-beta * @apiNote let's take two sample images {@code abc_black.png} and * {@code abc_white.png} in the folder {@code /icons/} and load them. *
* To do that theme sensitve, we only have to call - * {@code IconUtil.loadDefaultThemeSensitive("abc_")} + * {@code IconUtil.loadIconThemeSensitive("abc_")} */ - public static Image loadDefaultThemeSensitive(String name) { return loadDefault(name + themeSpecificSuffix()); } + public static Image loadIconThemeSensitive(String name) { return loadIcon(themeSpecificSubFolder() + name); } /** * Loads a {@code .png} icon whose design depends on the currently active theme @@ -125,7 +125,7 @@ public class IconUtil { *

* The suffix {@code .png} is automatically appended. * - * @param name the image name without the .png - suffix + * @param name the image name without the .png suffix * @param size the size of the image to scale to * @return the loaded image * @since Envoy Client v0.1-beta @@ -134,9 +134,9 @@ public class IconUtil { * size 16. *
* To do that theme sensitve, we only have to call - * {@code IconUtil.loadDefaultThemeSensitive("abc_", 16)} + * {@code IconUtil.loadIconThemeSensitive("abc_", 16)} */ - public static Image loadDefaultThemeSensitive(String name, int size) { return loadDefault(name + themeSpecificSuffix(), size); } + public static Image loadIconThemeSensitive(String name, int size) { return loadIcon(themeSpecificSubFolder() + name, size); } /** * @@ -163,11 +163,13 @@ public class IconUtil { /** * This method should be called if the display of an icon depends upon the * currently active theme.
- * In case of the dark theme, the suffix {@code "white"} will be appended, else - * the suffix {@code "black"} will be appended. + * In case of a default theme, the string returned will be + * returned ({@code dark/} or {@code light/}), else it will be empty. * - * @return the theme specific suffix + * @return the theme specific folder * @since Envoy Client v0.1-beta */ - public static String themeSpecificSuffix() { return Settings.getInstance().getCurrentTheme().equals("dark") ? "white" : "black"; } + public static String themeSpecificSubFolder() { + return Settings.getInstance().isUsingDefaultTheme() ? Settings.getInstance().getCurrentTheme() + "/" : ""; + } } diff --git a/src/main/java/envoy/client/ui/Startup.java b/src/main/java/envoy/client/ui/Startup.java index a28963a..0240e84 100644 --- a/src/main/java/envoy/client/ui/Startup.java +++ b/src/main/java/envoy/client/ui/Startup.java @@ -102,7 +102,7 @@ public final class Startup extends Application { messageStatusCache = new Cache<>(); stage.setTitle("Envoy"); - stage.getIcons().add(IconUtil.loadDefault("envoy_logo")); + stage.getIcons().add(IconUtil.loadIcon("envoy_logo")); final var sceneContext = new SceneContext(stage); sceneContext.load(SceneInfo.LOGIN_SCENE); diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 75f500c..956ce21 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -110,8 +110,8 @@ public final class ChatScene implements Restorable { messageList.setCellFactory(MessageListCellFactory::new); userList.setCellFactory(ContactListCellFactory::new); - settingsButton.setGraphic(new ImageView(IconUtil.loadDefault("settings", 16))); - voiceButton.setGraphic(new ImageView(IconUtil.loadDefaultThemeSensitive("", 24))); + settingsButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("settings", 16))); + voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", 20))); // Listen to received messages eventBus.register(MessageCreationEvent.class, e -> { @@ -265,17 +265,17 @@ public final class ChatScene implements Restorable { recording = true; Platform.runLater(() -> { voiceButton.setText("Recording"); - voiceButton.setGraphic(new ImageView(IconUtil.loadDefault("microphone_recording", 24))); + voiceButton.setGraphic(new ImageView(IconUtil.loadIcon("microphone_recording", 24))); }); recorder.start(); } else { pendingAttachment = new Attachment(recorder.finish(), AttachmentType.VOICE); recording = false; Platform.runLater(() -> { - voiceButton.setGraphic(new ImageView(IconUtil.loadDefaultThemeSensitive("microphone_", 24))); + voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", 20))); voiceButton.setText(null); checkPostConditions(false); - attachmentView.setImage(IconUtil.loadDefaultThemeSensitive("attachment_present_", 20)); + attachmentView.setImage(IconUtil.loadIconThemeSensitive("attachment_present", 20)); attachmentView.setVisible(true); }); } diff --git a/src/main/resources/icons/attachment_white.png b/src/main/resources/icons/dark/attachment.png similarity index 100% rename from src/main/resources/icons/attachment_white.png rename to src/main/resources/icons/dark/attachment.png diff --git a/src/main/resources/icons/attachment_present_white.png b/src/main/resources/icons/dark/attachment_present.png similarity index 100% rename from src/main/resources/icons/attachment_present_white.png rename to src/main/resources/icons/dark/attachment_present.png diff --git a/src/main/resources/icons/clear_button_white.png b/src/main/resources/icons/dark/clear_button.png similarity index 100% rename from src/main/resources/icons/clear_button_white.png rename to src/main/resources/icons/dark/clear_button.png diff --git a/src/main/resources/icons/forward.png b/src/main/resources/icons/dark/forward.png similarity index 100% rename from src/main/resources/icons/forward.png rename to src/main/resources/icons/dark/forward.png diff --git a/src/main/resources/icons/microphone_white.png b/src/main/resources/icons/dark/microphone.png similarity index 100% rename from src/main/resources/icons/microphone_white.png rename to src/main/resources/icons/dark/microphone.png diff --git a/src/main/resources/icons/settings.png b/src/main/resources/icons/dark/settings.png similarity index 100% rename from src/main/resources/icons/settings.png rename to src/main/resources/icons/dark/settings.png diff --git a/src/main/resources/icons/attachment_black.png b/src/main/resources/icons/light/attachment.png similarity index 100% rename from src/main/resources/icons/attachment_black.png rename to src/main/resources/icons/light/attachment.png diff --git a/src/main/resources/icons/attachment_present_black.png b/src/main/resources/icons/light/attachment_present.png similarity index 100% rename from src/main/resources/icons/attachment_present_black.png rename to src/main/resources/icons/light/attachment_present.png diff --git a/src/main/resources/icons/clear_button_black.png b/src/main/resources/icons/light/clear_button.png similarity index 100% rename from src/main/resources/icons/clear_button_black.png rename to src/main/resources/icons/light/clear_button.png diff --git a/src/main/resources/icons/forward_white.png b/src/main/resources/icons/light/forward.png similarity index 100% rename from src/main/resources/icons/forward_white.png rename to src/main/resources/icons/light/forward.png diff --git a/src/main/resources/icons/microphone_black.png b/src/main/resources/icons/light/microphone.png similarity index 100% rename from src/main/resources/icons/microphone_black.png rename to src/main/resources/icons/light/microphone.png diff --git a/src/main/resources/icons/settings_black.png b/src/main/resources/icons/light/settings.png similarity index 100% rename from src/main/resources/icons/settings_black.png rename to src/main/resources/icons/light/settings.png diff --git a/src/main/resources/icons/settings_white.png b/src/main/resources/icons/settings_white.png deleted file mode 100644 index f956615..0000000 Binary files a/src/main/resources/icons/settings_white.png and /dev/null differ