Compare commits

...

7 Commits

8 changed files with 139 additions and 12 deletions

View File

@@ -29,6 +29,12 @@
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@@ -69,6 +69,9 @@ public class CalendarPanel extends JPanel {
}
private void toggleSelection(LocalDate date) {
if (pointEngine.getPointsOfDay(date) == 0.0)
return;
if (selectedDates.contains(date)) {
selectedDates.remove(date);
} else {
@@ -156,8 +159,12 @@ public class CalendarPanel extends JPanel {
LocalDate cellDate = currentMonth.atDay(day);
boolean isToday = cellDate.equals(today);
boolean isSelected = selectedDates.contains(cellDate);
double points = pointEngine.getPointsOfDay(cellDate);
if (isSelected && isToday) {
if (points == 0.0) {
g.setColor(new Color(255, 100, 100));
g.fillRect(x, y, cellWidth, cellHeight);
} else if (isSelected && isToday) {
g.setColor(new Color(123, 166, 180));
g.fillRect(x, y, cellWidth, cellHeight);
} else if (isSelected) {
@@ -176,7 +183,7 @@ public class CalendarPanel extends JPanel {
int textY = y + (cellHeight - fm.getHeight()) / 2 + fm.getAscent() - 8;
g.drawString(dayStr, textX, textY);
String pointsStr = "(" + pointEngine.getPointsOfDay(cellDate) + ")";
String pointsStr = "(" + points + ")";
Font smallFont = new Font("Arial", Font.PLAIN, 10);
FontMetrics smallFm = g.getFontMetrics(smallFont);
g.setFont(smallFont);

View File

@@ -23,9 +23,9 @@ public class PointEngine {
DATE,
}
static final Pattern DOW_PATTERN = Pattern.compile("dow=(sun|mon|tue|wed|thu|fri|sat) (\\d+\\.\\d+)", Pattern.CASE_INSENSITIVE);
static final Pattern MONTH_PATTERN = Pattern.compile("m=(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec) (\\d+\\.\\d+)", Pattern.CASE_INSENSITIVE);
static final Pattern DATE_PATTERN = Pattern.compile("(\\d{4}-\\d{2}-\\d{2}) (\\d+\\.\\d+)", Pattern.CASE_INSENSITIVE);
static final Pattern DOW_PATTERN = Pattern.compile("dow=(sun|mon|tue|wed|thu|fri|sat)\\s+(\\d+\\.\\d+)", Pattern.CASE_INSENSITIVE);
static final Pattern MONTH_PATTERN = Pattern.compile("m=(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\\s+(\\d+\\.\\d+)", Pattern.CASE_INSENSITIVE);
static final Pattern DATE_PATTERN = Pattern.compile("(\\d{4}-\\d{2}-\\d{2})\\s+(\\d+\\.\\d+)", Pattern.CASE_INSENSITIVE);
private RuleType type;
private DayOfWeek dow;
@@ -77,16 +77,19 @@ public class PointEngine {
}
public void importPointsFile(File pointsFile) {
Pattern defaultPattern = Pattern.compile("default (\\d+\\.\\d+)");
Pattern defaultPattern = Pattern.compile("default\\s+(\\d+\\.\\d+)", Pattern.CASE_INSENSITIVE);
try (BufferedReader br = new BufferedReader(new FileReader(pointsFile))) {
String line;
while ((line = br.readLine()) != null) {
if (line.isEmpty() || line.charAt(0) == '#')
continue;
Matcher defaultMatcher = defaultPattern.matcher(line);
if (defaultMatcher.find()) {
defaultPoints = Double.parseDouble(defaultMatcher.group(1));
} else {
rules.add(new PointRule(line));
rules.addFirst(new PointRule(line));
}
}
} catch (IOException e) {
@@ -97,12 +100,11 @@ public class PointEngine {
public void reset() { rules.clear(); }
public double getPointsOfDay(LocalDate date) {
double points = defaultPoints;
for (PointRule rule : rules) {
if (rule.applies(date)) {
points = rule.getPoints();
return rule.getPoints();
}
}
return points;
return defaultPoints;
}
}

View File

@@ -3,7 +3,10 @@ package net.themusicinnoise.vaccalc;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.time.YearMonth;
import java.util.Properties;
import java.util.stream.Collectors;
public class VacCalc extends JFrame {
private CalendarPanel calendarPanel;
@@ -48,6 +51,42 @@ public class VacCalc extends JFrame {
});
appMenu.add(exitItem);
menuBar.add(appMenu);
JMenu helpMenu = new JMenu("Help");
JMenuItem manualItem = new JMenuItem("Usage Manual");
manualItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
BufferedReader br = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("manual.html")));
String manualText = br.lines().collect(Collectors.joining());
JEditorPane textArea = new JEditorPane("text/html", manualText);
textArea.setEditable(false);
JFrame manualFrame = new JFrame("VacCalc Manual");
manualFrame.getContentPane().add(new JScrollPane(textArea));
manualFrame.setSize(500, 500);
manualFrame.setVisible(true);
}
});
helpMenu.add(manualItem);
JMenuItem aboutItem = new JMenuItem("About");
aboutItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
BufferedReader br = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("about.html")));
Properties properties = new Properties();
try {
properties.load(getClass().getClassLoader().getResourceAsStream("project.properties"));
} catch (IOException e) {
System.err.println("Failed to load project properties.");
e.printStackTrace();
}
String aboutText = br.lines().collect(Collectors.joining());
aboutText = aboutText.replace("VERSION", properties.getProperty("version"));
JOptionPane.showMessageDialog(VacCalc.this, aboutText, "About",
JOptionPane.INFORMATION_MESSAGE);
}
});
helpMenu.add(aboutItem);
menuBar.add(helpMenu);
setJMenuBar(menuBar);
pointEngine = new PointEngine();

