Java Code Examples for org.jfree.text.TextUtilities#drawRotatedString()

The following examples show how to use org.jfree.text.TextUtilities#drawRotatedString() . 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: YIntervalRenderer.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws an item label.
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 */
private void drawAdditionalItemLabel(Graphics2D g2,
        PlotOrientation orientation, XYDataset dataset, int series,
        int item, double x, double y) {

    if (this.additionalItemLabelGenerator == null) {
        return;
    }

    Font labelFont = getItemLabelFont(series, item);
    Paint paint = getItemLabelPaint(series, item);
    g2.setFont(labelFont);
    g2.setPaint(paint);
    String label = this.additionalItemLabelGenerator.generateLabel(dataset,
            series, item);

    ItemLabelPosition position = getNegativeItemLabelPosition(series, item);
    Point2D anchorPoint = calculateLabelAnchorPoint(
            position.getItemLabelAnchor(), x, y, orientation);
    TextUtilities.drawRotatedString(label, g2,
            (float) anchorPoint.getX(), (float) anchorPoint.getY(),
            position.getTextAnchor(), position.getAngle(),
            position.getRotationAnchor());
}
 
Example 2
Source File: YIntervalRenderer.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Draws an item label.
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 */
private void drawAdditionalItemLabel(Graphics2D g2,
        PlotOrientation orientation, XYDataset dataset, int series,
        int item, double x, double y) {

    if (this.additionalItemLabelGenerator == null) {
        return;
    }

    Font labelFont = getItemLabelFont(series, item);
    Paint paint = getItemLabelPaint(series, item);
    g2.setFont(labelFont);
    g2.setPaint(paint);
    String label = this.additionalItemLabelGenerator.generateLabel(dataset,
            series, item);

    ItemLabelPosition position = getNegativeItemLabelPosition(series, item);
    Point2D anchorPoint = calculateLabelAnchorPoint(
            position.getItemLabelAnchor(), x, y, orientation);
    TextUtilities.drawRotatedString(label, g2,
            (float) anchorPoint.getX(), (float) anchorPoint.getY(),
            position.getTextAnchor(), position.getAngle(),
            position.getRotationAnchor());
}
 
Example 3
Source File: YIntervalRenderer.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws an item label.
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 */
private void drawAdditionalItemLabel(Graphics2D g2,
        PlotOrientation orientation, XYDataset dataset, int series,
        int item, double x, double y) {

    if (this.additionalItemLabelGenerator == null) {
        return;
    }

    Font labelFont = getItemLabelFont(series, item);
    Paint paint = getItemLabelPaint(series, item);
    g2.setFont(labelFont);
    g2.setPaint(paint);
    String label = this.additionalItemLabelGenerator.generateLabel(dataset,
            series, item);

    ItemLabelPosition position = getNegativeItemLabelPosition(series, item);
    Point2D anchorPoint = calculateLabelAnchorPoint(
            position.getItemLabelAnchor(), x, y, orientation);
    TextUtilities.drawRotatedString(label, g2,
            (float) anchorPoint.getX(), (float) anchorPoint.getY(),
            position.getTextAnchor(), position.getAngle(),
            position.getRotationAnchor());
}
 
Example 4
Source File: YIntervalRenderer.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws an item label.
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 */
private void drawAdditionalItemLabel(Graphics2D g2,
        PlotOrientation orientation, XYDataset dataset, int series,
        int item, double x, double y) {

    if (this.additionalItemLabelGenerator == null) {
        return;
    }

    Font labelFont = getItemLabelFont(series, item);
    Paint paint = getItemLabelPaint(series, item);
    g2.setFont(labelFont);
    g2.setPaint(paint);
    String label = this.additionalItemLabelGenerator.generateLabel(dataset,
            series, item);

    ItemLabelPosition position = getNegativeItemLabelPosition(series, item);
    Point2D anchorPoint = calculateLabelAnchorPoint(
            position.getItemLabelAnchor(), x, y, orientation);
    TextUtilities.drawRotatedString(label, g2,
            (float) anchorPoint.getX(), (float) anchorPoint.getY(),
            position.getTextAnchor(), position.getAngle(),
            position.getRotationAnchor());
}
 
