Example usage for org.jfree.chart.axis DateTickUnit rollDate

List of usage examples for org.jfree.chart.axis DateTickUnit rollDate

Introduction

In this page you can find the example usage for org.jfree.chart.axis DateTickUnit rollDate.

Prototype

public Date rollDate(Date base) 

Source Link

Document

Rolls the date forward by the amount specified by the roll unit and count.

Usage

From source file:figs.treeVisualization.gui.PhyloDateAxis.java

protected List<DateTick> refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea) {

    List<DateTick> result = new ArrayList<DateTick>();
    DateFormat formatter = getDateFormatOverride();

    Font tickLabelFont = getTickLabelFont();
    g2.setFont(tickLabelFont);/* w  w w .  ja va 2 s .  c o  m*/

    if (isAutoTickUnitSelection()) {
        selectAutoTickUnit(g2, dataArea, RectangleEdge.RIGHT);
    }
    DateTickUnit unit = getTickUnit();

    // nextStandardDate is adding to the min which makes no sense, so just call previous
    Date tickDate = previousStandardDate(getMinimumDate(), unit);
    Date upperDate = getMaximumDate();
    while (!tickDate.after(upperDate)) {

        if (!isHiddenValue(tickDate.getTime())) {
            // work out the value, label and position
            String tickLabel;
            if (formatter != null) {
                tickLabel = formatter.format(tickDate);
            } else {
                tickLabel = this.getTickUnit().dateToString(tickDate);
            }
            TextAnchor anchor = null;
            TextAnchor rotationAnchor = null;
            double angle = 0.0;
            if (isVerticalTickLabels()) {
                anchor = TextAnchor.BOTTOM_CENTER;
                rotationAnchor = TextAnchor.BOTTOM_CENTER;
                // RectangeEdge.RIGHT
                angle = Math.PI / 2.0;
            } else {
                // RectangeEdge.RIGHT
                anchor = TextAnchor.CENTER_LEFT;
                rotationAnchor = TextAnchor.CENTER_LEFT;
            }

            DateTick tick = new DateTick(tickDate, tickLabel, anchor, rotationAnchor, angle);
            result.add(tick);
            tickDate = unit.addToDate(tickDate);
        } else {
            tickDate = unit.rollDate(tickDate);
        }
    }

    return result;
}