From 4bf0068051d44fc7ecb685743e602047ed127377 Mon Sep 17 00:00:00 2001 From: "J. Neugebauer" Date: Thu, 21 Jul 2022 20:59:28 +0200 Subject: [PATCH] =?UTF-8?q?Icons=20werden=20nun=20in=20allen=20Gr=C3=B6?= =?UTF-8?q?=C3=9Fen=20geladen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Alle vorhandenen Icons werden geladen und mit Jframe.setIconImages() dem Fenster hinzugefügt. Unter macOS wird nur die Größe 512 geladen und als Dock-Icon gesetzt. --- .../java/schule/ngb/zm/Zeichenmaschine.java | 27 ++++++++++++------ .../{ => schule/ngb/zm}/icon_128.png | Bin .../resources/{ => schule/ngb/zm}/icon_32.png | Bin .../{ => schule/ngb/zm}/icon_512.png | Bin .../resources/{ => schule/ngb/zm}/icon_64.png | Bin 5 files changed, 18 insertions(+), 9 deletions(-) rename src/main/resources/{ => schule/ngb/zm}/icon_128.png (100%) rename src/main/resources/{ => schule/ngb/zm}/icon_32.png (100%) rename src/main/resources/{ => schule/ngb/zm}/icon_512.png (100%) rename src/main/resources/{ => schule/ngb/zm}/icon_64.png (100%) diff --git a/src/main/java/schule/ngb/zm/Zeichenmaschine.java b/src/main/java/schule/ngb/zm/Zeichenmaschine.java index 75f4388..1840329 100644 --- a/src/main/java/schule/ngb/zm/Zeichenmaschine.java +++ b/src/main/java/schule/ngb/zm/Zeichenmaschine.java @@ -5,9 +5,9 @@ import schule.ngb.zm.layers.ColorLayer; import schule.ngb.zm.layers.DrawingLayer; import schule.ngb.zm.layers.ImageLayer; import schule.ngb.zm.layers.ShapesLayer; -import schule.ngb.zm.util.tasks.TaskRunner; import schule.ngb.zm.util.ImageLoader; import schule.ngb.zm.util.Log; +import schule.ngb.zm.util.tasks.TaskRunner; import javax.imageio.ImageIO; import javax.swing.*; @@ -17,6 +17,8 @@ import java.awt.event.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; import java.util.concurrent.*; import java.util.logging.Level; @@ -353,20 +355,27 @@ public class Zeichenmaschine extends Constants { frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); // Das Icon des Fensters ändern - try { - // TODO: Add image sizes - ImageIcon icon = new ImageIcon(ImageIO.read(new File("res/icon_64.png"))); - if( MACOS ) { + //Image icon = ImageIO.read(new File("resources/icon_512.png")); + URL iconUrl = Zeichenmaschine.class.getResource("icon_512.png"); + Image icon = ImageIO.read(iconUrl); // Dock Icon in macOS setzen Taskbar taskbar = Taskbar.getTaskbar(); - taskbar.setIconImage(icon.getImage()); + taskbar.setIconImage(icon); } else { - // Kleines Icon des Frames setzen - frame.setIconImage(icon.getImage()); + ArrayList icons = new ArrayList<>(4); + for( int size = 32; size <= 512; size *= size ) { + icons.add(ImageIO.read(new File("icon_" + size + ".png"))); + } + + frame.setIconImages(icons); } - } catch( IOException e ) { + } catch( IllegalArgumentException | IOException e ) { + LOG.warn(e, "Could not load image icons. Some icons may be missing."); + } catch( SecurityException | UnsupportedOperationException macex ) { + // Dock Icon in macOS konnte nicht gesetzt werden :( + LOG.warn(macex, "Could not set dock icon."); } diff --git a/src/main/resources/icon_128.png b/src/main/resources/schule/ngb/zm/icon_128.png similarity index 100% rename from src/main/resources/icon_128.png rename to src/main/resources/schule/ngb/zm/icon_128.png diff --git a/src/main/resources/icon_32.png b/src/main/resources/schule/ngb/zm/icon_32.png similarity index 100% rename from src/main/resources/icon_32.png rename to src/main/resources/schule/ngb/zm/icon_32.png diff --git a/src/main/resources/icon_512.png b/src/main/resources/schule/ngb/zm/icon_512.png similarity index 100% rename from src/main/resources/icon_512.png rename to src/main/resources/schule/ngb/zm/icon_512.png diff --git a/src/main/resources/icon_64.png b/src/main/resources/schule/ngb/zm/icon_64.png similarity index 100% rename from src/main/resources/icon_64.png rename to src/main/resources/schule/ngb/zm/icon_64.png