Example 5
Source File: AbstractCategoryItemRenderer.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws an item label.
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param row  the row.
 * @param column  the column.
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 * @param negative  indicates a negative value (which affects the item
 *                  label position).
 */
protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation,
        CategoryDataset dataset, int row, int column,
        double x, double y, boolean negative) {

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row,
            column);
    if (generator != null) {
        Font labelFont = getItemLabelFont(row, column);
        Paint paint = getItemLabelPaint(row, column);
        g2.setFont(labelFont);
        g2.setPaint(paint);
        String label = generator.generateLabel(dataset, row, column);
        ItemLabelPosition position;
        if (!negative) {
            position = getPositiveItemLabelPosition(row, column);
        }
        else {
            position = getNegativeItemLabelPosition(row, column);
        }
        Point2D anchorPoint = calculateLabelAnchorPoint(
                position.getItemLabelAnchor(), x, y, orientation);
        TextUtilities.drawRotatedString(label, g2,
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(),
                position.getAngle(), position.getRotationAnchor());
    }

}
 
Example 6
Source File: CategoryTextAnnotation.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 */
@Override
public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea,
        CategoryAxis domainAxis, ValueAxis rangeAxis) {

    CategoryDataset dataset = plot.getDataset();
    int catIndex = dataset.getColumnIndex(this.category);
    int catCount = dataset.getColumnCount();

    float anchorX = 0.0f;
    float anchorY = 0.0f;
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);

    if (orientation == PlotOrientation.HORIZONTAL) {
        anchorY = (float) domainAxis.getCategoryJava2DCoordinate(
                this.categoryAnchor, catIndex, catCount, dataArea,
                domainEdge);
        anchorX = (float) rangeAxis.valueToJava2D(this.value, dataArea,
                rangeEdge);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        anchorX = (float) domainAxis.getCategoryJava2DCoordinate(
                this.categoryAnchor, catIndex, catCount, dataArea,
                domainEdge);
        anchorY = (float) rangeAxis.valueToJava2D(this.value, dataArea,
                rangeEdge);
    }
    g2.setFont(getFont());
    g2.setPaint(getPaint());
    TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY,
            getTextAnchor(), getRotationAngle(), getRotationAnchor());

}
 
Example 7
Source File: DrawStringPanel.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Paints the panel.
 *
 * @param g  the graphics device.
 */
public void paintComponent(final Graphics g) {

    super.paintComponent(g);
    final Graphics2D g2 = (Graphics2D) g;

    final Dimension size = getSize();
    final Insets insets = getInsets();
    final Rectangle2D available = new Rectangle2D.Double(
        insets.left, insets.top,
        size.getWidth() - insets.left - insets.right,
        size.getHeight() - insets.top - insets.bottom
    );

    final double x = available.getCenterX();
    final double y = available.getCenterY();

    final Line2D line1 = new Line2D.Double(x - 2.0, y + 2.0, x + 2.0, y - 2.0);
    final Line2D line2 = new Line2D.Double(x - 2.0, y - 2.0, x + 2.0, y + 2.0);
    g2.setPaint(Color.red);
    g2.draw(line1);
    g2.draw(line2);

    g2.setFont(this.font);
    g2.setPaint(Color.black);
    if (this.rotate) {
        TextUtilities.drawRotatedString(
            this.text, g2, (float) x, (float) y,
            this.anchor, this.angle, this.rotationAnchor
        );
    }
    else {
        TextUtilities.drawAlignedString(this.text, g2, (float) x, (float) y, this.anchor);
    }

}
 
