From b5fc80709ee529fb42782db523602c0a8ad8e598 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 27 Jun 2020 11:03:30 +0200 Subject: [PATCH] Removed unnecessary IOException in IconUtil This is a normal @CyB3RC0nN0R commit: Adding functionality by deleting code. --- src/main/java/envoy/client/ui/IconUtil.java | 24 ++++++++----------- .../java/envoy/client/ui/MessageListCell.java | 18 +++----------- .../envoy/client/ui/controller/ChatScene.java | 6 +---- 3 files changed, 14 insertions(+), 34 deletions(-) diff --git a/src/main/java/envoy/client/ui/IconUtil.java b/src/main/java/envoy/client/ui/IconUtil.java index e2577ec..201fdbc 100644 --- a/src/main/java/envoy/client/ui/IconUtil.java +++ b/src/main/java/envoy/client/ui/IconUtil.java @@ -1,6 +1,5 @@ package envoy.client.ui; -import java.io.IOException; import java.util.EnumMap; import java.util.EnumSet; @@ -23,46 +22,43 @@ public class IconUtil { /** * Loads an icon from the resource folder. - * + * * @param path the path to the icon inside the resource folder * @return the icon - * @throws IOException if the loading process failed * @since Envoy Client v0.1-beta */ - public static Image load(String path) throws IOException { return new Image(IconUtil.class.getResource(path).toExternalForm()); } + public static Image load(String path) { return new Image(IconUtil.class.getResource(path).toExternalForm()); } /** * Loads an icon from the resource folder and scales it to a given size. - * + * * @param path the path to the icon inside the resource folder * @param size the size to scale the icon to * @return the scaled icon - * @throws IOException if the loading process failed * @since Envoy Client v0.1-beta */ - public static Image load(String path, int size) throws IOException { + public static Image load(String path, int size) { return new Image(IconUtil.class.getResource(path).toExternalForm(), size, size, true, true); } /** - * + * * Loads icons specified by an enum. The images have to be named like the * lowercase enum constants with {@code .png} extension and be located inside a * folder with the lowercase name of the enum, which must be contained inside * the {@code /icons} folder. - * + * * @param the enum that specifies the icons to load * @param enumClass the class of the enum * @param size the size to scale the icons to * @return a map containing the loaded icons with the corresponding enum * constants as keys - * @throws IOException if the loading process failed * @since Envoy Client v0.1-beta */ - public static > EnumMap loadByEnum(Class enumClass, int size) throws IOException { - var icons = new EnumMap(enumClass); - var path = "/icons/" + enumClass.getSimpleName().toLowerCase() + "/"; - for (var e : EnumSet.allOf(enumClass)) + public static > EnumMap loadByEnum(Class enumClass, int size) { + final var icons = new EnumMap(enumClass); + final var path = "/icons/" + enumClass.getSimpleName().toLowerCase() + "/"; + for (final var e : EnumSet.allOf(enumClass)) icons.put(e, load(path + e.toString().toLowerCase() + ".png", size)); return icons; } diff --git a/src/main/java/envoy/client/ui/MessageListCell.java b/src/main/java/envoy/client/ui/MessageListCell.java index 22aa188..21a094e 100644 --- a/src/main/java/envoy/client/ui/MessageListCell.java +++ b/src/main/java/envoy/client/ui/MessageListCell.java @@ -1,9 +1,7 @@ package envoy.client.ui; -import java.io.IOException; import java.time.format.DateTimeFormatter; import java.util.Map; -import java.util.logging.Level; import javafx.geometry.Insets; import javafx.scene.control.Label; @@ -15,7 +13,6 @@ import javafx.scene.layout.VBox; import envoy.data.Message; import envoy.data.Message.MessageStatus; import envoy.data.User; -import envoy.util.EnvoyLog; /** * Displays a single message inside the message list. @@ -29,18 +26,9 @@ import envoy.util.EnvoyLog; */ public class MessageListCell extends ListCell { - private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm"); - private static Map statusImages; - private static User client; - - static { - try { - statusImages = IconUtil.loadByEnum(MessageStatus.class, 16); - } catch (final IOException e) { - e.printStackTrace(); - EnvoyLog.getLogger(MessageListCell.class).log(Level.WARNING, "could not load status icons: ", e); - } - } + private static User client; + private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm"); + private static final Map statusImages = IconUtil.loadByEnum(MessageStatus.class, 16); /** * Displays the text, the data of creation and the status of a message. diff --git a/src/main/java/envoy/client/ui/controller/ChatScene.java b/src/main/java/envoy/client/ui/controller/ChatScene.java index 3f6188f..b6da87c 100644 --- a/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -89,11 +89,7 @@ public final class ChatScene { messageList.setCellFactory(listView -> new MessageListCell()); userList.setCellFactory(listView -> new ContactListCell()); - try { - settingsButton.setGraphic(new ImageView(IconUtil.load("/icons/settings.png", 16))); - } catch (final IOException e2) { - logger.log(Level.WARNING, "Could not load settings icon", e2); - } + settingsButton.setGraphic(new ImageView(IconUtil.load("/icons/settings.png", 16))); // Listen to received messages eventBus.register(MessageCreationEvent.class, e -> {