Added several improvements, changes and bug fixes

This commit is contained in:
Robert Vokac 2024-03-16 16:44:28 +00:00
parent 1e518b5964
commit 2e338de4d2
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
5 changed files with 72 additions and 70 deletions

View File

@ -39,7 +39,7 @@ public class Activity implements Comparable<Activity> {
} }
public String createTotalComment() { public String createTotalComment() {
return ticket + SUBJECT_FIELD_SEPARATOR + year + "-" + month + "-" + day return ticket + SUBJECT_FIELD_SEPARATOR + year + "-" + (month < 10 ? "0" : "") + month + "-" + (day < 10 ? "0" : "") + day
+ SUBJECT_FIELD_SEPARATOR + ( + SUBJECT_FIELD_SEPARATOR + (
NumberFormats.FORMATTER_TWO_DECIMAL_PLACES.format(spentHours + spentMinutes / 60d) NumberFormats.FORMATTER_TWO_DECIMAL_PLACES.format(spentHours + spentMinutes / 60d)
+ "h") + SUBJECT_FIELD_SEPARATOR + "h") + SUBJECT_FIELD_SEPARATOR

View File

@ -28,6 +28,6 @@ public interface ActivityRepositoryApi {
public Activity getFromClipboard(); public Activity getFromClipboard();
public int getLargestSortkey(int year, int month, int day); public int getNextSortkey(int year, int month, int day);
} }

View File

@ -349,15 +349,21 @@ public class ActivityRepositorySQLiteImpl implements ActivityRepositoryApi {
} }
@Override @Override
public int getLargestSortkey(int year, int month, int day) { public int getNextSortkey(int year, int month, int day) {
OptionalInt optional = OptionalInt optional =
list(year, month, day).stream().map(Activity::getSortkey) list(year, month, day).stream().map(Activity::getSortkey)
.mapToInt(e -> e).max(); .mapToInt(e -> e).max();
if (optional.isPresent()) { if (optional.isPresent()) {
System.out.println("getLargestSortkey=" +optional.getAsInt()); System.out.println("getLargestSortkey=" +optional.getAsInt());
return optional.getAsInt(); int result = optional.getAsInt() + 10;
if(result % 10 != 0) {
while(result % 10 != 0) {
result++;
}
}
return result;
} else { } else {
return 1; return 10;
} }
} }

View File

