Added several improvements, changes and bug fixes
This commit is contained in:
parent
2e338de4d2
commit
97aa529b62
@ -70,7 +70,7 @@ public class ActivitiesWindow extends TWindow {
|
||||
try {
|
||||
Integer.parseInt(year_);
|
||||
} catch (NumberFormatException ex) {
|
||||
JOptionPane.showMessageDialog(this, "Error: this is not year: " + currentYear);
|
||||
JOptionPane.showMessageDialog(this, "Error: this is not year: " + year_);
|
||||
throw ex;
|
||||
}
|
||||
for (int i = 0; i < tp.getTabCount(); i++) {
|
||||
@ -100,6 +100,7 @@ public class ActivitiesWindow extends TWindow {
|
||||
}
|
||||
};
|
||||
tp.addChangeListener(changeListener);
|
||||
tp.switchTo(currentYearS);
|
||||
getYearPanel(currentYearS).setSelectedMonth(currentMonthS);
|
||||
getYearPanel(currentYearS).getMonthPanel(currentMonthS).setSelectedDay(currentDayS);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.nanoboot.utils.timecalc.swing.common;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.nanoboot.utils.timecalc.entity.Activity;
|
||||
import org.nanoboot.utils.timecalc.persistence.api.ActivityRepositoryApi;
|
||||
@ -13,10 +14,7 @@ import javax.swing.JTextField;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* @author Robert
|
||||
@ -26,42 +24,56 @@ public class ActivityPanel extends JPanel implements Comparable<ActivityPanel> {
|
||||
|
||||
@Getter
|
||||
private final DayPanel dayPanel;
|
||||
|
||||
private boolean mouseOver;
|
||||
class TTextFieldForActivityPanel extends TTextField {
|
||||
|
||||
public TTextFieldForActivityPanel(String s, String name, Consumer<String> consumer, boolean sort) {
|
||||
public TTextFieldForActivityPanel(String s, String name) {
|
||||
this(s, name, null);
|
||||
}
|
||||
public TTextFieldForActivityPanel(String s, String name, BiConsumer<Activity, String> additionalAction) {
|
||||
this(s, name, additionalAction, false);
|
||||
}
|
||||
public TTextFieldForActivityPanel(String s, String name, BiConsumer<Activity, String> additionalAction, boolean sort) {
|
||||
super(s);
|
||||
setEditable(false);
|
||||
setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
setCaretPosition(0);
|
||||
//setToolTipText(s);
|
||||
|
||||
if(consumer != null) {
|
||||
if(additionalAction != null) {
|
||||
addMouseListener((MouseClickedListener) e -> {
|
||||
String result = (String) JOptionPane.showInputDialog(
|
||||
null,
|
||||
"Select new " + name,
|
||||
"New " + name,
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
name.equals("comment") ? JOptionPane.QUESTION_MESSAGE : JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
null,
|
||||
getText()
|
||||
);
|
||||
if (result != null) {
|
||||
consumer.accept(result);
|
||||
additionalAction.accept(activity, result);
|
||||
activityRepository.update(activity);
|
||||
setText(result);
|
||||
if(sort) {
|
||||
dayPanel.sortActivityPanels();
|
||||
}
|
||||
setCaretPosition(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public TTextFieldForActivityPanel(String s, String name) {
|
||||
this(s, name, null, false);
|
||||
public void setText(String text) {
|
||||
super.setText(text);
|
||||
//if(!text.isEmpty()) {
|
||||
//setToolTipText(text);
|
||||
setCaretPosition(0);
|
||||
//} else {
|
||||
// setToolTipText(null);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
public static final Dimension PREFERRED_SIZE = new Dimension(200, 40);
|
||||
public static final Dimension PREFERRED_SIZE1 = new Dimension(80, 40);
|
||||
@ -72,18 +84,23 @@ public class ActivityPanel extends JPanel implements Comparable<ActivityPanel> {
|
||||
@Getter
|
||||
private final Activity activity;
|
||||
|
||||
private TTextField sortkey = new TTextFieldForActivityPanel("1", "sortkey", (r)->getActivity().setSortkey(
|
||||
Integer.parseInt(r)), true);
|
||||
private TTextField name = new TTextFieldForActivityPanel("", "name");
|
||||
private TTextField comment = new TTextFieldForActivityPanel("", "comment");
|
||||
private TTextField ticket = new TTextFieldForActivityPanel("", "ticket");
|
||||
private TTextField spentTime = new TTextFieldForActivityPanel("00:00", "spentTime");
|
||||
private final TTextField sortkey;
|
||||
private final TTextField name;
|
||||
private final TTextField comment;
|
||||
private final TTextField ticket;
|
||||
|
||||
private final TTextField spentTime;
|
||||
|
||||
private final TTextField flags;
|
||||
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private final TTextField subject;
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private final TTextField totalComment;
|
||||
|
||||
public final TTextField today;
|
||||
public final TTextField remains;
|
||||
|
||||
private TTextField flags = new TTextFieldForActivityPanel("Flags", "flags");
|
||||
private TTextField subject = new TTextFieldForActivityPanel("", "subject");
|
||||
private TTextField totalComment = new TTextFieldForActivityPanel("", "totalComment");
|
||||
public TTextField today = new TTextFieldForActivityPanel("00:00", "today");
|
||||
public TTextField remains = new TTextFieldForActivityPanel("00:00", "remains");
|
||||
@Getter
|
||||
private boolean deleted;
|
||||
|
||||
@ -92,6 +109,30 @@ public class ActivityPanel extends JPanel implements Comparable<ActivityPanel> {
|
||||
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
||||
this.activity = activity;
|
||||
|
||||
{
|
||||
this.subject = new TTextFieldForActivityPanel("", "subject");
|
||||
this.totalComment = new TTextFieldForActivityPanel("", "totalComment");
|
||||
this.sortkey = new TTextFieldForActivityPanel("1", "sortkey", (a, r)->a.setSortkey(Integer.parseInt(r)), true);
|
||||
this.name = new TTextFieldForActivityPanel("", "name", (a, r)->{a.setName(r);getSubject().setText(a.createSubject());}, false);
|
||||
this.comment = new TTextFieldForActivityPanel("", "comment", (a, r)->{a.setComment(r);getTotalComment().setText(a.createTotalComment());}, false);
|
||||
this.ticket = new TTextFieldForActivityPanel("", "ticket",
|
||||
(a, r) -> {a.setTicket(r);
|
||||
getSubject().setText(a.createSubject());
|
||||
getTotalComment().setText(a.createTotalComment());}, false);
|
||||
|
||||
this.spentTime =
|
||||
new TTextFieldForActivityPanel("00:00", "spentTime", (a, r) -> {
|
||||
TTime spentTimeTTime = new TTime(r);
|
||||
getActivity().setSpentHours(spentTimeTTime.getHour());
|
||||
getActivity().setSpentMinutes(spentTimeTTime.getMinute());
|
||||
getTotalComment().setText(getActivity().createTotalComment());
|
||||
}, true);
|
||||
|
||||
this.flags = new TTextFieldForActivityPanel("Flags", "flags", (a, r)->a.setFlags(r), false);
|
||||
this.today = new TTextFieldForActivityPanel("00:00", "today");
|
||||
this.remains = new TTextFieldForActivityPanel("00:00", "remains");
|
||||
}
|
||||
|
||||
this.dayPanel = dayPanel;
|
||||
add(sortkey);
|
||||
add(name);
|
||||
@ -110,17 +151,15 @@ public class ActivityPanel extends JPanel implements Comparable<ActivityPanel> {
|
||||
|
||||
JButton copyButton = new SmallTButton("Copy");
|
||||
JButton deleteButton = new SmallTButton("Delete");
|
||||
JButton subjectButton = new SmallTButton("Sub");
|
||||
JButton totalCommentButton = new SmallTButton("TotCom");
|
||||
JButton moveButton = new SmallTButton("Move");
|
||||
|
||||
add(copyButton);
|
||||
add(deleteButton);
|
||||
add(subjectButton);
|
||||
add(totalCommentButton);
|
||||
add(moveButton);
|
||||
|
||||
copyButton.setFont(SwingUtils.SMALL_FONT);
|
||||
deleteButton.setFont(SwingUtils.SMALL_FONT);
|
||||
subjectButton.setFont(SwingUtils.SMALL_FONT);
|
||||
totalCommentButton.setFont(SwingUtils.SMALL_FONT);
|
||||
moveButton.setFont(SwingUtils.SMALL_FONT);
|
||||
|
||||
sortkey.setPreferredSize(PREFERRED_SIZE1);
|
||||
name.setPreferredSize(PREFERRED_SIZE);
|
||||
@ -136,100 +175,9 @@ public class ActivityPanel extends JPanel implements Comparable<ActivityPanel> {
|
||||
|
||||
copyButton.setPreferredSize(PREFERRED_SIZE4);
|
||||
deleteButton.setPreferredSize(PREFERRED_SIZE4);
|
||||
subjectButton.setPreferredSize(PREFERRED_SIZE4);
|
||||
totalCommentButton.setPreferredSize(PREFERRED_SIZE3);
|
||||
moveButton.setPreferredSize(PREFERRED_SIZE4);
|
||||
this.setPreferredSize(new Dimension(getWidth(), 40));
|
||||
|
||||
name.addMouseListener((MouseClickedListener) e -> {
|
||||
String result = (String) JOptionPane.showInputDialog(
|
||||
null,
|
||||
"Select new name",
|
||||
"New name",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
null,
|
||||
name.getText()
|
||||
);
|
||||
if (result != null) {
|
||||
activity.setName(result);
|
||||
activityRepository.update(activity);
|
||||
name.setText(result);
|
||||
subject.setText(activity.createSubject());
|
||||
}
|
||||
});
|
||||
comment.addMouseListener((MouseClickedListener) e -> {
|
||||
String result = (String) JOptionPane.showInputDialog(
|
||||
null,
|
||||
"Select new comment",
|
||||
"New comment",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
null,
|
||||
comment.getText()
|
||||
);
|
||||
if (result != null) {
|
||||
activity.setComment(result);
|
||||
activityRepository.update(activity);
|
||||
comment.setText(result);
|
||||
totalComment.setText(activity.createTotalComment());
|
||||
}
|
||||
});
|
||||
ticket.addMouseListener((MouseClickedListener) e -> {
|
||||
String result = (String) JOptionPane.showInputDialog(
|
||||
null,
|
||||
"Select new ticket",
|
||||
"New ticket",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
null,
|
||||
ticket.getText()
|
||||
);
|
||||
if (result != null) {
|
||||
activity.setTicket(result);
|
||||
activityRepository.update(activity);
|
||||
ticket.setText(result);
|
||||
subject.setText(activity.createSubject());
|
||||
totalComment.setText(activity.createTotalComment());
|
||||
}
|
||||
});
|
||||
spentTime.addMouseListener((MouseClickedListener) e -> {
|
||||
String result = (String) JOptionPane.showInputDialog(
|
||||
null,
|
||||
"Select new spent time",
|
||||
"New spent time",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
null,
|
||||
spentTime.getText()
|
||||
);
|
||||
if (result != null) {
|
||||
TTime spentTimeTTime = new TTime(result);
|
||||
activity.setSpentHours(spentTimeTTime.getHour());
|
||||
activity.setSpentMinutes(spentTimeTTime.getMinute());
|
||||
activityRepository.update(activity);
|
||||
spentTime.setText(result);
|
||||
totalComment.setText(activity.createTotalComment());
|
||||
dayPanel.sortActivityPanels();
|
||||
}
|
||||
});
|
||||
|
||||
flags.addMouseListener((MouseClickedListener) e -> {
|
||||
String result = (String) JOptionPane.showInputDialog(
|
||||
null,
|
||||
"Select new flags",
|
||||
"New flags",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
null,
|
||||
flags.getText()
|
||||
);
|
||||
if (result != null) {
|
||||
activity.setFlags(result);
|
||||
activityRepository.update(activity);
|
||||
flags.setText(result);
|
||||
|
||||
}
|
||||
});
|
||||
sortkey.setText(String.valueOf(activity.getSortkey()));
|
||||
name.setText(activity.getName());
|
||||
comment.setText(activity.getComment());
|
||||
@ -245,14 +193,14 @@ public class ActivityPanel extends JPanel implements Comparable<ActivityPanel> {
|
||||
this.activityRepository = activityRepository;
|
||||
//this.setBorder(BorderFactory.createLineBorder(Color.ORANGE, 1));
|
||||
setAlignmentX(LEFT_ALIGNMENT);
|
||||
// moveThisButton.addActionListener(e-> {
|
||||
// //dayPanel.switchPositionsForThisActivityAndThePreviousActivity(getActivity());
|
||||
// //dayPanel.markActivityAsToBeMoved(getActivity());
|
||||
// });
|
||||
//
|
||||
// moveBeforeButton.addActionListener(e-> {
|
||||
// //dayPanel.moveMarkedActivityBeforeThisActivity(getActivity());
|
||||
// });
|
||||
// moveThisButton.addActionListener(e-> {
|
||||
// //dayPanel.switchPositionsForThisActivityAndThePreviousActivity(getActivity());
|
||||
// //dayPanel.markActivityAsToBeMoved(getActivity());
|
||||
// });
|
||||
//
|
||||
// moveBeforeButton.addActionListener(e-> {
|
||||
// //dayPanel.moveMarkedActivityBeforeThisActivity(getActivity());
|
||||
// });
|
||||
deleteButton.addActionListener(e -> {
|
||||
activityRepository.delete(this.activity.getId());
|
||||
this.setVisible(false);
|
||||
@ -261,13 +209,8 @@ public class ActivityPanel extends JPanel implements Comparable<ActivityPanel> {
|
||||
copyButton.addActionListener(e -> {
|
||||
activityRepository.putToClipboard(this.activity);
|
||||
});
|
||||
subjectButton.addActionListener(e-> {
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
clipboard.setContents(new StringSelection(subject.getText()), null);
|
||||
});
|
||||
totalCommentButton.addActionListener(e-> {
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
clipboard.setContents(new StringSelection(totalComment.getText()), null);
|
||||
moveButton.addActionListener(e-> {
|
||||
this.dayPanel.markActivityPanelToBeMoved(this);
|
||||
});
|
||||
dayPanel.sortActivityPanels();
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.Timer;
|
||||
@ -41,6 +42,7 @@ public class DayPanel extends JPanel {
|
||||
private JButton loadButton;
|
||||
private JScrollPane scrollPane;
|
||||
private JPanel panelInsideScrollPane;
|
||||
private ActivityPanel markActivityPanelToBeMoved = null;
|
||||
|
||||
public DayPanel(String yearIn, String monthIn, String dayIn,
|
||||
ActivityRepositoryApi activityRepository) {
|
||||
@ -85,7 +87,7 @@ public class DayPanel extends JPanel {
|
||||
JButton newButton = new JButton("New");
|
||||
JButton pasteButton = new JButton("Paste");
|
||||
|
||||
JButton reviewButton = new JButton("Review");
|
||||
JButton reviewButton = new JButton("Copy all Total comments to clipboard");
|
||||
JButton statusButton = new JButton("Status");
|
||||
buttons.add(newButton);
|
||||
buttons.add(pasteButton);
|
||||
@ -124,6 +126,7 @@ public class DayPanel extends JPanel {
|
||||
|
||||
if(!list.isEmpty()) {
|
||||
list.forEach(c->panelInsideScrollPane.remove(c));
|
||||
sortActivityPanels();
|
||||
}
|
||||
revalidate();
|
||||
}).start();
|
||||
@ -159,14 +162,18 @@ public class DayPanel extends JPanel {
|
||||
revalidate();
|
||||
});
|
||||
reviewButton.addActionListener(e->{
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
clipboard.setContents(new StringSelection(Arrays
|
||||
String comments = Arrays
|
||||
.stream(panelInsideScrollPane.getComponents())
|
||||
.filter(c-> c instanceof ActivityPanel)
|
||||
.map(ap->((ActivityPanel) ap).getActivity())
|
||||
.map(a->a.createTotalComment())
|
||||
.collect(
|
||||
Collectors.joining("\n"))), null);
|
||||
Collectors.joining("\n"));
|
||||
JOptionPane
|
||||
.showMessageDialog(null, comments, "All comments for: " + year + "-" + (month.length() < 2 ? "0" : "") + month + "-" + (day.length() < 2 ? "0" : "") + day , JOptionPane.INFORMATION_MESSAGE);
|
||||
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
clipboard.setContents(new StringSelection(comments), null);
|
||||
});
|
||||
statusButton.addActionListener(e-> {
|
||||
List<ActivityPanel> activityPanels = new ArrayList<>();
|
||||
@ -238,8 +245,12 @@ public class DayPanel extends JPanel {
|
||||
double now = ap.getActivity().getSpentHours() + ap.getActivity().getSpentMinutes() / 60d;
|
||||
done = done + now;
|
||||
todo = todo - now;
|
||||
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));
|
||||
TTime doneTTime =
|
||||
TTime.ofMilliseconds((int) (done * 60d * 60d * 1000d));
|
||||
ap.today.setText(doneTTime.toString().substring(0,5));
|
||||
TTime todoTTime =
|
||||
TTime.ofMilliseconds((int) (todo * 60d * 60d * 1000d));
|
||||
ap.remains.setText(todoTTime.toString().substring(0,todoTTime.isNegative() ? 6 : 5));
|
||||
panelInsideScrollPane.add(ap);
|
||||
ap.setVisible(false);
|
||||
ap.setVisible(true);
|
||||
@ -249,4 +260,7 @@ public class DayPanel extends JPanel {
|
||||
revalidate();
|
||||
}
|
||||
|
||||
public void markActivityPanelToBeMoved(ActivityPanel activityPanel) {
|
||||
this.markActivityPanelToBeMoved = activityPanel;
|
||||
}
|
||||
}
|
||||
|
@ -27,12 +27,10 @@ import org.nanoboot.utils.timecalc.utils.common.Jokes;
|
||||
import org.nanoboot.utils.timecalc.utils.common.TTime;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFrame;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Insets;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.io.File;
|
||||
@ -105,6 +103,9 @@ public class MainWindow extends TWindow {
|
||||
|
||||
public MainWindow(String startTimeIn, String overTimeIn,
|
||||
TimeCalcApp timeCalcApp) {
|
||||
// ToolTipManager ttm = ToolTipManager.sharedInstance();
|
||||
// ttm.setInitialDelay(0);
|
||||
// ttm.setDismissDelay(10000);
|
||||
setFocusable(true);
|
||||
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user