patch10
This commit is contained in:
parent
86245d0b46
commit
462e4c9c6e
@ -165,6 +165,8 @@ public class TimeCalcConfiguration {
|
||||
= new BooleanProperty("testModeProperty", false);
|
||||
public final StringProperty profileNameProperty
|
||||
= new StringProperty(TimeCalcProperty.PROFILE_NAME.getKey());
|
||||
public final StringProperty activityNeededFlagsProperty
|
||||
= new StringProperty(TimeCalcProperty.ACTIVITY_NEEDED_FLAGS.getKey());
|
||||
public final BooleanProperty testEnabledProperty = new BooleanProperty(TimeCalcProperty.TEST_ENABLED.getKey(), false);
|
||||
public final IntegerProperty testYearCustomProperty = new IntegerProperty(TimeCalcProperty.TEST_CLOCK_CUSTOM_YEAR
|
||||
.getKey(), Integer.MAX_VALUE);
|
||||
@ -236,6 +238,7 @@ public class TimeCalcConfiguration {
|
||||
walkingHumanVisibleProperty,
|
||||
mainWindowCustomTitleProperty,
|
||||
profileNameProperty,
|
||||
activityNeededFlagsProperty,
|
||||
testEnabledProperty,
|
||||
testYearCustomProperty,
|
||||
testMonthCustomProperty,
|
||||
|
@ -87,7 +87,8 @@ public enum TimeCalcProperty {
|
||||
TEST_CLOCK_CUSTOM_HOUR("test.clock.custom.hour", "Test : Clock : Custom : Hour", Integer.class),
|
||||
TEST_CLOCK_CUSTOM_MINUTE("test.clock.custom.minute", "Test : Clock : Custom : Minute", Integer.class),
|
||||
TEST_CLOCK_CUSTOM_SECOND("test.clock.custom.second", "Test : Clock : Custom : Second", Integer.class),
|
||||
TEST_CLOCK_CUSTOM_MILLISECOND("test.clock.custom.millisecond", "Test : Clock : Custom : Millisecond", Integer.class);
|
||||
TEST_CLOCK_CUSTOM_MILLISECOND("test.clock.custom.millisecond", "Test : Clock : Custom : Millisecond", Integer.class),
|
||||
ACTIVITY_NEEDED_FLAGS("activity.needed-flags", "Activity : Needed flags", String.class);
|
||||
|
||||
@Getter
|
||||
private final String key;
|
||||
|
@ -1,8 +1,12 @@
|
||||
package org.nanoboot.utils.timecalc.persistence.api;
|
||||
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcConfiguration;
|
||||
import org.nanoboot.utils.timecalc.entity.Activity;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Robert Vokac
|
||||
@ -10,6 +14,34 @@ import java.util.List;
|
||||
*/
|
||||
public interface ActivityRepositoryApi {
|
||||
|
||||
default double getProgressForDay(int year, int month, int day, TimeCalcConfiguration timeCalcConfiguration) {
|
||||
List<Activity> list = list(year, month, day);
|
||||
double done = 0d;
|
||||
double todo = 8d;
|
||||
|
||||
loopName:
|
||||
for(Activity a:list) {
|
||||
Set<String> flags = a.flagsAsSet();
|
||||
String neededFlags = timeCalcConfiguration.activityNeededFlagsProperty.getValue();
|
||||
System.out.println("neededFlags=" + neededFlags);
|
||||
neededFlags.replace(",", ":");
|
||||
String[] neededFlagsArray = neededFlags.split(":");
|
||||
Set<String> neededFlagsSet = Arrays.stream(neededFlagsArray).filter(f -> !f.isEmpty()).collect(
|
||||
Collectors.toSet());
|
||||
if(!neededFlagsSet.isEmpty()) {
|
||||
for(String f:neededFlagsSet) {
|
||||
if(!flags.contains(f)) {
|
||||
continue loopName;
|
||||
}
|
||||
}
|
||||
}
|
||||
double now = a.getSpentHours() + a.getSpentMinutes() / 60d;
|
||||
done = done + now;
|
||||
todo = todo - now;
|
||||
}
|
||||
double progress = done / 8d;
|
||||
return progress;
|
||||
}
|
||||
void create(Activity activity);
|
||||
|
||||
List<Activity> list(int year, int month, int day);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.nanoboot.utils.timecalc.swing.common;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcConfiguration;
|
||||
import org.nanoboot.utils.timecalc.entity.Activity;
|
||||
import org.nanoboot.utils.timecalc.persistence.api.ActivityRepositoryApi;
|
||||
import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
|
||||
@ -40,6 +41,7 @@ public class DayPanel extends JPanel {
|
||||
|
||||
private final Map<String, DayPanel> map = new HashMap<>();
|
||||
private final ActivityRepositoryApi activityRepository;
|
||||
private final TimeCalcConfiguration timeCalcConfiguration;
|
||||
private JButton loadButton;
|
||||
private JScrollPane scrollPane;
|
||||
private JPanel panelInsideScrollPane;
|
||||
@ -47,13 +49,14 @@ public class DayPanel extends JPanel {
|
||||
private ActivityPanel markActivityPanelToBeMoved = null;
|
||||
|
||||
public DayPanel(String yearIn, String monthIn, String dayIn,
|
||||
ActivityRepositoryApi activityRepository) {
|
||||
ActivityRepositoryApi activityRepository, TimeCalcConfiguration timeCalcConfiguration) {
|
||||
super();
|
||||
|
||||
this.year = yearIn;
|
||||
this.month = monthIn;
|
||||
this.day = dayIn;
|
||||
this.activityRepository = activityRepository;
|
||||
this.timeCalcConfiguration = timeCalcConfiguration;
|
||||
setSize(1450, 600);
|
||||
|
||||
this.setLayout(null);
|
||||
@ -168,22 +171,41 @@ public class DayPanel extends JPanel {
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
clipboard.setContents(new StringSelection(comments), null);
|
||||
});
|
||||
|
||||
statusButton.addActionListener(e-> {
|
||||
// String neededFlags = timeCalcConfiguration.activityNeededFlagsProperty.getValue();
|
||||
// System.out.println("neededFlags=" + neededFlags);
|
||||
// neededFlags.replace(",", ":");
|
||||
// String[] neededFlagsArray = neededFlags.split(":");
|
||||
// Set<String> neededFlagsSet = Arrays.stream(neededFlagsArray).filter(f -> !f.isEmpty()).collect(Collectors.toSet());
|
||||
List<ActivityPanel> activityPanels = new ArrayList<>();
|
||||
Arrays
|
||||
.stream(panelInsideScrollPane.getComponents())
|
||||
.filter(c-> c instanceof ActivityPanel).forEach(f-> activityPanels.add((ActivityPanel) f));
|
||||
Collections.sort(activityPanels);
|
||||
|
||||
double done = 0d;
|
||||
double todo = 8d;
|
||||
for(ActivityPanel ap:activityPanels) {
|
||||
// double done = 0d;
|
||||
// double todo = 8d;
|
||||
// loopName:
|
||||
// for(ActivityPanel ap:activityPanels) {
|
||||
// Set<String> flags = ap.getActivity().flagsAsSet();
|
||||
// if(!neededFlagsSet.isEmpty()) {
|
||||
// for(String f:neededFlagsSet) {
|
||||
// if(!flags.contains(f)) {
|
||||
// continue loopName;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// double now = ap.getActivity().getSpentHours() + ap.getActivity().getSpentMinutes() / 60d;
|
||||
// done = done + now;
|
||||
// todo = todo - now;
|
||||
// }
|
||||
// double progress = done / 8d;
|
||||
double progress = activityRepository.getProgressForDay(Integer.valueOf(year), Integer.valueOf(month), Integer.valueOf(day), timeCalcConfiguration);
|
||||
|
||||
double now = ap.getActivity().getSpentHours() + ap.getActivity().getSpentMinutes() / 60d;
|
||||
done = done + now;
|
||||
todo = todo - now;
|
||||
}
|
||||
Utils.showNotification("Current status: done=" + NumberFormats.FORMATTER_TWO_DECIMAL_PLACES.format(done) + "h, todo="+ NumberFormats.FORMATTER_TWO_DECIMAL_PLACES.format(todo));
|
||||
double doneHours = progress * 8d;
|
||||
double todoHours = (8d - doneHours);
|
||||
Utils.showNotification("Current status: done=" + NumberFormats.FORMATTER_TWO_DECIMAL_PLACES.format(doneHours) + "h, todo="+ NumberFormats.FORMATTER_TWO_DECIMAL_PLACES.format(todoHours));
|
||||
|
||||
});
|
||||
sortActivityPanels();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.nanoboot.utils.timecalc.swing.common;
|
||||
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcConfiguration;
|
||||
import org.nanoboot.utils.timecalc.swing.controls.TTabbedPane;
|
||||
import org.nanoboot.utils.timecalc.persistence.api.ActivityRepositoryApi;
|
||||
|
||||
@ -24,10 +25,13 @@ public class MonthPanel extends JPanel {
|
||||
private final TTabbedPane tp;
|
||||
private final ActivityRepositoryApi activityRepository;
|
||||
private final Calendar cal;
|
||||
private final TimeCalcConfiguration timeCalcConfiguration;
|
||||
|
||||
private boolean loaded = false;
|
||||
public MonthPanel(String yearIn, String monthIn, ActivityRepositoryApi activityRepository) {
|
||||
public MonthPanel(String yearIn, String monthIn, ActivityRepositoryApi activityRepository, TimeCalcConfiguration timeCalcConfiguration) {
|
||||
super();
|
||||
this.activityRepository = activityRepository;
|
||||
this.timeCalcConfiguration = timeCalcConfiguration;
|
||||
|
||||
this.year = yearIn;
|
||||
this.month = monthIn;
|
||||
@ -69,7 +73,7 @@ public class MonthPanel extends JPanel {
|
||||
for (int day = 1; day <= maxDay; day++) {
|
||||
String dayS = String.valueOf(day);
|
||||
DayPanel dayPanel = new DayPanel(year, month, dayS,
|
||||
activityRepository);
|
||||
activityRepository, timeCalcConfiguration);
|
||||
tp.add(dayS, dayPanel);
|
||||
days.put(dayS, dayPanel);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.nanoboot.utils.timecalc.swing.common;
|
||||
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcConfiguration;
|
||||
import org.nanoboot.utils.timecalc.swing.controls.TTabbedPane;
|
||||
import org.nanoboot.utils.timecalc.persistence.api.ActivityRepositoryApi;
|
||||
|
||||
@ -20,12 +21,15 @@ public class YearPanel extends JPanel {
|
||||
private final Map<String, MonthPanel> months;
|
||||
private final TTabbedPane tp;
|
||||
private final ActivityRepositoryApi activityRepository;
|
||||
private final TimeCalcConfiguration timeCalcConfiguration;
|
||||
private boolean loaded = false;
|
||||
|
||||
public YearPanel(String yearIn, ActivityRepositoryApi activityRepository) {
|
||||
public YearPanel(String yearIn, ActivityRepositoryApi activityRepository, TimeCalcConfiguration timeCalcConfiguration) {
|
||||
super();
|
||||
this.year = yearIn;
|
||||
this.months = new HashMap<>();
|
||||
this.timeCalcConfiguration = timeCalcConfiguration;
|
||||
|
||||
setLayout(null);
|
||||
this.tp = new TTabbedPane();
|
||||
add(tp);
|
||||
@ -60,7 +64,7 @@ public class YearPanel extends JPanel {
|
||||
System.out.println("Loaded: " + year);
|
||||
for (int month = 1; month <= 12; month++) {
|
||||
final String monthS = String.valueOf(month);
|
||||
MonthPanel monthPanel = new MonthPanel(year, String.valueOf(month), activityRepository);
|
||||
MonthPanel monthPanel = new MonthPanel(year, String.valueOf(month), activityRepository, timeCalcConfiguration);
|
||||
tp.add(String.valueOf(month), monthPanel);
|
||||
months.put(monthS, monthPanel);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.nanoboot.utils.timecalc.swing.windows;
|
||||
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcConfiguration;
|
||||
import org.nanoboot.utils.timecalc.swing.controls.TWindow;
|
||||
import org.nanoboot.utils.timecalc.swing.controls.TTabbedPane;
|
||||
import java.util.HashMap;
|
||||
@ -27,7 +28,7 @@ public class ActivitiesWindow extends TWindow {
|
||||
private final ActivityRepositoryApi activityRepository;
|
||||
private final Map<String, YearPanel> years;
|
||||
|
||||
public ActivitiesWindow(ActivityRepositoryApi activityRepositoryApiIn, Time time) {
|
||||
public ActivitiesWindow(ActivityRepositoryApi activityRepositoryApiIn, Time time, TimeCalcConfiguration timeCalcConfiguration) {
|
||||
setSize(1600, 800);
|
||||
setTitle("Activities");
|
||||
this.activityRepository = activityRepositoryApiIn;
|
||||
@ -57,13 +58,13 @@ public class ActivitiesWindow extends TWindow {
|
||||
|
||||
tp.setBounds(addYearButton.getX(), addYearButton.getY() + addYearButton.getHeight() + SwingUtils.MARGIN, 1500, 750);
|
||||
yearsList.forEach(y -> {
|
||||
final YearPanel yearPanel = new YearPanel(y, activityRepository);
|
||||
final YearPanel yearPanel = new YearPanel(y, activityRepository, timeCalcConfiguration);
|
||||
tp.add(y, yearPanel);
|
||||
years.put(y, yearPanel);
|
||||
}
|
||||
);
|
||||
if (!yearsList.contains(currentYearS)) {
|
||||
YearPanel yearPanel = new YearPanel(currentYearS, activityRepository);
|
||||
YearPanel yearPanel = new YearPanel(currentYearS, activityRepository, timeCalcConfiguration);
|
||||
tp.add(currentYearS, yearPanel);
|
||||
years.put(currentYearS, yearPanel);
|
||||
}
|
||||
@ -84,7 +85,7 @@ public class ActivitiesWindow extends TWindow {
|
||||
throw new TimeCalcException(msg);
|
||||
}
|
||||
}
|
||||
YearPanel yearPanel = new YearPanel(year_, activityRepository);
|
||||
YearPanel yearPanel = new YearPanel(year_, activityRepository, timeCalcConfiguration);
|
||||
tp.add(year_, yearPanel);
|
||||
years.put(currentYearS, yearPanel);
|
||||
|
||||
|
@ -1,10 +1,14 @@
|
||||
package org.nanoboot.utils.timecalc.swing.windows;
|
||||
|
||||
import org.nanoboot.utils.timecalc.swing.controls.TButton;
|
||||
import org.nanoboot.utils.timecalc.swing.controls.TWindow;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcConfiguration;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.swing.common.SwingUtils;
|
||||
import org.nanoboot.utils.timecalc.swing.controls.MouseClickedListener;
|
||||
import org.nanoboot.utils.timecalc.swing.controls.TButton;
|
||||
import org.nanoboot.utils.timecalc.swing.controls.TTabbedPane;
|
||||
import org.nanoboot.utils.timecalc.swing.controls.TWindow;
|
||||
import org.nanoboot.utils.timecalc.utils.common.TTime;
|
||||
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
|
||||
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
||||
|
||||
@ -15,6 +19,7 @@ import javax.swing.JColorChooser;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextField;
|
||||
@ -34,8 +39,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.nanoboot.utils.timecalc.swing.common.SwingUtils;
|
||||
import org.nanoboot.utils.timecalc.swing.controls.TTabbedPane;
|
||||
|
||||
/**
|
||||
* @author Robert Vokac
|
||||
@ -50,6 +53,7 @@ public class ConfigWindow extends TWindow {
|
||||
public static final String THREE_DASHES = "---";
|
||||
private static final Font BIG_FONT = new Font("sans", Font.BOLD, 24);
|
||||
private static final String FIVE_SPACES = " ";
|
||||
private static final String EDITABLE_ONLY_IN_DIALOG = "editableOnlyInDialog";
|
||||
public final JComboBox visibilityDefaultProperty = new JComboBox(
|
||||
Arrays.stream(Visibility.values()).map(v -> v.name()).collect(
|
||||
Collectors.toList()).toArray());
|
||||
@ -174,6 +178,8 @@ public class ConfigWindow extends TWindow {
|
||||
= new JTextField();
|
||||
private final JTextField profileNameProperty
|
||||
= new JTextField();
|
||||
public final JTextField activityNeededFlagsProperty
|
||||
= new JTextField(TimeCalcProperty.ACTIVITY_NEEDED_FLAGS.getKey());
|
||||
private final JCheckBox testEnabledProperty
|
||||
= new JCheckBox(TimeCalcProperty.TEST_ENABLED.getKey());
|
||||
private final JTextField testClockCustomYearProperty
|
||||
@ -391,6 +397,7 @@ public class ConfigWindow extends TWindow {
|
||||
walkingHumanVisibleProperty,
|
||||
mainWindowCustomTitleProperty,
|
||||
profileNameProperty,
|
||||
activityNeededFlagsProperty,
|
||||
visibilityDefaultProperty,
|
||||
visibilitySupportedColoredProperty));
|
||||
//
|
||||
@ -435,6 +442,40 @@ public class ConfigWindow extends TWindow {
|
||||
p.putClientProperty(CLIENT_PROPERTY_KEY,
|
||||
TimeCalcProperty.PROFILE_NAME.getKey());
|
||||
}
|
||||
if (p == activityNeededFlagsProperty) {
|
||||
final JLabel jLabel = new JLabel(
|
||||
TimeCalcProperty.ACTIVITY_NEEDED_FLAGS.getDescription());
|
||||
jLabel.putClientProperty(CLIENT_PROPERTY_KEY,
|
||||
TimeCalcProperty.ACTIVITY_NEEDED_FLAGS.getKey());
|
||||
addToNextRow(jLabel);
|
||||
p.putClientProperty(CLIENT_PROPERTY_KEY,
|
||||
TimeCalcProperty.ACTIVITY_NEEDED_FLAGS.getKey());
|
||||
activityNeededFlagsProperty.setEditable(false);
|
||||
activityNeededFlagsProperty.setBackground(Color.WHITE);
|
||||
activityNeededFlagsProperty.putClientProperty(
|
||||
EDITABLE_ONLY_IN_DIALOG, "");
|
||||
activityNeededFlagsProperty
|
||||
.addMouseListener((MouseClickedListener) f -> {
|
||||
|
||||
String result =
|
||||
(String) JOptionPane.showInputDialog(
|
||||
null,
|
||||
"Select new value",
|
||||
"New value",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
null,
|
||||
activityNeededFlagsProperty
|
||||
.getText()
|
||||
);
|
||||
if (result != null) {
|
||||
activityNeededFlagsProperty.setText(result);
|
||||
timeCalcConfiguration.activityNeededFlagsProperty.setValue(result);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (p == testClockCustomYearProperty) {
|
||||
JLabel label = new JLabel("Test");
|
||||
label.setFont(BIG_FONT);
|
||||
@ -584,7 +625,7 @@ public class ConfigWindow extends TWindow {
|
||||
timeCalcConfiguration
|
||||
.getProperty(timeCalcProperty).addListener(e -> {
|
||||
|
||||
textField.setText(isInteger
|
||||
textField.setText(isInteger
|
||||
? String.valueOf(timeCalcConfiguration
|
||||
.getProperty(timeCalcProperty).getValue())
|
||||
: (String) timeCalcConfiguration
|
||||
@ -609,6 +650,9 @@ public class ConfigWindow extends TWindow {
|
||||
}
|
||||
|
||||
private void update(DocumentEvent e) {
|
||||
if(textField.getClientProperty(EDITABLE_ONLY_IN_DIALOG) != null) {
|
||||
return;
|
||||
}
|
||||
String text = textField.getText();
|
||||
boolean isInteger = Integer.class == timeCalcProperty.getClazz();
|
||||
timeCalcConfiguration
|
||||
|
@ -30,7 +30,6 @@ import org.nanoboot.utils.timecalc.swing.progress.DayBattery;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.HourBattery;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.MinuteBattery;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.MonthBattery;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.PlaceHolderWidget;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.ProgressCircle;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.ProgressSquare;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.Time;
|
||||
@ -45,7 +44,6 @@ import org.nanoboot.utils.timecalc.utils.common.TTime;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||
import org.nanoboot.utils.timecalc.utils.property.ChangeListener;
|
||||
import org.nanoboot.utils.timecalc.utils.property.IntegerProperty;
|
||||
import org.nanoboot.utils.timecalc.utils.property.Property;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFrame;
|
||||
@ -475,7 +473,7 @@ public class MainWindow extends TWindow {
|
||||
});
|
||||
activitiesButton.addActionListener(e -> {
|
||||
if (activitiesWindow == null) {
|
||||
this.activitiesWindow = new ActivitiesWindow(this.activityRepository, time);
|
||||
this.activitiesWindow = new ActivitiesWindow(this.activityRepository, time, timeCalcConfiguration);
|
||||
}
|
||||
activitiesWindow.setVisible(true);
|
||||
});
|
||||
|
@ -61,3 +61,4 @@ test.clock.custom.millisecond=2147483647
|
||||
logs.detailed=false
|
||||
battery.percent-precision.count-of-decimal-points=5
|
||||
main-window.custom-title=---
|
||||
activity.needed-flags=
|
||||
|
Loading…
x
Reference in New Issue
Block a user