View File

@@ -0,0 +1,7 @@
<html>
<p><b>VacCalc VERSION</b></p>
<hr />
<p>Copyright &copy; 2026 Nicolás A. Ortega Froysa &lt;nicolas@ortegas.org&gt;</p>
<p>License: Zlib</p>
<p>Home page: <a href="https://code.ortegas.org/nortega/vaccalc" >https://code.ortegas.org/nortega/vaccalc</a></p>
</html>

View File

@@ -0,0 +1,59 @@
<html>
<h1>VacCalc Manual</h1>
<hr />
<p>VacCalc assigns points to each day on the basis of the rules found in a
file which is imported via the “VacCalc &gt; Import points” menu item. This
file must be written manually. What follows are descriptions on how to write
this file.</p>
<h2>Rules</h2>
<p>There are a total of four different kinds of rules possible: default,
date, day-of-week, and month. Rules are applied with a priority for the last
defined rule, with the exception of the default rule which is only used if
no other rule applies.</p>
<h3>Default Rule</h3>
<p>Definition: <code>default <i>points</i></code></p>
<p>The default rule establishes the default point value for every day of the
year. E.g. <code>default 1.0</code> sets the default points to
<code>1.0</code>.
<h3>Date Rule</h3>
<p>Definition: <code><i>YYYY</i>-<i>MM</i>-<i>DD</i> <i>points</i></code></p>
<p>A date rule specifies the points which a specific date has. E.g.
<code>2026-12-24 0.5</code> would set Christmas Eve (December
24<sup>th</sup>) of 2026 to <code>0.5</code> points</p>
<h3>Day-Of-Week Rule</h3>
<p>Definition: <code>dow=<i>day</i> <i>points</i></p>
<p>A day-of-week rule specifies the points for all days of the year which
coincide with a particular day of the week. This day of the week is
specified using the three-letter format, such as <code>Fri</code> for
Friday. E.g. <code>dow=Fri 0.8</code> would set all Fridays of the year to
<code>0.8</code> points.</p>
<h3>Month Rule</h3>
<p>Definition: <code>m=<i>month</i> <i>points</i></p>
<p>A month rule establishes the same points for every day of a given month.
E.g. <code>m=Aug 0.8</code> sets all the days of the month of August to
<code>0.8</code> points.
<h3>Zero Point Rules</h3>
<p>Rules that have zero points allocated to them (i.e. <code>0.0</code>) are
considered <em>free days</em>, and as such are disabled. This could be
assigned to days such as Christmas or the Weekends (Saturday and
Sunday).</p>
<h3>Comments</h3>
<p>Definition: <code># <i>comment</i></p>
<p>Comments are supported in single lines starting with the <code>#</code>
character. Everything after that is ignored by the parser.</p>
<h3>Example</h3>
<code>
default 1.0<br />
dow=Fri 0.825<br />
m=Jul 0.825<br />
m=Aug 0.825<br />
2026-12-24 0.5<br />
2026-12-31 0.5<br />
<br />
# Weekends and Holidays<br />
dow=Sun 0.0<br />
dow=Sat 0.0<br />
2026-01-01 0.0<br />
2026-12-25 0.0
</code>
</html>

View File

@@ -0,0 +1 @@
version=${project.version}

View File

@@ -1,6 +1,12 @@
default 1.0
dow=Fri 0.825
2026-12-24 0.5
2026-12-31 0.5
m=Jul 0.825
m=Aug 0.825
2026-12-24 0.5
2026-12-31 0.5
# Weekends & Holidays
dow=Sun 0.0
dow=Sat 0.0
2026-01-01 0.0
2026-12-25 0.0