Added Fuel Gauge Icon - work in progress I

This commit is contained in:
Robert Vokac 2024-03-28 09:26:51 +01:00
parent 9faeb4f7d7
commit 6f187222f8
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
10 changed files with 86 additions and 1 deletions

BIN
fuel_gauge_icon.odg Normal file

Binary file not shown.

View File

@ -197,6 +197,8 @@ public class TimeCalcConfiguration {
= new BooleanProperty(TimeCalcProperty.FUEL_HIDDEN.getKey());
public final StringProperty fuelTypeProperty
= new StringProperty(TimeCalcProperty.FUEL_TYPE.getKey());
public final BooleanProperty fuelIconVisibleProperty
= new BooleanProperty(TimeCalcProperty.FUEL_ICON_VISIBLE.getKey());
public final BooleanProperty circleVisibleProperty
= new BooleanProperty(TimeCalcProperty.CIRCLE_VISIBLE.getKey());
public final BooleanProperty circleHiddenProperty
@ -328,6 +330,7 @@ public class TimeCalcConfiguration {
circleVisibleProperty,circleTypeProperty,
dotVisibleProperty,dotTypeProperty,
fuelVisibleProperty, fuelTypeProperty, fuelHiddenProperty,
fuelIconVisibleProperty,
swingVisibleProperty,
swingTypeProperty,
swingQuarterIconVisibleProperty,

View File

@ -95,6 +95,7 @@ public enum TimeCalcProperty {
FUEL_VISIBLE("fuel.visible", "Fuel"),
FUEL_TYPE("fuel.type", "Fuel : Type"),
FUEL_HIDDEN("fuel.hidden", "Fuel : Hidden"),
FUEL_ICON_VISIBLE("fuel.icon.visible", "Fuel : Icon"),
CIRCLE_VISIBLE("circle.visible", "Circle"),
CIRCLE_TYPE("circle.type", "Circle : Type"),
CIRCLE_HIDDEN("circle.hidden", "Circle : Hidden"),

View File

@ -0,0 +1,41 @@
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 smileyUrl = getClass()
.getResource("/fuel_gauge/fuel_gauge_icon_" + (reserve
? "orange" : "white") + ".gif");
ImageIcon tmpIcon = new ImageIcon(smileyUrl);
this.icon = new ImageIcon(tmpIcon.getImage()
.getScaledInstance(32, 132, Image.SCALE_SMOOTH));
}
public static FuelGaugeIcon getInstance(boolean reserve) {
if (!cache.containsKey(reserve)) {
cache.put(reserve, new FuelGaugeIcon(reserve));
}
return cache.get(reserve);
}
}

View File

@ -1,6 +1,7 @@
package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.app.GetProperty;
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
import org.nanoboot.utils.timecalc.entity.Visibility;
import org.nanoboot.utils.timecalc.entity.WidgetType;
import org.nanoboot.utils.timecalc.swing.common.Brush;
@ -9,8 +10,10 @@ 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.property.BooleanProperty;
import org.nanoboot.utils.timecalc.utils.property.Property;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.Timer;
import java.awt.BasicStroke;
@ -33,6 +36,13 @@ 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 final BooleanProperty fuelIconVisibleProperty
= new BooleanProperty(TimeCalcProperty.FUEL_ICON_VISIBLE.getKey());
private List<JMenuItem> menuItems = null;
public ProgressFuelGauge() {
@ -42,6 +52,17 @@ public class ProgressFuelGauge extends Widget implements GetProperty {
setFocusable(false);
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));
new Timer(100, e -> {
@ -156,6 +177,19 @@ 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);
}
} else {
this.fuelIconOrange.setVisible(false);
this.fuelIconWhite.setVisible(false);
}
//tBrush.drawBorder(startX, startY, 10, length_ - 4 - 5, getAngle.apply(donePercent()), 3f, brush.getColor());
this.setToolTipText(NumberFormats.FORMATTER_TWO_DECIMAL_PLACES.format(donePercent() * 100d) + "%");
}

View File

@ -241,6 +241,8 @@ public class ConfigWindow extends TWindow {
new JTextField(TimeCalcProperty.FUEL_TYPE.getKey());
private final JCheckBox fuelHiddenProperty
= new JCheckBox(TimeCalcProperty.FUEL_HIDDEN.getKey());
private final JCheckBox fuelIconVisibleProperty
= new JCheckBox(TimeCalcProperty.FUEL_ICON_VISIBLE.getKey());
//
public final JCheckBox clockHiddenProperty
= new JCheckBox(TimeCalcProperty.CLOCK_HIDDEN.getKey());
@ -462,6 +464,7 @@ public class ConfigWindow extends TWindow {
swingQuarterIconVisibleProperty.setSelected(enable);
walkingHumanVisibleProperty.setSelected(enable);
fuelVisibleProperty.setSelected(enable);
fuelIconVisibleProperty.setSelected(enable);
// clockHiddenProperty.setSelected(!enable);
// batteryMinuteHiddenProperty.setSelected(!enable);
// batteryHourHiddenProperty.setSelected(!enable);
@ -547,7 +550,7 @@ public class ConfigWindow extends TWindow {
squareVisibleProperty,squareHiddenProperty,squareTypeProperty,
circleVisibleProperty,circleHiddenProperty,circleTypeProperty,
dotVisibleProperty,dotHiddenProperty,dotTypeProperty,
fuelVisibleProperty,fuelTypeProperty,fuelHiddenProperty,
fuelVisibleProperty,fuelTypeProperty,fuelHiddenProperty,fuelIconVisibleProperty,
swingVisibleProperty,swingHiddenProperty,swingTypeProperty,swingQuarterIconVisibleProperty,
walkingHumanVisibleProperty,walkingHumanHiddenProperty,walkingHumanTypeProperty,
lifeVisibleProperty,lifeHiddenProperty,lifeTypeProperty,lifeBirthDateProperty,

View File

@ -423,6 +423,8 @@ public class MainWindow extends TWindow {
.bindTo(timeCalcConfiguration.fuelTypeProperty);
progressFuelGauge.hiddenProperty
.bindTo(timeCalcConfiguration.fuelHiddenProperty);
progressFuelGauge.fuelIconVisibleProperty
.bindTo(timeCalcConfiguration.fuelIconVisibleProperty);
add(progressFuelGauge);

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -64,6 +64,7 @@ dot.hidden=false
fuel.visible=true
fuel.type=day
fuel.hidden=false
fuel.icon.visible=true
swing.visible=true
swing.type=day
swing.hidden=false