Example usage for java.awt.geom Arc2D OPEN

List of usage examples for java.awt.geom Arc2D OPEN

Introduction

In this page you can find the example usage for java.awt.geom Arc2D OPEN.

Prototype

int OPEN

To view the source code for java.awt.geom Arc2D OPEN.

Click Source Link

Document

The closure type for an open arc with no path segments connecting the two ends of the arc segment.

Usage

From source file:FilledArc.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int x = 5;// w  w w .j a  v  a  2 s.c  om
    int y = 7;

    // fill Arc2D
    g2.setPaint(Color.red);
    g2.fill(new Arc2D.Double(x, y, 200, 200, 90, 135, Arc2D.OPEN));
    g2.setPaint(Color.black);
    g2.drawString("Filled Arc2D", x, 250);

}

From source file:ArcDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);/*from   ww w  .j  a v a 2  s  .co m*/
    int x = 5;
    int y = 7;

    g2.setStroke(wideStroke);
    g2.draw(new Arc2D.Double(x, y, 200, 200, 90, 135, Arc2D.OPEN));
    g2.drawString("Arc2D", x, 250);
}

From source file:com.bdb.weather.display.current.WindDirPointer.java

/**
 * Draws the pointer./*from w ww . jav a2 s.  c o m*/
 * 
 * @param g2 The graphics target.
 * @param plot The plot.
 * @param frame The dial's reference frame.
 * @param view The dial's view.
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {
    g2.setPaint(Color.blue);
    g2.setStroke(new BasicStroke(1.0f));
    DialScale scale = plot.getScaleForDataset(getDatasetIndex());
    double value = plot.getValue(getDatasetIndex());
    double angle = scale.valueToAngle(value % 360.0);

    Rectangle2D outerRect = DialPlot.rectangleByRadius(frame, outerRadius, outerRadius);
    Rectangle2D innerRect = DialPlot.rectangleByRadius(frame, outerRadius - innerOffset,
            outerRadius - innerOffset);

    g2.setPaint(getOutlinePaint());
    Arc2D arc1 = new Arc2D.Double(outerRect, angle - (ARC_LENGTH / 2), ARC_LENGTH, Arc2D.OPEN);
    g2.draw(arc1);
    Arc2D arc2 = new Arc2D.Double(innerRect, angle, 0.0, Arc2D.OPEN);
    GeneralPath gp = new GeneralPath();
    gp.moveTo(arc1.getStartPoint().getX(), arc1.getStartPoint().getY());
    gp.lineTo(arc2.getStartPoint().getX(), arc2.getStartPoint().getY());
    gp.lineTo(arc1.getEndPoint().getX(), arc1.getEndPoint().getY());
    g2.draw(gp);
    if (fill) {
        g2.setPaint(getFillPaint());
        g2.fill(gp);
    }
}

From source file:net.sf.jasperreports.chartthemes.spring.ScaledDialRange.java

