package com.ht.ui.controls.cell;

import java.text.Format;
import java.util.Locale;

import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.text.TextAlignment;
import javafx.util.Callback;

/**
 * A class containing cell factories that format numbers such that they appear
 * as to represent a currency. 
 *  
 * <p>Note that the cells in this class are styled using CSS. The style class
 * for all cells is <code>money-cell</code>. The added pseudo class states are
 * <code>negative</code> and <code>positive</code>. The default CSS for the
 * cells in this class is of the form:
 * 
 * <pre>
 * {@code
 * .money-cell {
 *   -fx-text-fill: -fx-text-inner-color;
 * }
 *
 * .money-cell:selected {
 *   -fx-text-fill: white;
 * }
 * 
 * .money-cell:positive {
 *   -fx-text-fill: green;
 * }
 * 
 * .money-cell:negative {
 *   -fx-text-fill: red;
 * }}
 * </pre>
 * 
 * <p>You may customise this CSS in your own applications by providing your own
 * stylesheet that overrides these values.
 * 
 * @author <a href="http://www.jonathangiles.net">Jonathan Giles</a>
 */
public class NumberCellFactory {
    
    /** 
     * A String used to represent cells that have negative Number values in them, which
     * is then exposed via CSS to allow for easy styling of these cells.
     */
    public static final String NEGATIVE_STATE = "negative";
    
    /** 
     * A String used to represent cells that have positive Number values in them, which
     * is then exposed via CSS to allow for easy styling of these cells.
     */
    public static final String POSITIVE_STATE = "positive";

    private NumberCellFactory() { }
    
//    /**
//     * Returns a cell factory that creates a default {@link MoneyListCell} with the 
//     * default Locale for the users computer.
//     */
//    public static <T extends Number> Callback<ListView<T>, ListCell<T>> forListView() {
//        return forListView(Locale.getDefault());
//    }
//    
//    /**
//     * Returns a cell factory that creates a {@link MoneyListCell} with the given Locale.
//     */
//    public static <T extends Number> Callback<ListView<T>, ListCell<T>> forListView(final Locale locale) {
//        return new Callback<ListView<T>, ListCell<T>>() {
//            @Override public ListCell<T> call(ListView<T> list) {
//                return new MoneyListCell<T>(locale);
//            }
//        };
//    }
    
    /**
     * Returns a cell factory that creates a default {@link MoneyTableCell} with the 
     * default Locale for the users computer.
     */
    public static <S,T extends Number> Callback<TableColumn<S,T>, TableCell<S,T>> forTableColumn() {
        return forTableColumn(TextAlignment.RIGHT);
    }
    
    /**
     * Returns a cell factory that creates a default {@link MoneyTableCell} with the 
     * default Locale for the users computer.
     */
    public static <S,T extends Number> Callback<TableColumn<S,T>, TableCell<S,T>> forTableColumn(TextAlignment align) {
        return forTableColumn(align, null);
    }
    
    public static <S,T extends Number> Callback<TableColumn<S,T>, TableCell<S,T>> forTableColumn(Format format) {
        return forTableColumn(TextAlignment.RIGHT, format);
    }
    
    /**
     * Returns a cell factory that creates a {@link MoneyTableCell} with the given Locale.
     */
    public static <S,T extends Number> Callback<TableColumn<S,T>, TableCell<S,T>> forTableColumn(final TextAlignment align, final Format format) {
        return new Callback<TableColumn<S,T>, TableCell<S,T>>() {
            @Override public TableCell<S,T> call(TableColumn<S,T> list) {
                return new NumberTableCell<S,T>(align, format);
            }
        };
    }
}
