mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
Added smiley head to walking human
This commit is contained in:
parent
1f18d57c6b
commit
d53818010a
@ -3,6 +3,7 @@ package org.nanoboot.utils.timecalc.app;
|
|||||||
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.MainWindow;
|
||||||
import org.nanoboot.utils.timecalc.swing.progress.Time;
|
import org.nanoboot.utils.timecalc.swing.progress.Time;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.progress.WalkingHumanProgress;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.FileConstants;
|
import org.nanoboot.utils.timecalc.utils.common.FileConstants;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.Jokes;
|
import org.nanoboot.utils.timecalc.utils.common.Jokes;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.TTime;
|
import org.nanoboot.utils.timecalc.utils.common.TTime;
|
||||||
|
@ -775,6 +775,9 @@ public class MainWindow extends TWindow {
|
|||||||
int secondNow = clock.secondProperty.getValue();
|
int secondNow = clock.secondProperty.getValue();
|
||||||
int millisecondNow = clock.millisecondProperty.getValue();
|
int millisecondNow = clock.millisecondProperty.getValue();
|
||||||
|
|
||||||
|
if(arrivalTextField.getText().isEmpty() || departureTextField.getText().isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
TTime startTime = arrivalTextField.asTTime();
|
TTime startTime = arrivalTextField.asTTime();
|
||||||
TTime endTime = departureTextField.asTTime();
|
TTime endTime = departureTextField.asTTime();
|
||||||
TTime nowTime = TTime.of(time.asCalendar());
|
TTime nowTime = TTime.of(time.asCalendar());
|
||||||
|
@ -35,7 +35,9 @@ public class Widget extends JPanel implements
|
|||||||
protected static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
protected static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
||||||
protected static final Font BIG_FONT = new Font("sans", Font.BOLD, 24);
|
protected static final Font BIG_FONT = new Font("sans", Font.BOLD, 24);
|
||||||
protected static final Font MEDIUM_FONT = new Font("sans", Font.BOLD, 16);
|
protected static final Font MEDIUM_FONT = new Font("sans", Font.BOLD, 16);
|
||||||
|
protected static final String HEAD = " () ";
|
||||||
|
protected static final String BODY = "/||\\";
|
||||||
|
protected static final String LEGS = " /\\ ";
|
||||||
public static final Color CLOSE_BUTTON_FOREGROUND_COLOR
|
public static final Color CLOSE_BUTTON_FOREGROUND_COLOR
|
||||||
= new Color(127, 127, 127);
|
= new Color(127, 127, 127);
|
||||||
public static final Color CLOSE_BUTTON_BACKGROUND_COLOR = Color.LIGHT_GRAY;
|
public static final Color CLOSE_BUTTON_BACKGROUND_COLOR = Color.LIGHT_GRAY;
|
||||||
@ -229,12 +231,13 @@ public class Widget extends JPanel implements
|
|||||||
public Property getVisibilitySupportedColoredProperty() {
|
public Property getVisibilitySupportedColoredProperty() {
|
||||||
return visibilitySupportedColoredProperty;
|
return visibilitySupportedColoredProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void paintSmiley(Visibility visibility, Graphics2D brush, int x,
|
protected void paintSmiley(Visibility visibility, Graphics2D brush, int x,
|
||||||
int y) {
|
int y) {
|
||||||
if (smileysVisibleProperty.isDisabled() || (!mouseOver
|
paintSmiley(visibility, brush, x, y, false);
|
||||||
&& smileysVisibleOnlyIfMouseMovingOverProperty
|
}
|
||||||
.isEnabled())) {
|
protected void paintSmiley(Visibility visibility, Graphics2D brush, int x,
|
||||||
|
int y, boolean paintBody) {
|
||||||
|
if (!shouldBeSmileyPainted()) {
|
||||||
if (this.smileyIcon != null) {
|
if (this.smileyIcon != null) {
|
||||||
this.remove(smileyIcon);
|
this.remove(smileyIcon);
|
||||||
this.smileyIcon = null;
|
this.smileyIcon = null;
|
||||||
@ -248,7 +251,9 @@ public class Widget extends JPanel implements
|
|||||||
colored = false;
|
colored = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!colored) {
|
if (!colored) {
|
||||||
|
y = y - 2;
|
||||||
if (this.smileyIcon != null) {
|
if (this.smileyIcon != null) {
|
||||||
this.remove(smileyIcon);
|
this.remove(smileyIcon);
|
||||||
this.smileyIcon = null;
|
this.smileyIcon = null;
|
||||||
@ -263,6 +268,7 @@ public class Widget extends JPanel implements
|
|||||||
brush.setColor(Color.BLACK);
|
brush.setColor(Color.BLACK);
|
||||||
}
|
}
|
||||||
Color currentColor = brush.getColor();
|
Color currentColor = brush.getColor();
|
||||||
|
Font currentFont = brush.getFont();
|
||||||
brush.setColor(visibility.isStronglyColored() ? Color.WHITE
|
brush.setColor(visibility.isStronglyColored() ? Color.WHITE
|
||||||
: BACKGROUND_COLOR);
|
: BACKGROUND_COLOR);
|
||||||
brush.fillRect(
|
brush.fillRect(
|
||||||
@ -274,10 +280,12 @@ public class Widget extends JPanel implements
|
|||||||
brush.setFont(MEDIUM_FONT);
|
brush.setFont(MEDIUM_FONT);
|
||||||
brush.drawString(
|
brush.drawString(
|
||||||
ProgressSmiley.forProgress(donePercent).getCharacter(),
|
ProgressSmiley.forProgress(donePercent).getCharacter(),
|
||||||
x, y + 16
|
x + 1, y + 16
|
||||||
);
|
);
|
||||||
|
brush.setFont(currentFont);
|
||||||
}
|
}
|
||||||
if (colored) {
|
if (colored) {
|
||||||
|
x = x + 2;
|
||||||
ImageIcon imageIcon = ProgressSmileyIcon
|
ImageIcon imageIcon = ProgressSmileyIcon
|
||||||
.forSmiley(ProgressSmiley.forProgress(donePercent))
|
.forSmiley(ProgressSmiley.forProgress(donePercent))
|
||||||
.getIcon();
|
.getIcon();
|
||||||
@ -289,6 +297,20 @@ public class Widget extends JPanel implements
|
|||||||
smileyIcon.setBounds(x, y, 15, 15);
|
smileyIcon.setBounds(x, y, 15, 15);
|
||||||
this.add(smileyIcon);
|
this.add(smileyIcon);
|
||||||
}
|
}
|
||||||
|
if(colored) {
|
||||||
|
x = x - 2;
|
||||||
|
y = y - 2;
|
||||||
|
}
|
||||||
|
if(paintBody) {
|
||||||
|
brush.drawString(BODY, x - 5, y + 26);
|
||||||
|
brush.drawString(LEGS, x - 5, y + 36);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean shouldBeSmileyPainted() {
|
||||||
|
return smileysVisibleProperty.isEnabled() && (mouseOver
|
||||||
|
|| !smileysVisibleOnlyIfMouseMovingOverProperty
|
||||||
|
.isEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean changedInTheLastXMilliseconds(int milliseconds) {
|
protected boolean changedInTheLastXMilliseconds(int milliseconds) {
|
||||||
|
@ -17,6 +17,7 @@ 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.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
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;
|
||||||
@ -31,6 +32,7 @@ public class WalkingHumanProgress extends Widget implements
|
|||||||
|
|
||||||
private static final String WALL = "||";
|
private static final String WALL = "||";
|
||||||
private final Set<Integer> alreadyShownPercents = new HashSet<>();
|
private final Set<Integer> alreadyShownPercents = new HashSet<>();
|
||||||
|
private static final int LINE_WHERE_HEAD_IS = 2;
|
||||||
|
|
||||||
public WalkingHumanProgress() {
|
public WalkingHumanProgress() {
|
||||||
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11));
|
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11));
|
||||||
@ -81,8 +83,18 @@ public class WalkingHumanProgress extends Widget implements
|
|||||||
// }
|
// }
|
||||||
brush.setFont(SwingUtils.MEDIUM_MONOSPACE_FONT);
|
brush.setFont(SwingUtils.MEDIUM_MONOSPACE_FONT);
|
||||||
int y = SwingUtils.MARGIN;
|
int y = SwingUtils.MARGIN;
|
||||||
|
int lineNumber = 0;
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
|
++lineNumber;
|
||||||
brush.drawString(line, SwingUtils.MARGIN, y);
|
brush.drawString(line, SwingUtils.MARGIN, y);
|
||||||
|
|
||||||
|
if(lineNumber == LINE_WHERE_HEAD_IS) {
|
||||||
|
paintSmiley(visibility,
|
||||||
|
(Graphics2D) brush,
|
||||||
|
//29 309
|
||||||
|
29 + ((int) (280 * donePercent)),
|
||||||
|
y - 4, true);
|
||||||
|
}
|
||||||
y = y + SwingUtils.MARGIN;
|
y = y + SwingUtils.MARGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,6 +106,7 @@ public class WalkingHumanProgress extends Widget implements
|
|||||||
//nothing to do
|
//nothing to do
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
boolean bodyEnabled = !shouldBeSmileyPainted();
|
||||||
Visibility visibility
|
Visibility visibility
|
||||||
= Visibility.valueOf(visibilityProperty.getValue());
|
= Visibility.valueOf(visibilityProperty.getValue());
|
||||||
this.setVisible(visibility != Visibility.NONE);
|
this.setVisible(visibility != Visibility.NONE);
|
||||||
@ -146,15 +159,15 @@ public class WalkingHumanProgress extends Widget implements
|
|||||||
.append(spacesTodo == 0 ? "" : "| |").append("\n");
|
.append(spacesTodo == 0 ? "" : "| |").append("\n");
|
||||||
|
|
||||||
sb.append(
|
sb.append(
|
||||||
WALL + createSpaces(spacesDone) + " () " + createSpaces(
|
WALL + createSpaces(spacesDone) + (bodyEnabled ? HEAD : " ") + createSpaces(
|
||||||
spacesTodo) + (spacesTodo == 0
|
spacesTodo) + (spacesTodo == 0
|
||||||
? " \\☼☼☼☼/ "
|
? " \\☼☼☼☼/ "
|
||||||
: "| _ |") + Constants.NEW_LINE
|
: "| _ |") + Constants.NEW_LINE
|
||||||
+ WALL + createSpaces(spacesDone) + "/||\\" + createSpaces(
|
+ WALL + createSpaces(spacesDone) + (bodyEnabled ? BODY : " ") + createSpaces(
|
||||||
spacesTodo) + (spacesTodo == 0
|
spacesTodo) + (spacesTodo == 0
|
||||||
? " ☼☼☼☼☼☼ "
|
? " ☼☼☼☼☼☼ "
|
||||||
: "| | |") + Constants.NEW_LINE
|
: "| | |") + Constants.NEW_LINE
|
||||||
+ WALL + createSpaces(spacesDone) + " /\\ " + createSpaces(
|
+ WALL + createSpaces(spacesDone) + (bodyEnabled ? LEGS : " ") + createSpaces(
|
||||||
spacesTodo) + (spacesTodo == 0
|
spacesTodo) + (spacesTodo == 0
|
||||||
? " /☼☼☼☼\\ "
|
? " /☼☼☼☼\\ "
|
||||||
: "| |") + Constants.NEW_LINE
|
: "| |") + Constants.NEW_LINE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user