/**
 * Draws the range.//from  w  w w  . java2s. co  m
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame (in Java2D space).
 * @param view  the dial's view rectangle (in Java2D space).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame, this.getInnerRadius(), this.getInnerRadius());
    Rectangle2D arcRectOuter = DialPlot.rectangleByRadius(frame, this.getOuterRadius(), this.getOuterRadius());

    DialScale scale = plot.getScale(this.getScaleIndex());
    if (scale == null) {
        throw new RuntimeException("No scale for scaleIndex = " + this.getScaleIndex());
    }
    double angleMin = scale.valueToAngle(this.getLowerBound());
    double angleMax = scale.valueToAngle(this.getUpperBound());

    Arc2D arcInner = new Arc2D.Double(arcRectInner, angleMin, angleMax - angleMin, Arc2D.OPEN);
    Arc2D arcOuter = new Arc2D.Double(arcRectOuter, angleMax, angleMin - angleMax, Arc2D.OPEN);

    g2.setPaint(this.getPaint());
    g2.setStroke(new BasicStroke(this.lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    g2.draw(arcInner);
    g2.draw(arcOuter);
}

From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialRange.java

/**
 * Draws the range.//from   ww w.j  a va  2 s . c o m
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame (in Java2D space).
 * @param view  the dial's view rectangle (in Java2D space).
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame, this.getInnerRadius(), this.getInnerRadius());
    Rectangle2D arcRectOuter = DialPlot.rectangleByRadius(frame, this.getOuterRadius(), this.getOuterRadius());

    DialScale scale = plot.getScale(this.getScaleIndex());
    if (scale == null) {
        throw new RuntimeException("No scale for scaleIndex = " + this.getScaleIndex());
    }
    double angleMin = scale.valueToAngle(this.getLowerBound());
    double angleMax = scale.valueToAngle(this.getUpperBound());

    Arc2D arcInner = new Arc2D.Double(arcRectInner, angleMin, angleMax - angleMin, Arc2D.OPEN);
    Arc2D arcOuter = new Arc2D.Double(arcRectOuter, angleMax, angleMin - angleMax, Arc2D.OPEN);

    g2.setPaint(this.getPaint());
    g2.setStroke(new BasicStroke(this.lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    g2.draw(arcInner);
    g2.draw(arcOuter);
}

From source file:net.sf.jasperreports.chartthemes.spring.ScaledDialValueIndicator.java

/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been
 * set to this window before this method is called.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle (<code>null</code> not permitted).
 *//* ww w .jav a 2s. c  o m*/
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    // work out the anchor point
    Rectangle2D f = DialPlot.rectangleByRadius(frame, getRadius(), this.getRadius());
    Arc2D arc = new Arc2D.Double(f, this.getAngle(), 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();

    // calculate the bounds of the template value
    FontMetrics fm = g2.getFontMetrics(this.getFont());
    String s = this.getNumberFormat().format(this.getTemplateValue());
    Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm);

    // align this rectangle to the frameAnchor
    Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(tb.getWidth(), tb.getHeight()), pt.getX(),
            pt.getY(), this.getFrameAnchor());

    // add the insets
    Rectangle2D fb = this.getInsets().createOutsetRectangle(bounds);

    // draw the background
    g2.setPaint(this.getBackgroundPaint());
    g2.fill(fb);

    // draw the border
    g2.setStroke(this.getOutlineStroke());
    g2.setPaint(this.getOutlinePaint());
    g2.draw(fb);

    // now find the text anchor point
    String valueStr = this.getNumberFormat()
            .format(ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale));
    Point2D pt2 = RectangleAnchor.coordinates(bounds, this.getValueAnchor());
    g2.setPaint(this.getPaint());
    g2.setFont(this.getFont());
    TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.getTextAnchor());

}

From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialValueIndicator.java

/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been
 * set to this window before this method is called.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle (<code>null</code> not permitted).
 *//*  w ww. j  a va2 s .c  o m*/
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    // work out the anchor point
    Rectangle2D f = DialPlot.rectangleByRadius(frame, getRadius(), this.getRadius());
    Arc2D arc = new Arc2D.Double(f, this.getAngle(), 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();

    // calculate the bounds of the template value
    FontMetrics fm = g2.getFontMetrics(this.getFont());
    String s = this.getNumberFormat().format(this.getTemplateValue());
    Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm);

    // align this rectangle to the frameAnchor
    Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(tb.getWidth(), tb.getHeight()), pt.getX(),
            pt.getY(), this.getFrameAnchor());

    // add the insets
    Rectangle2D fb = this.getInsets().createOutsetRectangle(bounds);

    // draw the background
    g2.setPaint(this.getBackgroundPaint());
    g2.fill(fb);

    // draw the border
    g2.setStroke(this.getOutlineStroke());
    g2.setPaint(this.getOutlinePaint());
    g2.draw(fb);

    // now find the text anchor point
    String valueStr = this.getNumberFormat()
            .format(ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale));
    Point2D pt2 = RectangleAnchor.coordinates(bounds, this.getValueAnchor());
    g2.setPaint(this.getPaint());
    g2.setFont(this.getFont());
    TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.getTextAnchor());

}

From source file:net.sf.jasperreports.chartthemes.spring.ScaledDialScale.java