Example 8
Source File: AbstractCategoryItemRenderer.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws an item label.
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param row  the row.
 * @param column  the column.
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 * @param negative  indicates a negative value (which affects the item
 *                  label position).
 */
protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation,
        CategoryDataset dataset, int row, int column,
        double x, double y, boolean negative) {

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row,
            column);
    if (generator != null) {
        Font labelFont = getItemLabelFont(row, column);
        Paint paint = getItemLabelPaint(row, column);
        g2.setFont(labelFont);
        g2.setPaint(paint);
        String label = generator.generateLabel(dataset, row, column);
        ItemLabelPosition position;
        if (!negative) {
            position = getPositiveItemLabelPosition(row, column);
        }
        else {
            position = getNegativeItemLabelPosition(row, column);
        }
        Point2D anchorPoint = calculateLabelAnchorPoint(
                position.getItemLabelAnchor(), x, y, orientation);
        TextUtilities.drawRotatedString(label, g2,
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(),
                position.getAngle(), position.getRotationAnchor());
    }

}
 
Example 9
Source File: CategoryTextAnnotation.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 */
@Override
public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea,
        CategoryAxis domainAxis, ValueAxis rangeAxis) {

    CategoryDataset dataset = plot.getDataset();
    int catIndex = dataset.getColumnIndex(this.category);
    int catCount = dataset.getColumnCount();

    float anchorX = 0.0f;
    float anchorY = 0.0f;
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);

    if (orientation == PlotOrientation.HORIZONTAL) {
        anchorY = (float) domainAxis.getCategoryJava2DCoordinate(
                this.categoryAnchor, catIndex, catCount, dataArea,
                domainEdge);
        anchorX = (float) rangeAxis.valueToJava2D(this.value, dataArea,
                rangeEdge);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        anchorX = (float) domainAxis.getCategoryJava2DCoordinate(
                this.categoryAnchor, catIndex, catCount, dataArea,
                domainEdge);
        anchorY = (float) rangeAxis.valueToJava2D(this.value, dataArea,
                rangeEdge);
    }
    g2.setFont(getFont());
    g2.setPaint(getPaint());
    TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY,
            getTextAnchor(), getRotationAngle(), getRotationAnchor());

}
 
Example 10
Source File: AbstractCategoryItemRenderer.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws an item label.
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param row  the row.
 * @param column  the column.
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 * @param negative  indicates a negative value (which affects the item
 *                  label position).
 */
protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation,
        CategoryDataset dataset, int row, int column,
        double x, double y, boolean negative) {

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row,
            column);
    if (generator != null) {
        Font labelFont = getItemLabelFont(row, column);
        Paint paint = getItemLabelPaint(row, column);
        g2.setFont(labelFont);
        g2.setPaint(paint);
        String label = generator.generateLabel(dataset, row, column);
        ItemLabelPosition position;
        if (!negative) {
            position = getPositiveItemLabelPosition(row, column);
        }
        else {
            position = getNegativeItemLabelPosition(row, column);
        }
        Point2D anchorPoint = calculateLabelAnchorPoint(
                position.getItemLabelAnchor(), x, y, orientation);
        TextUtilities.drawRotatedString(label, g2,
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(),
                position.getAngle(), position.getRotationAnchor());
    }

}
 
Example 11
Source File: AbstractXYItemRenderer.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws an item label.
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 * @param negative  indicates a negative value (which affects the item
 *                  label position).
 */
protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation,
        XYDataset dataset, int series, int item, double x, double y,
        boolean negative) {

    XYItemLabelGenerator generator = getItemLabelGenerator(series, item);
    if (generator != null) {
        Font labelFont = getItemLabelFont(series, item);
        Paint paint = getItemLabelPaint(series, item);
        g2.setFont(labelFont);
        g2.setPaint(paint);
        String label = generator.generateLabel(dataset, series, item);

        // get the label position..
        ItemLabelPosition position;
        if (!negative) {
            position = getPositiveItemLabelPosition(series, item);
        }
        else {
            position = getNegativeItemLabelPosition(series, item);
        }

        // work out the label anchor point...
        Point2D anchorPoint = calculateLabelAnchorPoint(
                position.getItemLabelAnchor(), x, y, orientation);
        TextUtilities.drawRotatedString(label, g2,
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());
    }

}
 
