WalkingHumanProgress was refactored with several changes and improvements

This commit is contained in:
Robert Vokac 2024-03-03 12:22:58 +00:00
parent 9a7bdb15a1
commit 0f9f32bc32
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
4 changed files with 265 additions and 234 deletions

View File

@ -226,7 +226,6 @@ public class ConfigWindow extends TWindow {
circleVisibleProperty.setSelected(enable);
walkingHumanVisibleProperty.setSelected(enable);
MainWindow.hideShowCheckBox.setSelected(enable);
mainWindowCustomTitleProperty.setText(enable ? THREE_DASHES : "");
});
}

View File

@ -17,7 +17,7 @@ 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.Time;
import org.nanoboot.utils.timecalc.swing.progress.WalkingHumanProgressAsciiArt;
import org.nanoboot.utils.timecalc.swing.progress.WalkingHumanProgress;
import org.nanoboot.utils.timecalc.swing.progress.WeekBattery;
import org.nanoboot.utils.timecalc.swing.progress.YearBattery;
import org.nanoboot.utils.timecalc.utils.common.Constants;
@ -146,17 +146,18 @@ public class MainWindow extends TWindow {
add(progressCircle);
progressCircle.visibleProperty.bindTo(timeCalcConfiguration.circleVisibleProperty);
WalkingHumanProgressAsciiArt walkingHumanProgressAsciiArt
= new WalkingHumanProgressAsciiArt(analogClock.getX(), analogClock.getY() + analogClock.getHeight() + SwingUtils.MARGIN, 420, 180);
add(walkingHumanProgressAsciiArt);
walkingHumanProgressAsciiArt.visibleProperty.bindTo(timeCalcConfiguration.walkingHumanVisibleProperty);
WalkingHumanProgress walkingHumanProgress
= new WalkingHumanProgress();
walkingHumanProgress.setBounds(analogClock.getX(), analogClock.getY() + analogClock.getHeight() + SwingUtils.MARGIN, 420, 180);
add(walkingHumanProgress);
walkingHumanProgress.visibleProperty.bindTo(timeCalcConfiguration.walkingHumanVisibleProperty);
weatherButton
.setBounds(SwingUtils.MARGIN, walkingHumanProgressAsciiArt.getY()
+ walkingHumanProgressAsciiArt.getHeight()
+ SwingUtils.MARGIN);
.setBounds(SwingUtils.MARGIN, walkingHumanProgress.getY()
+ walkingHumanProgress.getHeight()
+ SwingUtils.MARGIN);
configButton.setBoundsFromTop(walkingHumanProgressAsciiArt);
configButton.setBoundsFromTop(walkingHumanProgress);
workDaysButton.setBoundsFromLeft(configButton);
activitiesButton.setBoundsFromLeft(workDaysButton);
restartButton.setBoundsFromLeft(activitiesButton);
@ -503,7 +504,7 @@ public class MainWindow extends TWindow {
toasterManager.setDisplayTime(30000);
toasterManager.showToaster(
"Congratulation :-) It is the time to go home.");
walkingHumanProgressAsciiArt
walkingHumanProgress
.printPercentToAscii(done, timeRemains.getHour(),
timeRemains.getMinute(), done,
totalSecondsRemainsDouble, endTime);
@ -520,7 +521,7 @@ public class MainWindow extends TWindow {
}
}
} else {
walkingHumanProgressAsciiArt
walkingHumanProgress
.printPercentToAscii(done, timeRemains.getHour(),
timeRemains.getMinute(), done,
totalSecondsRemainsDouble, endTime);

View File

@ -30,6 +30,7 @@ public class SwingUtils {
public static final Color CLOSE_BUTTON_BACKGROUND_COLOR = new Color(127, 127, 127);
public static final Font SMALL_FONT = new Font("sans", Font.BOLD, 10);
public static final Font MEDIUM_MONOSPACE_FONT = new Font(Font.MONOSPACED, Font.PLAIN, 12);
public static final Color getColorFromString(String s) {
if (s.isEmpty()) {
System.out.println("error: empty string for color");

View File

@ -1,25 +1,26 @@
package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.app.GetProperty;
import org.nanoboot.utils.timecalc.swing.common.MainWindow;
import org.nanoboot.utils.timecalc.entity.Visibility;
import org.nanoboot.utils.timecalc.swing.common.MainWindow;
import org.nanoboot.utils.timecalc.swing.common.SwingUtils;
import org.nanoboot.utils.timecalc.swing.common.Toaster;
import org.nanoboot.utils.timecalc.swing.common.Widget;
import org.nanoboot.utils.timecalc.utils.common.Constants;
import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
import org.nanoboot.utils.timecalc.utils.common.TimeHM;
import org.nanoboot.utils.timecalc.utils.common.Utils;
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
import org.nanoboot.utils.timecalc.utils.property.Property;
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JTextPane;
import javax.swing.Timer;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.font.LineBreakMeasurer;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.util.HashSet;
@ -29,20 +30,19 @@ import java.util.Set;
* @author Robert Vokac
* @since 21.02.2024
*/
public class WalkingHumanProgressAsciiArt extends JTextPane implements
public class WalkingHumanProgress extends Widget implements
GetProperty {
private static final String WALL = "||";
private final Set<Integer> alreadyShownPercents = new HashSet<>();
public StringProperty visibilityProperty
= new StringProperty("visibilityProperty",
Visibility.STRONGLY_COLORED.name());
public final BooleanProperty visibilitySupportedColoredProperty
= new BooleanProperty("visibilitySupportedColoredProperty", true);
public final BooleanProperty visibleProperty
= new BooleanProperty("visibleProperty", true);
public WalkingHumanProgressAsciiArt(int x, int y, int width, int height) {
private double percent;
private int hourRemains;
private int minuteRemains;
private double done;
private double totalSecondsRemainsDouble;
private TimeHM endTime;
public WalkingHumanProgress() {
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11));
putClientProperty("mouseEntered", "false");
setFocusable(false);
@ -86,7 +86,6 @@ public class WalkingHumanProgressAsciiArt extends JTextPane implements
putClientProperty("mouseEntered", "false");
}
});
setBounds(x, y, width, height);
new Timer(100, e -> {
Visibility visibility
= Visibility.valueOf(visibilityProperty.getValue());
@ -110,12 +109,33 @@ public class WalkingHumanProgressAsciiArt extends JTextPane implements
return sb.toString();
}
public void printPercentToAscii(double percent, int hourRemains,
int minuteRemains, double done,
double totalSecondsRemainsDouble, TimeHM endTime) {
@Override
public void paintWidget(Graphics brush) {
String string = printPercentToAscii();
if (string.isEmpty()) {
//nothing to do
} else {
String[] lines = string.split("\n");
Visibility visibility
= Visibility.valueOf(visibilityProperty.getValue());
brush.setColor(visibility.isStronglyColored() ? Color.BLUE : visibility.isWeaklyColored() ? Color.GRAY : Color.LIGHT_GRAY);
brush.setFont(SwingUtils.MEDIUM_MONOSPACE_FONT);
int y = SwingUtils.MARGIN;
for (String line : lines) {
brush.drawString(line, SwingUtils.MARGIN, y);
y = y + SwingUtils.MARGIN;
}
}
}
private String printPercentToAscii() {
if (visibleProperty.isDisabled()) {
setText("");
return;
//nothing to do
return "";
}
Visibility visibility
= Visibility.valueOf(visibilityProperty.getValue());
@ -156,7 +176,7 @@ public class WalkingHumanProgressAsciiArt extends JTextPane implements
}
sb.append("\n" + msg + "\n\n");
sb.append(msg + "\n\n");
int spacesTotal = 40;
int spacesDone = (int) (percent * spacesTotal);
@ -172,15 +192,15 @@ public class WalkingHumanProgressAsciiArt extends JTextPane implements
sb.append(
WALL + createSpaces(spacesDone) + " () " + createSpaces(
spacesTodo) + (spacesTodo == 0
spacesTodo) + (spacesTodo == 0
? " \\☼☼☼☼/ "
: "| _ |") + Constants.NEW_LINE
+ WALL + createSpaces(spacesDone) + "/||\\" + createSpaces(
spacesTodo) + (spacesTodo == 0
spacesTodo) + (spacesTodo == 0
? " ☼☼☼☼☼☼ "
: "| | |") + Constants.NEW_LINE
+ WALL + createSpaces(spacesDone) + " /\\ " + createSpaces(
spacesTodo) + (spacesTodo == 0
spacesTodo) + (spacesTodo == 0
? " /☼☼☼☼\\ "
: "| |") + Constants.NEW_LINE
+ createRepeatedString(spacesTotal + 16, '=')
@ -189,8 +209,18 @@ public class WalkingHumanProgressAsciiArt extends JTextPane implements
.format(percent * ((double) spacesTotal)) + "/"
+ spacesTotal
);
this.setText(sb.toString());
return sb.toString();
}
public void printPercentToAscii(double percent, int hourRemains,
int minuteRemains, double done,
double totalSecondsRemainsDouble, TimeHM endTime) {
this.percent = percent;
this.hourRemains = hourRemains;
this.minuteRemains = minuteRemains;
this.done = done;
this.totalSecondsRemainsDouble = totalSecondsRemainsDouble;
this.endTime = endTime;
}
private String createMessage(int hourRemains, int minuteRemains,