List of usage examples for java.awt Graphics2D setStroke
public abstract void setStroke(Stroke s);
From source file:org.pentaho.platform.uifoundation.chart.BubbleRenderer.java
/** * Draws the visual representation of a single data item. * /* ww w . ja va 2 s . c om*/ * @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 (an {@link XYZDataset} 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. */ @Override public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea, final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis, final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState, final int pass) { PlotOrientation orientation = plot.getOrientation(); // get the data point... double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = Double.NaN; if (dataset instanceof XYZDataset) { XYZDataset xyzData = (XYZDataset) dataset; z = xyzData.getZValue(series, item); } if (!Double.isNaN(z)) { RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation); double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation); double circleSize; circleSize = maxSize * (z / maxZ); circleSize = Math.abs(circleSize); Ellipse2D circle = null; if (orientation == PlotOrientation.VERTICAL) { circle = new Ellipse2D.Double(transX - circleSize / 2.0, transY - circleSize / 2.0, circleSize, circleSize); } else if (orientation == PlotOrientation.HORIZONTAL) { circle = new Ellipse2D.Double(transY - circleSize / 2.0, transX - circleSize / 2.0, circleSize, circleSize); } 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)) { if (orientation == PlotOrientation.VERTICAL) { drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false); } else if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false); } } // setup for collecting optional entity info... EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } // add an entity for the item... if (entities != null) { String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } String url = null; if (getURLGenerator() != null) { url = getURLGenerator().generateURL(dataset, series, item); } XYItemEntity entity = new XYItemEntity(circle, dataset, series, item, tip, url); entities.add(entity); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); } }
From source file:msi.gama.outputs.layers.charts.StandardXYItemRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2/* w ww . ja va 2 s . c o m*/ * 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 axis. * @param rangeAxis * the range axis. * @param dataset * the dataset. * @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. */ @Override public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea, final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis, final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState, final int pass) { boolean itemVisible = getItemVisible(series, item); // setup for collecting optional entity info... Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } final PlotOrientation orientation = plot.getOrientation(); final Paint paint = getItemPaint(series, item); final Stroke seriesStroke = getItemStroke(series, item); g2.setPaint(paint); g2.setStroke(seriesStroke); // get the data point... final double x1 = dataset.getXValue(series, item); final double y1 = dataset.getYValue(series, item); if (Double.isNaN(x1) || Double.isNaN(y1)) { itemVisible = false; } final RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); final RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); final double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); final double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (getPlotLines()) { if (this.drawSeriesLineAsPath) { final State s = (State) state; if (s.getSeriesIndex() != series) { // we are starting a new series path s.seriesPath.reset(); s.lastPointGood = false; s.setSeriesIndex(series); } // update path to reflect latest point if (itemVisible && !Double.isNaN(transX1) && !Double.isNaN(transY1)) { float x = (float) transX1; float y = (float) transY1; if (orientation == PlotOrientation.HORIZONTAL) { x = (float) transY1; y = (float) transX1; } if (s.isLastPointGood()) { // TODO: check threshold s.seriesPath.lineTo(x, y); } else { s.seriesPath.moveTo(x, y); } s.setLastPointGood(true); } else { s.setLastPointGood(false); } if (item == dataset.getItemCount(series) - 1) { if (s.seriesIndex == series) { // draw path g2.setStroke(lookupSeriesStroke(series)); g2.setPaint(lookupSeriesPaint(series)); g2.draw(s.seriesPath); } } } else if (item != 0 && itemVisible) { // get the previous data point... final double x0 = dataset.getXValue(series, item - 1); final double y0 = dataset.getYValue(series, item - 1); if (!Double.isNaN(x0) && !Double.isNaN(y0)) { boolean drawLine = true; if (getPlotDiscontinuous()) { // only draw a line if the gap between the current and // previous data point is within the threshold final int numX = dataset.getItemCount(series); final double minX = dataset.getXValue(series, 0); final double maxX = dataset.getXValue(series, numX - 1); if (this.gapThresholdType == UnitType.ABSOLUTE) { drawLine = Math.abs(x1 - x0) <= this.gapThreshold; } else { drawLine = Math.abs(x1 - x0) <= (maxX - minX) / numX * getGapThreshold(); } } if (drawLine) { final double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); final double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } 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.draw(state.workingLine); } } } } } // we needed to get this far even for invisible items, to ensure that // seriesPath updates happened, but now there is nothing more we need // to do for non-visible items... if (!itemVisible) { return; } if (getBaseShapesVisible()) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } if (shape.intersects(dataArea)) { if (getItemShapeFilled(series, item)) { g2.fill(shape); } else { g2.draw(shape); } } entityArea = shape; } if (getPlotImages()) { final Image image = getImage(plot, series, item, transX1, transY1); if (image != null) { final Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image); g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null); entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(), image.getWidth(null), image.getHeight(null)); } } double xx = transX1; double yy = transY1; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY1; yy = transX1; } // draw the item label if there is one... if (isItemLabelVisible(series, item)) { drawItemLabel(g2, orientation, dataset, series, item, xx, yy, y1 < 0.0); } final int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); final int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation); // add an entity for the item... if (entities != null && isPointInRect(dataArea, xx, yy)) { addEntity(entities, entityArea, dataset, series, item, xx, yy); } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.BubbleRenderer.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 (an {@link XYZDataset} 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. *//*from w w w . jav a 2 s .com*/ public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea, final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis, final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState, final int pass) { final PlotOrientation orientation = plot.getOrientation(); // get the data point... final double x = dataset.getXValue(series, item); final double y = dataset.getYValue(series, item); double z = Double.NaN; if (dataset instanceof XYZDataset) { final XYZDataset xyzData = (XYZDataset) dataset; z = xyzData.getZValue(series, item); } if (!Double.isNaN(z)) { final RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); final RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); final double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation); final double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation); double circleSize; circleSize = maxSize * (z / maxZ); circleSize = Math.abs(circleSize); Ellipse2D circle = null; if (orientation == PlotOrientation.VERTICAL) { circle = new Ellipse2D.Double(transX - circleSize / 2.0, transY - circleSize / 2.0, circleSize, circleSize); } else if (orientation == PlotOrientation.HORIZONTAL) { circle = new Ellipse2D.Double(transY - circleSize / 2.0, transX - circleSize / 2.0, circleSize, circleSize); } 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)) { if (orientation == PlotOrientation.VERTICAL) { drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false); } else if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false); } } // setup for collecting optional entity info... EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } // add an entity for the item... if (entities != null) { String tip = null; final XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } String url = null; if (getURLGenerator() != null) { url = getURLGenerator().generateURL(dataset, series, item); } final XYItemEntity entity = new XYItemEntity(circle, dataset, series, item, tip, url); entities.add(entity); } final int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); final int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); } }
From source file:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java
/** * Draws the gridlines for the plot, if they are visible. * * @param g2 the graphics device.//w w w.j a v a2 s .com * @param dataArea the data area. * @param ticks the ticks. */ @Override protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) { // draw the range grid lines, if the flag says they're visible... if (isRangeGridlinesVisible()) { Iterator 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(getRangeGridlinePaint()); g2.setStroke(getRangeGridlineStroke()); g2.draw(line); } } }
From source file:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java
/** * Draws the gridlines for the plot, if they are visible. * * @param g2 the graphics device./*from w w w. ja v a 2 s . com*/ * @param dataArea the data area. * @param ticks the ticks. */ @Override protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) { // draw the domain grid lines, if the flag says they're visible... if (isDomainGridlinesVisible()) { Iterator 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(getDomainGridlinePaint()); g2.setStroke(getDomainGridlineStroke()); g2.draw(line); } } }
From source file:com.att.aro.ui.view.diagnostictab.CreateBarPlot.java
public XYPlot drawYIntervalPlot() { // Create the plot renderer YIntervalRenderer renderer = new YIntervalRenderer() { private static final long serialVersionUID = 1L; 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) { // setup for collecting optional entity info... Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); }/*from w w w.ja v a2 s . com*/ IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset; double x = intervalDataset.getXValue(series, item); double yLow = intervalDataset.getStartYValue(series, item); double yHigh = intervalDataset.getEndYValue(series, item); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation); double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation); Paint p = getItemPaint(series, item); Stroke s = getItemStroke(series, item); Line2D line = null; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(yyLow, xx, yyHigh, xx); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(xx, yyLow, xx, yyHigh); } g2.setPaint(p); g2.setStroke(s); g2.draw(line); // add an entity for the item... if (entities != null && line != null) { if (entityArea == null) { entityArea = line.getBounds(); } String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, null); entities.add(entity); } } }; renderer.setAdditionalItemLabelGenerator(null); renderer.setBaseShape(new Rectangle()); renderer.setAutoPopulateSeriesShape(false); renderer.setAutoPopulateSeriesPaint(false); renderer.setBasePaint(Color.GRAY); // Create the plot XYPlot plot = new XYPlot(null, null, new NumberAxis(), renderer); plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); plot.getRangeAxis().setVisible(false); return plot; }
From source file:org.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java
protected void paintSelectionRectangle(final Graphics2D g2) { final Point origin = selectionHandler.getSelectionRectangleOrigin(); final Point target = selectionHandler.getSelectionRectangleTarget(); if (origin == null || target == null) { return;/*from w ww . j av a 2 s.c om*/ } g2.setColor(Color.BLUE); g2.setStroke(SELECTION_STROKE); final double y1 = Math.min(origin.getY(), target.getY()); final double x1 = Math.min(origin.getX(), target.getX()); final double y2 = Math.max(origin.getY(), target.getY()); final double x2 = Math.max(origin.getX(), target.getX()); g2.draw(new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1)); }
From source file:nl.vu.nat.jfreechartcustom.XYBlockRenderer.java
/** * Draws the block representing the specified item. * * @param g2 the graphics device./*from w w w . j a va 2 s . c o m*/ * @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) { boolean bAddEntity = false; double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = 0.0; if (dataset instanceof XYZDataset) { z = ((XYZDataset) dataset).getZValue(series, item); } Paint p = this.paintScale.getPaint(z); double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea, plot.getRangeAxisEdge()); double xx1 = domainAxis.valueToJava2D(x + this.blockWidth + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight + this.yOffset, dataArea, plot.getRangeAxisEdge()); Rectangle2D block; PlotOrientation orientation = plot.getOrientation(); if (orientation.equals(PlotOrientation.HORIZONTAL)) { block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0), Math.abs(xx0 - xx1)); } else { // Detect if Rectangle is smaller than 2 by 2 pixels block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0), Math.abs(yy1 - yy0)); } g2.setPaint(p); g2.fill(block); g2.setStroke(new BasicStroke(1.0f)); // g2.draw(block); EntityCollection entities = state.getEntityCollection(); if (entities != null && bAddEntity) { addEntity(entities, block, dataset, series, item, 0.0, 0.0); } }
From source file:org.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java
protected void paintElementAlignment(final Graphics2D g2d) { if (WorkspaceSettings.getInstance().isShowElementAlignmentHints()) { final float scaleFactor = getRenderContext().getZoomModel().getZoomAsPercentage(); g2d.setColor(WorkspaceSettings.getInstance().getAlignmentHintColor()); g2d.setStroke(new BasicStroke(.2f)); final double gridHeight = getHeight(); final double gridWidth = getWidth(); final long[] hPositions; if (getHorizontalPositionsModel() == null) { final BreakPositionsList horizontalPositions = getHorizontalEdgePositions(); hPositions = horizontalPositions.getKeys(); } else {//from w w w.j a va2 s .co m hPositions = getHorizontalPositionsModel().getBreaks(); } final Line2D.Double line = new Line2D.Double(); for (int i = 0; i < hPositions.length; i++) { final double position = StrictGeomUtility.toExternalValue(hPositions[i]); final double x = position * scaleFactor; line.setLine(x, 0, x, gridHeight); g2d.draw(line); } final Point2D offset = getOffset(); final BreakPositionsList verticalPositions = getVerticalEdgePositions(); final long[] vPositions = verticalPositions.getKeys(); for (int i = 0; i < vPositions.length; i++) { final double position = StrictGeomUtility.toExternalValue(vPositions[i]) - offset.getY(); final double y2 = position * scaleFactor; line.setLine(0, y2, gridWidth, y2); g2d.draw(line); } } }
From source file:net.sourceforge.processdash.ev.ui.chart.RangeXYItemRenderer.java
private void drawItemRangeGradient(Graphics2D g2, Line2D line, Paint paint, Stroke stroke, double x2, double y2, double x3, double y3) { Line2D edge1, edge2, mainLine; Polygon fillArea;/*from w w w . ja v a 2 s . co m*/ Stroke mainLineStroke, edgeLineStroke; Paint mainLinePaint, edgeLinePaint, fillPaint; double x0 = line.getX1(); double y0 = line.getY1(); double x1 = line.getX2(); double y1 = line.getY2(); mainLine = new Line2D.Double(x0, y0, x1, y1); edge1 = new Line2D.Double(x0, y0, x2, y2); edge2 = new Line2D.Double(x0, y0, x3, y3); fillArea = new Polygon(); fillArea.addPoint((int) Math.round(x0), (int) Math.round(y0)); fillArea.addPoint((int) Math.round(x2), (int) Math.round(y2)); fillArea.addPoint((int) Math.round(x3), (int) Math.round(y3)); mainLinePaint = paint; if (mainLinePaint instanceof Color) { Color c = (Color) mainLinePaint; Color dark = transp(c, calcAlpha(c)); Color light = transp(c, 0.01); edgeLinePaint = fillPaint = c; try { fillPaint = new GradientPaint(gradientStart(x0, y0, x1, y1, x2, y2, x3, y3), light, new Point2D.Double(x1, y1), dark, true); } catch (Exception e) { } } else { edgeLinePaint = fillPaint = mainLinePaint; } if (stroke instanceof BasicStroke) { float lineWidth = ((BasicStroke) stroke).getLineWidth(); edgeLineStroke = new BasicStroke(lineWidth / 4); mainLineStroke = new BasicStroke(lineWidth * 2); } else { mainLineStroke = edgeLineStroke = stroke; } g2.setPaint(fillPaint); g2.fill(fillArea); g2.fill(fillArea); g2.setStroke(edgeLineStroke); g2.setPaint(edgeLinePaint); g2.draw(edge1); g2.draw(edge2); g2.setStroke(mainLineStroke); g2.setPaint(mainLinePaint); g2.draw(mainLine); }