Example 12
Source File: AbstractCategoryItemRenderer.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Draws an item label.
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param row  the row.
 * @param column  the column.
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 * @param negative  indicates a negative value (which affects the item 
 *                  label position).
 */
protected void drawItemLabel(Graphics2D g2, 
                             PlotOrientation orientation,
                             CategoryDataset dataset, 
                             int row, int column,
                             double x, double y, 
                             boolean negative) {
                                 
    CategoryItemLabelGenerator generator 
        = getItemLabelGenerator(row, column);
    if (generator != null) {
        Font labelFont = getItemLabelFont(row, column);
        Paint paint = getItemLabelPaint(row, column);
        g2.setFont(labelFont);
        g2.setPaint(paint);
        String label = generator.generateLabel(dataset, row, column);
        ItemLabelPosition position = null;
        if (!negative) {
            position = getPositiveItemLabelPosition(row, column);
        }
        else {
            position = getNegativeItemLabelPosition(row, column);
        }
        Point2D anchorPoint = calculateLabelAnchorPoint(
                position.getItemLabelAnchor(), x, y, orientation);
        TextUtilities.drawRotatedString(label, g2, 
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), 
                position.getAngle(), position.getRotationAnchor());
    }

}
 
Example 13
Source File: XYBarRenderer.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws an item label.  This method is provided as an alternative to
 * {@link #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int,
 * double, double, boolean)} so that the bar can be used to calculate the
 * label anchor point.
 *
 * @param g2  the graphics device.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param plot  the plot.
 * @param generator  the label generator (<code>null</code> permitted, in
 *         which case the method does nothing, just returns).
 * @param bar  the bar.
 * @param negative  a flag indicating a negative value.
 */
protected void drawItemLabel(Graphics2D g2, XYDataset dataset,
        int series, int item, XYPlot plot, XYItemLabelGenerator generator,
        Rectangle2D bar, boolean negative) {

    if (generator == null) {
        return;  // nothing to do
    }
    String label = generator.generateLabel(dataset, series, item);
    if (label == null) {
        return;  // nothing to do
    }

    Font labelFont = getItemLabelFont(series, item);
    g2.setFont(labelFont);
    Paint paint = getItemLabelPaint(series, item);
    g2.setPaint(paint);

    // find out where to place the label...
    ItemLabelPosition position;
    if (!negative) {
        position = getPositiveItemLabelPosition(series, item);
    }
    else {
        position = getNegativeItemLabelPosition(series, item);
    }

    // work out the label anchor point...
    Point2D anchorPoint = calculateLabelAnchorPoint(
            position.getItemLabelAnchor(), bar, plot.getOrientation());

    if (isInternalAnchor(position.getItemLabelAnchor())) {
        Shape bounds = TextUtilities.calculateRotatedStringBounds(label,
                g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());

        if (bounds != null) {
            if (!bar.contains(bounds.getBounds2D())) {
                if (!negative) {
                    position = getPositiveItemLabelPositionFallback();
                }
                else {
                    position = getNegativeItemLabelPositionFallback();
                }
                if (position != null) {
                    anchorPoint = calculateLabelAnchorPoint(
                            position.getItemLabelAnchor(), bar,
                            plot.getOrientation());
                }
            }
        }

    }

    if (position != null) {
        TextUtilities.drawRotatedString(label, g2,
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());
    }
}
 
Example 14
Source File: BarRenderer.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws an item label.  This method is overridden so that the bar can be
 * used to calculate the label anchor point.
 *
 * @param g2  the graphics device.
 * @param data  the dataset.
 * @param row  the row.
 * @param column  the column.
 * @param plot  the plot.
 * @param generator  the label generator.
 * @param bar  the bar.
 * @param negative  a flag indicating a negative value.
 */
