Added several improvements, changes and bug fixes

This commit is contained in:
Robert Vokac 2024-03-16 13:17:22 +00:00
parent 82f8c9b683
commit d7feedcf1f
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
6 changed files with 118 additions and 21 deletions

View File

@ -74,7 +74,7 @@ public class ActivityRepositorySQLiteImpl implements ActivityRepositoryApi {
@Override
public void delete(String id) {
System.out.println("Going to delete: " + id);
Activity activityToBeDeleted = read(id);
if(!Utils.askYesNo(null, "Do you really want to delete this activity? " + read(id), "Deletion of activity")) {
return;
}
@ -103,6 +103,13 @@ public class ActivityRepositorySQLiteImpl implements ActivityRepositoryApi {
ex.printStackTrace();
throw new TimeCalcException(ex);
}
Activity previousActivity = getPreviousActivity(id);
Activity nextActivity = read(activityToBeDeleted.getNextActivityId());
if(previousActivity != null) {
previousActivity.setNextActivityId(nextActivity == null ? null : nextActivity.getId());
update(previousActivity);
}
}
@Override

View File

@ -49,13 +49,13 @@ public class ActivitiesWindow extends TWindow {
tp.setBounds(addYearButton.getX(), addYearButton.getY() + addYearButton.getHeight() + SwingUtils.MARGIN, 1180, 600);
yearsList.forEach(y -> {
final YearPanel yearPanel = new YearPanel(y);
final YearPanel yearPanel = new YearPanel(y, activityRepository);
tp.add(y, yearPanel);
years.put(y, yearPanel);
}
);
if (!yearsList.contains(currentYearS)) {
YearPanel yearPanel = new YearPanel(currentYearS);
YearPanel yearPanel = new YearPanel(currentYearS, activityRepository);
tp.add(currentYearS, yearPanel);
years.put(currentYearS, yearPanel);
}
@ -76,7 +76,7 @@ public class ActivitiesWindow extends TWindow {
throw new TimeCalcException(msg);
}
}
YearPanel yearPanel = new YearPanel(year_);
YearPanel yearPanel = new YearPanel(year_, activityRepository);
tp.add(year_, yearPanel);
years.put(currentYearS, yearPanel);

View File

@ -0,0 +1,57 @@
package org.nanoboot.utils.timecalc.swing.common;
import org.nanoboot.utils.timecalc.entity.Activity;
import org.nanoboot.utils.timecalc.persistence.api.ActivityRepositoryApi;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
/**
* @author Robert
* @since 13.03.2024
*/
public class ActivityPanel extends JPanel {
private final ActivityRepositoryApi activityRepository;
private String id;
private int year;
private int month;
private int day;
private TTextField name = new TTextField("");
private TTextField comment = new TTextField("");
private TTextField ticket = new TTextField("");
private TTextField spentHours = new TTextField("");
private TTextField spentMinutes = new TTextField("");
private TTextField flags = new TTextField("");
private String nextActivityId;
public ActivityPanel(ActivityRepositoryApi activityRepository, Activity activity) {
this.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 0));
add(name);
add(comment);
add(ticket);
add(spentHours);
add(spentMinutes);
add(flags);
name.setPreferredSize(new Dimension(100, 40));
comment.setPreferredSize(new Dimension(100, 40));
ticket.setPreferredSize(new Dimension(100, 40));
spentHours.setPreferredSize(new Dimension(100, 40));
spentMinutes.setPreferredSize(new Dimension(100, 40));
flags.setPreferredSize(new Dimension(100, 40));
name.setText(activity.getName());
comment.setText(activity.getComment());
ticket.setText(activity.getTicket());
spentHours.setText(String.valueOf(activity.getSpentHours()));
spentMinutes.setText(String.valueOf(activity.getSpentMinutes()));
flags.setText(activity.getFlags());
this.activityRepository = activityRepository;
this.setBackground(Color.BLUE);
this.setBorder(BorderFactory.createLineBorder(Color.green));
setAlignmentX(LEFT_ALIGNMENT);
}
}

View File

