Search in sources :

Example 11 with TextAnchor

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

the class CyclicNumberAxis method refreshVerticalTicks.

/**
 * Builds a list of ticks for the axis.  This method is called when the
 * axis is at the left or right of the chart (so the axis is "vertical").
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param edge  the edge.
 *
 * @return A list of ticks.
 */
protected List refreshVerticalTicks(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    List result = new java.util.ArrayList();
    result.clear();
    Font tickLabelFont = getTickLabelFont();
    g2.setFont(tickLabelFont);
    if (isAutoTickUnitSelection()) {
        selectAutoTickUnit(g2, dataArea, edge);
    }
    double unit = getTickUnit().getSize();
    double cycleBound = getCycleBound();
    double currentTickValue = Math.ceil(cycleBound / unit) * unit;
    double upperValue = getRange().getUpperBound();
    boolean cycled = false;
    boolean boundMapping = this.boundMappedToLastCycle;
    this.boundMappedToLastCycle = true;
    NumberTick lastTick = null;
    float lastY = 0.0f;
    if (upperValue == cycleBound) {
        currentTickValue = calculateLowestVisibleTickValue();
        cycled = true;
        this.boundMappedToLastCycle = true;
    }
    while (currentTickValue <= upperValue) {
        // Cycle when necessary
        boolean cyclenow = false;
        if ((currentTickValue + unit > upperValue) && !cycled) {
            cyclenow = true;
        }
        double yy = valueToJava2D(currentTickValue, dataArea, edge);
        String tickLabel;
        NumberFormat formatter = getNumberFormatOverride();
        if (formatter != null) {
            tickLabel = formatter.format(currentTickValue);
        } else {
            tickLabel = getTickUnit().valueToString(currentTickValue);
        }
        float y = (float) yy;
        TextAnchor anchor;
        TextAnchor rotationAnchor;
        double angle = 0.0;
        if (isVerticalTickLabels()) {
            if (edge == RectangleEdge.LEFT) {
                anchor = TextAnchor.BOTTOM_CENTER;
                if ((lastTick != null) && (lastY == y) && (currentTickValue != cycleBound)) {
                    anchor = isInverted() ? TextAnchor.BOTTOM_LEFT : TextAnchor.BOTTOM_RIGHT;
                    result.remove(result.size() - 1);
                    result.add(new CycleBoundTick(this.boundMappedToLastCycle, lastTick.getNumber(), lastTick.getText(), anchor, anchor, lastTick.getAngle()));
                    this.internalMarkerWhenTicksOverlap = true;
                    anchor = isInverted() ? TextAnchor.BOTTOM_RIGHT : TextAnchor.BOTTOM_LEFT;
                }
                rotationAnchor = anchor;
                angle = -Math.PI / 2.0;
            } else {
                anchor = TextAnchor.BOTTOM_CENTER;
                if ((lastTick != null) && (lastY == y) && (currentTickValue != cycleBound)) {
                    anchor = isInverted() ? TextAnchor.BOTTOM_RIGHT : TextAnchor.BOTTOM_LEFT;
                    result.remove(result.size() - 1);
                    result.add(new CycleBoundTick(this.boundMappedToLastCycle, lastTick.getNumber(), lastTick.getText(), anchor, anchor, lastTick.getAngle()));
                    this.internalMarkerWhenTicksOverlap = true;
                    anchor = isInverted() ? TextAnchor.BOTTOM_LEFT : TextAnchor.BOTTOM_RIGHT;
                }
                rotationAnchor = anchor;
                angle = Math.PI / 2.0;
            }
        } else {
            if (edge == RectangleEdge.LEFT) {
                anchor = TextAnchor.CENTER_RIGHT;
                if ((lastTick != null) && (lastY == y) && (currentTickValue != cycleBound)) {
                    anchor = isInverted() ? TextAnchor.BOTTOM_RIGHT : TextAnchor.TOP_RIGHT;
                    result.remove(result.size() - 1);
                    result.add(new CycleBoundTick(this.boundMappedToLastCycle, lastTick.getNumber(), lastTick.getText(), anchor, anchor, lastTick.getAngle()));
                    this.internalMarkerWhenTicksOverlap = true;
                    anchor = isInverted() ? TextAnchor.TOP_RIGHT : TextAnchor.BOTTOM_RIGHT;
                }
                rotationAnchor = anchor;
            } else {
                anchor = TextAnchor.CENTER_LEFT;
                if ((lastTick != null) && (lastY == y) && (currentTickValue != cycleBound)) {
                    anchor = isInverted() ? TextAnchor.BOTTOM_LEFT : TextAnchor.TOP_LEFT;
                    result.remove(result.size() - 1);
                    result.add(new CycleBoundTick(this.boundMappedToLastCycle, lastTick.getNumber(), lastTick.getText(), anchor, anchor, lastTick.getAngle()));
                    this.internalMarkerWhenTicksOverlap = true;
                    anchor = isInverted() ? TextAnchor.TOP_LEFT : TextAnchor.BOTTOM_LEFT;
                }
                rotationAnchor = anchor;
            }
        }
        CycleBoundTick tick = new CycleBoundTick(this.boundMappedToLastCycle, new Double(currentTickValue), tickLabel, anchor, rotationAnchor, angle);
        if (currentTickValue == cycleBound) {
            this.internalMarkerCycleBoundTick = tick;
        }
        result.add(tick);
        lastTick = tick;
        lastY = y;
        if (currentTickValue == cycleBound) {
            this.internalMarkerCycleBoundTick = tick;
        }
        currentTickValue += unit;
        if (cyclenow) {
            currentTickValue = calculateLowestVisibleTickValue();
            upperValue = cycleBound;
            cycled = true;
            this.boundMappedToLastCycle = false;
        }
    }
    this.boundMappedToLastCycle = boundMapping;
    return result;
}
Also used : TextAnchor(org.jfree.ui.TextAnchor) Font(java.awt.Font) List(java.util.List) NumberFormat(java.text.NumberFormat)

Example 12 with TextAnchor

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

the class CyclicNumberAxis method refreshTicksHorizontal.

/**
 * Builds a list of ticks for the axis.  This method is called when the
 * axis is at the top or bottom of the chart (so the axis is "horizontal").
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param edge  the edge.
 *
 * @return A list of ticks.
 */
@Override
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);
    }
    double unit = getTickUnit().getSize();
    double cycleBound = getCycleBound();
    double currentTickValue = Math.ceil(cycleBound / unit) * unit;
    double upperValue = getRange().getUpperBound();
    boolean cycled = false;
    boolean boundMapping = this.boundMappedToLastCycle;
    this.boundMappedToLastCycle = false;
    CycleBoundTick lastTick = null;
    float lastX = 0.0f;
    if (upperValue == cycleBound) {
        currentTickValue = calculateLowestVisibleTickValue();
        cycled = true;
        this.boundMappedToLastCycle = true;
    }
    while (currentTickValue <= upperValue) {
        // Cycle when necessary
        boolean cyclenow = false;
        if ((currentTickValue + unit > upperValue) && !cycled) {
            cyclenow = true;
        }
        double xx = valueToJava2D(currentTickValue, dataArea, edge);
        String tickLabel;
        NumberFormat formatter = getNumberFormatOverride();
        if (formatter != null) {
            tickLabel = formatter.format(currentTickValue);
        } else {
            tickLabel = getTickUnit().valueToString(currentTickValue);
        }
        float x = (float) xx;
        TextAnchor anchor;
        TextAnchor rotationAnchor;
        double angle = 0.0;
        if (isVerticalTickLabels()) {
            if (edge == RectangleEdge.TOP) {
                angle = Math.PI / 2.0;
            } else {
                angle = -Math.PI / 2.0;
            }
            anchor = TextAnchor.CENTER_RIGHT;
            // If tick overlap when cycling, update last tick too
            if ((lastTick != null) && (lastX == x) && (currentTickValue != cycleBound)) {
                anchor = isInverted() ? TextAnchor.TOP_RIGHT : TextAnchor.BOTTOM_RIGHT;
                result.remove(result.size() - 1);
                result.add(new CycleBoundTick(this.boundMappedToLastCycle, lastTick.getNumber(), lastTick.getText(), anchor, anchor, lastTick.getAngle()));
                this.internalMarkerWhenTicksOverlap = true;
                anchor = isInverted() ? TextAnchor.BOTTOM_RIGHT : TextAnchor.TOP_RIGHT;
            }
            rotationAnchor = anchor;
        } else {
            if (edge == RectangleEdge.TOP) {
                anchor = TextAnchor.BOTTOM_CENTER;
                if ((lastTick != null) && (lastX == x) && (currentTickValue != cycleBound)) {
                    anchor = isInverted() ? TextAnchor.BOTTOM_LEFT : TextAnchor.BOTTOM_RIGHT;
                    result.remove(result.size() - 1);
                    result.add(new CycleBoundTick(this.boundMappedToLastCycle, lastTick.getNumber(), lastTick.getText(), anchor, anchor, lastTick.getAngle()));
                    this.internalMarkerWhenTicksOverlap = true;
                    anchor = isInverted() ? TextAnchor.BOTTOM_RIGHT : TextAnchor.BOTTOM_LEFT;
                }
                rotationAnchor = anchor;
            } else {
                anchor = TextAnchor.TOP_CENTER;
                if ((lastTick != null) && (lastX == x) && (currentTickValue != cycleBound)) {
                    anchor = isInverted() ? TextAnchor.TOP_LEFT : TextAnchor.TOP_RIGHT;
                    result.remove(result.size() - 1);
                    result.add(new CycleBoundTick(this.boundMappedToLastCycle, lastTick.getNumber(), lastTick.getText(), anchor, anchor, lastTick.getAngle()));
                    this.internalMarkerWhenTicksOverlap = true;
                    anchor = isInverted() ? TextAnchor.TOP_RIGHT : TextAnchor.TOP_LEFT;
                }
                rotationAnchor = anchor;
            }
        }
        CycleBoundTick tick = new CycleBoundTick(this.boundMappedToLastCycle, new Double(currentTickValue), tickLabel, anchor, rotationAnchor, angle);
        if (currentTickValue == cycleBound) {
            this.internalMarkerCycleBoundTick = tick;
        }
        result.add(tick);
        lastTick = tick;
        lastX = x;
        currentTickValue += unit;
        if (cyclenow) {
            currentTickValue = calculateLowestVisibleTickValue();
            upperValue = cycleBound;
            cycled = true;
            this.boundMappedToLastCycle = true;
        }
    }
    this.boundMappedToLastCycle = boundMapping;
    return result;
}
Also used : TextAnchor(org.jfree.ui.TextAnchor) List(java.util.List) Font(java.awt.Font) NumberFormat(java.text.NumberFormat)

Example 13 with TextAnchor

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

the class LogAxis method refreshTicksHorizontal.

/**
 * Returns a list of ticks for an axis at the top or bottom of the chart.
 *
 * @param g2  the graphics device ({@code null} not permitted).
 * @param dataArea  the data area ({@code null} not permitted).
 * @param edge  the edge ({@code null} not permitted).
 *
 * @return A list of ticks.
 */
protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    Range range = getRange();
    List ticks = new ArrayList();
    Font tickLabelFont = getTickLabelFont();
    g2.setFont(tickLabelFont);
    TextAnchor textAnchor;
    if (edge == RectangleEdge.TOP) {
        textAnchor = TextAnchor.BOTTOM_CENTER;
    } else {
        textAnchor = TextAnchor.TOP_CENTER;
    }
    if (isAutoTickUnitSelection()) {
        selectAutoTickUnit(g2, dataArea, edge);
    }
    int minorTickCount = this.tickUnit.getMinorTickCount();
    double unit = getTickUnit().getSize();
    double index = Math.ceil(calculateLog(getRange().getLowerBound()) / unit);
    double start = index * unit;
    double end = calculateLog(getUpperBound());
    double current = start;
    boolean hasTicks = (this.tickUnit.getSize() > 0.0) && !Double.isInfinite(start);
    while (hasTicks && current <= end) {
        double v = calculateValueNoINF(current);
        if (range.contains(v)) {
            ticks.add(new LogTick(TickType.MAJOR, v, createTickLabel(v), textAnchor));
        }
        // add minor ticks (for gridlines)
        double next = Math.pow(this.base, current + this.tickUnit.getSize());
        for (int i = 1; i < minorTickCount; i++) {
            double minorV = v + i * ((next - v) / minorTickCount);
            if (range.contains(minorV)) {
                ticks.add(new LogTick(TickType.MINOR, minorV, null, textAnchor));
            }
        }
        current = current + this.tickUnit.getSize();
    }
    return ticks;
}
Also used : TextAnchor(org.jfree.ui.TextAnchor) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Range(org.jfree.data.Range) Font(java.awt.Font)

Example 14 with TextAnchor

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

the class CategoryTickTest method testHashCode.

/**
 * Two objects that are equal are required to return the same hashCode.
 */
@Test
public void testHashCode() {
    Comparable c1 = "C1";
    TextBlock tb1 = new TextBlock();
    tb1.addLine(new TextLine("Block 1"));
    tb1.addLine(new TextLine("Block 2"));
    TextBlockAnchor tba1 = TextBlockAnchor.CENTER;
    TextAnchor ta1 = TextAnchor.CENTER;
    CategoryTick t1 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
    CategoryTick t2 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
    assertTrue(t1.equals(t2));
    int h1 = t1.hashCode();
    int h2 = t2.hashCode();
    assertEquals(h1, h2);
}
Also used : TextAnchor(org.jfree.ui.TextAnchor) TextLine(org.jfree.text.TextLine) TextBlockAnchor(org.jfree.text.TextBlockAnchor) TextBlock(org.jfree.text.TextBlock) Test(org.junit.Test)

Example 15 with TextAnchor

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

the class PolarPlot method refreshAngleTicks.

/**
 * Generates a list of tick values for the angular tick marks.
 *
 * @return A list of {@link NumberTick} instances.
 *
 * @since 1.0.10
 */
protected List refreshAngleTicks() {
    List ticks = new ArrayList();
    for (double currentTickVal = 0.0; currentTickVal < 360.0; currentTickVal += this.angleTickUnit.getSize()) {
        TextAnchor ta = calculateTextAnchor(currentTickVal);
        NumberTick tick = new NumberTick(new Double(currentTickVal), this.angleTickUnit.valueToString(currentTickVal), ta, TextAnchor.CENTER, 0.0);
        ticks.add(tick);
    }
    return ticks;
}
Also used : TextAnchor(org.jfree.ui.TextAnchor) NumberTick(org.jfree.chart.axis.NumberTick) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ObjectList(org.jfree.util.ObjectList)

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