@ -16,6 +16,7 @@ import java.awt.FlowLayout;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.StringSelection;
import java.util.function.Consumer;
/** /**
* @author Robert * @author Robert
@ -23,6 +24,45 @@ import java.awt.datatransfer.StringSelection;
*/ */
public class ActivityPanel extends JPanel implements Comparable<ActivityPanel> { public class ActivityPanel extends JPanel implements Comparable<ActivityPanel> {
@Getter
private final DayPanel dayPanel;
class TTextFieldForActivityPanel extends TTextField {
public TTextFieldForActivityPanel(String s, String name, Consumer<String> consumer, boolean sort) {
super(s);
setEditable(false);
setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
setCaretPosition(0);
if(consumer != null) {
addMouseListener((MouseClickedListener) e -> {
String result = (String) JOptionPane.showInputDialog(
null,
"Select new " + name,
"New " + name,
JOptionPane.PLAIN_MESSAGE,
null,
null,
getText()
);
if (result != null) {
consumer.accept(result);
activityRepository.update(activity);
setText(result);
if(sort) {
dayPanel.sortActivityPanels();
}
setCaretPosition(0);
}
});
}
}
public TTextFieldForActivityPanel(String s, String name) {
this(s, name, null, false);
}
}
public static final Dimension PREFERRED_SIZE = new Dimension(200, 40); public static final Dimension PREFERRED_SIZE = new Dimension(200, 40);
public static final Dimension PREFERRED_SIZE1 = new Dimension(80, 40); public static final Dimension PREFERRED_SIZE1 = new Dimension(80, 40);
public static final Dimension PREFERRED_SIZE3 = new Dimension(60, 40); public static final Dimension PREFERRED_SIZE3 = new Dimension(60, 40);
@ -32,17 +72,18 @@ public class ActivityPanel extends JPanel implements Comparable<ActivityPanel> {
@Getter @Getter
private final Activity activity; private final Activity activity;
private TTextField sortkey = new TTextField("1"); private TTextField sortkey = new TTextFieldForActivityPanel("1", "sortkey", (r)->getActivity().setSortkey(
private TTextField name = new TTextField(""); Integer.parseInt(r)), true);
private TTextField comment = new TTextField(""); private TTextField name = new TTextFieldForActivityPanel("", "name");
private TTextField ticket = new TTextField(""); private TTextField comment = new TTextFieldForActivityPanel("", "comment");
private TTextField spentTime = new TTextField("00:00"); private TTextField ticket = new TTextFieldForActivityPanel("", "ticket");
private TTextField spentTime = new TTextFieldForActivityPanel("00:00", "spentTime");
private TTextField flags = new TTextField("Flags"); private TTextField flags = new TTextFieldForActivityPanel("Flags", "flags");
private TTextField subject = new TTextField(""); private TTextField subject = new TTextFieldForActivityPanel("", "subject");
private TTextField totalComment = new TTextField(""); private TTextField totalComment = new TTextFieldForActivityPanel("", "totalComment");
public TTextField today = new TTextField("00:00"); public TTextField today = new TTextFieldForActivityPanel("00:00", "today");
public TTextField remains = new TTextField("00:00"); public TTextField remains = new TTextFieldForActivityPanel("00:00", "remains");
@Getter @Getter
private boolean deleted; private boolean deleted;
@ -51,6 +92,7 @@ public class ActivityPanel extends JPanel implements Comparable<ActivityPanel> {
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
this.activity = activity; this.activity = activity;
this.dayPanel = dayPanel;
add(sortkey); add(sortkey);
add(name); add(name);
add(comment); add(comment);
@ -66,21 +108,15 @@ public class ActivityPanel extends JPanel implements Comparable<ActivityPanel> {
comment.setHorizontalAlignment(JTextField.LEFT); comment.setHorizontalAlignment(JTextField.LEFT);
ticket.setHorizontalAlignment(JTextField.LEFT); ticket.setHorizontalAlignment(JTextField.LEFT);
// JButton moveThisButton = new SmallTButton("Move ");
// JButton moveBeforeButton = new SmallTButton("Here");
JButton copyButton = new SmallTButton("Copy"); JButton copyButton = new SmallTButton("Copy");
JButton deleteButton = new SmallTButton("Delete"); JButton deleteButton = new SmallTButton("Delete");
JButton subjectButton = new SmallTButton("Sub"); JButton subjectButton = new SmallTButton("Sub");
JButton totalCommentButton = new SmallTButton("TotCom"); JButton totalCommentButton = new SmallTButton("TotCom");
// add(moveThisButton);
// add(moveBeforeButton);
add(copyButton); add(copyButton);
add(deleteButton); add(deleteButton);
add(subjectButton); add(subjectButton);
add(totalCommentButton); add(totalCommentButton);
// moveThisButton.setFont(SwingUtils.SMALL_FONT);
// moveBeforeButton.setFont(SwingUtils.SMALL_FONT);
copyButton.setFont(SwingUtils.SMALL_FONT); copyButton.setFont(SwingUtils.SMALL_FONT);
deleteButton.setFont(SwingUtils.SMALL_FONT); deleteButton.setFont(SwingUtils.SMALL_FONT);
subjectButton.setFont(SwingUtils.SMALL_FONT); subjectButton.setFont(SwingUtils.SMALL_FONT);
@ -98,56 +134,12 @@ public class ActivityPanel extends JPanel implements Comparable<ActivityPanel> {
today.setPreferredSize(PREFERRED_SIZE3); today.setPreferredSize(PREFERRED_SIZE3);
remains.setPreferredSize(PREFERRED_SIZE3); remains.setPreferredSize(PREFERRED_SIZE3);
// moveThisButton.setPreferredSize(PREFERRED_SIZE4);
// moveBeforeButton.setPreferredSize(PREFERRED_SIZE4);
copyButton.setPreferredSize(PREFERRED_SIZE4); copyButton.setPreferredSize(PREFERRED_SIZE4);
deleteButton.setPreferredSize(PREFERRED_SIZE4); deleteButton.setPreferredSize(PREFERRED_SIZE4);
subjectButton.setPreferredSize(PREFERRED_SIZE4); subjectButton.setPreferredSize(PREFERRED_SIZE4);
totalCommentButton.setPreferredSize(PREFERRED_SIZE3); totalCommentButton.setPreferredSize(PREFERRED_SIZE3);
this.setPreferredSize(new Dimension(getWidth(), 40)); this.setPreferredSize(new Dimension(getWidth(), 40));
sortkey.setEditable(false);
name.setEditable(false);
comment.setEditable(false);
ticket.setEditable(false);
spentTime.setEditable(false);
flags.setEditable(false);
subject.setEditable(false);
totalComment.setEditable(false);
today.setEditable(false);
remains.setEditable(false);
sortkey.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
name.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
comment.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
ticket.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
spentTime.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
flags.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
subject.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
totalComment.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
today.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
remains.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
sortkey.addMouseListener((MouseClickedListener) e -> {
String result = (String) JOptionPane.showInputDialog(
null,
"Select new sortkey",
"New sortkey",
JOptionPane.PLAIN_MESSAGE,
null,
null,
sortkey.getText()
);
if (result != null) {
activity.setSortkey(Integer.valueOf(result));
activityRepository.update(activity);
sortkey.setText(result);
dayPanel.sortActivityPanels();
}
});
name.addMouseListener((MouseClickedListener) e -> { name.addMouseListener((MouseClickedListener) e -> {
String result = (String) JOptionPane.showInputDialog( String result = (String) JOptionPane.showInputDialog(
null, null,
@ -238,6 +230,7 @@ public class ActivityPanel extends JPanel implements Comparable<ActivityPanel> {
} }
}); });
sortkey.setText(String.valueOf(activity.getSortkey()));
name.setText(activity.getName()); name.setText(activity.getName());
comment.setText(activity.getComment()); comment.setText(activity.getComment());
ticket.setText(activity.getTicket()); ticket.setText(activity.getTicket());
@ -245,7 +238,7 @@ public class ActivityPanel extends JPanel implements Comparable<ActivityPanel> {
flags.setText(activity.getFlags()); flags.setText(activity.getFlags());
subject.setText(activity.createSubject()); subject.setText(activity.createSubject());
totalComment.setText(activity.createTotalComment()); totalComment.setText(activity.createTotalComment());
sortkey.setText(String.valueOf(activity.getSortkey()));
name.setFont(SwingUtils.VERY_SMALL_FONT); name.setFont(SwingUtils.VERY_SMALL_FONT);
comment.setFont(SwingUtils.VERY_SMALL_FONT); comment.setFont(SwingUtils.VERY_SMALL_FONT);
ticket.setFont(SwingUtils.VERY_SMALL_FONT); ticket.setFont(SwingUtils.VERY_SMALL_FONT);
@ -262,6 +255,7 @@ public class ActivityPanel extends JPanel implements Comparable<ActivityPanel> {
// }); // });
deleteButton.addActionListener(e -> { deleteButton.addActionListener(e -> {
activityRepository.delete(this.activity.getId()); activityRepository.delete(this.activity.getId());
this.setVisible(false);
deleted = true; deleted = true;
}); });
copyButton.addActionListener(e -> { copyButton.addActionListener(e -> {

View File

@ -129,7 +129,7 @@ public class DayPanel extends JPanel {
}).start(); }).start();
revalidate(); revalidate();
newButton.addActionListener(e-> { newButton.addActionListener(e-> {
Activity newActivity = new Activity(UUID.randomUUID().toString(), Integer.valueOf(year), Integer.valueOf(month), Integer.valueOf(day), "", "", "", 0, 0, "", 1 + activityRepository.getLargestSortkey(Integer.valueOf(year), Integer.valueOf(month), Integer.valueOf(day))); Activity newActivity = new Activity(UUID.randomUUID().toString(), Integer.valueOf(year), Integer.valueOf(month), Integer.valueOf(day), "", "", "", 0, 0, "", activityRepository.getNextSortkey(Integer.valueOf(year), Integer.valueOf(month), Integer.valueOf(day)));
ActivityPanel comp = ActivityPanel comp =
new ActivityPanel(activityRepository, newActivity, this); new ActivityPanel(activityRepository, newActivity, this);
comp.setMaximumSize(new Dimension(1200, 40)); comp.setMaximumSize(new Dimension(1200, 40));
@ -147,7 +147,7 @@ public class DayPanel extends JPanel {
return; return;
} }
Activity newActivity = new Activity(UUID.randomUUID().toString(), Integer.valueOf(year), Integer.valueOf(month), Integer.valueOf(day), Activity newActivity = new Activity(UUID.randomUUID().toString(), Integer.valueOf(year), Integer.valueOf(month), Integer.valueOf(day),
afc.getName(), afc.getComment(), afc.getTicket(), 0, 0, "", 1 + activityRepository.getLargestSortkey(Integer.valueOf(year), Integer.valueOf(month), Integer.valueOf(day))); afc.getName(), afc.getComment(), afc.getTicket(), 0, 0, "", activityRepository.getNextSortkey(Integer.valueOf(year), Integer.valueOf(month), Integer.valueOf(day)));
ActivityPanel comp = ActivityPanel comp =
new ActivityPanel(activityRepository, newActivity, this); new ActivityPanel(activityRepository, newActivity, this);
comp.setMaximumSize(new Dimension(1200, 40)); comp.setMaximumSize(new Dimension(1200, 40));
@ -183,7 +183,7 @@ public class DayPanel extends JPanel {
done = done + now; done = done + now;
todo = todo - 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)); Utils.showNotification("Current status: done=" + NumberFormats.FORMATTER_TWO_DECIMAL_PLACES.format(done) + "h, todo="+ NumberFormats.FORMATTER_TWO_DECIMAL_PLACES.format(todo));
}); });
// for (int i = 0; i < 10; i++) { // for (int i = 0; i < 10; i++) {
@ -241,6 +241,8 @@ public class DayPanel extends JPanel {
ap.today.setText(TTime.ofMilliseconds((int)(done * 60d * 60d * 1000d)).toString().substring(0,5)); ap.today.setText(TTime.ofMilliseconds((int)(done * 60d * 60d * 1000d)).toString().substring(0,5));
ap.remains.setText(TTime.ofMilliseconds((int)(todo * 60d * 60d * 1000d)).toString().substring(0,5)); ap.remains.setText(TTime.ofMilliseconds((int)(todo * 60d * 60d * 1000d)).toString().substring(0,5));
panelInsideScrollPane.add(ap); panelInsideScrollPane.add(ap);
ap.setVisible(false);
ap.setVisible(true);
ap.revalidate(); ap.revalidate();
} }