int width = getWidth();
int height = getHeight();
// TODO take these from the model
Interval interval = new Interval(dtFrom, dtTo);
Period p = interval.toPeriod(PeriodType.days());
// try to determine length if we had to show milliseconds
int n = p.getDays();
int unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("wednesday ", null)).getWidth();
if (n < (width / unitSize)) {
//System.out.println("jour");
for (int i = 0; i < n; i++) {
g2d.drawString(dtFrom.plusDays(i).dayOfWeek().getAsText(LOCALE),
leftMargin + 2 + i * (width / n),
textTopPosition);
g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin);
paintSmallGraduations(g2d,
leftMargin + i * (width / n),
leftMargin + (i + 1) * (width / n),
Hours.hoursBetween(dtFrom.plusDays(i), dtFrom.plusDays(i + 1)).getHours());
}
return;
}
unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("wed ", null)).getWidth();
if (n < (width / unitSize)) {
//System.out.println("jou");
for (int i = 0; i < n; i++) {
g2d.drawString(dtFrom.plusDays(i).dayOfWeek().getAsShortText(LOCALE),
leftMargin + 2 + i * (width / n),
textTopPosition);
g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin);
paintSmallGraduations(g2d,
leftMargin + i * (width / n),
leftMargin + (i + 1) * (width / n),
Hours.hoursBetween(dtFrom.plusDays(i), dtFrom.plusDays(i + 1)).getHours());
}
return;
}
p = interval.toPeriod(PeriodType.days());
n = p.getDays();
unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("30", null)).getWidth();
if (n < (width / unitSize)) {
//System.out.println("j");
for (int i = 0; i < n; i++) {
g2d.drawString("" + (dtFrom.getDayOfMonth() + i),
leftMargin + 2 + i * (width / n),
textTopPosition);
g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin);
paintSmallGraduations(g2d,
leftMargin + i * (width / n),
leftMargin + (i + 1) * (width / n),
Hours.hoursBetween(dtFrom.plusDays(i), dtFrom.plusDays(i + 1)).getHours());
}
return;
}
p = interval.toPeriod(PeriodType.months());
n = p.getMonths();
unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("September ", null)).getWidth();
if (n < (width / unitSize)) {
//System.out.println("mois");
for (int i = 0; i < n; i++) {
g2d.drawString(dtFrom.plusMonths(i).monthOfYear().getAsText(LOCALE),
leftMargin + 2 + i * (width / n),
textTopPosition);
g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin);
paintSmallGraduations(g2d,
leftMargin + i * (width / n),
leftMargin + (i + 1) * (width / n),
Days.daysBetween(dtFrom.plusMonths(i), dtFrom.plusMonths(i + 1)).getDays());
}
return;
}
unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("dec ", null)).getWidth();
if (n < (width / unitSize)) {
//System.out.println("mo");
for (int i = 0; i < n; i++) {
g2d.drawString(dtFrom.plusMonths(i).monthOfYear().getAsShortText(LOCALE),
leftMargin + 2 + i * (width / n),
textTopPosition);
g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin);
paintSmallGraduations(g2d,
leftMargin + i * (width / n),
leftMargin + (i + 1) * (width / n),
Days.daysBetween(dtFrom.plusMonths(i), dtFrom.plusMonths(i + 1)).getDays());
}
return;
}
unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("29 ", null)).getWidth();
if (n < (width / unitSize)) {
//System.out.println("m");
for (int i = 0; i < n; i++) {
g2d.drawString("" + (dtFrom.getMonthOfYear() + i), leftMargin + 2 + i * (width / n),
textTopPosition);
g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin);
paintSmallGraduations(g2d,
leftMargin + i * (width / n),
leftMargin + (i + 1) * (width / n),
Days.daysBetween(dtFrom.plusMonths(i), dtFrom.plusMonths(i + 1)).getDays());
}
return;
}
p = interval.toPeriod(PeriodType.years());
n = p.getYears();
unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("1980 ", null)).getWidth();
if (n < (width / unitSize)) {
//System.out.println("year");
for (int i = 0; i < n; i++) {