protected void drawItemLabel(Graphics2D g2,
                             CategoryDataset data,
                             int row,
                             int column,
                             CategoryPlot plot,
                             CategoryItemLabelGenerator generator,
                             Rectangle2D bar,
                             boolean negative) {

    String label = generator.generateLabel(data, row, column);
    if (label == null) {
        return;  // nothing to do
    }

    Font labelFont = getItemLabelFont(row, column);
    g2.setFont(labelFont);
    Paint paint = getItemLabelPaint(row, column);
    g2.setPaint(paint);

    // find out where to place the label...
    ItemLabelPosition position;
    if (!negative) {
        position = getPositiveItemLabelPosition(row, column);
    }
    else {
        position = getNegativeItemLabelPosition(row, column);
    }

    // work out the label anchor point...
    Point2D anchorPoint = calculateLabelAnchorPoint(
            position.getItemLabelAnchor(), bar, plot.getOrientation());

    if (isInternalAnchor(position.getItemLabelAnchor())) {
        Shape bounds = TextUtilities.calculateRotatedStringBounds(label,
                g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());

        if (bounds != null) {
            if (!bar.contains(bounds.getBounds2D())) {
                if (!negative) {
                    position = getPositiveItemLabelPositionFallback();
                }
                else {
                    position = getNegativeItemLabelPositionFallback();
                }
                if (position != null) {
                    anchorPoint = calculateLabelAnchorPoint(
                            position.getItemLabelAnchor(), bar,
                            plot.getOrientation());
                }
            }
        }

    }

    if (position != null) {
        TextUtilities.drawRotatedString(label, g2,
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());
    }
}
 
Example 15
Source File: XYTextAnnotation.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  an optional info object that will be populated with
 *              entity information.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
                 ValueAxis domainAxis, ValueAxis rangeAxis,
                 int rendererIndex, PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);

    float anchorX = (float) domainAxis.valueToJava2D(
            this.x, dataArea, domainEdge);
    float anchorY = (float) rangeAxis.valueToJava2D(
            this.y, dataArea, rangeEdge);

    if (orientation == PlotOrientation.HORIZONTAL) {
        float tempAnchor = anchorX;
        anchorX = anchorY;
        anchorY = tempAnchor;
    }

    g2.setFont(getFont());
    Shape hotspot = TextUtilities.calculateRotatedStringBounds(
            getText(), g2, anchorX, anchorY, getTextAnchor(),
            getRotationAngle(), getRotationAnchor());
    if (this.backgroundPaint != null) {
        g2.setPaint(this.backgroundPaint);
        g2.fill(hotspot);
    }
    g2.setPaint(getPaint());
    TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY,
            getTextAnchor(), getRotationAngle(), getRotationAnchor());
    if (this.outlineVisible) {
        g2.setStroke(this.outlineStroke);
        g2.setPaint(this.outlinePaint);
        g2.draw(hotspot);
    }

    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, hotspot, rendererIndex, toolTip, url);
    }

}
 
Example 16
Source File: XYBarRenderer.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Draws an item label.  This method is overridden so that the bar can be 
 * used to calculate the label anchor point.
 * 
 * @param g2  the graphics device.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param plot  the plot.
 * @param generator  the label generator.
 * @param bar  the bar.
 * @param negative  a flag indicating a negative value.
 */
