Example usage for org.jfree.chart.axis SegmentedTimeline setAdjustForDaylightSaving

List of usage examples for org.jfree.chart.axis SegmentedTimeline setAdjustForDaylightSaving

Introduction

In this page you can find the example usage for org.jfree.chart.axis SegmentedTimeline setAdjustForDaylightSaving.

Prototype

public void setAdjustForDaylightSaving(boolean adjust) 

Source Link

Document

Sets the flag that controls whether or not the daylight saving adjustment is applied.

Usage

From source file:ch.algotrader.client.chart.ChartTab.java

private void initAxis() {

    DateAxis domainAxis = (DateAxis) getPlot().getDomainAxis();

    // configure the Date Axis (if startTime & endTime is set)
    if (this.chartDefinition.getStartTime() != null && this.chartDefinition.getEndTime() != null
            && !this.chartDefinition.getStartTime().equals(this.chartDefinition.getEndTime())) {

        // creat the SegmentedTimeline
        long startTime = this.chartDefinition.getStartTime().getTime();
        long endTime = this.chartDefinition.getEndTime().getTime();
        if (endTime == -3600000) {
            // adjust 00:00
            endTime += 86400000;//from   ww w. j  a  va 2s . c  om
        }
        long segmentSize = 60 * 1000; // minute
        int segmentsIncluded = (int) (endTime - startTime) / (60 * 1000);
        int segmentsExcluded = 24 * 60 - segmentsIncluded;
        SegmentedTimeline timeline = new SegmentedTimeline(segmentSize, segmentsIncluded, segmentsExcluded);

        Date fromDate = domainAxis.getMinimumDate();
        Date toDate = domainAxis.getMaximumDate();
        long fromTime = fromDate.getTime();
        long toTime = toDate.getTime();

        // get year/month/day from fromTime and hour/minute from diagrm.startTime
        Date truncatedDate = DateUtils.truncate(fromDate, Calendar.DAY_OF_MONTH);
        Calendar truncatedCalendar = DateUtils.toCalendar(truncatedDate);
        Calendar startCalendar = DateUtils.toCalendar(this.chartDefinition.getStartTime());
        truncatedCalendar.set(Calendar.HOUR_OF_DAY, startCalendar.get(Calendar.HOUR_OF_DAY));
        truncatedCalendar.set(Calendar.MINUTE, startCalendar.get(Calendar.MINUTE));

        timeline.setStartTime(truncatedCalendar.getTimeInMillis());
        timeline.setBaseTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());
        timeline.addBaseTimelineExclusions(fromTime, toTime);
        timeline.setAdjustForDaylightSaving(true);

        domainAxis.setTimeline(timeline);
    }

    // make sure the markers are within the rangeAxis
    ValueAxis rangeAxis = getPlot().getRangeAxis();
    for (Marker marker : this.markers.values()) {

        if (marker instanceof ValueMarker) {

            ValueMarker valueMarker = (ValueMarker) marker;
            if (marker.getAlpha() > 0 && valueMarker.getValue() != 0.0) {

                if (valueMarker.getValue() < rangeAxis.getLowerBound()) {
                    rangeAxis.setLowerBound(valueMarker.getValue());
                    marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
                    marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
                }

                if (valueMarker.getValue() > rangeAxis.getUpperBound()) {
                    rangeAxis.setUpperBound(valueMarker.getValue());
                    marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
                    marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
                }
            }
        } else {

            IntervalMarker intervalMarker = (IntervalMarker) marker;
            if (marker.getAlpha() > 0 && intervalMarker.getStartValue() != 0.0) {

                if (intervalMarker.getStartValue() < rangeAxis.getLowerBound()) {
                    rangeAxis.setLowerBound(intervalMarker.getStartValue());
                    marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
                    marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
                }

                if (intervalMarker.getEndValue() > rangeAxis.getUpperBound()) {
                    rangeAxis.setUpperBound(intervalMarker.getEndValue());
                    marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
                    marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
                }
            }
        }
    }
}