/**
 * Draws the scale on the dial plot./*from   ww  w  .ja v  a 2 s  . co  m*/
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the dial plot (<code>null</code> not permitted).
 * @param frame  the reference frame that is used to construct the
 *     geometry of the plot (<code>null</code> not permitted).
 * @param view  the visible part of the plot (<code>null</code> not 
 *     permitted).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, this.getTickRadius(), this.getTickRadius());
    Rectangle2D arcRectMajor = DialPlot.rectangleByRadius(frame,
            this.getTickRadius() - this.getMajorTickLength(), this.getTickRadius() - this.getMajorTickLength());
    Rectangle2D arcRectMinor = arcRect;
    if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) {
        arcRectMinor = DialPlot.rectangleByRadius(frame, this.getTickRadius() - this.getMinorTickLength(),
                this.getTickRadius() - this.getMinorTickLength());
    }
    Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame,
            this.getTickRadius() - this.getTickLabelOffset(), this.getTickRadius() - this.getTickLabelOffset());

    boolean firstLabel = true;

    Arc2D arc = new Arc2D.Double();
    Line2D workingLine = new Line2D.Double();
    Stroke arcStroke = new BasicStroke(0.75f);

    for (double v = this.getLowerBound(); v <= this.getUpperBound(); v += this.getMajorTickIncrement()) {
        arc.setArc(arcRect, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN);
        g2.setPaint(this.getMajorTickPaint());
        g2.setStroke(arcStroke);
        g2.draw(arc);

        Point2D pt0 = arc.getEndPoint();
        arc.setArc(arcRectMajor, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN);
        Point2D pt1 = arc.getEndPoint();
        g2.setPaint(this.getMajorTickPaint());
        g2.setStroke(this.getMajorTickStroke());
        workingLine.setLine(pt0, pt1);
        g2.draw(workingLine);
        arc.setArc(arcRectForLabels, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN);
        Point2D pt2 = arc.getEndPoint();

        if (this.getTickLabelsVisible()) {
            if (!firstLabel || this.getFirstTickLabelVisible()) {
                g2.setFont(this.getTickLabelFont());
                TextUtilities.drawAlignedString(this.getTickLabelFormatter().format(v), g2, (float) pt2.getX(),
                        (float) pt2.getY(), TextAnchor.CENTER);
            }
        }
        firstLabel = false;

        // now do the minor tick marks
        if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) {
            double minorTickIncrement = this.getMajorTickIncrement() / (this.getMinorTickCount() + 1);
            for (int i = 0; i < this.getMinorTickCount(); i++) {
                double vv = v + ((i + 1) * minorTickIncrement);
                if (vv >= this.getUpperBound()) {
                    break;
                }
                double angle = valueToAngle(vv);

                arc.setArc(arcRect, this.getStartAngle(), angle - this.getStartAngle(), Arc2D.OPEN);
                pt0 = arc.getEndPoint();
                arc.setArc(arcRectMinor, this.getStartAngle(), angle - this.getStartAngle(), Arc2D.OPEN);
                Point2D pt3 = arc.getEndPoint();
                g2.setStroke(this.getMinorTickStroke());
                g2.setPaint(this.getMinorTickPaint());
                workingLine.setLine(pt0, pt3);
                g2.draw(workingLine);
            }
        }

    }
}

From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialScale.java

/**
 * Draws the scale on the dial plot./*from   w ww  .j  a v a2  s. c om*/
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the dial plot (<code>null</code> not permitted).
 * @param frame  the reference frame that is used to construct the
 *     geometry of the plot (<code>null</code> not permitted).
 * @param view  the visible part of the plot (<code>null</code> not 
 *     permitted).
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, this.getTickRadius(), this.getTickRadius());
    Rectangle2D arcRectMajor = DialPlot.rectangleByRadius(frame,
            this.getTickRadius() - this.getMajorTickLength(), this.getTickRadius() - this.getMajorTickLength());
    Rectangle2D arcRectMinor = arcRect;
    if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) {
        arcRectMinor = DialPlot.rectangleByRadius(frame, this.getTickRadius() - this.getMinorTickLength(),
                this.getTickRadius() - this.getMinorTickLength());
    }
    Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame,
            this.getTickRadius() - this.getTickLabelOffset(), this.getTickRadius() - this.getTickLabelOffset());

    boolean firstLabel = true;

    Arc2D arc = new Arc2D.Double();
    Line2D workingLine = new Line2D.Double();
    Stroke arcStroke = new BasicStroke(0.75f);

    for (double v = this.getLowerBound(); v <= this.getUpperBound(); v += this.getMajorTickIncrement()) {
        arc.setArc(arcRect, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN);
        g2.setPaint(this.getMajorTickPaint());
        g2.setStroke(arcStroke);
        g2.draw(arc);

        Point2D pt0 = arc.getEndPoint();
        arc.setArc(arcRectMajor, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN);
        Point2D pt1 = arc.getEndPoint();
        g2.setPaint(this.getMajorTickPaint());
        g2.setStroke(this.getMajorTickStroke());
        workingLine.setLine(pt0, pt1);
        g2.draw(workingLine);
        arc.setArc(arcRectForLabels, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN);
        Point2D pt2 = arc.getEndPoint();

        if (this.getTickLabelsVisible()) {
            if (!firstLabel || this.getFirstTickLabelVisible()) {
                g2.setFont(this.getTickLabelFont());
                TextUtilities.drawAlignedString(this.getTickLabelFormatter().format(v), g2, (float) pt2.getX(),
                        (float) pt2.getY(), TextAnchor.CENTER);
            }
        }
        firstLabel = false;

        // now do the minor tick marks
        if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) {
            double minorTickIncrement = this.getMajorTickIncrement() / (this.getMinorTickCount() + 1);
            for (int i = 0; i < this.getMinorTickCount(); i++) {
                double vv = v + ((i + 1) * minorTickIncrement);
                if (vv >= this.getUpperBound()) {
                    break;
                }
                double angle = valueToAngle(vv);

                arc.setArc(arcRect, this.getStartAngle(), angle - this.getStartAngle(), Arc2D.OPEN);
                pt0 = arc.getEndPoint();
                arc.setArc(arcRectMinor, this.getStartAngle(), angle - this.getStartAngle(), Arc2D.OPEN);
                Point2D pt3 = arc.getEndPoint();
                g2.setStroke(this.getMinorTickStroke());
                g2.setPaint(this.getMinorTickPaint());
                workingLine.setLine(pt0, pt3);
                g2.draw(workingLine);
            }
        }

    }
}