protected void drawItemLabel(Graphics2D g2, XYDataset dataset,
        int series, int item, XYPlot plot, XYItemLabelGenerator generator, 
        Rectangle2D bar, boolean negative) {
                                 
    String label = generator.generateLabel(dataset, series, item);
    if (label == null) {
        return;  // nothing to do   
    }
    
    Font labelFont = getItemLabelFont(series, item);
    g2.setFont(labelFont);
    Paint paint = getItemLabelPaint(series, item);
    g2.setPaint(paint);

    // find out where to place the label...
    ItemLabelPosition position = null;
    if (!negative) {
        position = getPositiveItemLabelPosition(series, item);
    }
    else {
        position = getNegativeItemLabelPosition(series, item);
    }

    // work out the label anchor point...
    Point2D anchorPoint = calculateLabelAnchorPoint(
            position.getItemLabelAnchor(), bar, plot.getOrientation());
    
    if (isInternalAnchor(position.getItemLabelAnchor())) {
        Shape bounds = TextUtilities.calculateRotatedStringBounds(label, 
                g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());
        
        if (bounds != null) {
            if (!bar.contains(bounds.getBounds2D())) {
                if (!negative) {
                    position = getPositiveItemLabelPositionFallback();
                }
                else {
                    position = getNegativeItemLabelPositionFallback();
                }
                if (position != null) {
                    anchorPoint = calculateLabelAnchorPoint(
                            position.getItemLabelAnchor(), bar, 
                            plot.getOrientation());
                }
            }
        }
    
    }
    
    if (position != null) {
        TextUtilities.drawRotatedString(label, g2, 
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(), 
                position.getRotationAnchor());
    }        
}
 
Example 17
Source File: XYPointerAnnotation.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  the plot rendering info.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
        ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, 
        PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);
    double j2DX = domainAxis.valueToJava2D(getX(), dataArea, domainEdge);
    double j2DY = rangeAxis.valueToJava2D(getY(), dataArea, rangeEdge);
    if (orientation == PlotOrientation.HORIZONTAL) {
        double temp = j2DX;
        j2DX = j2DY;
        j2DY = temp;
    }
    double startX = j2DX + Math.cos(this.angle) * this.baseRadius;
    double startY = j2DY + Math.sin(this.angle) * this.baseRadius;

    double endX = j2DX + Math.cos(this.angle) * this.tipRadius;
    double endY = j2DY + Math.sin(this.angle) * this.tipRadius;

    double arrowBaseX = endX + Math.cos(this.angle) * this.arrowLength;
    double arrowBaseY = endY + Math.sin(this.angle) * this.arrowLength;

    double arrowLeftX = arrowBaseX
            + Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth;
    double arrowLeftY = arrowBaseY
            + Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth;

    double arrowRightX = arrowBaseX
            - Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth;
    double arrowRightY = arrowBaseY
            - Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth;

    GeneralPath arrow = new GeneralPath();
    arrow.moveTo((float) endX, (float) endY);
    arrow.lineTo((float) arrowLeftX, (float) arrowLeftY);
    arrow.lineTo((float) arrowRightX, (float) arrowRightY);
    arrow.closePath();

    g2.setStroke(this.arrowStroke);
    g2.setPaint(this.arrowPaint);
    Line2D line = new Line2D.Double(startX, startY, arrowBaseX, arrowBaseY);
    g2.draw(line);
    g2.fill(arrow);

    // draw the label
    double labelX = j2DX + Math.cos(this.angle) * (this.baseRadius
            + this.labelOffset);
    double labelY = j2DY + Math.sin(this.angle) * (this.baseRadius
            + this.labelOffset);
    g2.setFont(getFont());
    Shape hotspot = TextUtilities.calculateRotatedStringBounds(
            getText(), g2, (float) labelX, (float) labelY, getTextAnchor(),
            getRotationAngle(), getRotationAnchor());
    if (getBackgroundPaint() != null) {
        g2.setPaint(getBackgroundPaint());
        g2.fill(hotspot);
    }
    g2.setPaint(getPaint());
    TextUtilities.drawRotatedString(getText(), g2, (float) labelX,
            (float) labelY, getTextAnchor(), getRotationAngle(),
            getRotationAnchor());
    if (isOutlineVisible()) {
        g2.setStroke(getOutlineStroke());
        g2.setPaint(getOutlinePaint());
        g2.draw(hotspot);
    }

    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, hotspot, rendererIndex, toolTip, url);
    }

}
 
