Search in sources :

Example 1 with DateRange

use of org.jfree.data.time.DateRange in project SIMVA-SoS by SESoS.

the class DateAxis method estimateMaximumTickLabelHeight.

/**
 * Estimates the maximum width of the tick labels, assuming the specified
 * tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we
 * just look at two values: the lower bound and the upper bound for the
 * axis.  These two values will usually be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return The estimated maximum width of the tick labels.
 */
private double estimateMaximumTickLabelHeight(Graphics2D g2, DateTickUnit unit) {
    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getTop() + tickLabelInsets.getBottom();
    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
    if (!isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of
        // the font)...
        result += lm.getHeight();
    } else {
        // look at lower and upper bounds...
        DateRange range = (DateRange) getRange();
        Date lower = range.getLowerDate();
        Date upper = range.getUpperDate();
        String lowerStr, upperStr;
        DateFormat formatter = getDateFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        } else {
            lowerStr = unit.dateToString(lower);
            upperStr = unit.dateToString(upper);
        }
        FontMetrics fm = g2.getFontMetrics(tickLabelFont);
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }
    return result;
}
Also used : DateRange(org.jfree.data.time.DateRange) FontMetrics(java.awt.FontMetrics) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) RectangleInsets(org.jfree.ui.RectangleInsets) FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics) Font(java.awt.Font) Date(java.util.Date)

Example 2 with DateRange

use of org.jfree.data.time.DateRange in project SIMVA-SoS by SESoS.

the class DateAxis method getMaximumDate.

/**
 * Returns the latest date visible on the axis.
 *
 * @return The date.
 *
 * @see #setMaximumDate(Date)
 * @see #getMinimumDate()
 */
public Date getMaximumDate() {
    Date result;
    Range range = getRange();
    if (range instanceof DateRange) {
        DateRange r = (DateRange) range;
        result = r.getUpperDate();
    } else {
        result = new Date((long) range.getUpperBound());
    }
    return result;
}
Also used : DateRange(org.jfree.data.time.DateRange) DateRange(org.jfree.data.time.DateRange) Range(org.jfree.data.Range) Date(java.util.Date)

Example 3 with DateRange

use of org.jfree.data.time.DateRange in project SIMVA-SoS by SESoS.

the class DateAxis method getMinimumDate.

/**
 * Returns the earliest date visible on the axis.
 *
 * @return The date.
 *
 * @see #setMinimumDate(Date)
 * @see #getMaximumDate()
 */
public Date getMinimumDate() {
    Date result;
    Range range = getRange();
    if (range instanceof DateRange) {
        DateRange r = (DateRange) range;
        result = r.getLowerDate();
    } else {
        result = new Date((long) range.getLowerBound());
    }
    return result;
}
Also used : DateRange(org.jfree.data.time.DateRange) DateRange(org.jfree.data.time.DateRange) Range(org.jfree.data.Range) Date(java.util.Date)

Example 4 with DateRange

use of org.jfree.data.time.DateRange in project SIMVA-SoS by SESoS.

the class DateAxis method estimateMaximumTickLabelWidth.

/**
 * Estimates the maximum width of the tick labels, assuming the specified
 * tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we
 * just look at two values: the lower bound and the upper bound for the
 * axis.  These two values will usually be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return The estimated maximum width of the tick labels.
 */
private double estimateMaximumTickLabelWidth(Graphics2D g2, DateTickUnit unit) {
    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight();
    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
    if (isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of
        // the font)...
        result += lm.getHeight();
    } else {
        // look at lower and upper bounds...
        DateRange range = (DateRange) getRange();
        Date lower = range.getLowerDate();
        Date upper = range.getUpperDate();
        String lowerStr, upperStr;
        DateFormat formatter = getDateFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        } else {
            lowerStr = unit.dateToString(lower);
            upperStr = unit.dateToString(upper);
        }
        FontMetrics fm = g2.getFontMetrics(tickLabelFont);
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }
    return result;
}
Also used : DateRange(org.jfree.data.time.DateRange) FontMetrics(java.awt.FontMetrics) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) RectangleInsets(org.jfree.ui.RectangleInsets) FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics) Font(java.awt.Font) Date(java.util.Date)

Example 5 with DateRange

use of org.jfree.data.time.DateRange in project SIMVA-SoS by SESoS.

the class DateAxisTest method testSetRange.

/**
 * Test that the setRange() method works.
 */
@Test
public void testSetRange() {
    DateAxis axis = new DateAxis("Test Axis");
    Calendar calendar = Calendar.getInstance();
    calendar.set(1999, Calendar.JANUARY, 3);
    Date d1 = calendar.getTime();
    calendar.set(1999, Calendar.JANUARY, 31);
    Date d2 = calendar.getTime();
    axis.setRange(d1, d2);
    DateRange range = (DateRange) axis.getRange();
    assertEquals(d1, range.getLowerDate());
    assertEquals(d2, range.getUpperDate());
}
Also used : DateRange(org.jfree.data.time.DateRange) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) Date(java.util.Date) Test(org.junit.Test)

Aggregations

DateRange (org.jfree.data.time.DateRange)39 Date (java.util.Date)24 Range (org.jfree.data.Range)13 Font (java.awt.Font)7 FontMetrics (java.awt.FontMetrics)6 FontRenderContext (java.awt.font.FontRenderContext)6 LineMetrics (java.awt.font.LineMetrics)6 DateFormat (java.text.DateFormat)6 SimpleDateFormat (java.text.SimpleDateFormat)6 RectangleInsets (org.jfree.ui.RectangleInsets)4 Plot (org.jfree.chart.plot.Plot)3 ValueAxisPlot (org.jfree.chart.plot.ValueAxisPlot)3 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 RectangleInsets (org.jfree.chart.api.RectangleInsets)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 TransferStatus (com.tesshu.jpsonic.domain.TransferStatus)1 BoundedDateAxis (fr.jmmc.oiexplorer.core.gui.chart.BoundedDateAxis)1 BasicStroke (java.awt.BasicStroke)1