@ -1,13 +1,16 @@
package org.nanoboot.utils.timecalc.swing.common;
import java.util.HashMap;
import java.util.Map;
import org.nanoboot.utils.timecalc.entity.Activity;
import org.nanoboot.utils.timecalc.persistence.api.ActivityRepositoryApi;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.FlowLayout;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author robertvokac
*/
public class DayPanel extends JPanel {
@ -17,25 +20,51 @@ public class DayPanel extends JPanel {
private final String day;
private final Map<String, DayPanel> map = new HashMap<>();
private final ActivityRepositoryApi activityRepository;
private JButton loadButton;
public DayPanel(String yearIn, String monthIn, String dayIn) {
public DayPanel(String yearIn, String monthIn, String dayIn,
ActivityRepositoryApi activityRepository) {
super();
this.year = yearIn;
this.month = monthIn;
this.day = dayIn;
this.activityRepository = activityRepository;
setSize(1050, 600);
this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
JButton addButton = new JButton("Add");
JButton addButton2 = new JButton("Add");
JButton addButton3 = new JButton("Add");
JButton addButton4 = new JButton("Add");
add(addButton);
add(addButton2);
add(addButton3);
add(addButton4);
this.setLayout(null);
this.loadButton = new JButton("Load");
this.loadButton.setBounds(10, 10, 200, 30);
this.loadButton.addActionListener(e -> load(activityRepository));
add(loadButton);
}
private void load(ActivityRepositoryApi activityRepository) {
if (this.loadButton.isVisible()) {
this.loadButton.setVisible(false);
this.loadButton = null;
}
BoxLayout boxLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
this.setAlignmentX(LEFT_ALIGNMENT);
this.setLayout(boxLayout);
JPanel buttons = new JPanel();
buttons.setLayout(new FlowLayout(FlowLayout.LEFT));
buttons.setAlignmentX(LEFT_ALIGNMENT);
JButton newButton = new JButton("New");
JButton pasteButton = new JButton("Paste");
buttons.add(newButton);
buttons.add(pasteButton);
add(buttons);
for (int i = 0; i < 10; i++) {
add(new ActivityPanel(activityRepository,
new Activity("aaa", 2000, 7, 7, "a", "b", "c", 2, 30,
"a b c", null)));
}
}
}

View File

@ -1,5 +1,7 @@
package org.nanoboot.utils.timecalc.swing.common;
import org.nanoboot.utils.timecalc.persistence.api.ActivityRepositoryApi;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
@ -18,7 +20,7 @@ public class MonthPanel extends JPanel {
private final Map<String, DayPanel> days;
private final TTabbedPane tp;
public MonthPanel(String yearIn, String monthIn) {
public MonthPanel(String yearIn, String monthIn, ActivityRepositoryApi activityRepository) {
super();
this.year = yearIn;
@ -36,7 +38,7 @@ public class MonthPanel extends JPanel {
int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int day = 1; day <= maxDay; day++) {
String dayS = String.valueOf(day);
DayPanel dayPanel = new DayPanel(year, month, dayS);
DayPanel dayPanel = new DayPanel(year, month, dayS, activityRepository);
tp.add(dayS, dayPanel);
days.put(dayS, dayPanel);
}

View File

@ -1,5 +1,7 @@
package org.nanoboot.utils.timecalc.swing.common;
import org.nanoboot.utils.timecalc.persistence.api.ActivityRepositoryApi;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JPanel;
@ -14,7 +16,7 @@ public class YearPanel extends JPanel {
private final Map<String, MonthPanel> months;
private final TTabbedPane tp;
public YearPanel(String yearIn) {
public YearPanel(String yearIn, ActivityRepositoryApi activityRepository) {
super();
this.year = yearIn;
this.months = new HashMap<>();
@ -24,7 +26,7 @@ public class YearPanel extends JPanel {
tp.setBounds(0, 0, 1150, 700);
for (int month = 1; month <= 12; month++) {
final String monthS = String.valueOf(month);
MonthPanel monthPanel = new MonthPanel(year, String.valueOf(month));
MonthPanel monthPanel = new MonthPanel(year, String.valueOf(month), activityRepository);
tp.add(String.valueOf(month), monthPanel);
months.put(monthS, monthPanel);
}