This commit is contained in:
Robert Vokac 2024-03-23 08:20:02 +01:00
parent bde480f222
commit 888e4b2cbc
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
8 changed files with 215 additions and 77 deletions

View File

@ -156,6 +156,10 @@ public class TimeCalcConfiguration {
public final BooleanProperty squareVisibleProperty
= new BooleanProperty(TimeCalcProperty.SQUARE_VISIBLE.getKey());
public final BooleanProperty swingVisibleProperty
= new BooleanProperty(TimeCalcProperty.SWING_VISIBLE.getKey());
public final BooleanProperty swingQuarterIconVisibleProperty
= new BooleanProperty(TimeCalcProperty.SWING_QUARTER_ICON_VISIBLE.getKey());
public final BooleanProperty circleVisibleProperty
= new BooleanProperty(TimeCalcProperty.CIRCLE_VISIBLE.getKey());
public final BooleanProperty walkingHumanVisibleProperty
@ -239,6 +243,8 @@ public class TimeCalcConfiguration {
smileysColoredProperty,
squareVisibleProperty,
circleVisibleProperty,
swingVisibleProperty,
swingQuarterIconVisibleProperty,
walkingHumanVisibleProperty,
mainWindowCustomTitleProperty,
profileNameProperty,

View File

@ -76,6 +76,8 @@ public enum TimeCalcProperty {
"Smileys : Visible only, if mouse moving over"),
SMILEYS_COLORED("smileys.colored", "Smileys : Colored"),
SQUARE_VISIBLE("square.visible", "Square"),
SWING_VISIBLE("swing.visible", "Swing"),
SWING_QUARTER_ICON_VISIBLE("swing.quarter-icon.visible", "Swing: Quarter icon"),
CIRCLE_VISIBLE("circle.visible", "Circle"),
WALKING_HUMAN_VISIBLE("walking-human.visible", "Walking Human"),
MAIN_WINDOW_CUSTOM_TITLE("main-window.custom-title",

View File

@ -1,10 +1,11 @@
package org.nanoboot.utils.timecalc.swing.common;
import java.awt.BasicStroke;
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.swing.progress.Battery;
import org.nanoboot.utils.timecalc.swing.progress.ProgressSmileyIcon;
import org.nanoboot.utils.timecalc.swing.progress.ProgressSwing;
import org.nanoboot.utils.timecalc.utils.common.ProgressSmiley;
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
import org.nanoboot.utils.timecalc.utils.property.Property;
@ -14,6 +15,7 @@ import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
@ -62,7 +64,10 @@ public class Widget extends JPanel implements
protected boolean mouseOver = false;
private boolean mouseOverCloseButton = false;
protected JLabel smileyIcon;
protected JLabel smileyIcon2;
private long lastUpdate = System.nanoTime();
private static final Color PURPLE_STRONGLY_COLORED = new Color(153,51,255);
private static final Color PURPLE_WEAKLY_COLORED = new Color(204,153,255);
public Widget() {
setBackground(BACKGROUND_COLOR);
@ -237,11 +242,19 @@ public class Widget extends JPanel implements
}
protected void paintSmiley(Visibility visibility, Graphics2D brush, int x,
int y, boolean paintBody) {
paintSmiley(visibility, brush, x, y, paintBody, -1, 1);
}
protected void paintSmiley(Visibility visibility, Graphics2D brush, int x,
int y, boolean paintBody, double customDonePercent, int smileyNumber) {
if (!shouldBeSmileyPainted()) {
if (this.smileyIcon != null) {
this.remove(smileyIcon);
this.smileyIcon = null;
}
if (this.smileyIcon2 != null) {
this.remove(smileyIcon2);
this.smileyIcon2 = null;
}
//nothing more to do
return;
@ -251,13 +264,16 @@ public class Widget extends JPanel implements
colored = false;
}
if (!colored) {
y = y - 2;
if (this.smileyIcon != null) {
this.remove(smileyIcon);
this.smileyIcon = null;
}
if (this.smileyIcon2 != null) {
this.remove(smileyIcon2);
this.smileyIcon2 = null;
}
Color originalColor = brush.getColor();
if (!visibility.isStronglyColored()) {
brush.setColor(Color.GRAY);
@ -280,8 +296,8 @@ public class Widget extends JPanel implements
brush.setColor(currentColor);
brush.setFont(MEDIUM_FONT);
brush.drawString(
ProgressSmiley.forProgress(donePercent).getCharacter(),
x + 1, y + 16
ProgressSmiley.forProgress(customDonePercent >= 0 ? customDonePercent : donePercent).getCharacter(),
x + 1 + (getClass() == ProgressSwing.class ? -8 : 0), y + 16
);
brush.setFont(currentFont);
brush.setColor(originalColor);
@ -289,15 +305,25 @@ public class Widget extends JPanel implements
if (colored) {
x = x + 2;
ImageIcon imageIcon = ProgressSmileyIcon
.forSmiley(ProgressSmiley.forProgress(donePercent))
.forSmiley(ProgressSmiley.forProgress(customDonePercent >= 0 ? customDonePercent : donePercent))
.getIcon();
if (this.smileyIcon != null) {
this.remove(smileyIcon);
this.smileyIcon = null;
if(smileyNumber < 2) {
if (this.smileyIcon != null) {
this.remove(smileyIcon);
this.smileyIcon = null;
}
this.smileyIcon = new JLabel(imageIcon);
smileyIcon.setBounds(x + (getClass() == ProgressSwing.class ? - 8 : 0), y, 15, 15);
this.add(smileyIcon);
} else {
if (this.smileyIcon2 != null) {
this.remove(smileyIcon2);
this.smileyIcon2 = null;
}
this.smileyIcon2 = new JLabel(imageIcon);
smileyIcon2.setBounds(x + (getClass() == ProgressSwing.class ? - 8 : 0), y, 15, 15);
this.add(smileyIcon2);
}
this.smileyIcon = new JLabel(imageIcon);
smileyIcon.setBounds(x, y, 15, 15);
this.add(smileyIcon);
}
if(colored) {
x = x - 2;
@ -318,4 +344,75 @@ public class Widget extends JPanel implements
protected boolean changedInTheLastXMilliseconds(int milliseconds) {
return (System.nanoTime() - lastUpdate) < milliseconds * 1000000;
}
protected void paintQuarterIcon(Graphics2D brush,
Visibility visibility, int totalWidth, int totalHeight) {
paintQuarterIcon(brush, visibility, totalWidth, totalHeight, -1, -1);
}
protected void paintQuarterIcon(Graphics2D brush,
Visibility visibility, int totalWidth, int totalHeight, int x, int y) {
Color currentColor = brush.getColor();
//Color currentBackgroundColor = brush.getBackground();
Font currentFont = brush.getFont();
brush.setFont(BIG_FONT);
int q = donePercent < 0.25 ? 0 : (donePercent < 0.5 ? 1 :
(donePercent < 0.75 ? 2 : (donePercent < 1.0 ? 3 : 4)));
Color color;
Color backgroundColor;
switch (visibility) {
case STRONGLY_COLORED:
backgroundColor = Color.WHITE;
break;
case WEAKLY_COLORED:
backgroundColor = Color.LIGHT_GRAY;
break;
default:
backgroundColor = Color.LIGHT_GRAY;
}
switch (q) {
case 0:
color = Battery.getColourForProgress(0.05, visibility,
mouseOver);
break;
case 1:
color = Battery.getColourForProgress(0.25, visibility,
mouseOver);
break;
case 2:
color = Battery.getColourForProgress(0.85, visibility,
mouseOver);
break;
case 3:
color = Battery.getColourForProgress(0.95, visibility,
mouseOver);
break;
case 4:
color = visibility.isStronglyColored() ? PURPLE_STRONGLY_COLORED : (visibility.isWeaklyColored() ? PURPLE_WEAKLY_COLORED : Color.GRAY);
break;
default:
color = Color.LIGHT_GRAY;
}
brush.setColor(backgroundColor);
if(x< 0 || y < 0) {
brush.fillRect(((int) (totalWidth * 0.08)),
(donePercent < 0.5 ? totalHeight / 4 * 3
: (totalHeight / 4 * 1) + 10) + -8, 20, 20);
} else {
brush.fillRect(x, y, 20, 20);
}
brush.setColor(color);
if(x< 0 || y < 0) {
brush.drawString(
String.valueOf(q), ((int) (totalWidth * 0.13)),
(donePercent < 0.5 ? totalHeight / 4 * 3
: (totalHeight / 4 * 1) + 10) + 10
);
} else {
brush.drawString(String.valueOf(q), x + 4, y + 18);
}
brush.setColor(currentColor);
//brush.setBackground(currentBackgroundColor);
brush.setFont(currentFont);
}
}

View File

@ -317,7 +317,7 @@ public class Battery extends Widget {
}
if (quarterIconVisibleProperty.isEnabled()) {
paintQuarterIcon(brush, visibility);
paintQuarterIcon(brush, visibility, totalWidth, totalHeight);
}
if (circleProgressVisibleProperty.isEnabled()) {
@ -364,68 +364,6 @@ public class Battery extends Widget {
}
private static final Color PURPLE_STRONGLY_COLORED = new Color(153,51,255);
private static final Color PURPLE_WEAKLY_COLORED = new Color(204,153,255);
private void paintQuarterIcon(Graphics2D brush,
Visibility visibility) {
Color currentColor = brush.getColor();
//Color currentBackgroundColor = brush.getBackground();
Font currentFont = brush.getFont();
brush.setFont(BIG_FONT);
int q = donePercent < 0.25 ? 0 : (donePercent < 0.5 ? 1 :
(donePercent < 0.75 ? 2 : (donePercent < 1.0 ? 3 : 4)));
Color color;
Color backgroundColor;
switch (visibility) {
case STRONGLY_COLORED:
backgroundColor = Color.WHITE;
break;
case WEAKLY_COLORED:
backgroundColor = Color.LIGHT_GRAY;
break;
default:
backgroundColor = Color.LIGHT_GRAY;
}
switch (q) {
case 0:
color = Battery.getColourForProgress(0.05, visibility,
mouseOver);
break;
case 1:
color = Battery.getColourForProgress(0.25, visibility,
mouseOver);
break;
case 2:
color = Battery.getColourForProgress(0.85, visibility,
mouseOver);
break;
case 3:
color = Battery.getColourForProgress(0.95, visibility,
mouseOver);
break;
case 4:
color = visibility.isStronglyColored() ? PURPLE_STRONGLY_COLORED : (visibility.isWeaklyColored() ? PURPLE_WEAKLY_COLORED : Color.GRAY);
break;
default:
color = Color.LIGHT_GRAY;
}
brush.setColor(backgroundColor);
brush.fillRect( ((int) (totalWidth * 0.08)),
(donePercent < 0.5 ? totalHeight / 4 * 3
: (totalHeight / 4 * 1) + 10) + -8, 20, 20);
brush.setColor(color);
brush.drawString(
String.valueOf(q), ((int) (totalWidth * 0.13)),
(donePercent < 0.5 ? totalHeight / 4 * 3
: (totalHeight / 4 * 1) + 10) + 10
);
brush.setColor(currentColor);
//brush.setBackground(currentBackgroundColor);
brush.setFont(currentFont);
}
public void paintChargingCharacter(Graphics2D brush) {
brush.drawString(
CHARCHING, ((int) (totalWidth * 0.45)),

View File

@ -0,0 +1,73 @@
package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
import org.nanoboot.utils.timecalc.entity.Visibility;
import org.nanoboot.utils.timecalc.swing.common.Widget;
import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
public class ProgressSwing extends Widget {
public final BooleanProperty quarterIconVisibleProperty
= new BooleanProperty(
TimeCalcProperty.SWING_QUARTER_ICON_VISIBLE
.getKey(), true);
public ProgressSwing() {
setPreferredSize(new Dimension(200, 100));
}
@Override
public void paintWidget(Graphics g) {
Visibility visibility
= Visibility.valueOf(visibilityProperty.getValue());
Graphics2D brush = (Graphics2D) g;
brush.setColor(
visibility.isStronglyColored() || mouseOver ? Color.darkGray
: FOREGROUND_COLOR);
brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
brush.setStroke(new BasicStroke(0.5f));
//brush.drawRect(1,1, getWidth() - 2, getHeight() - 2);
brush.setStroke(new BasicStroke(1.5f));
brush.drawLine(getWidth() /2, getHeight(), getWidth()/2,
(int) (getHeight() * 0.66) - 10);
brush.fillOval(getWidth()/2 - 3,
(int) (getHeight() * 0.66) - 10 - 3, 6, 6);
brush.drawLine(1, getHeight() - 2, getWidth(), getHeight() - 2);
int startX = (int) (getWidth() * 0.10);
int startY = (int) (getHeight() - getHeight() * 0.66 * (1 - donePercent)) - 10;
int endX = (int) (getWidth() * 0.90);
int endY = (int) (getHeight() - getHeight() * 0.66 * donePercent) - 10;
brush.drawLine(startX, startY, endX, endY);
// brush.drawLine(startX, startY, getWidth()/2,
// (int) (getHeight() * 0.6));
// brush.drawLine(endX, endY, getWidth()/2,
// (int) (getHeight() * 0.6));
paintSmiley(visibility, brush, startX, startY - 25, true);
paintSmiley(visibility, brush, endX, endY - 25, true, 1.0 - donePercent, 2);
brush.drawString(
NumberFormats.FORMATTER_ZERO_DECIMAL_PLACES
.format(donePercent * 100) + "%",
(int) (getWidth() * 0.45), (int) (getHeight() * 0.9));
if (quarterIconVisibleProperty.isEnabled()) {
paintQuarterIcon(brush, visibility, getWidth(), getHeight(),
(int) (getWidth() * 0.45), (int) (getHeight() * 0.25));
}
}
}

View File

@ -175,6 +175,10 @@ public class ConfigWindow extends TWindow {
= new JCheckBox(TimeCalcProperty.SQUARE_VISIBLE.getKey());
private final JCheckBox circleVisibleProperty
= new JCheckBox(TimeCalcProperty.CIRCLE_VISIBLE.getKey());
private final JCheckBox swingVisibleProperty
= new JCheckBox(TimeCalcProperty.SWING_VISIBLE.getKey());
private final JCheckBox swingQuarterIconVisibleProperty
= new JCheckBox(TimeCalcProperty.SWING_QUARTER_ICON_VISIBLE.getKey());
private final JCheckBox walkingHumanVisibleProperty
= new JCheckBox(TimeCalcProperty.WALKING_HUMAN_VISIBLE.getKey());
private final JTextField mainWindowCustomTitleProperty
@ -342,6 +346,8 @@ public class ConfigWindow extends TWindow {
.setSelected(!enable);
squareVisibleProperty.setSelected(enable);
circleVisibleProperty.setSelected(enable);
swingVisibleProperty.setSelected(enable);
swingQuarterIconVisibleProperty.setSelected(enable);
walkingHumanVisibleProperty.setSelected(enable);
MainWindow.hideShowFormsCheckBox.setSelected(enable);
});
@ -399,6 +405,8 @@ public class ConfigWindow extends TWindow {
notificationsVisibleProperty,
squareVisibleProperty,
circleVisibleProperty,
swingVisibleProperty,
swingQuarterIconVisibleProperty,
walkingHumanVisibleProperty,
mainWindowCustomTitleProperty,
profileNameProperty,

View File

@ -32,6 +32,7 @@ import org.nanoboot.utils.timecalc.swing.progress.MinuteBattery;
import org.nanoboot.utils.timecalc.swing.progress.MonthBattery;
import org.nanoboot.utils.timecalc.swing.progress.ProgressCircle;
import org.nanoboot.utils.timecalc.swing.progress.ProgressSquare;
import org.nanoboot.utils.timecalc.swing.progress.ProgressSwing;
import org.nanoboot.utils.timecalc.swing.progress.Time;
import org.nanoboot.utils.timecalc.swing.progress.WalkingHumanProgress;
import org.nanoboot.utils.timecalc.swing.progress.WeekBattery;
@ -203,6 +204,7 @@ public class MainWindow extends TWindow {
AnalogClock clock = new AnalogClock();
{
arrivalTextField.valueProperty.addListener(e -> {
if (!arrivalTextField.valueProperty.getValue().isEmpty()) {
@ -301,9 +303,16 @@ public class MainWindow extends TWindow {
// add(placeHolderWidget);
// placeHolderWidget.setBounds(progressSquare.getX() + progressSquare.getWidth() + SwingUtils.MARGIN, SwingUtils.MARGIN, 50, 50);
ProgressSwing progressSwing = new ProgressSwing();
progressSwing.setBounds(clock.getX(), clock.getY() + clock.getHeight() + SwingUtils.MARGIN,
200, 100);
add(progressSwing);
progressSwing.visibleProperty
.bindTo(timeCalcConfiguration.swingVisibleProperty);
progressSwing.quarterIconVisibleProperty.bindTo(timeCalcConfiguration.swingQuarterIconVisibleProperty);
TLabel arrivalTextFieldLabel = new TLabel("Arrival:", 70);
arrivalTextFieldLabel.setBoundsFromTop(clock, 3);
arrivalTextFieldLabel.setBoundsFromTop(progressSwing, 3);
arrivalTextField.setBoundsFromLeft(arrivalTextFieldLabel);
TButton arrivalIncreaseButton = new SmallTButton('+');
@ -781,7 +790,7 @@ public class MainWindow extends TWindow {
dayBattery,
weekBattery, monthBattery, yearBattery,
walkingHumanProgress,
progressSquare, progressCircle, componentRegistry, arrivalTextFieldLabel)) {
progressSquare, progressCircle, progressSwing, componentRegistry, arrivalTextFieldLabel)) {
break;
}
}
@ -812,7 +821,9 @@ public class MainWindow extends TWindow {
Battery dayBattery, Battery weekBattery, Battery monthBattery,
Battery yearBattery, WalkingHumanProgress walkingHumanProgress,
ProgressSquare progressSquare, ProgressCircle progressCircle,
ComponentRegistry<Component> componentRegistry, TLabel arrivalTextFieldLabel) {
ProgressSwing progressSwing,
ComponentRegistry<Component> componentRegistry,
TLabel arrivalTextFieldLabel) {
//System.out.println("timeCalcConfiguration.handsLongProperty=" + timeCalcConfiguration.clockHandLongProperty.isEnabled());
if (!departureTextField.valueProperty.getValue().isEmpty() && !arrivalTextField.valueProperty.getValue().isEmpty()) {
@ -943,6 +954,7 @@ public class MainWindow extends TWindow {
}
progressSquare.setDonePercent(done);
progressCircle.setDonePercent(done);
progressSwing.setDonePercent(done);
dayBattery.setDonePercent(done);
WeekStatistics weekStatistics = new WeekStatistics(clock, time);

View File

@ -46,6 +46,8 @@ smileys.visible-only-if-mouse-moving-over=true
smileys.colored=true
square.visible=true
circle.visible=true
swing.visible=true
swing.quarter-icon.visible=true
walking-human.visible=true
main-window.custom-title=---
profile.name=