Search in sources :

Example 6 with RectangleAnchor

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

the class Crosshair method setLabelAnchor.

/**
 * Sets the label anchor point and sends a property change event (with the
 * name 'labelAnchor') to all registered listeners.
 *
 * @param anchor  the anchor (<code>null</code> not permitted).
 *
 * @see #getLabelAnchor()
 */
public void setLabelAnchor(RectangleAnchor anchor) {
    RectangleAnchor old = this.labelAnchor;
    this.labelAnchor = anchor;
    this.pcs.firePropertyChange("labelAnchor", old, anchor);
}
Also used : RectangleAnchor(org.jfree.ui.RectangleAnchor)

Example 7 with RectangleAnchor

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

the class AbstractCategoryItemRenderer method drawDomainMarker.

/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
@Override
public void drawDomainMarker(Graphics2D g2, CategoryPlot plot, CategoryAxis axis, CategoryMarker marker, Rectangle2D dataArea) {
    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }
    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, marker.getAlpha()));
    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);
        } else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());
        } else {
            throw new IllegalStateException();
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    } else {
        double v0 = axis.getCategoryStart(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0, dataArea.getWidth(), (v1 - v0));
        } else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(), (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }
    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(g2, orientation, dataArea, bounds, marker.getLabelOffset(), marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Rectangle2D(java.awt.geom.Rectangle2D) RectangleAnchor(org.jfree.ui.RectangleAnchor) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Font(java.awt.Font) Point2D(java.awt.geom.Point2D) CategoryDataset(org.jfree.data.category.CategoryDataset)

Example 8 with RectangleAnchor

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

the class BarRenderer3D method drawRangeMarker.

/**
 * Draws a range marker.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param marker  the marker.
 * @param dataArea  the area for plotting data (not including 3D effect).
 */
@Override
public void drawRangeMarker(Graphics2D g2, CategoryPlot plot, ValueAxis axis, Marker marker, Rectangle2D dataArea) {
    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());
    if (marker instanceof ValueMarker) {
        ValueMarker vm = (ValueMarker) marker;
        double value = vm.getValue();
        Range range = axis.getRange();
        if (!range.contains(value)) {
            return;
        }
        GeneralPath path = null;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            float x = (float) axis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge());
            float y = (float) adjusted.getMaxY();
            path = new GeneralPath();
            path.moveTo(x, y);
            path.lineTo((float) (x + getXOffset()), y - (float) getYOffset());
            path.lineTo((float) (x + getXOffset()), (float) (adjusted.getMinY() - getYOffset()));
            path.lineTo(x, (float) adjusted.getMinY());
            path.closePath();
        } else if (orientation == PlotOrientation.VERTICAL) {
            float y = (float) axis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge());
            float x = (float) dataArea.getX();
            path = new GeneralPath();
            path.moveTo(x, y);
            path.lineTo(x + (float) this.xOffset, y - (float) this.yOffset);
            path.lineTo((float) (adjusted.getMaxX() + this.xOffset), y - (float) this.yOffset);
            path.lineTo((float) (adjusted.getMaxX()), y);
            path.closePath();
        } else {
            throw new IllegalStateException();
        }
        g2.setPaint(marker.getPaint());
        g2.fill(path);
        g2.setPaint(marker.getOutlinePaint());
        g2.draw(path);
        String label = marker.getLabel();
        RectangleAnchor anchor = marker.getLabelAnchor();
        if (label != null) {
            Font labelFont = marker.getLabelFont();
            g2.setFont(labelFont);
            g2.setPaint(marker.getLabelPaint());
            Point2D coordinates = calculateRangeMarkerTextAnchorPoint(g2, orientation, dataArea, path.getBounds2D(), marker.getLabelOffset(), LengthAdjustmentType.EXPAND, anchor);
            TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor());
        }
    } else {
        super.drawRangeMarker(g2, plot, axis, marker, adjusted);
    // TODO: draw the interval marker with a 3D effect
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) GeneralPath(java.awt.geom.GeneralPath) Rectangle2D(java.awt.geom.Rectangle2D) RectangleAnchor(org.jfree.ui.RectangleAnchor) Range(org.jfree.data.Range) Font(java.awt.Font) Point2D(java.awt.geom.Point2D) ValueMarker(org.jfree.chart.plot.ValueMarker)

Aggregations

RectangleAnchor (org.jfree.ui.RectangleAnchor)8 Point2D (java.awt.geom.Point2D)7 Paint (java.awt.Paint)6 Line2D (java.awt.geom.Line2D)6 Font (java.awt.Font)5 Rectangle2D (java.awt.geom.Rectangle2D)5 PlotOrientation (org.jfree.chart.plot.PlotOrientation)5 AlphaComposite (java.awt.AlphaComposite)4 Composite (java.awt.Composite)4 GradientPaint (java.awt.GradientPaint)4 ValueMarker (org.jfree.chart.plot.ValueMarker)4 Range (org.jfree.data.Range)4 IntervalMarker (org.jfree.chart.plot.IntervalMarker)3 GradientPaintTransformer (org.jfree.ui.GradientPaintTransformer)3 Shape (java.awt.Shape)2 Stroke (java.awt.Stroke)2 TextAnchor (org.jfree.ui.TextAnchor)2 GeneralPath (java.awt.geom.GeneralPath)1 CategoryDataset (org.jfree.data.category.CategoryDataset)1