Example 18
Source File: BarRenderer.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Draws an item label.  This method is overridden so that the bar can be 
 * used to calculate the label anchor point.
 * 
 * @param g2  the graphics device.
 * @param data  the dataset.
 * @param row  the row.
 * @param column  the column.
 * @param plot  the plot.
 * @param generator  the label generator.
 * @param bar  the bar.
 * @param negative  a flag indicating a negative value.
 */
protected void drawItemLabel(Graphics2D g2,
                             CategoryDataset data,
                             int row,
                             int column,
                             CategoryPlot plot,
                             CategoryItemLabelGenerator generator,
                             Rectangle2D bar,
                             boolean negative) {
                                 
    String label = generator.generateLabel(data, row, column);
    if (label == null) {
        return;  // nothing to do   
    }
    
    Font labelFont = getItemLabelFont(row, column);
    g2.setFont(labelFont);
    Paint paint = getItemLabelPaint(row, column);
    g2.setPaint(paint);

    // find out where to place the label...
    ItemLabelPosition position = null;
    if (!negative) {
        position = getPositiveItemLabelPosition(row, column);
    }
    else {
        position = getNegativeItemLabelPosition(row, column);
    }

    // work out the label anchor point...
    Point2D anchorPoint = calculateLabelAnchorPoint(
            position.getItemLabelAnchor(), bar, plot.getOrientation());
    
    if (isInternalAnchor(position.getItemLabelAnchor())) {
        Shape bounds = TextUtilities.calculateRotatedStringBounds(label, 
                g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());
        
        if (bounds != null) {
            if (!bar.contains(bounds.getBounds2D())) {
                if (!negative) {
                    position = getPositiveItemLabelPositionFallback();
                }
                else {
                    position = getNegativeItemLabelPositionFallback();
                }
                if (position != null) {
                    anchorPoint = calculateLabelAnchorPoint(
                            position.getItemLabelAnchor(), bar, 
                            plot.getOrientation());
                }
            }
        }
    
    }
    
    if (position != null) {
        TextUtilities.drawRotatedString(label, g2, 
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(), 
                position.getRotationAnchor());
    }        
}
 
Example 19
Source File: XYBarRenderer.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Draws an item label.  This method is provided as an alternative to
 * {@link #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int,
 * double, double, boolean)} so that the bar can be used to calculate the
 * label anchor point.
 *
 * @param g2  the graphics device.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param plot  the plot.
 * @param generator  the label generator (<code>null</code> permitted, in
 *         which case the method does nothing, just returns).
 * @param bar  the bar.
 * @param negative  a flag indicating a negative value.
 */
protected void drawItemLabel(Graphics2D g2, XYDataset dataset,
        int series, int item, XYPlot plot, XYItemLabelGenerator generator,
        Rectangle2D bar, boolean negative) {

    if (generator == null) {
        return;  // nothing to do
    }
    String label = generator.generateLabel(dataset, series, item);
    if (label == null) {
        return;  // nothing to do
    }

    Font labelFont = getItemLabelFont(series, item);
    g2.setFont(labelFont);
    Paint paint = getItemLabelPaint(series, item);
    g2.setPaint(paint);

    // find out where to place the label...
    ItemLabelPosition position;
    if (!negative) {
        position = getPositiveItemLabelPosition(series, item);
    }
    else {
        position = getNegativeItemLabelPosition(series, item);
    }

    // work out the label anchor point...
    Point2D anchorPoint = calculateLabelAnchorPoint(
            position.getItemLabelAnchor(), bar, plot.getOrientation());

    if (isInternalAnchor(position.getItemLabelAnchor())) {
        Shape bounds = TextUtilities.calculateRotatedStringBounds(label,
                g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());

        if (bounds != null) {
            if (!bar.contains(bounds.getBounds2D())) {
                if (!negative) {
                    position = getPositiveItemLabelPositionFallback();
                }
                else {
                    position = getNegativeItemLabelPositionFallback();
                }
                if (position != null) {
                    anchorPoint = calculateLabelAnchorPoint(
                            position.getItemLabelAnchor(), bar,
                            plot.getOrientation());
                }
            }
        }

    }

    if (position != null) {
        TextUtilities.drawRotatedString(label, g2,
                (float) anchorPoint.getX(), (float) anchorPoint.getY(),
                position.getTextAnchor(), position.getAngle(),
                position.getRotationAnchor());
    }
}
 
