Search in sources :

Example 21 with TextAnchor

use of org.jfree.ui.TextAnchor in project SIMVA-SoS by SESoS.

the class DateAxis method refreshTicksHorizontal.

/**
 * Recalculates the ticks for the date axis.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area in which the data is to be drawn.
 * @param edge  the location of the axis.
 *
 * @return A list of ticks.
 */
protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    List result = new java.util.ArrayList();
    Font tickLabelFont = getTickLabelFont();
    g2.setFont(tickLabelFont);
    if (isAutoTickUnitSelection()) {
        selectAutoTickUnit(g2, dataArea, edge);
    }
    DateTickUnit unit = getTickUnit();
    Date tickDate = calculateLowestVisibleTickValue(unit);
    Date upperDate = getMaximumDate();
    boolean hasRolled = false;
    while (tickDate.before(upperDate)) {
        // could add a flag to make the following correction optional...
        if (!hasRolled) {
            tickDate = correctTickDateForPosition(tickDate, unit, this.tickMarkPosition);
        }
        long lowestTickTime = tickDate.getTime();
        long distance = unit.addToDate(tickDate, this.timeZone).getTime() - lowestTickTime;
        int minorTickSpaces = getMinorTickCount();
        if (minorTickSpaces <= 0) {
            minorTickSpaces = unit.getMinorTickCount();
        }
        for (int minorTick = 1; minorTick < minorTickSpaces; minorTick++) {
            long minorTickTime = lowestTickTime - distance * minorTick / minorTickSpaces;
            if (minorTickTime > 0 && getRange().contains(minorTickTime) && (!isHiddenValue(minorTickTime))) {
                result.add(new DateTick(TickType.MINOR, new Date(minorTickTime), "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0));
            }
        }
        if (!isHiddenValue(tickDate.getTime())) {
            // work out the value, label and position
            String tickLabel;
            DateFormat formatter = getDateFormatOverride();
            if (formatter != null) {
                tickLabel = formatter.format(tickDate);
            } else {
                tickLabel = this.tickUnit.dateToString(tickDate);
            }
            TextAnchor anchor, rotationAnchor;
            double angle = 0.0;
            if (isVerticalTickLabels()) {
                anchor = TextAnchor.CENTER_RIGHT;
                rotationAnchor = TextAnchor.CENTER_RIGHT;
                if (edge == RectangleEdge.TOP) {
                    angle = Math.PI / 2.0;
                } else {
                    angle = -Math.PI / 2.0;
                }
            } else {
                if (edge == RectangleEdge.TOP) {
                    anchor = TextAnchor.BOTTOM_CENTER;
                    rotationAnchor = TextAnchor.BOTTOM_CENTER;
                } else {
                    anchor = TextAnchor.TOP_CENTER;
                    rotationAnchor = TextAnchor.TOP_CENTER;
                }
            }
            Tick tick = new DateTick(tickDate, tickLabel, anchor, rotationAnchor, angle);
            result.add(tick);
            hasRolled = false;
            long currentTickTime = tickDate.getTime();
            tickDate = unit.addToDate(tickDate, this.timeZone);
            long nextTickTime = tickDate.getTime();
            for (int minorTick = 1; minorTick < minorTickSpaces; minorTick++) {
                long minorTickTime = currentTickTime + (nextTickTime - currentTickTime) * minorTick / minorTickSpaces;
                if (getRange().contains(minorTickTime) && (!isHiddenValue(minorTickTime))) {
                    result.add(new DateTick(TickType.MINOR, new Date(minorTickTime), "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0));
                }
            }
        } else {
            tickDate = unit.rollDate(tickDate, this.timeZone);
            hasRolled = true;
            continue;
        }
    }
    return result;
}
Also used : TextAnchor(org.jfree.ui.TextAnchor) Font(java.awt.Font) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) List(java.util.List)

Example 22 with TextAnchor

use of org.jfree.ui.TextAnchor in project SIMVA-SoS by SESoS.

the class DateAxis method refreshTicksVertical.

/**
 * Recalculates the ticks for the date axis.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area in which the plot should be drawn.
 * @param edge  the location of the axis.
 *
 * @return A list of ticks.
 */
protected List refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    List result = new java.util.ArrayList();
    Font tickLabelFont = getTickLabelFont();
    g2.setFont(tickLabelFont);
    if (isAutoTickUnitSelection()) {
        selectAutoTickUnit(g2, dataArea, edge);
    }
    DateTickUnit unit = getTickUnit();
    Date tickDate = calculateLowestVisibleTickValue(unit);
    Date upperDate = getMaximumDate();
    boolean hasRolled = false;
    while (tickDate.before(upperDate)) {
        // could add a flag to make the following correction optional...
        if (!hasRolled) {
            tickDate = correctTickDateForPosition(tickDate, unit, this.tickMarkPosition);
        }
        long lowestTickTime = tickDate.getTime();
        long distance = unit.addToDate(tickDate, this.timeZone).getTime() - lowestTickTime;
        int minorTickSpaces = getMinorTickCount();
        if (minorTickSpaces <= 0) {
            minorTickSpaces = unit.getMinorTickCount();
        }
        for (int minorTick = 1; minorTick < minorTickSpaces; minorTick++) {
            long minorTickTime = lowestTickTime - distance * minorTick / minorTickSpaces;
            if (minorTickTime > 0 && getRange().contains(minorTickTime) && (!isHiddenValue(minorTickTime))) {
                result.add(new DateTick(TickType.MINOR, new Date(minorTickTime), "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0));
            }
        }
        if (!isHiddenValue(tickDate.getTime())) {
            // work out the value, label and position
            String tickLabel;
            DateFormat formatter = getDateFormatOverride();
            if (formatter != null) {
                tickLabel = formatter.format(tickDate);
            } else {
                tickLabel = this.tickUnit.dateToString(tickDate);
            }
            TextAnchor anchor, rotationAnchor;
            double angle = 0.0;
            if (isVerticalTickLabels()) {
                anchor = TextAnchor.BOTTOM_CENTER;
                rotationAnchor = TextAnchor.BOTTOM_CENTER;
                if (edge == RectangleEdge.LEFT) {
                    angle = -Math.PI / 2.0;
                } else {
                    angle = Math.PI / 2.0;
                }
            } else {
                if (edge == RectangleEdge.LEFT) {
                    anchor = TextAnchor.CENTER_RIGHT;
                    rotationAnchor = TextAnchor.CENTER_RIGHT;
                } else {
                    anchor = TextAnchor.CENTER_LEFT;
                    rotationAnchor = TextAnchor.CENTER_LEFT;
                }
            }
            Tick tick = new DateTick(tickDate, tickLabel, anchor, rotationAnchor, angle);
            result.add(tick);
            hasRolled = false;
            long currentTickTime = tickDate.getTime();
            tickDate = unit.addToDate(tickDate, this.timeZone);
            long nextTickTime = tickDate.getTime();
            for (int minorTick = 1; minorTick < minorTickSpaces; minorTick++) {
                long minorTickTime = currentTickTime + (nextTickTime - currentTickTime) * minorTick / minorTickSpaces;
                if (getRange().contains(minorTickTime) && (!isHiddenValue(minorTickTime))) {
                    result.add(new DateTick(TickType.MINOR, new Date(minorTickTime), "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0));
                }
            }
        } else {
            tickDate = unit.rollDate(tickDate, this.timeZone);
            hasRolled = true;
        }
    }
    return result;
}
Also used : TextAnchor(org.jfree.ui.TextAnchor) Font(java.awt.Font) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) List(java.util.List)

Example 23 with TextAnchor

use of org.jfree.ui.TextAnchor in project SIMVA-SoS by SESoS.

the class PolarPlot method calculateTextAnchor.

/**
 * Calculate the text position for the given degrees.
 *
 * @param angleDegrees  the angle in degrees.
 *
 * @return The optimal text anchor.
 * @since 1.0.14
 */
protected TextAnchor calculateTextAnchor(double angleDegrees) {
    TextAnchor ta = TextAnchor.CENTER;
    // normalize angle
    double offset = this.angleOffset;
    while (offset < 0.0) {
        offset += 360.0;
    }
    double normalizedAngle = (((this.counterClockwise ? -1 : 1) * angleDegrees) + offset) % 360;
    while (this.counterClockwise && (normalizedAngle < 0.0)) {
        normalizedAngle += 360.0;
    }
    if (normalizedAngle == 0.0) {
        ta = TextAnchor.CENTER_LEFT;
    } else if (normalizedAngle > 0.0 && normalizedAngle < 90.0) {
        ta = TextAnchor.TOP_LEFT;
    } else if (normalizedAngle == 90.0) {
        ta = TextAnchor.TOP_CENTER;
    } else if (normalizedAngle > 90.0 && normalizedAngle < 180.0) {
        ta = TextAnchor.TOP_RIGHT;
    } else if (normalizedAngle == 180) {
        ta = TextAnchor.CENTER_RIGHT;
    } else if (normalizedAngle > 180.0 && normalizedAngle < 270.0) {
        ta = TextAnchor.BOTTOM_RIGHT;
    } else if (normalizedAngle == 270) {
        ta = TextAnchor.BOTTOM_CENTER;
    } else if (normalizedAngle > 270.0 && normalizedAngle < 360.0) {
        ta = TextAnchor.BOTTOM_LEFT;
    }
    return ta;
}
Also used : TextAnchor(org.jfree.ui.TextAnchor)

Aggregations

TextAnchor (org.jfree.ui.TextAnchor)23 List (java.util.List)13 Font (java.awt.Font)11 NumberFormat (java.text.NumberFormat)7 Paint (java.awt.Paint)5 Rectangle2D (java.awt.geom.Rectangle2D)5 Date (java.util.Date)5 Shape (java.awt.Shape)4 Test (org.junit.Test)4 Line2D (java.awt.geom.Line2D)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 ArrayList (java.util.ArrayList)3 Range (org.jfree.data.Range)3 FontMetrics (java.awt.FontMetrics)2 Stroke (java.awt.Stroke)2 AffineTransform (java.awt.geom.AffineTransform)2 Point2D (java.awt.geom.Point2D)2 TextBlock (org.jfree.text.TextBlock)2 TextBlockAnchor (org.jfree.text.TextBlockAnchor)2