mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-26 07:49:25 +01:00
WalkingHumanProgress was refactored with several changes and improvements
This commit is contained in:
parent
9a7bdb15a1
commit
0f9f32bc32
@ -226,7 +226,6 @@ public class ConfigWindow extends TWindow {
|
|||||||
circleVisibleProperty.setSelected(enable);
|
circleVisibleProperty.setSelected(enable);
|
||||||
walkingHumanVisibleProperty.setSelected(enable);
|
walkingHumanVisibleProperty.setSelected(enable);
|
||||||
MainWindow.hideShowCheckBox.setSelected(enable);
|
MainWindow.hideShowCheckBox.setSelected(enable);
|
||||||
mainWindowCustomTitleProperty.setText(enable ? THREE_DASHES : "");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.ProgressCircle;
|
||||||
import org.nanoboot.utils.timecalc.swing.progress.ProgressSquare;
|
import org.nanoboot.utils.timecalc.swing.progress.ProgressSquare;
|
||||||
import org.nanoboot.utils.timecalc.swing.progress.Time;
|
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.WeekBattery;
|
||||||
import org.nanoboot.utils.timecalc.swing.progress.YearBattery;
|
import org.nanoboot.utils.timecalc.swing.progress.YearBattery;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.Constants;
|
import org.nanoboot.utils.timecalc.utils.common.Constants;
|
||||||
@ -146,17 +146,18 @@ public class MainWindow extends TWindow {
|
|||||||
add(progressCircle);
|
add(progressCircle);
|
||||||
progressCircle.visibleProperty.bindTo(timeCalcConfiguration.circleVisibleProperty);
|
progressCircle.visibleProperty.bindTo(timeCalcConfiguration.circleVisibleProperty);
|
||||||
|
|
||||||
WalkingHumanProgressAsciiArt walkingHumanProgressAsciiArt
|
WalkingHumanProgress walkingHumanProgress
|
||||||
= new WalkingHumanProgressAsciiArt(analogClock.getX(), analogClock.getY() + analogClock.getHeight() + SwingUtils.MARGIN, 420, 180);
|
= new WalkingHumanProgress();
|
||||||
add(walkingHumanProgressAsciiArt);
|
walkingHumanProgress.setBounds(analogClock.getX(), analogClock.getY() + analogClock.getHeight() + SwingUtils.MARGIN, 420, 180);
|
||||||
walkingHumanProgressAsciiArt.visibleProperty.bindTo(timeCalcConfiguration.walkingHumanVisibleProperty);
|
add(walkingHumanProgress);
|
||||||
|
walkingHumanProgress.visibleProperty.bindTo(timeCalcConfiguration.walkingHumanVisibleProperty);
|
||||||
|
|
||||||
weatherButton
|
weatherButton
|
||||||
.setBounds(SwingUtils.MARGIN, walkingHumanProgressAsciiArt.getY()
|
.setBounds(SwingUtils.MARGIN, walkingHumanProgress.getY()
|
||||||
+ walkingHumanProgressAsciiArt.getHeight()
|
+ walkingHumanProgress.getHeight()
|
||||||
+ SwingUtils.MARGIN);
|
+ SwingUtils.MARGIN);
|
||||||
|
|
||||||
configButton.setBoundsFromTop(walkingHumanProgressAsciiArt);
|
configButton.setBoundsFromTop(walkingHumanProgress);
|
||||||
workDaysButton.setBoundsFromLeft(configButton);
|
workDaysButton.setBoundsFromLeft(configButton);
|
||||||
activitiesButton.setBoundsFromLeft(workDaysButton);
|
activitiesButton.setBoundsFromLeft(workDaysButton);
|
||||||
restartButton.setBoundsFromLeft(activitiesButton);
|
restartButton.setBoundsFromLeft(activitiesButton);
|
||||||
@ -503,7 +504,7 @@ public class MainWindow extends TWindow {
|
|||||||
toasterManager.setDisplayTime(30000);
|
toasterManager.setDisplayTime(30000);
|
||||||
toasterManager.showToaster(
|
toasterManager.showToaster(
|
||||||
"Congratulation :-) It is the time to go home.");
|
"Congratulation :-) It is the time to go home.");
|
||||||
walkingHumanProgressAsciiArt
|
walkingHumanProgress
|
||||||
.printPercentToAscii(done, timeRemains.getHour(),
|
.printPercentToAscii(done, timeRemains.getHour(),
|
||||||
timeRemains.getMinute(), done,
|
timeRemains.getMinute(), done,
|
||||||
totalSecondsRemainsDouble, endTime);
|
totalSecondsRemainsDouble, endTime);
|
||||||
@ -520,7 +521,7 @@ public class MainWindow extends TWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
walkingHumanProgressAsciiArt
|
walkingHumanProgress
|
||||||
.printPercentToAscii(done, timeRemains.getHour(),
|
.printPercentToAscii(done, timeRemains.getHour(),
|
||||||
timeRemains.getMinute(), done,
|
timeRemains.getMinute(), done,
|
||||||
totalSecondsRemainsDouble, endTime);
|
totalSecondsRemainsDouble, endTime);
|
||||||
|
@ -30,6 +30,7 @@ public class SwingUtils {
|
|||||||
public static final Color CLOSE_BUTTON_BACKGROUND_COLOR = new Color(127, 127, 127);
|
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 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) {
|
public static final Color getColorFromString(String s) {
|
||||||
if (s.isEmpty()) {
|
if (s.isEmpty()) {
|
||||||
System.out.println("error: empty string for color");
|
System.out.println("error: empty string for color");
|
||||||
|
@ -1,25 +1,26 @@
|
|||||||
package org.nanoboot.utils.timecalc.swing.progress;
|
package org.nanoboot.utils.timecalc.swing.progress;
|
||||||
|
|
||||||
import org.nanoboot.utils.timecalc.app.GetProperty;
|
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.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.Toaster;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.common.Widget;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.Constants;
|
import org.nanoboot.utils.timecalc.utils.common.Constants;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
|
import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.TimeHM;
|
import org.nanoboot.utils.timecalc.utils.common.TimeHM;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
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.Property;
|
||||||
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JTextPane;
|
|
||||||
import javax.swing.Timer;
|
import javax.swing.Timer;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
import java.awt.Graphics;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseListener;
|
import java.awt.event.MouseListener;
|
||||||
|
import java.awt.font.LineBreakMeasurer;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -29,20 +30,19 @@ import java.util.Set;
|
|||||||
* @author Robert Vokac
|
* @author Robert Vokac
|
||||||
* @since 21.02.2024
|
* @since 21.02.2024
|
||||||
*/
|
*/
|
||||||
public class WalkingHumanProgressAsciiArt extends JTextPane implements
|
public class WalkingHumanProgress extends Widget implements
|
||||||
GetProperty {
|
GetProperty {
|
||||||
|
|
||||||
private static final String WALL = "||";
|
private static final String WALL = "||";
|
||||||
private final Set<Integer> alreadyShownPercents = new HashSet<>();
|
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));
|
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11));
|
||||||
putClientProperty("mouseEntered", "false");
|
putClientProperty("mouseEntered", "false");
|
||||||
setFocusable(false);
|
setFocusable(false);
|
||||||
@ -86,7 +86,6 @@ public class WalkingHumanProgressAsciiArt extends JTextPane implements
|
|||||||
putClientProperty("mouseEntered", "false");
|
putClientProperty("mouseEntered", "false");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setBounds(x, y, width, height);
|
|
||||||
new Timer(100, e -> {
|
new Timer(100, e -> {
|
||||||
Visibility visibility
|
Visibility visibility
|
||||||
= Visibility.valueOf(visibilityProperty.getValue());
|
= Visibility.valueOf(visibilityProperty.getValue());
|
||||||
@ -110,12 +109,33 @@ public class WalkingHumanProgressAsciiArt extends JTextPane implements
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printPercentToAscii(double percent, int hourRemains,
|
@Override
|
||||||
int minuteRemains, double done,
|
public void paintWidget(Graphics brush) {
|
||||||
double totalSecondsRemainsDouble, TimeHM endTime) {
|
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()) {
|
if (visibleProperty.isDisabled()) {
|
||||||
setText("");
|
//nothing to do
|
||||||
return;
|
return "";
|
||||||
}
|
}
|
||||||
Visibility visibility
|
Visibility visibility
|
||||||
= Visibility.valueOf(visibilityProperty.getValue());
|
= 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 spacesTotal = 40;
|
||||||
int spacesDone = (int) (percent * spacesTotal);
|
int spacesDone = (int) (percent * spacesTotal);
|
||||||
@ -189,8 +209,18 @@ public class WalkingHumanProgressAsciiArt extends JTextPane implements
|
|||||||
.format(percent * ((double) spacesTotal)) + "/"
|
.format(percent * ((double) spacesTotal)) + "/"
|
||||||
+ 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,
|
private String createMessage(int hourRemains, int minuteRemains,
|
Loading…
x
Reference in New Issue
Block a user