From source file:ro.nextreports.engine.util.chart.CylinderRenderer.java

/**
 * Draws a cylinder to represent one data item.
 * // ww w.  j a  va  2s. c om
 * @param g2 the graphics device.
 * @param state the renderer state.
 * @param dataArea the area for plotting the data.
 * @param plot the plot.
 * @param domainAxis the domain axis.
 * @param rangeAxis the range axis.
 * @param dataset the dataset.
 * @param row the row index (zero-based).
 * @param column the column index (zero-based).
 * @param pass the pass index.
 */
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // check the value we are plotting...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }

    double value = dataValue.doubleValue();

    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(),
            dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());

    PlotOrientation orientation = plot.getOrientation();

    double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column);
    double[] barL0L1 = calculateBarL0L1(value);
    if (barL0L1 == null) {
        return; // the bar is not visible
    }

    RectangleEdge edge = plot.getRangeAxisEdge();
    float transL0 = (float) rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
    float transL1 = (float) rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    float barL0 = Math.min(transL0, transL1);
    float barLength = Math.abs(transL1 - transL0);

    // draw the bar...
    GeneralPath bar = new GeneralPath();
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar.moveTo(barL0, (float) barW0);
        bar.lineTo(barL0, (float) (barW0 + state.getBarWidth()));
        bar.lineTo(barL0 + barLength, (float) (barW0 + state.getBarWidth()));
        bar.lineTo(barL0 + barLength, (float) barW0);
        bar.closePath();
    } else {
        bar.moveTo((float) barW0, (float) (barL0 - getYOffset() / 2));
        bar.lineTo((float) barW0, (float) (barL0 + barLength - getYOffset() / 2));
        Arc2D arc = new Arc2D.Double(barW0, (barL0 + barLength - getYOffset()), state.getBarWidth(),
                getYOffset(), 180, 180, Arc2D.OPEN);
        bar.append(arc, true);
        bar.lineTo((float) (barW0 + state.getBarWidth()), (float) (barL0 - getYOffset() / 2));
        arc = new Arc2D.Double(barW0, (barL0 - getYOffset()), state.getBarWidth(), getYOffset(), 0, -180,
                Arc2D.OPEN);
        bar.append(arc, true);
        bar.closePath();
    }
    Paint itemPaint = getItemPaint(row, column);
    if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) itemPaint;
        itemPaint = getGradientPaintTransformer().transform(gp, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    Shape bar3dTop = new Ellipse2D.Double(barW0, barL0 - getYOffset(), state.getBarWidth(), getYOffset());
    if (itemPaint instanceof GradientPaint) {
        g2.setPaint(((GradientPaint) itemPaint).getColor2());
    }
    g2.fill(bar3dTop);

    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemOutlineStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
        if (bar3dTop != null) {
            g2.draw(bar3dTop);
        }
    }

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar.getBounds2D(), (value < 0.0));
    }

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {

            String tip = null;
            CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
            if (tipster != null) {
                tip = tipster.generateToolTip(dataset, row, column);
            }
            String url = null;
            if (getItemURLGenerator(row, column) != null) {
                url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
            }
            CategoryItemEntity entity = new CategoryItemEntity(bar.getBounds2D(), tip, url, dataset,
                    dataset.getRowKey(row), dataset.getColumnKey(column));
            entities.add(entity);
        }
    }

}