package eu.ortlepp.tasklist.gui.components;

import eu.ortlepp.tasklist.model.Task;

import javafx.scene.control.TableCell;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;

/**
 * A custom renderer for date columns in the table. The date will be formatted
 * according to the set format.
 *
 * @author Thorsten Ortlepp
 */
public class DateTableCell extends TableCell<Task, LocalDate> {


    /** Format for the date. */
    private final DateTimeFormatter formatter;


    /**
     * Initialize the date format for the output of the date in the table.
     */
    public DateTableCell() {
        super();
        formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM);
    }



    /**
     * Customize the appearance of the data shown in the table. The date is formatted
     * according to the format initialized in the constructor.
     *
     * @param item The item for the cell; in this case a date
     * @param empty Indicator if the cell contains data or is empty
     */
    @Override
    protected void updateItem(final LocalDate item, final boolean empty) {
        super.updateItem(item, empty);

        if (item == null || empty || item.equals(LocalDate.MIN)) {
            setText(null);
        } else {
            setText(item.format(formatter));
        }
    }

}

@@ -116,16 +116,49 @@
 bleCell;
+%0Aimport javafx.scene.paint.Color;
 %0A%0Aimport
@@ -374,16 +374,95 @@
  format.
+ If the Date is equal to or before the current%0A * date it is displayed colored.
 %0A *%0A * @
@@ -1013,16 +1013,99 @@
 tructor.
+ If the Date is equal to%0A     * or before the current date it is displayed colored.
 %0A     *%0A
@@ -1465,16 +1465,16 @@
 (null);%0A
-
         
@@ -1482,16 +1482,343 @@
  else %7B%0A
+%0A            /* Set color depending on the date */%0A            if (item.isEqual(LocalDate.now())) %7B%0A                setTextFill(Color.BLUEVIOLET);%0A            %7D else if (item.isBefore(LocalDate.now())) %7B%0A                setTextFill(Color.DEEPPINK);%0A            %7D else %7B%0A                setTextFill(Color.BLACK);%0A            %7D%0A%0A
         

Use color for displaying dates