List of usage examples for java.awt Graphics2D setStroke
public abstract void setStroke(Stroke s);
From source file:edu.ucla.stat.SOCR.motionchart.MotionBubbleRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param info collects information about the drawing. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain (horizontal) axis. * @param rangeAxis the range (vertical) axis. * @param dataset the dataset (a {@link edu.ucla.stat.SOCR.motionchart.MotionDataSet} is expected). * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. *//*w w w . ja va 2 s .c o m*/ @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) { if (!(dataset instanceof MotionDataSet)) { throw new IllegalArgumentException("The dataset must be of type MotionDataSet."); } // return straight away if the item is not visible if (!getItemVisible(series, item)) { return; } PlotOrientation orientation = plot.getOrientation(); Ellipse2D.Double shape = (Ellipse2D.Double) getItemShape(series, item); if (shape.getWidth() != 0 && shape.getHeight() != 0) { Ellipse2D.Double circle = translateShape(shape, plot, dataArea); g2.setPaint(getItemPaint(series, item)); g2.fill(circle); g2.setStroke(getItemOutlineStroke(series, item)); g2.setPaint(getItemOutlinePaint(series, item)); g2.draw(circle); if (isItemLabelVisible(series, item)) { currCircle = circle; if (orientation == PlotOrientation.VERTICAL) { drawItemLabel(g2, orientation, dataset, series, item, circle.getCenterX(), circle.getCenterY(), false); } else if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel(g2, orientation, dataset, series, item, circle.getCenterY(), circle.getCenterX(), false); } } // add an entity if this info is being collected EntityCollection entities; if (info != null) { entities = info.getOwner().getEntityCollection(); if (entities != null && circle.intersects(dataArea)) { addEntity(entities, circle, dataset, series, item, circle.getCenterX(), circle.getCenterY()); } } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, shape.getCenterX(), shape.getCenterY(), domainAxisIndex, rangeAxisIndex, circle.getCenterX(), circle.getCenterY(), orientation); } }
From source file:org.mwc.cmap.grideditor.chart.RendererWithDynamicFeedback.java
/** * All parameters are domain coordinates that have to be translated to * Java2D points./*w ww. j av a2s . c o m*/ */ private void drawFeedbackEdge(final double x0, final double y0, final double x1, final double y1, final XYItemRendererState state, final Graphics2D g2, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis, final Rectangle2D dataArea) { if (Double.isNaN(y0) || Double.isNaN(x0) || Double.isNaN(y1) || Double.isNaN(x1)) { return; } final RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); final RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); final double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); final double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); final double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); final double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } final PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); } if (state.workingLine.intersects(dataArea)) { g2.setStroke(getFeedbackStroke()); g2.setPaint(getFeedbackEdgePaint()); g2.draw(state.workingLine); } }
From source file:gov.nih.nci.caintegrator.application.geneexpression.BoxAndWhiskerCoinPlotRenderer.java
/** * {@inheritDoc}//from w w w . jav a2s . c om */ @Override public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) { BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset; double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double categoryWidth = categoryEnd - categoryStart; double xx = categoryStart; int seriesCount = getRowCount(); int categoryCount = getColumnCount(); xx = retrieveXx(state, dataArea, row, categoryWidth, xx, seriesCount, categoryCount); Paint p = null; if (this.getPlotColor() != null) { p = PaintUtilities.stringToColor(getPlotColor()); // coin plot should all be one color } else { p = getItemPaint(row, column); } if (p != null) { g2.setPaint(p); } Stroke s = getItemStroke(row, column); g2.setStroke(s); double aRadius = 0; // average radius RectangleEdge location = drawRectangles(g2, state, dataArea, plot, rangeAxis, row, column, bawDataset, xx); g2.setPaint(getArtifactPaint()); if (this.isDisplayMean()) { aRadius = drawMean(g2, state, dataArea, rangeAxis, row, column, bawDataset, xx, aRadius, location); } if (this.isDisplayMedian()) { // draw median... Number yMedian = bawDataset.getMedianValue(row, column); if (yMedian != null) { double yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location); g2.draw(new Line2D.Double(xx, yyMedian, xx + state.getBarWidth(), yyMedian)); } } double maxAxisValue = rangeAxis.valueToJava2D(rangeAxis.getUpperBound(), dataArea, location) + aRadius; double minAxisValue = rangeAxis.valueToJava2D(rangeAxis.getLowerBound(), dataArea, location) - aRadius; g2.setPaint(p); drawOutliers(g2, state, dataArea, rangeAxis, row, column, bawDataset, xx, aRadius, location, maxAxisValue, minAxisValue); }
From source file:org.proteosuite.FastScatterPlot.java
/** * Draws the gridlines for the plot, if they are visible. * * @param g2 the graphics device./*from w w w . j a v a 2s . c o m*/ * @param dataArea the data area. * @param ticks the ticks. */ protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List<ValueTick> ticks) { // draw the range grid lines, if any... if (isRangeGridlinesVisible()) { Stroke gridStroke = getRangeGridlineStroke(); Paint gridPaint = getRangeGridlinePaint(); if ((gridStroke != null) && (gridPaint != null)) { Iterator<ValueTick> iterator = ticks.iterator(); while (iterator.hasNext()) { ValueTick tick = (ValueTick) iterator.next(); double v = this.rangeAxis.valueToJava2D(tick.getValue(), dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); g2.setPaint(gridPaint); g2.setStroke(gridStroke); g2.draw(line); } } } }
From source file:org.proteosuite.FastScatterPlot.java
/** * Draws the gridlines for the plot, if they are visible. * * @param g2 the graphics device./* w w w . j ava 2s . c o m*/ * @param dataArea the data area. * @param ticks the ticks. */ protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List<ValueTick> ticks) { // draw the domain grid lines, if any... if (isDomainGridlinesVisible()) { Stroke gridStroke = getDomainGridlineStroke(); Paint gridPaint = getDomainGridlinePaint(); if ((gridStroke != null) && (gridPaint != null)) { Iterator<ValueTick> iterator = ticks.iterator(); while (iterator.hasNext()) { ValueTick tick = (ValueTick) iterator.next(); double v = this.domainAxis.valueToJava2D(tick.getValue(), dataArea, RectangleEdge.BOTTOM); Line2D line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); g2.setPaint(gridPaint); g2.setStroke(gridStroke); g2.draw(line); } } } }
From source file:org.jfree.experimental.chart.renderer.xy.VectorRenderer.java
/** * Draws the block representing the specified item. * /* w ww . jav a 2s .c om*/ * @param g2 the graphics device. * @param state the state. * @param dataArea the data area. * @param info the plot rendering info. * @param plot the plot. * @param domainAxis the x-axis. * @param rangeAxis the y-axis. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param crosshairState the crosshair state. * @param pass the pass index. */ 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) { double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double dx = 0.0; double dy = 0.0; if (dataset instanceof VectorXYDataset) { dx = ((VectorXYDataset) dataset).getDeltaXValue(series, item); dy = ((VectorXYDataset) dataset).getDeltaYValue(series, item); } double xx0 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); double yy0 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge()); double xx1 = domainAxis.valueToJava2D(x + dx, dataArea, plot.getDomainAxisEdge()); double yy1 = rangeAxis.valueToJava2D(y + dy, dataArea, plot.getRangeAxisEdge()); Line2D line; PlotOrientation orientation = plot.getOrientation(); if (orientation.equals(PlotOrientation.HORIZONTAL)) { line = new Line2D.Double(yy0, xx0, yy1, xx1); } else { line = new Line2D.Double(xx0, yy0, xx1, yy1); } g2.setPaint(getItemPaint(series, item)); g2.setStroke(getItemStroke(series, item)); g2.draw(line); // calculate the arrow head and draw it... double dxx = (xx1 - xx0); double dyy = (yy1 - yy0); double bx = xx0 + (1.0 - this.baseLength) * dxx; double by = yy0 + (1.0 - this.baseLength) * dyy; double cx = xx0 + (1.0 - this.headLength) * dxx; double cy = yy0 + (1.0 - this.headLength) * dyy; double angle = 0.0; if (dxx != 0.0) { angle = Math.PI / 2.0 - Math.atan(dyy / dxx); } double deltaX = 2.0 * Math.cos(angle); double deltaY = 2.0 * Math.sin(angle); double leftx = cx + deltaX; double lefty = cy - deltaY; double rightx = cx - deltaX; double righty = cy + deltaY; GeneralPath p = new GeneralPath(); p.moveTo((float) xx1, (float) yy1); p.lineTo((float) rightx, (float) righty); p.lineTo((float) bx, (float) by); p.lineTo((float) leftx, (float) lefty); p.closePath(); g2.draw(p); }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChart.java
/** * draw the time line/*from w ww.ja v a 2s. com*/ * * @param g2 param * @param plot param * @param dataArea param * @param domainAxis param * @param rangeAxis param * @param rendererIndex param * @param info param */ private void drawTime(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { try { Animation animation = control.getSomeAnimation(); if (animation == null) { return; } Real dttm = animation.getAniValue(); if (dttm == null) { return; } g2.setStroke(new BasicStroke()); g2.setColor(Color.black); double timeValue = dttm.getValue(CommonUnit.secondsSinceTheEpoch); int x = (int) domainAxis.valueToJava2D(timeValue * 1000, dataArea, RectangleEdge.BOTTOM); if ((x < dataArea.getX()) || (x > dataArea.getX() + dataArea.getWidth())) { return; } int bottom = (int) (dataArea.getY() + dataArea.getHeight()); int top = (int) (dataArea.getY()); int offset = 0; if (false && (clockImage == null)) { clockImage = GuiUtils.getImage("/auxdata/ui/icons/clock.gif"); clockImage.getHeight(this); offset = clockImage.getHeight(null); } // g2.drawLine(x, (int) dataArea.getY(), x, bottom - offset); int w = 8; int w2 = w / 2; int[] xs = { x - w2, x, x + w2, x }; int[] ys = { top, top + w, top, top }; // g2.drawLine(x, top, x, top+10); g2.fillPolygon(xs, ys, xs.length); if (clockImage != null) { g2.drawImage(clockImage, x - clockImage.getWidth(null) / 2, bottom - clockImage.getHeight(null), null); } } catch (VisADException exc) { } catch (RemoteException exc) { } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java
/** * Renders the glyphs stored in the text node. * * @param renderableText//from w w w .j a v a 2 s . c o m * the text node that should be rendered. * @param contentX2 */ protected void drawText(final RenderableText renderableText, final long contentX2) { if (renderableText.getLength() == 0) { // This text is empty. return; } final long posX = renderableText.getX(); final long posY = renderableText.getY(); final Graphics2D g2; if (getTextSpec() == null) { g2 = (Graphics2D) getGraphics().create(); final StyleSheet layoutContext = renderableText.getStyleSheet(); configureGraphics(layoutContext, g2); g2.setStroke(LogicalPageDrawable.DEFAULT_STROKE); if (RenderUtility.isFontSmooth(layoutContext, metaData)) { g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } else { g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } } else { g2 = getTextSpec().getGraphics(); } // This shifting is necessary to make sure that all text is rendered like in the previous versions. // In the earlier versions, we did not really obey to the baselines of the text, we just hoped and prayed. // Therefore, all text was printed at the bottom of the text elements. With the introduction of the full // font metrics setting, this situation got a little bit better, for the price that text-elements became // nearly unpredictable .. // // The code below may be weird, but at least it is predictable weird. final FontMetrics fm = g2.getFontMetrics(); final Rectangle2D rect = fm.getMaxCharBounds(g2); final long awtBaseLine = StrictGeomUtility.toInternalValue(-rect.getY()); final GlyphList gs = renderableText.getGlyphs(); if (metaData.isFeatureSupported(OutputProcessorFeature.FAST_FONTRENDERING) && isNormalTextSpacing(renderableText)) { final int maxLength = renderableText.computeMaximumTextSize(contentX2); final String text = gs.getText(renderableText.getOffset(), maxLength, codePointBuffer); final float y = (float) StrictGeomUtility.toExternalValue(posY + awtBaseLine); g2.drawString(text, (float) StrictGeomUtility.toExternalValue(posX), y); } else { final ExtendedBaselineInfo baselineInfo = renderableText.getBaselineInfo(); final int maxPos = renderableText.getOffset() + renderableText.computeMaximumTextSize(contentX2); long runningPos = posX; final long baseline = baselineInfo.getBaseline(baselineInfo.getDominantBaseline()); final long baselineDelta = awtBaseLine - baseline; final float y = (float) (StrictGeomUtility.toExternalValue(posY + awtBaseLine + baselineDelta)); for (int i = renderableText.getOffset(); i < maxPos; i++) { final Glyph g = gs.getGlyph(i); g2.drawString(gs.getGlyphAsString(i, codePointBuffer), (float) StrictGeomUtility.toExternalValue(runningPos), y); runningPos += RenderableText.convert(g.getWidth()) + g.getSpacing().getMinimum(); } } g2.dispose(); }
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java
/** * Paints the vertex <code>v</code> at the location <code>(x,y)</code> * on the graphics context <code>g_gen</code>. The vertex is painted * using the shape returned by this instance's <code>VertexShapeFunction</code>, * and the foreground and background (border) colors provided by this * instance's <code>VertexColorFunction</code>. Delegates drawing the * label (if any) for this vertex to <code>labelVertex</code>. *//*from w ww.java2 s. c om*/ public void paintVertex(Graphics g, Vertex v, int x, int y) { if (!vertexIncludePredicate.evaluate(v)) return; boolean vertexHit = true; Rectangle deviceRectangle = null; Graphics2D g2d = (Graphics2D) g; if (screenDevice != null) { Dimension d = screenDevice.getSize(); if (d.width <= 0 || d.height <= 0) { d = screenDevice.getPreferredSize(); } deviceRectangle = new Rectangle(0, 0, d.width, d.height); } Stroke old_stroke = g2d.getStroke(); Stroke new_stroke = vertexStrokeFunction.getStroke(v); if (new_stroke != null) { g2d.setStroke(new_stroke); } // get the shape to be rendered Shape s = vertexShapeFunction.getShape(v); // create a transform that translates to the location of // the vertex to be rendered AffineTransform xform = AffineTransform.getTranslateInstance(x, y); // transform the vertex shape with xtransform s = xform.createTransformedShape(s); vertexHit = viewTransformer.transform(s).intersects(deviceRectangle); if (vertexHit) { if (vertexIconFunction != null) { paintIconForVertex(g2d, v, x, y); } else { paintShapeForVertex(g2d, v, s); } if (new_stroke != null) { g2d.setStroke(old_stroke); } String label = vertexStringer.getLabel(v); if (label != null) { labelVertex(g, v, label, x, y); } } }
From source file:savant.view.tracks.BAMTrackRenderer.java
/** * Draw the legend for bases, but also the entries for insertions and * deletions.// ww w .j a v a 2 s . co m */ private void drawBaseLegendExtended(Graphics2D g2, int x, int y, ColourKey... keys) { drawBaseLegend(g2, x, y, keys); y += LEGEND_LINE_HEIGHT; g2.setColor(Color.BLACK); g2.fillRect(x, y - SWATCH_SIZE.height + 2, SWATCH_SIZE.width, SWATCH_SIZE.height); g2.setColor(Color.BLACK); g2.drawString("Deletion", x + SWATCH_SIZE.width + 3, y); x += 66; Shape s = drawInsertion(g2, x, y - SWATCH_SIZE.height + 2, 12.0, SWATCH_SIZE.height); g2.setColor(Color.BLACK); g2.setStroke(new BasicStroke(0.25f)); g2.draw(s); g2.drawString("Insertion", x + 12, y); }