package com.borlander.rac353542.bislider.cdata;

import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import com.borlander.rac353542.bislider.BiSliderUIModel;
import com.borlander.rac353542.bislider.DefaultBiSliderUIModel;

/**
 * Single pack of objects required to instantiate BiSlider working with custom
 * object data model of <code>java.util.Date</code> values, representing
 * midnights in the current time zone.
 */
public class CalendarDateSuite {
    private static final DateFormat ourDateFormat = DateFormat.getDateInstance();

    public CalendarDateModel createDataModel(Date totalMin, Date totalMax, Date userMin, Date userMax) {
        CalendarDateModel result = new CalendarDateModel();
        result.setTotalRange(totalMin, totalMax);
        result.setUserMinimum(userMin);
        result.setUserMaximum(userMax);
        return result;
    }

    public BiSliderUIModel createUIModel() {
        DefaultBiSliderUIModel result = new DefaultBiSliderUIModel();
        result.setLabelProvider(createLabelProvider());
        // date values requires a lot of space
        result.setVerticalLabels(true);
        result.setLabelInsets(100);
        return result;
    }

    public DataObjectLabelProvider createLabelProvider() {
        return new DataObjectLabelProvider(CALENDAR_DATE) {
            public String getLabel(Object dataObject) {
                Date date = (Date) dataObject;
                return ourDateFormat.format(date);
            }
        };
    }

    public static class CalendarDateModel extends DataObjectDataModel {
        public CalendarDateModel() {
            super(CALENDAR_DATE);
        }

        public Date getTotalMinimumDate() {
            return (Date) getTotalMinimumObject();
        }

        public Date getTotalMaximumDate() {
            return (Date) getTotalMaximumObject();
        }

        public Date getUserMinimumDate() {
            return (Date) getUserMinimumObject();
        }

        public Date getUserMaximumDate() {
            return (Date) getUserMaximumObject();
        }

        public void setUserMaximum(Date maximum) {
            setUserMaximumObject(maximum);
        }

        public void setUserMinimum(Date minimum) {
            setUserMinimumObject(minimum);
        }

        public void setTotalRange(Date minimum, Date maximum) {
            setTotalObjectRange(minimum, maximum);
        }
    }

    /**
     * Mapper for date's. Each data object is some <code>java.util.Date</code>
     * representing a midnight in current locale's time zone.
     */
    public static DataObjectMapper CALENDAR_DATE = new DataObjectMapper() {

        private final Calendar myCalendar = Calendar.getInstance();

        public Object double2object(double value) {
            myCalendar.setTimeInMillis(Math.round(value));
        //    setToMidnight();
            return myCalendar.getTime();
        }

        public double object2double(Object object) {
            myCalendar.setTime((Date) object);
         //   setToMidnight();
            return myCalendar.getTimeInMillis();
        }

        private void setToMidnight() {
            myCalendar.set(Calendar.HOUR, 0);
            myCalendar.set(Calendar.AM_PM, Calendar.AM);
            myCalendar.set(Calendar.MINUTE, 0);
            myCalendar.set(Calendar.SECOND, 0);
            myCalendar.set(Calendar.MILLISECOND, 0);
        }
    };
}

@@ -2842,24 +2842,26 @@
 alue));%0A
+//
         
 //    se
@@ -2852,18 +2852,16 @@
         
-//
     setT
@@ -3025,16 +3025,18 @@
 bject);%0A
+//
         
@@ -3036,18 +3036,16 @@
         
-//
    setTo
@@ -3108,32 +3108,34 @@
 s();%0A        %7D%0A%0A
+//
         private 
@@ -3153,24 +3153,26 @@
 idnight() %7B%0A
+//
             
@@ -3201,24 +3201,26 @@
 r.HOUR, 0);%0A
+//
             
@@ -3264,16 +3264,18 @@
 ar.AM);%0A
+//
         
@@ -3310,24 +3310,26 @@
 MINUTE, 0);%0A
+//
             
@@ -3356,32 +3356,34 @@
 dar.SECOND, 0);%0A
+//
             myCa
@@ -3415,24 +3415,156 @@
 SECOND, 0);%0A
+//        %7D%0A        %0A        public double getPrecision() %7B%0A            return 1000 * 30;%0A//            return 1000 * 60 * 60 * 24;%0A
         %7D%0A  

Allow times, not just dates - change precision of fine-adjuster