diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/FuelGaugeIcon.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/FuelGaugeIcon.java deleted file mode 100644 index 7adadb1..0000000 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/FuelGaugeIcon.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.nanoboot.utils.timecalc.swing.progress; - -import lombok.Getter; -import org.nanoboot.utils.timecalc.utils.common.ProgressSmiley; - -import javax.swing.ImageIcon; -import java.awt.Image; -import java.util.HashMap; -import java.util.Map; - -/** - * @author Robert Vokac - * @since 27.02.2024 - */ -public class FuelGaugeIcon extends ImageIcon { - - private static final Map cache - = new HashMap<>(); - @Getter - private boolean reserve; - @Getter - private final ImageIcon icon; - - private FuelGaugeIcon(boolean reserve) { - this.reserve = reserve; - java.net.URL iconUrl = getClass() - .getResource("/fuel_gauge/fuel_gauge_icon_" + (reserve - ? "orange" : "white") + ".gif"); - ImageIcon tmpIcon = new ImageIcon(iconUrl); - this.icon = new ImageIcon(tmpIcon.getImage() - .getScaledInstance(32, 32, Image.SCALE_SMOOTH)); - } - - public static FuelGaugeIcon getInstance(boolean reserve) { - if (!cache.containsKey(reserve)) { - cache.put(reserve, new FuelGaugeIcon(reserve)); - } - return cache.get(reserve); - } - -} diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressFuelGauge.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressFuelGauge.java index fd49246..8d23bbd 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressFuelGauge.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressFuelGauge.java @@ -10,9 +10,11 @@ import org.nanoboot.utils.timecalc.swing.common.Widget; import org.nanoboot.utils.timecalc.swing.progress.battery.Battery; import org.nanoboot.utils.timecalc.swing.windows.MainWindow; import org.nanoboot.utils.timecalc.utils.common.NumberFormats; +import org.nanoboot.utils.timecalc.utils.common.ProgressSmiley; import org.nanoboot.utils.timecalc.utils.property.BooleanProperty; import org.nanoboot.utils.timecalc.utils.property.Property; +import javax.imageio.ImageIO; import javax.swing.JLabel; import javax.swing.JMenuItem; import javax.swing.Timer; @@ -21,7 +23,10 @@ import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.Image; import java.awt.RenderingHints; +import java.awt.image.BufferedImage; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -35,15 +40,17 @@ public class ProgressFuelGauge extends Widget implements GetProperty { public static final Color BLACK2 = new Color(64, 64,64); public static final Color LIGHT_GRAY2 = new Color(160,160,160); - - - protected JLabel fuelIconOrange = null; - protected JLabel fuelIconWhite = null; + public static final String FUEL_GAUGE_FUEL_GAUGE_ICON_ORANGE_PNG = + "/fuel_gauge/fuel_gauge_icon_orange.png"; + public static final String FUEL_GAUGE_FUEL_GAUGE_ICON_DARK_GRAY_PNG = + "/fuel_gauge/fuel_gauge_icon_dark_gray.png"; public final BooleanProperty fuelIconVisibleProperty = new BooleanProperty(TimeCalcProperty.FUEL_ICON_VISIBLE.getKey()); private List menuItems = null; + private Image orangeIcon; + private Image darkGrayIcon; public ProgressFuelGauge() { @@ -53,15 +60,7 @@ public class ProgressFuelGauge extends Widget implements GetProperty { setForeground(Color.GRAY); setBackground(MainWindow.BACKGROUND_COLOR); - this.fuelIconOrange = new JLabel(FuelGaugeIcon.getInstance(true)); - this.fuelIconWhite = new JLabel(FuelGaugeIcon.getInstance(false)); - fuelIconOrange.setVisible(false); - fuelIconWhite.setVisible(false); - add(fuelIconOrange); - add(fuelIconWhite); this.setLayout(null); - fuelIconOrange.setBounds(1, 1, 40, 40); - fuelIconWhite.setBounds(fuelIconOrange.getBounds()); this.typeProperty.setValue(WidgetType.DAY.name().toLowerCase(Locale.ROOT)); @@ -178,16 +177,24 @@ public class ProgressFuelGauge extends Widget implements GetProperty { brush.setColor(Color.WHITE); if (fuelIconVisibleProperty.isEnabled()) { - if (donePercent() <= 0.15d) { - this.fuelIconOrange.setVisible(true); - this.fuelIconWhite.setVisible(false); - } else { - this.fuelIconOrange.setVisible(false); - this.fuelIconWhite.setVisible(true); + if(this.orangeIcon == null) { + try { + this.orangeIcon = ImageIO.read(getClass().getResource( + FUEL_GAUGE_FUEL_GAUGE_ICON_ORANGE_PNG)); + } catch (IOException e) { + e.printStackTrace(); + } } - } else { - this.fuelIconOrange.setVisible(false); - this.fuelIconWhite.setVisible(false); + if(this.darkGrayIcon == null) { + try { + this.darkGrayIcon = ImageIO.read(getClass().getResource( + FUEL_GAUGE_FUEL_GAUGE_ICON_DARK_GRAY_PNG)); + } catch (IOException e) { + e.printStackTrace(); + } + } + brush.drawImage(donePercent() <= 0.15d ? this.orangeIcon : this.darkGrayIcon, getWidth() - 32, getHeight() - 48, 32, 32, null); + } //tBrush.drawBorder(startX, startY, 10, length_ - 4 - 5, getAngle.apply(donePercent()), 3f, brush.getColor()); diff --git a/modules/time-calc-app/src/main/resources/fuel_gauge/fuel_gauge_icon_dark_gray.png b/modules/time-calc-app/src/main/resources/fuel_gauge/fuel_gauge_icon_dark_gray.png new file mode 100644 index 0000000..48bedca Binary files /dev/null and b/modules/time-calc-app/src/main/resources/fuel_gauge/fuel_gauge_icon_dark_gray.png differ diff --git a/modules/time-calc-app/src/main/resources/fuel_gauge/fuel_gauge_icon_orange.gif b/modules/time-calc-app/src/main/resources/fuel_gauge/fuel_gauge_icon_orange.gif deleted file mode 100644 index 3977557..0000000 Binary files a/modules/time-calc-app/src/main/resources/fuel_gauge/fuel_gauge_icon_orange.gif and /dev/null differ diff --git a/modules/time-calc-app/src/main/resources/fuel_gauge/fuel_gauge_icon_orange.png b/modules/time-calc-app/src/main/resources/fuel_gauge/fuel_gauge_icon_orange.png new file mode 100644 index 0000000..0e28b65 Binary files /dev/null and b/modules/time-calc-app/src/main/resources/fuel_gauge/fuel_gauge_icon_orange.png differ diff --git a/modules/time-calc-app/src/main/resources/fuel_gauge/fuel_gauge_icon_white.gif b/modules/time-calc-app/src/main/resources/fuel_gauge/fuel_gauge_icon_white.gif deleted file mode 100644 index e1738a6..0000000 Binary files a/modules/time-calc-app/src/main/resources/fuel_gauge/fuel_gauge_icon_white.gif and /dev/null differ