List of usage examples for java.awt Graphics2D draw
public abstract void draw(Shape s);
From source file:org.pentaho.plugin.jfreereport.reportcharts.JFreeChartReportDrawable.java
public void draw(final Graphics2D graphics2D, final Rectangle2D bounds) { this.bounds = (Rectangle2D) bounds.clone(); if (chartRenderingInfo != null) { this.chartRenderingInfo.clear(); }/*from ww w.j a v a 2 s. co m*/ final Graphics2D g2 = (Graphics2D) graphics2D.create(); this.chart.draw(g2, bounds, chartRenderingInfo); g2.dispose(); if (chartRenderingInfo == null || debugRendering == false) { return; } graphics2D.setColor(Color.RED); final Rectangle2D dataArea = getDataAreaOffset(); final EntityCollection entityCollection = chartRenderingInfo.getEntityCollection(); for (int i = 0; i < entityCollection.getEntityCount(); i++) { final ChartEntity chartEntity = entityCollection.getEntity(i); if (chartEntity instanceof XYItemEntity || chartEntity instanceof CategoryItemEntity || chartEntity instanceof PieSectionEntity) { final Area a = new Area(chartEntity.getArea()); if (buggyDrawArea) { a.transform(AffineTransform.getTranslateInstance(dataArea.getX(), dataArea.getY())); } a.intersect(new Area(dataArea)); graphics2D.draw(a); } else { graphics2D.draw(chartEntity.getArea()); } } }
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * * Pinta el rectangulo sombreado mientras se realiza la seleccin * @param g2 the graphics device. //from w w w. j av a2s .com */ private void drawRectangle(Graphics2D g2) { // Set XOR mode to draw the zoom rectangle g2.setXORMode(Color.gray); if (this.zoomRectangle != null) { if (this.fillZoomRectangle) { g2.fill(this.zoomRectangle); } else { g2.draw(this.zoomRectangle); } } // Reset to the default 'overwrite' mode g2.setPaintMode(); }
From source file:gov.nih.nci.caintegrator.application.geneexpression.BoxAndWhiskerCoinPlotRenderer.java
private RectangleEdge drawRectangles(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, ValueAxis rangeAxis, int row, int column, BoxAndWhiskerCategoryDataset bawDataset, double xx) { RectangleEdge location = plot.getRangeAxisEdge(); Number yQ1 = bawDataset.getQ1Value(row, column); Number yQ3 = bawDataset.getQ3Value(row, column); Number yMax = bawDataset.getMaxRegularValue(row, column); Number yMin = bawDataset.getMinRegularValue(row, column); Shape box = null;/*from www .j a va 2s. c o m*/ if (yQ1 != null && yQ3 != null && yMax != null && yMin != null) { double yyQ1 = rangeAxis.valueToJava2D(yQ1.doubleValue(), dataArea, location); double yyQ3 = rangeAxis.valueToJava2D(yQ3.doubleValue(), dataArea, location); double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(), dataArea, location); double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(), dataArea, location); double xxmid = xx + state.getBarWidth() / 2.0; // draw the upper shadow... g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3)); g2.draw(new Line2D.Double(xx, yyMax, xx + state.getBarWidth(), yyMax)); // draw the lower shadow... g2.draw(new Line2D.Double(xxmid, yyMin, xxmid, yyQ1)); g2.draw(new Line2D.Double(xx, yyMin, xx + state.getBarWidth(), yyMin)); // draw the body... box = new Rectangle2D.Double(xx, Math.min(yyQ1, yyQ3), state.getBarWidth(), Math.abs(yyQ1 - yyQ3)); if (getFillBox()) { g2.fill(box); } g2.draw(box); } return location; }
From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialScale.java
/** * Draws the scale on the dial plot.//from w ww .j av a 2s . 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:net.sf.jasperreports.chartthemes.spring.ScaledDialScale.java
/** * Draws the scale on the dial plot./*from ww w.j a v a2 s . c o 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:org.kalypso.ogc.sensor.diagview.jfreechart.ObservationPlot.java
/** * Draw alarmlevels (horizontal line and text annotation) *//*from w ww . j a v a 2 s . co m*/ private void drawAlarmLevels(final Graphics2D g2, final Rectangle2D dataArea) { for (final Object element : m_yConsts.keySet()) { final AlarmLevelPlotElement vac = m_yConsts.get(element); final ValueAxis axis = m_diag2chartAxis.get(vac.getAxis()); if (axis == null) continue; if (axis.getRange().contains(vac.getAlarm().value)) { final double yy = axis.valueToJava2D(vac.getAlarm().value, dataArea, RectangleEdge.LEFT); final Line2D line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy); // always set stroke, else we got the stroke from the last drawn line g2.setStroke(AlarmLevelPlotElement.STROKE_ALARM); g2.setPaint(vac.getAlarm().color); g2.draw(line); // and draw the text annotation: if annotation is outside (on top); label it below the line if (yy < dataArea.getMinY() + 20) vac.getAnnotation().setAngle(Math.toRadians(20)); else vac.getAnnotation().setAngle(Math.toRadians(340)); vac.getAnnotation().draw(g2, this, dataArea, getDomainAxis(), axis); } } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java
private void drawTextDecoration(final FontDecorationSpec decorationSpec) { final Graphics2D graphics = (Graphics2D) getGraphics().create(); graphics.setColor(decorationSpec.getTextColor()); graphics.setStroke(new BasicStroke((float) decorationSpec.getLineWidth())); graphics.draw(new Line2D.Double(decorationSpec.getStart(), decorationSpec.getVerticalPosition(), decorationSpec.getEnd(), decorationSpec.getVerticalPosition())); graphics.dispose();// w w w . j av a 2s . com }
From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java
private void drawEntity(Shape entity, Graphics2D g2, Color fill, Color stroke, ChartPanel chartPanel, boolean scale, float alpha) { if (entity != null) { //System.out.println("Drawing entity with bbox: "+entity.getBounds2D()); Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); Color c = g2.getColor();/*w w w. j a va 2s . c o m*/ Composite comp = g2.getComposite(); g2.clip(dataArea); g2.setColor(fill); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); AffineTransform originalTransform = g2.getTransform(); Shape transformed = entity; FlatteningPathIterator iter = new FlatteningPathIterator( transformed.getPathIterator(new AffineTransform()), 1); Path2D.Float path = new Path2D.Float(); path.append(iter, false); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); g2.fill(path); if (stroke != null) { g2.setColor(stroke); g2.draw(path); } g2.setComposite(comp); g2.setColor(c); g2.setClip(savedClip); } else { Logger.getLogger(getClass().getName()).info("Entity is null!"); } }
From source file:com.android.ddmuilib.log.event.OccurrenceRenderer.java
@Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { TimeSeriesCollection timeDataSet = (TimeSeriesCollection) dataset; // get the x value for the series/item. double x = timeDataSet.getX(series, item).doubleValue(); // get the min/max of the range axis double yMin = rangeAxis.getLowerBound(); double yMax = rangeAxis.getUpperBound(); RectangleEdge domainEdge = plot.getDomainAxisEdge(); RectangleEdge rangeEdge = plot.getRangeAxisEdge(); // convert the coordinates to java2d. double x2D = domainAxis.valueToJava2D(x, dataArea, domainEdge); double yMin2D = rangeAxis.valueToJava2D(yMin, dataArea, rangeEdge); double yMax2D = rangeAxis.valueToJava2D(yMax, dataArea, rangeEdge); // get the paint information for the series/item Paint p = getItemPaint(series, item); Stroke s = getItemStroke(series, item); Line2D line = null;//from www .ja v a2 s. c om PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(yMin2D, x2D, yMax2D, x2D); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(x2D, yMin2D, x2D, yMax2D); } g2.setPaint(p); g2.setStroke(s); g2.draw(line); }
From source file:org.openaltimeter.desktopapp.annotations.XYHeightAnnotation.java
@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.getX(), dataArea, domainEdge); float anchorY = (float) rangeAxis.valueToJava2D(this.getY(), dataArea, rangeEdge); if (orientation == PlotOrientation.HORIZONTAL) { float tempAnchor = anchorX; anchorX = anchorY;//from w w w.j av a 2 s . co m anchorY = tempAnchor; } g2.setFont(getFont()); Shape hotspot = TextUtilities.calculateRotatedStringBounds(getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor()); if (this.getBackgroundPaint() != null) { g2.setPaint(this.getBackgroundPaint()); g2.fill(hotspot); } g2.setPaint(getPaint()); TextUtilities.drawRotatedString(getText(), g2, anchorX + (3.6f * DOT_SIZE), anchorY + (0.2f * DOT_SIZE), getTextAnchor(), getRotationAngle(), getRotationAnchor()); if (this.isOutlineVisible()) { g2.setStroke(this.getOutlineStroke()); g2.setPaint(this.getOutlinePaint()); g2.draw(hotspot); } // cross drawing // g2.setPaint(getPaint()); // g2.setStroke(new BasicStroke(1.0f)); // g2.drawLine((int) anchorX - CROSS_SIZE / 2, (int) anchorY, (int) anchorX + CROSS_SIZE / 2, (int) anchorY); // g2.drawLine((int) anchorX, (int) anchorY - CROSS_SIZE / 2, (int) anchorX, (int) anchorY + CROSS_SIZE / 2); // dot drawing g2.setPaint(getPaint()); g2.setStroke(new BasicStroke(1.0f)); Ellipse2D e = new Ellipse2D.Double(anchorX - DOT_SIZE / 2, anchorY - DOT_SIZE / 2, DOT_SIZE, DOT_SIZE); g2.fill(e); String toolTip = getToolTipText(); String url = getURL(); if (toolTip != null || url != null) { addEntity(info, hotspot, rendererIndex, toolTip, url); } }