List of usage examples for org.jfree.chart.axis DateTickUnit getCalendarField
public int getCalendarField()
Calendar
class. From source file:figs.treeVisualization.gui.PhyloDateAxis.java
/** * Returns the previous "standard" date, for a given date and tick unit. * * @param date the reference date./*from w w w . ja v a 2 s. c o m*/ * @param unit the tick unit. * * @return The previous "standard" date. */ @Override protected Date previousStandardDate(Date date, DateTickUnit unit) { int hours; int days; int months; int years; Calendar calendar = Calendar.getInstance(TimeZone.getDefault()); calendar.setTime(getMinimumDate()); int current = calendar.get(unit.getCalendarField()); // We only care about DAY, MONTH, YEAR DateTickMarkPosition tickMarkPosition = this.getTickMarkPosition(); switch (unit.getUnit()) { case (DateTickUnit.DAY): years = calendar.get(Calendar.YEAR); months = calendar.get(Calendar.MONTH); if (tickMarkPosition == DateTickMarkPosition.START) { hours = 0; } else if (tickMarkPosition == DateTickMarkPosition.MIDDLE) { hours = 12; } else { hours = 23; } calendar.clear(Calendar.MILLISECOND); calendar.set(years, months, current, hours, 0, 0); long result = calendar.getTime().getTime(); if (result > date.getTime()) { // move it back a day calendar.set(years, months, current - 1, hours, 0, 0); } return calendar.getTime(); case (DateTickUnit.MONTH): years = calendar.get(Calendar.YEAR); calendar.clear(Calendar.MILLISECOND); calendar.set(years, current, 1, 0, 0, 0); // TODO: /* Month month = new Month(calendar.getTime()); Date standardDate = calculateDateForPosition( month, tickMarkPosition ); long millis = standardDate.getTime(); if (millis > date.getTime()) { month = (Month) month.previous(); standardDate = calculateDateForPosition( month, tickMarkPosition ); } return standardDate; */ return calendar.getTime(); case (DateTickUnit.YEAR): if (tickMarkPosition == DateTickMarkPosition.START) { months = 0; days = 1; } else if (tickMarkPosition == DateTickMarkPosition.MIDDLE) { months = 6; days = 1; } else { months = 11; days = 31; } calendar.clear(Calendar.MILLISECOND); calendar.set(current, months, days, 0, 0, 0); return calendar.getTime(); default: return calendar.getTime(); } }