I have highlighted required dates in JDateChooser(version: jcalendar 1.4) by adding IDateEvaluator. Whenever I add new entries, I execute this class to highlight the new set of dates. This is working fine. But when I delete an entry, its still showing the respective date highlighted. Is there a fix for this?
my main fuction:
public void run() {
HighlightEvaluator evaluator = new HighlightEvaluator();
for(Date filled : getFilledDates()) {
evaluator.add(filled);
}
dateChooser.getJCalendar().getDayChooser().addDateEvaluator(evaluator);
}
my dateevaluator class:
private static class HighlightEvaluator implements IDateEvaluator {
private final List<Date> list = new ArrayList<>();
public void add(Date date) {
list.add(date);
}
@Override
public Color getInvalidBackroundColor() {
return Color.BLACK;
}
@Override
public Color getInvalidForegroundColor() {
return null;
}
@Override
public String getInvalidTooltip() {
return null;
}
@Override
public Color getSpecialBackroundColor() {
return Color.GREEN;
}
@Override
public Color getSpecialForegroundColor() {
return Color.RED;
}
@Override
public String getSpecialTooltip() {
return "filled";
}
@Override
public boolean isInvalid(Date date) {
return false;
}
@Override
public boolean isSpecial(Date date) {
return list.contains(date);
}
}
the run() function runs everytime the panel is loaded and it checks for set of text files in various folders and highlights those dates
here is my getFilledDates() function:
private List<Date> getFilledDates() {
List<Date> filledDates = new ArrayList<Date>();
String filename = StorageSpace.currentpath;
File folder = new File(filename);
String[] yearfolders = folder.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return new File(dir, name).isDirectory();
}
});
for(int i=0; i<yearfolders.length;i++) {
folder = new File(filename + "\\" + yearfolders[i]);
if(folder.exists()) {
String[] monthfolders = folder.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return new File(dir, name).isDirectory();
}
});
for(int j=0;j<monthfolders.length;j++) {
folder = new File(filename + "\\" + yearfolders[i] + "\\" + monthfolders[j]);
if(folder.exists()) {
File[] listOfFiles = folder.listFiles();
for (int n = 0; n < listOfFiles.length; n++) {
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, Integer.parseInt(yearfolders[i]));
c.set(Calendar.MONTH, Integer.parseInt(monthfolders[j])-1);
c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(listOfFiles[n].getName().replaceAll(".txt", "")));
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
filledDates.add(c.getTime());
}
}
}
}
}
return filledDates;
}
Now everytime a file is added, the entire folders and files are scanned again and the latest set of dates are highlighted. But when a file is deleted, the date is still in green colour although that particular date is not in the list returned by getFilledDates() and its definitely not added to the evaluator.
So this is my issue