Add a PointEngine to retrieve points.
This commit is contained in:
@@ -10,12 +10,14 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class CalendarPanel extends JPanel {
|
public class CalendarPanel extends JPanel {
|
||||||
|
private PointEngine pointEngine;
|
||||||
private YearMonth currentMonth;
|
private YearMonth currentMonth;
|
||||||
private final int cellHeight = 60;
|
private final int cellHeight = 60;
|
||||||
private final int cellWidth = 80;
|
private final int cellWidth = 80;
|
||||||
private final Set<LocalDate> selectedDates = new HashSet<>();
|
private final Set<LocalDate> selectedDates = new HashSet<>();
|
||||||
|
|
||||||
public CalendarPanel() {
|
public CalendarPanel(PointEngine pointEngine) {
|
||||||
|
this.pointEngine = pointEngine;
|
||||||
this.currentMonth = YearMonth.now();
|
this.currentMonth = YearMonth.now();
|
||||||
setPreferredSize(new Dimension(7 * cellWidth, 8 * cellHeight));
|
setPreferredSize(new Dimension(7 * cellWidth, 8 * cellHeight));
|
||||||
setBackground(Color.WHITE);
|
setBackground(Color.WHITE);
|
||||||
@@ -77,7 +79,13 @@ public class CalendarPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getTotalPoints() {
|
public double getTotalPoints() {
|
||||||
return selectedDates.size() * 1.0;
|
double totalPoints = 0.0;
|
||||||
|
|
||||||
|
for (LocalDate date : selectedDates) {
|
||||||
|
totalPoints += pointEngine.getPointsOfDay(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
private LocalDate getDateAtPoint(int x, int y) {
|
private LocalDate getDateAtPoint(int x, int y) {
|
||||||
@@ -168,7 +176,7 @@ public class CalendarPanel extends JPanel {
|
|||||||
int textY = y + (cellHeight - fm.getHeight()) / 2 + fm.getAscent() - 8;
|
int textY = y + (cellHeight - fm.getHeight()) / 2 + fm.getAscent() - 8;
|
||||||
g.drawString(dayStr, textX, textY);
|
g.drawString(dayStr, textX, textY);
|
||||||
|
|
||||||
String pointsStr = "(1.0)";
|
String pointsStr = "(" + pointEngine.getPointsOfDay(cellDate) + ")";
|
||||||
Font smallFont = new Font("Arial", Font.PLAIN, 10);
|
Font smallFont = new Font("Arial", Font.PLAIN, 10);
|
||||||
FontMetrics smallFm = g.getFontMetrics(smallFont);
|
FontMetrics smallFm = g.getFontMetrics(smallFont);
|
||||||
g.setFont(smallFont);
|
g.setFont(smallFont);
|
||||||
|
|||||||
17
src/main/java/net/themusicinnoise/vaccalc/PointEngine.java
Normal file
17
src/main/java/net/themusicinnoise/vaccalc/PointEngine.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package net.themusicinnoise.vaccalc;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
public class PointEngine {
|
||||||
|
private double defaultPoints;
|
||||||
|
|
||||||
|
public PointEngine() {
|
||||||
|
defaultPoints = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultPoints(float defaultPoints) { this.defaultPoints = defaultPoints; }
|
||||||
|
|
||||||
|
public double getPointsOfDay(LocalDate date) {
|
||||||
|
return defaultPoints;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ public class VacCalc extends JFrame {
|
|||||||
private CalendarPanel calendarPanel;
|
private CalendarPanel calendarPanel;
|
||||||
private JLabel monthLabel;
|
private JLabel monthLabel;
|
||||||
private JLabel pointsLabel;
|
private JLabel pointsLabel;
|
||||||
|
private PointEngine pointEngine;
|
||||||
|
|
||||||
public VacCalc() {
|
public VacCalc() {
|
||||||
setTitle("VacCalc");
|
setTitle("VacCalc");
|
||||||
@@ -29,7 +30,8 @@ public class VacCalc extends JFrame {
|
|||||||
menuBar.add(appMenu);
|
menuBar.add(appMenu);
|
||||||
setJMenuBar(menuBar);
|
setJMenuBar(menuBar);
|
||||||
|
|
||||||
calendarPanel = new CalendarPanel();
|
pointEngine = new PointEngine();
|
||||||
|
calendarPanel = new CalendarPanel(pointEngine);
|
||||||
|
|
||||||
JPanel headerPanel = createHeaderPanel();
|
JPanel headerPanel = createHeaderPanel();
|
||||||
JPanel footerPanel = createFooterPanel();
|
JPanel footerPanel = createFooterPanel();
|
||||||
|
|||||||
Reference in New Issue
Block a user