mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
Fuel Gauge was finished - icon was fixed
This commit is contained in:
parent
02f821d127
commit
f02e1d6f7e
@ -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<Boolean, FuelGaugeIcon> 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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.progress.battery.Battery;
|
||||||
import org.nanoboot.utils.timecalc.swing.windows.MainWindow;
|
import org.nanoboot.utils.timecalc.swing.windows.MainWindow;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
|
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.BooleanProperty;
|
||||||
import org.nanoboot.utils.timecalc.utils.property.Property;
|
import org.nanoboot.utils.timecalc.utils.property.Property;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.Timer;
|
import javax.swing.Timer;
|
||||||
@ -21,7 +23,10 @@ import java.awt.Color;
|
|||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Image;
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
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 BLACK2 = new Color(64, 64,64);
|
||||||
public static final Color LIGHT_GRAY2 = new Color(160,160,160);
|
public static final Color LIGHT_GRAY2 = new Color(160,160,160);
|
||||||
|
public static final String FUEL_GAUGE_FUEL_GAUGE_ICON_ORANGE_PNG =
|
||||||
|
"/fuel_gauge/fuel_gauge_icon_orange.png";
|
||||||
protected JLabel fuelIconOrange = null;
|
public static final String FUEL_GAUGE_FUEL_GAUGE_ICON_DARK_GRAY_PNG =
|
||||||
protected JLabel fuelIconWhite = null;
|
"/fuel_gauge/fuel_gauge_icon_dark_gray.png";
|
||||||
|
|
||||||
public final BooleanProperty fuelIconVisibleProperty
|
public final BooleanProperty fuelIconVisibleProperty
|
||||||
= new BooleanProperty(TimeCalcProperty.FUEL_ICON_VISIBLE.getKey());
|
= new BooleanProperty(TimeCalcProperty.FUEL_ICON_VISIBLE.getKey());
|
||||||
|
|
||||||
private List<JMenuItem> menuItems = null;
|
private List<JMenuItem> menuItems = null;
|
||||||
|
private Image orangeIcon;
|
||||||
|
private Image darkGrayIcon;
|
||||||
|
|
||||||
public ProgressFuelGauge() {
|
public ProgressFuelGauge() {
|
||||||
|
|
||||||
@ -53,15 +60,7 @@ public class ProgressFuelGauge extends Widget implements GetProperty {
|
|||||||
setForeground(Color.GRAY);
|
setForeground(Color.GRAY);
|
||||||
setBackground(MainWindow.BACKGROUND_COLOR);
|
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);
|
this.setLayout(null);
|
||||||
fuelIconOrange.setBounds(1, 1, 40, 40);
|
|
||||||
fuelIconWhite.setBounds(fuelIconOrange.getBounds());
|
|
||||||
|
|
||||||
this.typeProperty.setValue(WidgetType.DAY.name().toLowerCase(Locale.ROOT));
|
this.typeProperty.setValue(WidgetType.DAY.name().toLowerCase(Locale.ROOT));
|
||||||
|
|
||||||
@ -178,16 +177,24 @@ public class ProgressFuelGauge extends Widget implements GetProperty {
|
|||||||
brush.setColor(Color.WHITE);
|
brush.setColor(Color.WHITE);
|
||||||
|
|
||||||
if (fuelIconVisibleProperty.isEnabled()) {
|
if (fuelIconVisibleProperty.isEnabled()) {
|
||||||
if (donePercent() <= 0.15d) {
|
if(this.orangeIcon == null) {
|
||||||
this.fuelIconOrange.setVisible(true);
|
try {
|
||||||
this.fuelIconWhite.setVisible(false);
|
this.orangeIcon = ImageIO.read(getClass().getResource(
|
||||||
} else {
|
FUEL_GAUGE_FUEL_GAUGE_ICON_ORANGE_PNG));
|
||||||
this.fuelIconOrange.setVisible(false);
|
} catch (IOException e) {
|
||||||
this.fuelIconWhite.setVisible(true);
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
if(this.darkGrayIcon == null) {
|
||||||
this.fuelIconOrange.setVisible(false);
|
try {
|
||||||
this.fuelIconWhite.setVisible(false);
|
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());
|
//tBrush.drawBorder(startX, startY, 10, length_ - 4 - 5, getAngle.apply(donePercent()), 3f, brush.getColor());
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.9 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.9 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.9 KiB |
Loading…
x
Reference in New Issue
Block a user