Defined theme specific icon folders, renamed icon loading method

This commit is contained in:
delvh 2020-07-07 17:02:39 +02:00
parent 4f2c1f8a97
commit 1312a4afc7
18 changed files with 35 additions and 24 deletions

View File

@ -25,7 +25,7 @@ import envoy.util.SerializationUtils;
public class Settings { public class Settings {
// Actual settings accessible by the rest of the application // Actual settings accessible by the rest of the application
private Map<String, SettingsItem<?>> items; private Map<String, SettingsItem<?>> items;
/** /**
* Settings are stored in this file. * Settings are stored in this file.
@ -93,6 +93,15 @@ public class Settings {
*/ */
public void setCurrentTheme(String themeName) { ((SettingsItem<String>) items.get("currentTheme")).set(themeName); } public void setCurrentTheme(String themeName) { ((SettingsItem<String>) 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 * @return {@code true}, if pressing the {@code Enter} key suffices to send a
* message. Otherwise it has to be pressed in conjunction with the * message. Otherwise it has to be pressed in conjunction with the

View File

@ -47,7 +47,7 @@ public class ClearableTextField extends GridPane {
public ClearableTextField(String text, int size) { public ClearableTextField(String text, int size) {
// initializing the textField and the button // initializing the textField and the button
textField = new TextField(text); 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.setOnAction(e -> textField.clear());
clearButton.setFocusTraversable(false); clearButton.setFocusTraversable(false);
clearButton.getStyleClass().clear(); clearButton.getStyleClass().clear();

View File

@ -66,23 +66,23 @@ public class IconUtil {
* folder and scales it to 16px.<br> * folder and scales it to 16px.<br>
* The suffix {@code .png} is automatically appended. * 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 * @return the loaded image
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
* @apiNote let's take a sample image {@code abc.png} in the folder * @apiNote let's take a sample image {@code abc.png} in the folder
* {@code /icons/}. * {@code /icons/}.
* <br> * <br>
* To do that, we only have to call * 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 * Loads a {@code .png} icon from the sub-folder {@code /icons/} of the resource
* folder and scales it to a given size.<br> * folder and scales it to a given size.<br>
* The suffix {@code .png} is automatically appended. * 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 * @param size the size of the image to scale to
* @return the loaded image * @return the loaded image
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
@ -90,9 +90,9 @@ public class IconUtil {
* {@code /icons/} and load it in size 16. * {@code /icons/} and load it in size 16.
* <br> * <br>
* To do that, we only have to call * 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 * 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. * The suffix {@code .png} is automatically appended.
* *
* @param name the image name without the "black" or "white" suffix and without * @param name the image name without the "black" or "white" suffix and without
* the .png - suffix * the .png suffix
* @return the loaded image * @return the loaded image
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
* @apiNote let's take two sample images {@code abc_black.png} and * @apiNote let's take two sample images {@code abc_black.png} and
* {@code abc_white.png} in the folder {@code /icons/} and load them. * {@code abc_white.png} in the folder {@code /icons/} and load them.
* <br> * <br>
* To do that theme sensitve, we only have to call * 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 * Loads a {@code .png} icon whose design depends on the currently active theme
@ -125,7 +125,7 @@ public class IconUtil {
* <p> * <p>
* The suffix {@code .png} is automatically appended. * 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 * @param size the size of the image to scale to
* @return the loaded image * @return the loaded image
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
@ -134,9 +134,9 @@ public class IconUtil {
* size 16. * size 16.
* <br> * <br>
* To do that theme sensitve, we only have to call * 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 * This method should be called if the display of an icon depends upon the
* currently active theme.<br> * currently active theme.<br>
* In case of the dark theme, the suffix {@code "white"} will be appended, else * In case of a default theme, the string returned will be
* the suffix {@code "black"} will be appended. * 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 * @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() + "/" : "";
}
} }

View File

@ -102,7 +102,7 @@ public final class Startup extends Application {
messageStatusCache = new Cache<>(); messageStatusCache = new Cache<>();
stage.setTitle("Envoy"); stage.setTitle("Envoy");
stage.getIcons().add(IconUtil.loadDefault("envoy_logo")); stage.getIcons().add(IconUtil.loadIcon("envoy_logo"));
final var sceneContext = new SceneContext(stage); final var sceneContext = new SceneContext(stage);
sceneContext.load(SceneInfo.LOGIN_SCENE); sceneContext.load(SceneInfo.LOGIN_SCENE);

View File

@ -110,8 +110,8 @@ public final class ChatScene implements Restorable {
messageList.setCellFactory(MessageListCellFactory::new); messageList.setCellFactory(MessageListCellFactory::new);
userList.setCellFactory(ContactListCellFactory::new); userList.setCellFactory(ContactListCellFactory::new);
settingsButton.setGraphic(new ImageView(IconUtil.loadDefault("settings", 16))); settingsButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("settings", 16)));
voiceButton.setGraphic(new ImageView(IconUtil.loadDefaultThemeSensitive("", 24))); voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", 20)));
// Listen to received messages // Listen to received messages
eventBus.register(MessageCreationEvent.class, e -> { eventBus.register(MessageCreationEvent.class, e -> {
@ -265,17 +265,17 @@ public final class ChatScene implements Restorable {
recording = true; recording = true;
Platform.runLater(() -> { Platform.runLater(() -> {
voiceButton.setText("Recording"); voiceButton.setText("Recording");
voiceButton.setGraphic(new ImageView(IconUtil.loadDefault("microphone_recording", 24))); voiceButton.setGraphic(new ImageView(IconUtil.loadIcon("microphone_recording", 24)));
}); });
recorder.start(); recorder.start();
} else { } else {
pendingAttachment = new Attachment(recorder.finish(), AttachmentType.VOICE); pendingAttachment = new Attachment(recorder.finish(), AttachmentType.VOICE);
recording = false; recording = false;
Platform.runLater(() -> { Platform.runLater(() -> {
voiceButton.setGraphic(new ImageView(IconUtil.loadDefaultThemeSensitive("microphone_", 24))); voiceButton.setGraphic(new ImageView(IconUtil.loadIconThemeSensitive("microphone", 20)));
voiceButton.setText(null); voiceButton.setText(null);
checkPostConditions(false); checkPostConditions(false);
attachmentView.setImage(IconUtil.loadDefaultThemeSensitive("attachment_present_", 20)); attachmentView.setImage(IconUtil.loadIconThemeSensitive("attachment_present", 20));
attachmentView.setVisible(true); attachmentView.setVisible(true);
}); });
} }

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB