Java Code Examples for org.jfree.ui.TextAnchor#TOP_CENTER

The following examples show how to use org.jfree.ui.TextAnchor#TOP_CENTER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CategoricalChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public TextAnchor asTextAnchor() {
  switch ( this ) {
    case RIGHT:
      return TextAnchor.CENTER_RIGHT;
    case TOP_RIGHT:
      return TextAnchor.TOP_RIGHT;
    case TOP:
      return TextAnchor.TOP_CENTER;
    case TOP_LEFT:
      return TextAnchor.TOP_LEFT;
    case LEFT:
      return TextAnchor.CENTER_LEFT;
    case BOTTOM_LEFT:
      return TextAnchor.BOTTOM_LEFT;
    case BOTTOM:
      return TextAnchor.BOTTOM_CENTER;
    case BOTTOM_RIGHT:
      return TextAnchor.BOTTOM_RIGHT;
    default:
      return null;
  }
}
 
Example 2
Source File: CrosshairOverlay.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the text anchor that is used to align a label to its anchor
 * point.
 *
 * @param anchor  the anchor.
 *
 * @return The text alignment point.
 */
private TextAnchor textAlignPtForLabelAnchorH(RectangleAnchor anchor) {
    TextAnchor result = TextAnchor.CENTER;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = TextAnchor.BOTTOM_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.TOP)) {
        result = TextAnchor.BOTTOM_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = TextAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.LEFT)) {
        result = TextAnchor.HALF_ASCENT_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.RIGHT)) {
        result = TextAnchor.HALF_ASCENT_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = TextAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM)) {
        result = TextAnchor.TOP_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = TextAnchor.TOP_RIGHT;
    }
    return result;
}
 
Example 3
Source File: CrosshairOverlay.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the text anchor that is used to align a label to its anchor 
 * point.
 * 
 * @param anchor  the anchor.
 * 
 * @return The text alignment point.
 */
private TextAnchor textAlignPtForLabelAnchorV(RectangleAnchor anchor) {
    TextAnchor result = TextAnchor.CENTER;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = TextAnchor.TOP_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.TOP)) {
        result = TextAnchor.TOP_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = TextAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.LEFT)) {
        result = TextAnchor.HALF_ASCENT_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.RIGHT)) {
        result = TextAnchor.HALF_ASCENT_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = TextAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM)) {
        result = TextAnchor.BOTTOM_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = TextAnchor.BOTTOM_LEFT;
    }
    return result;
}
 
Example 4
Source File: CustomLogarithmicAxis.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void addHorizontalTicks(RectangleEdge edge, List ticks, double lowerBoundVal, String tickLabel, double tickVal) {
    if (tickVal >= lowerBoundVal - SMALL_LOG_VALUE) {
        //tick value not below lowest data value
        TextAnchor anchor;
        TextAnchor 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;
            }
        }

        ticks.add(new NumberTick(new Double(tickVal), tickLabel, anchor, rotationAnchor, angle));
    }
}
 
Example 5
Source File: CrosshairOverlay.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the text anchor that is used to align a label to its anchor 
 * point.
 * 
 * @param anchor  the anchor.
 * 
 * @return The text alignment point.
 */
private TextAnchor textAlignPtForLabelAnchorV(RectangleAnchor anchor) {
    TextAnchor result = TextAnchor.CENTER;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = TextAnchor.TOP_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.TOP)) {
        result = TextAnchor.TOP_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = TextAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.LEFT)) {
        result = TextAnchor.HALF_ASCENT_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.RIGHT)) {
        result = TextAnchor.HALF_ASCENT_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = TextAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM)) {
        result = TextAnchor.BOTTOM_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = TextAnchor.BOTTOM_LEFT;
    }
    return result;
}
 
Example 6
Source File: CrosshairOverlay.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the text anchor that is used to align a label to its anchor 
 * point.
 * 
 * @param anchor  the anchor.
 * 
 * @return The text alignment point.
 */
private TextAnchor textAlignPtForLabelAnchorV(RectangleAnchor anchor) {
    TextAnchor result = TextAnchor.CENTER;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = TextAnchor.TOP_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.TOP)) {
        result = TextAnchor.TOP_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = TextAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.LEFT)) {
        result = TextAnchor.HALF_ASCENT_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.RIGHT)) {
        result = TextAnchor.HALF_ASCENT_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = TextAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM)) {
        result = TextAnchor.BOTTOM_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = TextAnchor.BOTTOM_LEFT;
    }
    return result;
}
 
Example 7
Source File: CrosshairOverlay.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the text anchor that is used to align a label to its anchor 
 * point.
 * 
 * @param anchor  the anchor.
 * 
 * @return The text alignment point.
 */
private TextAnchor textAlignPtForLabelAnchorV(RectangleAnchor anchor) {
    TextAnchor result = TextAnchor.CENTER;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = TextAnchor.TOP_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.TOP)) {
        result = TextAnchor.TOP_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = TextAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.LEFT)) {
        result = TextAnchor.HALF_ASCENT_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.RIGHT)) {
        result = TextAnchor.HALF_ASCENT_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = TextAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM)) {
        result = TextAnchor.BOTTOM_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = TextAnchor.BOTTOM_LEFT;
    }
    return result;
}
 
Example 8
Source File: DialTextAnnotation.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new instance of <code>DialTextAnnotation</code>.
 *
 * @param label  the label (<code>null</code> not permitted).
 */
public DialTextAnnotation(String label) {
    ParamChecks.nullNotPermitted(label, "label");
    this.angle = -90.0;
    this.radius = 0.3;
    this.font = new Font("Dialog", Font.BOLD, 14);
    this.paint = Color.black;
    this.label = label;
    this.anchor = TextAnchor.TOP_CENTER;
}
 
Example 9
Source File: AbstractRenderer.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Default constructor.
 */
public AbstractRenderer() {
    this.seriesVisible = null;
    this.seriesVisibleList = new BooleanList();
    this.baseSeriesVisible = true;

    this.seriesVisibleInLegend = null;
    this.seriesVisibleInLegendList = new BooleanList();
    this.baseSeriesVisibleInLegend = true;

    this.paint = null;
    this.paintList = new PaintList();
    this.basePaint = DEFAULT_PAINT;
    this.autoPopulateSeriesPaint = true;

    this.fillPaint = null;
    this.fillPaintList = new PaintList();
    this.baseFillPaint = Color.white;
    this.autoPopulateSeriesFillPaint = false;

    this.outlinePaint = null;
    this.outlinePaintList = new PaintList();
    this.baseOutlinePaint = DEFAULT_OUTLINE_PAINT;
    this.autoPopulateSeriesOutlinePaint = false;

    this.stroke = null;
    this.strokeList = new StrokeList();
    this.baseStroke = DEFAULT_STROKE;
    this.autoPopulateSeriesStroke = true;

    this.outlineStroke = null;
    this.outlineStrokeList = new StrokeList();
    this.baseOutlineStroke = DEFAULT_OUTLINE_STROKE;
    this.autoPopulateSeriesOutlineStroke = false;

    this.shape = null;
    this.shapeList = new ShapeList();
    this.baseShape = DEFAULT_SHAPE;
    this.autoPopulateSeriesShape = true;

    this.itemLabelsVisible = null;
    this.itemLabelsVisibleList = new BooleanList();
    this.baseItemLabelsVisible = Boolean.FALSE;

    this.itemLabelFont = null;
    this.itemLabelFontMap = new HashMap<Integer, Font>();
    this.baseItemLabelFont = new Font("SansSerif", Font.PLAIN, 10);

    this.itemLabelPaint = null;
    this.itemLabelPaintList = new PaintList();
    this.baseItemLabelPaint = Color.black;

    this.positiveItemLabelPosition = null;
    this.positiveItemLabelPositionMap 
            = new HashMap<Integer, ItemLabelPosition>();
    this.basePositiveItemLabelPosition = new ItemLabelPosition(
            ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);

    this.negativeItemLabelPosition = null;
    this.negativeItemLabelPositionMap 
            = new HashMap<Integer, ItemLabelPosition>();
    this.baseNegativeItemLabelPosition = new ItemLabelPosition(
            ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);

    this.createEntities = null;
    this.createEntitiesList = new BooleanList();
    this.baseCreateEntities = true;

    this.defaultEntityRadius = 3;

    this.legendShapeList = new ShapeList();
    this.baseLegendShape = null;

    this.treatLegendShapeAsLine = false;

    this.legendTextFontMap = new HashMap<Integer, Font>();
    this.baseLegendTextFont = null;

    this.legendTextPaint = new PaintList();
    this.baseLegendTextPaint = null;

    this.listenerList = new EventListenerList();
}
 
Example 10
Source File: DrawStringDemo.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Converts a string to a corresponding {@link TextAnchor} instance.
 *
 * @param text  the text.
 *
 * @return The anchor.
 */
private TextAnchor convertStringToAnchor(final String text) {

    if (text.equals("TextAnchor.TOP_LEFT")) {
        return TextAnchor.TOP_LEFT;
    }
    else if (text.equals("TextAnchor.TOP_CENTER")) {
        return TextAnchor.TOP_CENTER;
    }
    else if (text.equals("TextAnchor.TOP_RIGHT")) {
        return TextAnchor.TOP_RIGHT;
    }
    else if (text.equals("TextAnchor.CENTER_LEFT")) {
        return TextAnchor.CENTER_LEFT;
    }
    else if (text.equals("TextAnchor.CENTER")) {
        return TextAnchor.CENTER;
    }
    else if (text.equals("TextAnchor.CENTER_RIGHT")) {
        return TextAnchor.CENTER_RIGHT;
    }
    else if (text.equals("TextAnchor.HALF_ASCENT_LEFT")) {
        return TextAnchor.HALF_ASCENT_LEFT;
    }
    else if (text.equals("TextAnchor.HALF_ASCENT_CENTER")) {
        return TextAnchor.HALF_ASCENT_CENTER;
    }
    else if (text.equals("TextAnchor.HALF_ASCENT_RIGHT")) {
        return TextAnchor.HALF_ASCENT_RIGHT;
    }
    else if (text.equals("TextAnchor.BASELINE_LEFT")) {
        return TextAnchor.BASELINE_LEFT;
    }
    else if (text.equals("TextAnchor.BASELINE_CENTER")) {
        return TextAnchor.BASELINE_CENTER;
    }
    else if (text.equals("TextAnchor.BASELINE_RIGHT")) {
        return TextAnchor.BASELINE_RIGHT;
    }
    else if (text.equals("TextAnchor.BOTTOM_LEFT")) {
        return TextAnchor.BOTTOM_LEFT;
    }
    else if (text.equals("TextAnchor.BOTTOM_CENTER")) {
        return TextAnchor.BOTTOM_CENTER;
    }
    else if (text.equals("TextAnchor.BOTTOM_RIGHT")) {
        return TextAnchor.BOTTOM_RIGHT;
    }
    else {
        return null;
    }

}
 
Example 11
Source File: LogAxis.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 12
Source File: PolarPlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 13
Source File: PolarPlot.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source File: LogAxis.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 15
Source File: LogAxis.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 16
Source File: AbstractRenderer.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Default constructor.
 */
public AbstractRenderer() {

    this.seriesVisible = null;
    this.seriesVisibleList = new BooleanList();
    this.baseSeriesVisible = true;
    
    this.seriesVisibleInLegend = null;
    this.seriesVisibleInLegendList = new BooleanList();
    this.baseSeriesVisibleInLegend = true;

    this.paint = null;
    this.paintList = new PaintList();
    this.basePaint = DEFAULT_PAINT;

    this.fillPaint = null;
    this.fillPaintList = new PaintList();
    this.baseFillPaint = Color.white;

    this.outlinePaint = null;
    this.outlinePaintList = new PaintList();
    this.baseOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.stroke = null;
    this.strokeList = new StrokeList();
    this.baseStroke = DEFAULT_STROKE;

    this.outlineStroke = null;
    this.outlineStrokeList = new StrokeList();
    this.baseOutlineStroke = DEFAULT_OUTLINE_STROKE;

    this.shape = null;
    this.shapeList = new ShapeList();
    this.baseShape = DEFAULT_SHAPE;

    this.itemLabelsVisible = null;
    this.itemLabelsVisibleList = new BooleanList();
    this.baseItemLabelsVisible = Boolean.FALSE;

    this.itemLabelFont = null;
    this.itemLabelFontList = new ObjectList();
    this.baseItemLabelFont = new Font("SansSerif", Font.PLAIN, 10);

    this.itemLabelPaint = null;
    this.itemLabelPaintList = new PaintList();
    this.baseItemLabelPaint = Color.black;

    this.positiveItemLabelPosition = null;
    this.positiveItemLabelPositionList = new ObjectList();
    this.basePositiveItemLabelPosition = new ItemLabelPosition(
        ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER
    );
    
    this.negativeItemLabelPosition = null;
    this.negativeItemLabelPositionList = new ObjectList();
    this.baseNegativeItemLabelPosition = new ItemLabelPosition(
        ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER
    );

    this.createEntities = null;
    this.createEntitiesList = new BooleanList();
    this.baseCreateEntities = true;
    
    this.listenerList = new EventListenerList();

}
 
Example 17
Source File: SymbolAxis.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Calculates the positions of the tick labels for the axis, storing the 
 * results in the tick label list (ready for drawing).
 *
 * @param g2  the graphics device.
 * @param dataArea  the area in which the data should be drawn.
 * @param edge  the location of the axis.
 * 
 * @return The ticks.
 */
protected List refreshTicksHorizontal(Graphics2D g2,
                                      Rectangle2D dataArea,
                                      RectangleEdge edge) {

    List ticks = new java.util.ArrayList();

    Font tickLabelFont = getTickLabelFont();
    g2.setFont(tickLabelFont);

    double size = getTickUnit().getSize();
    int count = calculateVisibleTickCount();
    double lowestTickValue = calculateLowestVisibleTickValue();

    double previousDrawnTickLabelPos = 0.0;         
    double previousDrawnTickLabelLength = 0.0;              

    if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {
        for (int i = 0; i < count; i++) {
            double currentTickValue = lowestTickValue + (i * size);
            double xx = valueToJava2D(currentTickValue, dataArea, edge);
            String tickLabel;
            NumberFormat formatter = getNumberFormatOverride();
            if (formatter != null) {
                tickLabel = formatter.format(currentTickValue);
            }
            else {
                tickLabel = valueToString(currentTickValue);
            }
            
            // avoid to draw overlapping tick labels
            Rectangle2D bounds = TextUtilities.getTextBounds(
                tickLabel, g2, g2.getFontMetrics()
            );
            double tickLabelLength = isVerticalTickLabels() 
                ? bounds.getHeight() : bounds.getWidth();
            boolean tickLabelsOverlapping = false;
            if (i > 0) {
                double avgTickLabelLength = (previousDrawnTickLabelLength 
                    + tickLabelLength) / 2.0;
                if (Math.abs(xx - previousDrawnTickLabelPos) 
                        < avgTickLabelLength) {
                    tickLabelsOverlapping = true;
                }
            }
            if (tickLabelsOverlapping) {
                tickLabel = ""; // don't draw this tick label
            }
            else {
                // remember these values for next comparison
                previousDrawnTickLabelPos = xx;
                previousDrawnTickLabelLength = tickLabelLength;         
            } 
            
            TextAnchor anchor = null;
            TextAnchor rotationAnchor = null;
            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 NumberTick(
                new Double(currentTickValue), tickLabel, anchor, 
                rotationAnchor, angle
            );
            ticks.add(tick);
        }
    }
    return ticks;

}
 
Example 18
Source File: PolarPlot.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 19
Source File: NumberAxis.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Calculates the positions of the tick labels for the axis, storing the 
 * results in the tick label list (ready for drawing).
 *
 * @param g2  the graphics device.
 * @param dataArea  the area in which the data should 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);
    }

    double size = getTickUnit().getSize();
    int count = calculateVisibleTickCount();
    double lowestTickValue = calculateLowestVisibleTickValue();

    if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {
        for (int i = 0; i < count; i++) {
            double currentTickValue = lowestTickValue + (i * size);
            String tickLabel;
            NumberFormat formatter = getNumberFormatOverride();
            if (formatter != null) {
                tickLabel = formatter.format(currentTickValue);
            }
            else {
                tickLabel = getTickUnit().valueToString(currentTickValue);
            }
            TextAnchor anchor = null;
            TextAnchor rotationAnchor = null;
            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 NumberTick(
                new Double(currentTickValue), tickLabel, anchor, 
                rotationAnchor, angle
            );
            result.add(tick);
        }
    }
    return result;

}
 
Example 20
Source File: AbstractRenderer.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Default constructor.
 */
public AbstractRenderer() {
    this.seriesVisible = null;
    this.seriesVisibleList = new BooleanList();
    this.baseSeriesVisible = true;

    this.seriesVisibleInLegend = null;
    this.seriesVisibleInLegendList = new BooleanList();
    this.baseSeriesVisibleInLegend = true;

    this.paint = null;
    this.paintList = new PaintList();
    this.basePaint = DEFAULT_PAINT;
    this.autoPopulateSeriesPaint = true;

    this.fillPaint = null;
    this.fillPaintList = new PaintList();
    this.baseFillPaint = Color.white;
    this.autoPopulateSeriesFillPaint = false;

    this.outlinePaint = null;
    this.outlinePaintList = new PaintList();
    this.baseOutlinePaint = DEFAULT_OUTLINE_PAINT;
    this.autoPopulateSeriesOutlinePaint = false;

    this.stroke = null;
    this.strokeList = new StrokeList();
    this.baseStroke = DEFAULT_STROKE;
    this.autoPopulateSeriesStroke = true;

    this.outlineStroke = null;
    this.outlineStrokeList = new StrokeList();
    this.baseOutlineStroke = DEFAULT_OUTLINE_STROKE;
    this.autoPopulateSeriesOutlineStroke = false;

    this.shape = null;
    this.shapeList = new ShapeList();
    this.baseShape = DEFAULT_SHAPE;
    this.autoPopulateSeriesShape = true;

    this.itemLabelsVisible = null;
    this.itemLabelsVisibleList = new BooleanList();
    this.baseItemLabelsVisible = Boolean.FALSE;

    this.itemLabelFont = null;
    this.itemLabelFontMap = new HashMap<Integer, Font>();
    this.baseItemLabelFont = new Font("SansSerif", Font.PLAIN, 10);

    this.itemLabelPaint = null;
    this.itemLabelPaintList = new PaintList();
    this.baseItemLabelPaint = Color.black;

    this.positiveItemLabelPosition = null;
    this.positiveItemLabelPositionMap 
            = new HashMap<Integer, ItemLabelPosition>();
    this.basePositiveItemLabelPosition = new ItemLabelPosition(
            ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);

    this.negativeItemLabelPosition = null;
    this.negativeItemLabelPositionMap 
            = new HashMap<Integer, ItemLabelPosition>();
    this.baseNegativeItemLabelPosition = new ItemLabelPosition(
            ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);

    this.createEntities = null;
    this.createEntitiesList = new BooleanList();
    this.baseCreateEntities = true;

    this.defaultEntityRadius = 3;

    this.legendShapeList = new ShapeList();
    this.baseLegendShape = null;

    this.treatLegendShapeAsLine = false;

    this.legendTextFontMap = new HashMap<Integer, Font>();
    this.baseLegendTextFont = null;

    this.legendTextPaint = new PaintList();
    this.baseLegendTextPaint = null;

    this.listenerList = new EventListenerList();
}