Added PRESENTATION to WidgetType enum
This commit is contained in:
parent
4eb43b0cdd
commit
3f2db2f80f
@ -6,6 +6,7 @@ import org.nanoboot.utils.timecalc.swing.progress.AnalogClock;
|
||||
import org.nanoboot.utils.timecalc.utils.common.TTime;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author pc00289
|
||||
@ -24,9 +25,41 @@ public class Progress {
|
||||
public void set(WidgetType type, double value) {
|
||||
array[type.getIndex()] = value > 1 ? 1 : (value < 0 ? 0 : value);
|
||||
}
|
||||
public double get(WidgetType type) {
|
||||
|
||||
public static WidgetType getWidgetType(WidgetType type) {
|
||||
if (type == WidgetType.PRESENTATION) {
|
||||
|
||||
long currentTime = new Date().getTime() / 1000l;
|
||||
long l = currentTime % 30;
|
||||
if (l >= 0 && l < 5) {
|
||||
type = WidgetType.MINUTE;
|
||||
}
|
||||
if (l >= 5 && l < 10) {
|
||||
type = WidgetType.HOUR;
|
||||
}
|
||||
if (l >= 10 && l < 15) {
|
||||
type = WidgetType.DAY;
|
||||
}
|
||||
if (l >= 15 && l < 20) {
|
||||
type = WidgetType.WEEK;
|
||||
}
|
||||
if (l >= 20 && l < 25) {
|
||||
type = WidgetType.MONTH;
|
||||
}
|
||||
if (l >= 25 && l < 30) {
|
||||
type = WidgetType.YEAR;
|
||||
}
|
||||
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public double getDonePercent(WidgetType type) {
|
||||
type = getWidgetType(type);
|
||||
|
||||
return array[type.getIndex()];
|
||||
}
|
||||
|
||||
public static double getMinuteProgress(int secondNow, int millisecondNow) {
|
||||
return millisecondNow / 60d / 1000d + secondNow / 60d;
|
||||
}
|
||||
@ -77,7 +110,8 @@ public class Progress {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static double getYearProgress(double monthProgress, Integer year, Integer month,
|
||||
public static double getYearProgress(double monthProgress, Integer year,
|
||||
Integer month,
|
||||
Integer day, Integer hour, Integer minute, Integer second,
|
||||
Integer millisecond) {
|
||||
double totalCountOfDaysInAYear = getTotalCountOfDaysInAYear(year);
|
||||
@ -91,44 +125,48 @@ public class Progress {
|
||||
cal.set(Calendar.SECOND, second);
|
||||
cal.set(Calendar.MILLISECOND, millisecond);
|
||||
int daysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||
if(month == 1) {
|
||||
if (month == 1) {
|
||||
return (daysInMonth * monthProgress) / totalCountOfDaysInAYear;
|
||||
} else {
|
||||
cal.set(Calendar.MONTH, month - 2);
|
||||
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
|
||||
int totalDaysUntilLastDayOfLastMonth = cal.get(Calendar.DAY_OF_YEAR);
|
||||
cal.set(Calendar.DAY_OF_MONTH,
|
||||
cal.getActualMaximum(Calendar.DAY_OF_MONTH));
|
||||
int totalDaysUntilLastDayOfLastMonth =
|
||||
cal.get(Calendar.DAY_OF_YEAR);
|
||||
cal.set(Calendar.MONTH, month - 1);
|
||||
cal.set(Calendar.DAY_OF_MONTH, day);
|
||||
return (totalDaysUntilLastDayOfLastMonth + (daysInMonth * monthProgress)) / totalCountOfDaysInAYear;
|
||||
return (totalDaysUntilLastDayOfLastMonth + (daysInMonth
|
||||
* monthProgress))
|
||||
/ totalCountOfDaysInAYear;
|
||||
}
|
||||
}
|
||||
|
||||
// public static double getYearProgress(Integer year, Integer month,
|
||||
// Integer day, Integer hour, Integer minute, Integer second,
|
||||
// Integer millisecond) {
|
||||
// Calendar cal = Calendar.getInstance();
|
||||
// cal.set(Calendar.YEAR, year);
|
||||
// cal.set(Calendar.MONTH, month - 1);
|
||||
// cal.set(Calendar.DAY_OF_MONTH, day);
|
||||
// cal.set(Calendar.HOUR, hour);
|
||||
// cal.set(Calendar.MINUTE, minute);
|
||||
// cal.set(Calendar.SECOND, second);
|
||||
// cal.set(Calendar.MILLISECOND, millisecond);
|
||||
//
|
||||
// double seconds = second + millisecond / 1000d;
|
||||
// double minutes = minute + seconds / 60d;
|
||||
// double hours = hour + minutes / 60d;
|
||||
// double days = cal.get(Calendar.DAY_OF_YEAR) + hours / 24d;
|
||||
// // System.out.println("millisecond=" + millisecond);
|
||||
// // System.out.println("seconds=" + seconds);
|
||||
// // System.out.println("minutes=" + minutes);
|
||||
// // System.out.println("hours=" + hours);
|
||||
// // System.out.println("days=" + days);
|
||||
// // System.out.println("cal.get(Calendar.DAY_OF_YEAR)=" + cal.get(Calendar.DAY_OF_YEAR));
|
||||
//
|
||||
// double totalCountOfDaysInAYear = getTotalCountOfDaysInAYear(year);
|
||||
// return days / totalCountOfDaysInAYear;
|
||||
// }
|
||||
// public static double getYearProgress(Integer year, Integer month,
|
||||
// Integer day, Integer hour, Integer minute, Integer second,
|
||||
// Integer millisecond) {
|
||||
// Calendar cal = Calendar.getInstance();
|
||||
// cal.set(Calendar.YEAR, year);
|
||||
// cal.set(Calendar.MONTH, month - 1);
|
||||
// cal.set(Calendar.DAY_OF_MONTH, day);
|
||||
// cal.set(Calendar.HOUR, hour);
|
||||
// cal.set(Calendar.MINUTE, minute);
|
||||
// cal.set(Calendar.SECOND, second);
|
||||
// cal.set(Calendar.MILLISECOND, millisecond);
|
||||
//
|
||||
// double seconds = second + millisecond / 1000d;
|
||||
// double minutes = minute + seconds / 60d;
|
||||
// double hours = hour + minutes / 60d;
|
||||
// double days = cal.get(Calendar.DAY_OF_YEAR) + hours / 24d;
|
||||
// // System.out.println("millisecond=" + millisecond);
|
||||
// // System.out.println("seconds=" + seconds);
|
||||
// // System.out.println("minutes=" + minutes);
|
||||
// // System.out.println("hours=" + hours);
|
||||
// // System.out.println("days=" + days);
|
||||
// // System.out.println("cal.get(Calendar.DAY_OF_YEAR)=" + cal.get(Calendar.DAY_OF_YEAR));
|
||||
//
|
||||
// double totalCountOfDaysInAYear = getTotalCountOfDaysInAYear(year);
|
||||
// return days / totalCountOfDaysInAYear;
|
||||
// }
|
||||
|
||||
private static double getTotalCountOfDaysInAYear(Integer year) {
|
||||
boolean leapYear = isLeapYear(year);
|
||||
@ -143,7 +181,8 @@ public class Progress {
|
||||
return year % 4 == 0;
|
||||
}
|
||||
|
||||
public static double getYearProgress(AnalogClock analogClock, double monthProgress) {
|
||||
public static double getYearProgress(AnalogClock analogClock,
|
||||
double monthProgress) {
|
||||
return getYearProgress(monthProgress,
|
||||
analogClock.yearProperty.getValue(),
|
||||
analogClock.monthProperty.getValue(),
|
||||
|
@ -7,7 +7,7 @@ import org.nanoboot.utils.timecalc.app.TimeCalcException;
|
||||
* @since 21.03.2024
|
||||
*/
|
||||
public enum WidgetType {
|
||||
MINUTE, HOUR, DAY, WEEK, MONTH, YEAR;
|
||||
MINUTE, HOUR, DAY, WEEK, MONTH, YEAR, PRESENTATION;
|
||||
public int getIndex() {
|
||||
int i = 0;
|
||||
for(WidgetType wt:WidgetType.values()) {
|
||||
|
@ -5,6 +5,10 @@ import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
|
||||
import org.nanoboot.utils.timecalc.entity.Progress;
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.entity.WidgetType;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.ProgressDot;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.ProgressFuelGauge;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.ProgressLife;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.ProgressMoney;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.battery.Battery;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.ProgressSmileyIcon;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.ProgressSwing;
|
||||
@ -27,6 +31,7 @@ import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Consumer;
|
||||
@ -60,6 +65,7 @@ public class Widget extends JPanel implements
|
||||
public static final Color MINIMIZE_BUTTON_BACKGROUND_COLOR_MOUSE_OVER_CLOSE_ICON = new Color(
|
||||
126, 179, 227);
|
||||
private static final Color VERY_LIGHT_GRAY = new Color(220, 220, 220);
|
||||
private static final Font FONT = new Font("sans", Font.PLAIN, 12);
|
||||
public final BooleanProperty visibilitySupportedColoredProperty
|
||||
= new BooleanProperty("visibilitySupportedColoredProperty", true);
|
||||
public final BooleanProperty visibleProperty
|
||||
@ -216,10 +222,10 @@ public class Widget extends JPanel implements
|
||||
// }
|
||||
public final void setProgress(Progress newProgress) {
|
||||
|
||||
double oldDonePercent = this.progress == null ? 0 : this.progress.get(WidgetType.DAY);
|
||||
double oldDonePercent = this.progress == null ? 0 : this.progress.getDonePercent(WidgetType.DAY);
|
||||
int oldDonePercentInt1000Mil = (int) (oldDonePercent * 1000000000);
|
||||
|
||||
int newDonePercentInt1000Mil = (int) (newProgress.get(WidgetType.DAY) * 1000000000);
|
||||
int newDonePercentInt1000Mil = (int) (newProgress.getDonePercent(WidgetType.DAY) * 1000000000);
|
||||
if (newDonePercentInt1000Mil != oldDonePercentInt1000Mil) {
|
||||
lastUpdate = System.nanoTime();
|
||||
}
|
||||
@ -228,12 +234,40 @@ public class Widget extends JPanel implements
|
||||
|
||||
protected double donePercent() {
|
||||
if(progress == null) {
|
||||
return 0;
|
||||
return 0d;
|
||||
}
|
||||
return progress.get(WidgetType.valueOf(typeProperty.getValue().toUpperCase(
|
||||
if(typeProperty.getValue().equals(WidgetType.PRESENTATION.name())) {
|
||||
long currentTime = new Date().getTime() / 1000l;
|
||||
long l = currentTime % 30;
|
||||
if (l >= 0 && l < 5) {
|
||||
return getDonePercentForWidgetType(WidgetType.MINUTE);
|
||||
}
|
||||
if (l >= 5 && l < 10) {
|
||||
return getDonePercentForWidgetType(WidgetType.HOUR);
|
||||
}
|
||||
if (l >= 10 && l < 15) {
|
||||
return getDonePercentForWidgetType(WidgetType.DAY);
|
||||
}
|
||||
if (l >= 15 && l < 20) {
|
||||
return getDonePercentForWidgetType(WidgetType.WEEK);
|
||||
}
|
||||
if (l >= 20 && l < 25) {
|
||||
return getDonePercentForWidgetType(WidgetType.MONTH);
|
||||
}
|
||||
if (l >= 25 && l < 30) {
|
||||
return getDonePercentForWidgetType(WidgetType.YEAR);
|
||||
}
|
||||
return getDonePercentForWidgetType(WidgetType.DAY);
|
||||
}
|
||||
return getDonePercentForWidgetType(WidgetType.valueOf(typeProperty.getValue().toUpperCase(
|
||||
Locale.ROOT)));
|
||||
}
|
||||
|
||||
private double getDonePercentForWidgetType(WidgetType widgetType) {
|
||||
return progress
|
||||
.getDonePercent(widgetType);
|
||||
}
|
||||
|
||||
public void setBounds(int x, int y, int side) {
|
||||
setBounds(x, y, side, side);
|
||||
}
|
||||
@ -301,6 +335,18 @@ public class Widget extends JPanel implements
|
||||
brush.drawRect(1, 1, getWidth() - 2, getHeight() - 2);
|
||||
brush.setColor(currentColor);
|
||||
}
|
||||
boolean isLife = getClass() == ProgressLife.class;
|
||||
boolean isMoney = getClass() == ProgressMoney.class;
|
||||
if (isLife || isMoney || typeProperty.getValue().equals(WidgetType.PRESENTATION.name().toLowerCase())) {
|
||||
brush.setColor(visibility.isStronglyColored() ? Color.BLUE : Color.GRAY);
|
||||
// if(visibility.isStronglyColored() && (getClass() == ProgressFuelGauge.class || getClass() == ProgressDot.class)) {
|
||||
// brush.setColor(Color.BLUE);
|
||||
// }
|
||||
brush.setFont(FONT);
|
||||
brush.drawString(progress.getWidgetType(WidgetType.valueOf(typeProperty.getValue().toUpperCase())).name(),
|
||||
(int) (getWidth() * 0.5d - 20d), 15);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void paintCloseIcon(Graphics brush, int width,
|
||||
|
@ -24,6 +24,7 @@ public class WidgetMenu extends JPopupMenu {
|
||||
private final JMenuItem typeWeekMenuItem;
|
||||
private final JMenuItem typeMonthMenuItem;
|
||||
private final JMenuItem typeYearMenuItem;
|
||||
private final JMenuItem typePresentationMenuItem;
|
||||
private final Widget widget;
|
||||
private WidgetType selectedType;
|
||||
private Consumer<Object> refreshConsumer;
|
||||
@ -47,12 +48,14 @@ public class WidgetMenu extends JPopupMenu {
|
||||
this.typeWeekMenuItem = new JMenuItem(WidgetType.WEEK.name());
|
||||
this.typeMonthMenuItem = new JMenuItem(WidgetType.MONTH.name());
|
||||
this.typeYearMenuItem = new JMenuItem(WidgetType.YEAR.name());
|
||||
this.typePresentationMenuItem = new JMenuItem(WidgetType.PRESENTATION.name());
|
||||
typeMenuItem.add(typeMinuteMenuItem);
|
||||
typeMenuItem.add(typeHourMenuItem);
|
||||
typeMenuItem.add(typeDayMenuItem);
|
||||
typeMenuItem.add(typeWeekMenuItem);
|
||||
typeMenuItem.add(typeMonthMenuItem);
|
||||
typeMenuItem.add(typeYearMenuItem);
|
||||
typeMenuItem.add(typePresentationMenuItem);
|
||||
|
||||
BiConsumer<JMenuItem, WidgetType> typeActionCreator = (m,w) -> {
|
||||
m.addActionListener(e -> {
|
||||
@ -70,22 +73,8 @@ public class WidgetMenu extends JPopupMenu {
|
||||
typeActionCreator.accept(typeWeekMenuItem, WidgetType.WEEK);
|
||||
typeActionCreator.accept(typeMonthMenuItem, WidgetType.MONTH);
|
||||
typeActionCreator.accept(typeYearMenuItem, WidgetType.YEAR);
|
||||
typeActionCreator.accept(typePresentationMenuItem, WidgetType.PRESENTATION);
|
||||
|
||||
typeWeekMenuItem.addActionListener(e -> {
|
||||
markAsSelected(WidgetType.WEEK);
|
||||
widget.typeProperty.setValue(WidgetType.WEEK
|
||||
.name().toLowerCase(Locale.ROOT));
|
||||
});
|
||||
typeMonthMenuItem.addActionListener(e -> {
|
||||
markAsSelected(WidgetType.MONTH);
|
||||
widget.typeProperty.setValue(WidgetType.MONTH
|
||||
.name().toLowerCase(Locale.ROOT));
|
||||
});
|
||||
typeYearMenuItem.addActionListener(e -> {
|
||||
markAsSelected(WidgetType.YEAR);
|
||||
widget.typeProperty.setValue(WidgetType.YEAR
|
||||
.name().toLowerCase(Locale.ROOT));
|
||||
});
|
||||
//if(!aClass.getSimpleName().contains("Battery")) {
|
||||
add(typeMenuItem);
|
||||
//}
|
||||
@ -103,6 +92,7 @@ public class WidgetMenu extends JPopupMenu {
|
||||
this.typeWeekMenuItem.setText(WidgetType.WEEK.name());
|
||||
this.typeMonthMenuItem.setText(WidgetType.MONTH.name());
|
||||
this.typeYearMenuItem.setText(WidgetType.YEAR.name());
|
||||
this.typePresentationMenuItem.setText(WidgetType.PRESENTATION.name());
|
||||
switch (widgetType) {
|
||||
case MINUTE: typeMinuteMenuItem.setText(typeMinuteMenuItem.getText() + " (*)");break;
|
||||
case HOUR: typeHourMenuItem.setText(typeHourMenuItem.getText() + " (*)");break;
|
||||
@ -110,6 +100,7 @@ public class WidgetMenu extends JPopupMenu {
|
||||
case WEEK: typeWeekMenuItem.setText(typeWeekMenuItem.getText() + " (*)");break;
|
||||
case MONTH: typeMonthMenuItem.setText(typeMonthMenuItem.getText() + " (*)");break;
|
||||
case YEAR: typeYearMenuItem.setText(typeYearMenuItem.getText() + " (*)");break;
|
||||
case PRESENTATION: typePresentationMenuItem.setText(typePresentationMenuItem.getText() + " (*)");break;
|
||||
default: throw new TimeCalcException("Unsupported WidgetType: " + widgetType);
|
||||
}
|
||||
this.selectedType = widgetType;
|
||||
|
@ -96,10 +96,10 @@ public class ProgressLife extends Widget implements GetProperty {
|
||||
// }
|
||||
brush.setFont(SwingUtils.MEDIUM_MONOSPACE_FONT);
|
||||
|
||||
brush.drawString(date, SwingUtils.MARGIN, SwingUtils.MARGIN + 5);
|
||||
brush.drawString(date, SwingUtils.MARGIN, SwingUtils.MARGIN + 16);
|
||||
brush.drawString(time, SwingUtils.MARGIN,
|
||||
(int) (2.5 * SwingUtils.MARGIN) + 5);
|
||||
brush.drawString(typeProperty.getValue(), SwingUtils.MARGIN, 4 * SwingUtils.MARGIN + 5);
|
||||
(int) (2.5 * SwingUtils.MARGIN) + 22);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import org.nanoboot.utils.timecalc.entity.WidgetType;
|
||||
import org.nanoboot.utils.timecalc.swing.common.SwingUtils;
|
||||
import org.nanoboot.utils.timecalc.swing.common.Widget;
|
||||
import org.nanoboot.utils.timecalc.swing.windows.MainWindow;
|
||||
import org.nanoboot.utils.timecalc.utils.common.DateFormats;
|
||||
import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
|
||||
import org.nanoboot.utils.timecalc.utils.property.IntegerProperty;
|
||||
import org.nanoboot.utils.timecalc.utils.property.Property;
|
||||
@ -17,8 +16,6 @@ import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
@ -69,14 +66,16 @@ public class ProgressMoney extends Widget implements GetProperty {
|
||||
boolean isWeekend = progress.isWeekend();
|
||||
double perDay = perMonth / workDaysInMonth;
|
||||
double value = 0;
|
||||
switch(WidgetType.valueOf(this.typeProperty.getValue().toUpperCase(
|
||||
Locale.ROOT))) {
|
||||
case MINUTE: value = isWeekend ? 0d : perDay / 8d / 60d * progress.get(WidgetType.MINUTE);break;
|
||||
case HOUR: value = isWeekend ? 0d : perDay / 8d * progress.get(WidgetType.HOUR);break;
|
||||
case DAY: value = isWeekend ? 0d : perDay * progress.get(WidgetType.DAY);break;
|
||||
case WEEK: value = perDay * 5d * progress.get(WidgetType.WEEK);break;
|
||||
case MONTH: value = perMonth * progress.get(WidgetType.MONTH);break;
|
||||
case YEAR: value = perMonth * 12 * progress.get(WidgetType.YEAR);break;
|
||||
WidgetType widgetType = WidgetType.valueOf(this.typeProperty.getValue().toUpperCase(
|
||||
Locale.ROOT));
|
||||
widgetType = progress.getWidgetType(widgetType);
|
||||
switch(widgetType) {
|
||||
case MINUTE: value = isWeekend ? 0d : perDay / 8d / 60d * progress.getDonePercent(WidgetType.MINUTE);break;
|
||||
case HOUR: value = isWeekend ? 0d : perDay / 8d * progress.getDonePercent(WidgetType.HOUR);break;
|
||||
case DAY: value = isWeekend ? 0d : perDay * progress.getDonePercent(WidgetType.DAY);break;
|
||||
case WEEK: value = perDay * 5d * progress.getDonePercent(WidgetType.WEEK);break;
|
||||
case MONTH: value = perMonth * progress.getDonePercent(WidgetType.MONTH);break;
|
||||
case YEAR: value = perMonth * 12 * progress.getDonePercent(WidgetType.YEAR);break;
|
||||
}
|
||||
|
||||
Visibility visibility
|
||||
@ -89,8 +88,7 @@ public class ProgressMoney extends Widget implements GetProperty {
|
||||
|
||||
NumberFormat formatter = value >= 10000d ? NumberFormats.FORMATTER_TWO_DECIMAL_PLACES : NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES;
|
||||
String valueFinal = formatter.format(value) + " " + this.currencyProperty.getValue();
|
||||
brush.drawString(valueFinal, SwingUtils.MARGIN, SwingUtils.MARGIN + 10);
|
||||
brush.drawString(typeProperty.getValue(), SwingUtils.MARGIN, SwingUtils.MARGIN + 25);
|
||||
brush.drawString(valueFinal, SwingUtils.MARGIN, SwingUtils.MARGIN + 20);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public class ProgressWeather extends Widget implements GetProperty {
|
||||
private static Map<Integer, List<WeatherForecast>> forecastsForYears = new HashMap<>();
|
||||
|
||||
public int getTimerDelay() {
|
||||
return 1000;
|
||||
return 100;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user