Example 20
Source File: ValueAxis.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the axis line, tick marks and tick mark labels.
 * 
 * @param g2  the graphics device.
 * @param cursor  the cursor.
 * @param plotArea  the plot area.
 * @param dataArea  the data area.
 * @param edge  the edge that the axis is aligned with.
 * 
 * @return The width or height used to draw the axis.
 */
protected AxisState drawTickMarksAndLabels(Graphics2D g2, 
                                           double cursor,
                                           Rectangle2D plotArea,
                                           Rectangle2D dataArea, 
                                           RectangleEdge edge) {
                                          
    AxisState state = new AxisState(cursor);

    if (isAxisLineVisible()) {
        drawAxisLine(g2, cursor, dataArea, edge);
    }

    double ol = getTickMarkOutsideLength();
    double il = getTickMarkInsideLength();

    List ticks = refreshTicks(g2, state, dataArea, edge);
    state.setTicks(ticks);
    g2.setFont(getTickLabelFont());
    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        ValueTick tick = (ValueTick) iterator.next();
        if (isTickLabelsVisible()) {
            g2.setPaint(getTickLabelPaint());
            float[] anchorPoint = calculateAnchorPoint(tick, cursor, 
                    dataArea, edge);
            TextUtilities.drawRotatedString(tick.getText(), g2, 
                    anchorPoint[0], anchorPoint[1], tick.getTextAnchor(), 
                    tick.getAngle(), tick.getRotationAnchor());
        }

        if (isTickMarksVisible()) {
            float xx = (float) valueToJava2D(tick.getValue(), dataArea, 
                    edge);
            Line2D mark = null;
            g2.setStroke(getTickMarkStroke());
            g2.setPaint(getTickMarkPaint());
            if (edge == RectangleEdge.LEFT) {
                mark = new Line2D.Double(cursor - ol, xx, cursor + il, xx);
            }
            else if (edge == RectangleEdge.RIGHT) {
                mark = new Line2D.Double(cursor + ol, xx, cursor - il, xx);
            }
            else if (edge == RectangleEdge.TOP) {
                mark = new Line2D.Double(xx, cursor - ol, xx, cursor + il);
            }
            else if (edge == RectangleEdge.BOTTOM) {
                mark = new Line2D.Double(xx, cursor + ol, xx, cursor - il);
            }
            g2.draw(mark);
        }
    }
    
    // need to work out the space used by the tick labels...
    // so we can update the cursor...
    double used = 0.0;
    if (isTickLabelsVisible()) {
        if (edge == RectangleEdge.LEFT) {
            used += findMaximumTickLabelWidth(ticks, g2, plotArea, 
                    isVerticalTickLabels());  
            state.cursorLeft(used);      
        }
        else if (edge == RectangleEdge.RIGHT) {
            used = findMaximumTickLabelWidth(ticks, g2, plotArea, 
                    isVerticalTickLabels());
            state.cursorRight(used);      
        }
        else if (edge == RectangleEdge.TOP) {
            used = findMaximumTickLabelHeight(ticks, g2, plotArea, 
                    isVerticalTickLabels());
            state.cursorUp(used);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            used = findMaximumTickLabelHeight(ticks, g2, plotArea, 
                    isVerticalTickLabels());
            state.cursorDown(used);
        }
    }
   
    return state;
}