Defined theme specific icon folders, renamed icon loading method

This commit is contained in:
delvh 2020-07-07 17:02:39 +02:00
parent 8a42e2f049
commit 9d5c430fe0
18 changed files with 35 additions and 24 deletions

View File

@ -93,6 +93,15 @@ public class Settings {
*/
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
* 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) {
// 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();

View File

@ -66,23 +66,23 @@ public class IconUtil {
* folder and scales it to 16px.<br>
* 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/}.
* <br>
* 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.<br>
* 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.
* <br>
* 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.
* <br>
* 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 {
* <p>
* 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.
* <br>
* 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.<br>
* 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() + "/" : "";
}
}

View File

@ -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);

View File

@ -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);
});
}

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