List of usage examples for java.awt Graphics2D fill
public abstract void fill(Shape s);
From source file:hudson.util.StackedAreaRenderer2.java
@Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // plot non-null values... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return;/*from w w w . j a v a2 s. c o m*/ } double value = dataValue.doubleValue(); // leave the y values (y1, y0) untranslated as it is going to be be // stacked up later by previous series values, after this it will be // translated. double xx1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double previousHeightx1 = getPreviousHeight(dataset, row, column); double y1 = value + previousHeightx1; RectangleEdge location = plot.getRangeAxisEdge(); double yy1 = rangeAxis.valueToJava2D(y1, dataArea, location); g2.setPaint(getItemPaint(row, column)); g2.setStroke(getItemStroke(row, column)); // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); // in column zero, the only job to do is draw any visible item labels // and this is done in the second pass... if (column == 0) { if (pass == 1) { // draw item labels, if visible if (isItemLabelVisible(row, column)) { drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, yy1, (y1 < 0.0)); } } } else { Number previousValue = dataset.getValue(row, column - 1); if (previousValue != null) { double xx0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double y0 = previousValue.doubleValue(); // Get the previous height, but this will be different for both // y0 and y1 as the previous series values could differ. double previousHeightx0 = getPreviousHeight(dataset, row, column - 1); // Now stack the current y values on top of the previous values. y0 += previousHeightx0; // Now translate the previous heights double previousHeightxx0 = rangeAxis.valueToJava2D(previousHeightx0, dataArea, location); double previousHeightxx1 = rangeAxis.valueToJava2D(previousHeightx1, dataArea, location); // Now translate the current y values. double yy0 = rangeAxis.valueToJava2D(y0, dataArea, location); if (pass == 0) { // left half Polygon p = new Polygon(); p.addPoint((int) xx0, (int) yy0); p.addPoint((int) (xx0 + xx1) / 2, (int) (yy0 + yy1) / 2); p.addPoint((int) (xx0 + xx1) / 2, (int) (previousHeightxx0 + previousHeightxx1) / 2); p.addPoint((int) xx0, (int) previousHeightxx0); g2.setPaint(getItemPaint(row, column - 1)); g2.setStroke(getItemStroke(row, column - 1)); g2.fill(p); if (entities != null) addItemEntity(entities, dataset, row, column - 1, p); // right half p = new Polygon(); p.addPoint((int) xx1, (int) yy1); p.addPoint((int) (xx0 + xx1) / 2, (int) (yy0 + yy1) / 2); p.addPoint((int) (xx0 + xx1) / 2, (int) (previousHeightxx0 + previousHeightxx1) / 2); p.addPoint((int) xx1, (int) previousHeightxx1); g2.setPaint(getItemPaint(row, column)); g2.setStroke(getItemStroke(row, column)); g2.fill(p); if (entities != null) addItemEntity(entities, dataset, row, column, p); } else { if (isItemLabelVisible(row, column)) { drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, yy1, (y1 < 0.0)); } } } } }
From source file:org.operamasks.faces.render.graph.CurveAndShapeRenderer.java
private void drawSeriesCurve(Graphics2D g2, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int series) { // do nothing if item is not visible if (!(getItemVisible(series, 0) && (getItemLineVisible(series, 0) || drawArea))) { return;/*from w w w .j a va 2s. c om*/ } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); PlotOrientation orientation = plot.getOrientation(); int itemCount = dataset.getColumnCount(); double[][] points = new double[itemCount][2]; int count = 0; // get data points for (int i = 0; i < itemCount; i++) { Number value = dataset.getValue(series, i); if (value != null) { points[count][0] = domainAxis.getCategoryMiddle(i, itemCount, dataArea, xAxisLocation); points[count][1] = rangeAxis.valueToJava2D(value.doubleValue(), dataArea, yAxisLocation); count++; } } if (count < 2) { return; } // draw curve CubicSplineFunction2D f = new CubicSplineFunction2D(points, count); GeneralPath path = new GeneralPath(); double startX = points[0][0]; double startY = points[0][1]; double endX = points[count - 1][0]; double endY = points[count - 1][1]; double yz = rangeAxis.valueToJava2D(0.0, dataArea, yAxisLocation); if (orientation == PlotOrientation.HORIZONTAL) { if (drawArea) { path.moveTo((float) yz, (float) startX); path.lineTo((float) startY, (float) startX); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) f.getValue(x), (float) x); } path.lineTo((float) endY, (float) endX); path.lineTo((float) yz, (float) endX); path.closePath(); } else { path.moveTo((float) startY, (float) startX); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) f.getValue(x), (float) x); } path.lineTo((float) endY, (float) endX); } } else { if (drawArea) { path.moveTo((float) startX, (float) yz); path.lineTo((float) startX, (float) startY); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) x, (float) f.getValue(x)); } path.lineTo((float) endX, (float) endY); path.lineTo((float) endX, (float) yz); path.closePath(); } else { path.moveTo((float) startX, (float) startY); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) x, (float) f.getValue(x)); } path.lineTo((float) endX, (float) endY); } } Paint paint = getSeriesPaint(series); Stroke stroke = getSeriesStroke(series); if (drawArea) { g2.setPaint(paint); g2.fill(path); // create paint for outline if (paint instanceof Color) { paint = ((Color) paint).darker(); } else if (paint instanceof GradientPaint) { paint = ((GradientPaint) paint).getColor1().darker(); } } if (getItemLineVisible(series, 0)) { g2.setPaint(paint); g2.setStroke(stroke); g2.draw(path); } }
From source file:com.newatlanta.bluedragon.CustomClusteredXYBarRenderer.java
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) { IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset; Paint seriesPaint = getItemPaint(series, item); double value0; double value1; if (getUseYInterval()) { value0 = intervalDataset.getStartYValue(series, item); value1 = intervalDataset.getEndYValue(series, item); } else {//w ww. ja v a 2 s . co m value0 = getBase(); value1 = intervalDataset.getYValue(series, item); } if (Double.isNaN(value0) || Double.isNaN(value1)) { return; } double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge()); double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge()); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); double x1 = intervalDataset.getStartXValue(series, item); double translatedX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double x2 = intervalDataset.getEndXValue(series, item); double translatedX2 = domainAxis.valueToJava2D(x2, dataArea, xAxisLocation); double translatedWidth = Math.max(1, Math.abs(translatedX2 - translatedX1)); double translatedHeight = Math.abs(translatedValue0 - translatedValue1); /* * With BlueDragon, this value is always false so it's safe to comment this * code out. if (this.centerBarAtStartValue) { translatedX1 -= * translatedWidth / 2; } */ PlotOrientation orientation = plot.getOrientation(); if (getMargin() > 0.0) { if (orientation == PlotOrientation.HORIZONTAL) { // BEGIN fix for horizontal bar charts that have a margin double cut = translatedWidth * getMargin(); translatedWidth = translatedWidth - cut; translatedX1 = translatedX1 - cut / 2; // END fix for horizontal bar charts that have a margin } else if (orientation == PlotOrientation.VERTICAL) { double cut = translatedWidth * getMargin(); translatedWidth = translatedWidth - cut; translatedX1 = translatedX1 + cut / 2; } } int numSeries = dataset.getSeriesCount(); double seriesBarWidth = translatedWidth / numSeries; Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(Math.min(translatedValue0, translatedValue1), translatedX1 - seriesBarWidth * (numSeries - series), translatedHeight, seriesBarWidth); } else if (orientation == PlotOrientation.VERTICAL) { bar = new Rectangle2D.Double(translatedX1 + seriesBarWidth * series, Math.min(translatedValue0, translatedValue1), seriesBarWidth, translatedHeight); } g2.setPaint(seriesPaint); g2.fill(bar); if (isDrawBarOutline() && Math.abs(translatedX2 - translatedX1) > 3) { g2.setStroke(getItemOutlineStroke(series, item)); g2.setPaint(getItemOutlinePaint(series, item)); g2.draw(bar); } // TODO: we need something better for the item labels if (isItemLabelVisible(series, item)) { // Change parameters passed to this method to call our local version drawItemLabel(g2, orientation, dataset, series, item, bar, value1 < 0.0); } // add an entity for the item... if (info != null) { EntityCollection entities = info.getOwner().getEntityCollection(); 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(bar, dataset, series, item, tip, url); entities.add(entity); } } }
From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java
/** * Draws the visual representation of a series as shapes. * * @param g2 the graphics device.//w w w. j a v a 2s . c o m * @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 crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. * @param drawShapes a flag indicating whether shapes should be drawn * @param createEntities a flag indicating whether entities should be * generated. */ protected void drawSeriesShapes(Graphics2D g2, State state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, CrosshairState crosshairState, int pass, boolean drawShapes, boolean createEntities) { if (!drawShapes && !createEntities) { return; } PlotOrientation orientation = plot.getOrientation(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double x = 0.0; double y = 0.0; double transX = 0.0; double transY = 0.0; boolean itemShapeFilled = getItemShapeFilled(series, 0); boolean drawOutlines = getDrawOutlines(); Paint itemFillPaint = getUseFillPaint() ? getItemFillPaint(series, 0) : getItemPaint(series, 0); Paint itemOutlinePaint = getUseOutlinePaint() ? getItemOutlinePaint(series, 0) : getItemPaint(series, 0); Stroke itemOutlineStroke = getItemOutlineStroke(series, 0); Shape centeredShape = getItemShape(series, 0); /* if(centeredShape instanceof LinedShape){ itemOutlinePaint = itemFillPaint; drawOutlines = true; itemShapeFilled = false; } */ //draw items //and create entities EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); for (int itemIndex = state.getFirstItemIndex(); itemIndex <= state.getLastItemIndex(); itemIndex++) { if (state.itemVisible(series, itemIndex)) { x = dataset.getXValue(series, itemIndex); y = dataset.getYValue(series, itemIndex); transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation); if (orientation == PlotOrientation.HORIZONTAL) { double temp = transX; transX = transY; transY = temp; } updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); Shape shape = ShapeUtilities.createTranslatedShape(centeredShape, transX, transY); if (drawShapes) { if (itemShapeFilled) { g2.setPaint(itemFillPaint); g2.fill(shape); } if (drawOutlines) { g2.setPaint(itemOutlinePaint); g2.setStroke(itemOutlineStroke); g2.draw(shape); } } if (createEntities && entities != null) { addEntity(entities, shape, dataset, series, itemIndex, transX, transY); } } } }
From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java
/** * Draws a radar plot polygon.// w w w .java 2 s. c o m * * @param g2 the graphics device. * @param plotArea the area we are plotting in (already adjusted). * @param centre the centre point of the radar axes * @param info chart rendering info. * @param series the series within the dataset we are plotting * @param catCount the number of categories per radar plot * @param headH the data point height * @param headW the data point width */ protected void drawRadarPoly(Graphics2D g2, Rectangle2D plotArea, Point2D centre, PlotRenderingInfo info, int series, int catCount, double headH, double headW) { Polygon polygon = new Polygon(); EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } // plot the data... for (int cat = 0; cat < catCount; cat++) { Number dataValue = getPlotValue(series, cat); if (dataValue != null) { double value = dataValue.doubleValue(); if (value >= 0) { // draw the polygon series... // Finds our starting angle from the centre for this axis double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / (catCount > 2 ? catCount : 3)); // The following angle calc will ensure there isn't a top // vertical axis - this may be useful if you don't want any // given criteria to 'appear' move important than the // others.. // + (getDirection().getFactor() // * (cat + 0.5) * 360 / catCount); // find the point at the appropriate distance end point // along the axis/angle identified above and add it to the // polygon Point2D point = getWebPoint(plotArea, angle, value / this.maxValue); polygon.addPoint((int) point.getX(), (int) point.getY()); // put an elipse at the point being plotted.. Paint paint = getSeriesPaint(series); Paint outlinePaint = getSeriesOutlinePaint(series); Stroke outlineStroke = getSeriesOutlineStroke(series); Ellipse2D head = new Ellipse2D.Double(point.getX() - headW / 2, point.getY() - headH / 2, headW, headH); g2.setPaint(paint); g2.fill(head); g2.setStroke(outlineStroke); g2.setPaint(outlinePaint); g2.draw(head); if (entities != null) { int row = 0; int col = 0; if (this.dataExtractOrder == TableOrder.BY_ROW) { row = series; col = cat; } else { row = cat; col = series; } String tip = null; if (this.toolTipGenerator != null) { tip = this.toolTipGenerator.generateToolTip(this.dataset, row, col); } String url = null; if (this.urlGenerator != null) { url = this.urlGenerator.generateURL(this.dataset, row, col); } Shape area = new Rectangle((int) (point.getX() - headW), (int) (point.getY() - headH), (int) (headW * 2), (int) (headH * 2)); CategoryItemEntity entity = new CategoryItemEntity(area, tip, url, this.dataset, this.dataset.getRowKey(row), this.dataset.getColumnKey(col)); entities.add(entity); } } } } // Plot the polygon Paint paint = getSeriesPaint(series); g2.setPaint(paint); g2.setStroke(getSeriesOutlineStroke(series)); g2.draw(polygon); // Lastly, fill the web polygon if this is required if (this.webFilled) { g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f)); g2.fill(polygon); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); } }
From source file:org.operamasks.faces.render.graph.XYCurveAndShapeRenderer.java
/** * Draws the item (first pass). This method draws the lines * connecting the items. Instead of drawing separate lines, * a GeneralPath is constructed and drawn at the end of * the series painting.//from w w w. j a v a 2 s . c o m * * @param g2 the graphics device. * @param state the renderer state. * @param plot the plot (can be used to obtain standard color information * etc). * @param dataset the dataset. * @param pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataArea the area within which the data is being drawn. */ protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { if (item != 0) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); PlotOrientation orientation = plot.getOrientation(); int itemCount = dataset.getItemCount(series); double[][] points = new double[itemCount][2]; int count = 0; for (int i = 0; i < itemCount; i++) { double x = dataset.getXValue(series, i); double y = dataset.getYValue(series, i); double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation); if (!Double.isNaN(transX) && !Double.isNaN(transY)) { points[count][0] = transX; points[count][1] = transY; count++; } } if (count < 2) { return; } // sort points according to x axis Arrays.sort(points, new Comparator<double[]>() { public int compare(double[] a, double[] b) { return a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0; } }); // draw curve CubicSplineFunction2D f = new CubicSplineFunction2D(points, count); GeneralPath path = new GeneralPath(); double startX = points[0][0]; double startY = points[0][1]; double endX = points[count - 1][0]; double endY = points[count - 1][1]; double yz = rangeAxis.valueToJava2D(0.0, dataArea, yAxisLocation); if (orientation == PlotOrientation.HORIZONTAL) { if (drawArea) { path.moveTo((float) yz, (float) startX); path.lineTo((float) startY, (float) startX); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) f.getValue(x), (float) x); } path.lineTo((float) endY, (float) endX); path.lineTo((float) yz, (float) endX); path.closePath(); } else { path.moveTo((float) startY, (float) startX); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) f.getValue(x), (float) x); } path.lineTo((float) endY, (float) endX); } } else { if (drawArea) { path.moveTo((float) startX, (float) yz); path.lineTo((float) startX, (float) startY); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) x, (float) f.getValue(x)); } path.lineTo((float) endX, (float) endY); path.lineTo((float) endX, (float) yz); path.closePath(); } else { path.moveTo((float) startX, (float) startY); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) x, (float) f.getValue(x)); } path.lineTo((float) endX, (float) endY); } } Paint paint = getItemPaint(series, item); Stroke stroke = getItemStroke(series, item); if (drawArea) { g2.setPaint(paint); g2.fill(path); // create paint for outline if (paint instanceof Color) { paint = ((Color) paint).darker(); } else if (paint instanceof GradientPaint) { paint = ((GradientPaint) paint).getColor1().darker(); } } g2.setPaint(paint); g2.setStroke(stroke); g2.draw(path); }
From source file:org.jfree.chart.demo.CylinderRenderer.java
public void drawItem(Graphics2D graphics2d, CategoryItemRendererState categoryitemrendererstate, Rectangle2D rectangle2d, CategoryPlot categoryplot, CategoryAxis categoryaxis, ValueAxis valueaxis, CategoryDataset categorydataset, int i, int j, int k) { Number number = categorydataset.getValue(i, j); if (number == null) return;//from w w w .ja v a 2s .com double d = number.doubleValue(); java.awt.geom.Rectangle2D.Double double1 = new java.awt.geom.Rectangle2D.Double(rectangle2d.getX(), rectangle2d.getY() + getYOffset(), rectangle2d.getWidth() - getXOffset(), rectangle2d.getHeight() - getYOffset()); PlotOrientation plotorientation = categoryplot.getOrientation(); double d1 = calculateBarW0(categoryplot, plotorientation, double1, categoryaxis, categoryitemrendererstate, i, j); double ad[] = calculateBarL0L1(d); if (ad == null) return; RectangleEdge rectangleedge = categoryplot.getRangeAxisEdge(); float f = (float) valueaxis.valueToJava2D(ad[0], double1, rectangleedge); float f1 = (float) valueaxis.valueToJava2D(ad[1], double1, rectangleedge); float f2 = Math.min(f, f1); float f3 = Math.abs(f1 - f); GeneralPath generalpath = new GeneralPath(); java.awt.geom.Ellipse2D.Double double2 = null; if (plotorientation == PlotOrientation.HORIZONTAL) { generalpath.moveTo((float) ((double) f2 + getXOffset() / 2D), (float) d1); generalpath.lineTo((float) ((double) (f2 + f3) + getXOffset() / 2D), (float) d1); java.awt.geom.Arc2D.Double double3 = new java.awt.geom.Arc2D.Double(f2 + f3, d1, getXOffset(), categoryitemrendererstate.getBarWidth(), 90D, 180D, 0); generalpath.append(double3, true); generalpath.lineTo((float) ((double) f2 + getXOffset() / 2D), (float) (d1 + categoryitemrendererstate.getBarWidth())); double3 = new java.awt.geom.Arc2D.Double(f2, d1, getXOffset(), categoryitemrendererstate.getBarWidth(), 270D, -180D, 0); generalpath.append(double3, true); generalpath.closePath(); double2 = new java.awt.geom.Ellipse2D.Double(f2 + f3, d1, getXOffset(), categoryitemrendererstate.getBarWidth()); } else { generalpath.moveTo((float) d1, (float) ((double) f2 - getYOffset() / 2D)); generalpath.lineTo((float) d1, (float) ((double) (f2 + f3) - getYOffset() / 2D)); java.awt.geom.Arc2D.Double double4 = new java.awt.geom.Arc2D.Double(d1, (double) (f2 + f3) - getYOffset(), categoryitemrendererstate.getBarWidth(), getYOffset(), 180D, 180D, 0); generalpath.append(double4, true); generalpath.lineTo((float) (d1 + categoryitemrendererstate.getBarWidth()), (float) ((double) f2 - getYOffset() / 2D)); double4 = new java.awt.geom.Arc2D.Double(d1, (double) f2 - getYOffset(), categoryitemrendererstate.getBarWidth(), getYOffset(), 0.0D, -180D, 0); generalpath.append(double4, true); generalpath.closePath(); double2 = new java.awt.geom.Ellipse2D.Double(d1, (double) f2 - getYOffset(), categoryitemrendererstate.getBarWidth(), getYOffset()); } Object obj = getItemPaint(i, j); if (getGradientPaintTransformer() != null && (obj instanceof GradientPaint)) { GradientPaint gradientpaint = (GradientPaint) obj; obj = getGradientPaintTransformer().transform(gradientpaint, generalpath); } graphics2d.setPaint(((java.awt.Paint) (obj))); graphics2d.fill(generalpath); if (obj instanceof GradientPaint) { graphics2d.setPaint(((GradientPaint) obj).getColor2()); } if (double2 != null) { graphics2d.fill(double2); } if (isDrawBarOutline() && categoryitemrendererstate.getBarWidth() > 3D) { graphics2d.setStroke(getItemOutlineStroke(i, j)); graphics2d.setPaint(getItemOutlinePaint(i, j)); graphics2d.draw(generalpath); if (double2 != null) graphics2d.draw(double2); } CategoryItemLabelGenerator categoryitemlabelgenerator = getItemLabelGenerator(i, j); if (categoryitemlabelgenerator != null && isItemLabelVisible(i, j)) drawItemLabel(graphics2d, categorydataset, i, j, categoryplot, categoryitemlabelgenerator, generalpath.getBounds2D(), d < 0.0D); if (categoryitemrendererstate.getInfo() != null) { EntityCollection entitycollection = categoryitemrendererstate.getEntityCollection(); if (entitycollection != null) { String s = null; CategoryToolTipGenerator categorytooltipgenerator = getToolTipGenerator(i, j); if (categorytooltipgenerator != null) s = categorytooltipgenerator.generateToolTip(categorydataset, i, j); String s1 = null; if (getItemURLGenerator(i, j) != null) s1 = getItemURLGenerator(i, j).generateURL(categorydataset, i, j); CategoryItemEntity categoryitementity = new CategoryItemEntity(generalpath.getBounds2D(), s, s1, categorydataset, categorydataset.getRowKey(i), categorydataset.getColumnKey(j)); entitycollection.add(categoryitementity); } } }
From source file:gda.plots.SimplePlot.java
/** * Part of the implementation of MouseListener - overrides the super class (ChartPanel) implementation so that the * mouse can be used to select a rectangle as well as for zooming. * // w ww.j a va2 s. c om * @param e * the mouse event which caused the call */ @Override public void mousePressed(MouseEvent e) { // Unless a rectangle is being dragged we just // want to call the super class method (which // deals with zooming) if (rd == null) { super.mousePressed(e); if (magnifyingImage || magnifyingData) { if (e.getButton() == MouseEvent.BUTTON1) { magnifyRectangle = null; magnifyXPoint = e.getX(); magnifyYPoint = e.getY(); } if (!e.isPopupTrigger()) { Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(dragColour); if (magnifyRectangle != null) { g2.fill(magnifyRectangle); } g2.dispose(); } } } else { rd.mousePressed(e); } }
From source file:gov.nih.nci.caintegrator.application.graphing.BoxAndWhiskerDotsRenderer.java
/** * Draws the visual representation of a single data item when the plot has * a horizontal orientation.//from w w w.j a v a2s . c o m * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the plot is being drawn. * @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 row the row index (zero-based). * @param column the column index (zero-based). */ public void drawHorizontalItem(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 = Math.abs(categoryEnd - categoryStart); double yy = categoryStart; int seriesCount = getRowCount(); int categoryCount = getColumnCount(); if (seriesCount > 1) { double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1)); double usedWidth = (state.getBarWidth() * seriesCount) + (seriesGap * (seriesCount - 1)); // offset the start of the boxes if the total width used is smaller // than the category width double offset = (categoryWidth - usedWidth) / 2; yy = yy + offset + (row * (state.getBarWidth() + seriesGap)); } else { // offset the start of the box if the box width is smaller than // the category width double offset = (categoryWidth - state.getBarWidth()) / 2; yy = yy + offset; } Paint p = getItemPaint(row, column); if (p != null) { g2.setPaint(p); } Stroke s = getItemStroke(row, column); g2.setStroke(s); RectangleEdge location = plot.getRangeAxisEdge(); Number xQ1 = bawDataset.getQ1Value(row, column); Number xQ3 = bawDataset.getQ3Value(row, column); Number xMax = bawDataset.getMaxRegularValue(row, column); Number xMin = bawDataset.getMinRegularValue(row, column); Shape box = null; if (xQ1 != null && xQ3 != null && xMax != null && xMin != null) { double xxQ1 = rangeAxis.valueToJava2D(xQ1.doubleValue(), dataArea, location); double xxQ3 = rangeAxis.valueToJava2D(xQ3.doubleValue(), dataArea, location); double xxMax = rangeAxis.valueToJava2D(xMax.doubleValue(), dataArea, location); double xxMin = rangeAxis.valueToJava2D(xMin.doubleValue(), dataArea, location); double yymid = yy + state.getBarWidth() / 2.0; // draw the upper shadow... g2.draw(new Line2D.Double(xxMax, yymid, xxQ3, yymid)); g2.draw(new Line2D.Double(xxMax, yy, xxMax, yy + state.getBarWidth())); // draw the lower shadow... g2.draw(new Line2D.Double(xxMin, yymid, xxQ1, yymid)); g2.draw(new Line2D.Double(xxMin, yy, xxMin, yy + state.getBarWidth())); // draw the box... box = new Rectangle2D.Double(Math.min(xxQ1, xxQ3), yy, Math.abs(xxQ1 - xxQ3), state.getBarWidth()); if (this.fillBox) { g2.fill(box); } g2.draw(box); } g2.setPaint(this.artifactPaint); double aRadius = 0; // average radius // draw mean - SPECIAL AIMS REQUIREMENT... Number xMean = bawDataset.getMeanValue(row, column); if (xMean != null) { double xxMean = rangeAxis.valueToJava2D(xMean.doubleValue(), dataArea, location); aRadius = state.getBarWidth() / 4; Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xxMean - aRadius, yy + aRadius, aRadius * 2, aRadius * 2); g2.fill(avgEllipse); g2.draw(avgEllipse); } // draw median... Number xMedian = bawDataset.getMedianValue(row, column); if (xMedian != null) { double xxMedian = rangeAxis.valueToJava2D(xMedian.doubleValue(), dataArea, location); g2.draw(new Line2D.Double(xxMedian, yy, xxMedian, yy + state.getBarWidth())); } // 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(box, tip, url, dataset, row, dataset.getColumnKey(column), column); entities.add(entity); } } }
From source file:gda.plots.SimplePlot.java
/** * Part of the implementation of MouseListener. Overrides the super class (ChartPanel) implementation so that the * mouse can be used to select a rectangle as well as for zooming. * //from w w w .j a va2s . c o m * @see #mousePressed(java.awt.event.MouseEvent) * @see #mouseDragged(java.awt.event.MouseEvent) * @param e * the mouse event which caused the call */ @Override public void mouseReleased(MouseEvent e) { // Unless a rectangle is being dragged we just // want to call the super class method (which // deals with zooming) if (rd == null) { super.mouseReleased(e); if (magnifyingImage || magnifyingData) { // If the button released is BUTTON1 then the rectangle for // magnification will have been resized. if (e.getButton() == MouseEvent.BUTTON1) { magnifyWidth = e.getX() - magnifyXPoint; magnifyHeight = e.getY() - magnifyYPoint; magnifyRectangleIsNew = true; } // If the button released is BUTTON2 then the rectangle will // have been being dragged around. Need to redraw in XOR mode // one // last time to remove rectangle from plot. else if (e.getButton() == MouseEvent.BUTTON2) { Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(dragColour); if (magnifyRectangle != null) { g2.fill(magnifyRectangle); } g2.dispose(); } recalculateMagnifyRectangle(e); magnifier.update(magnifyRectangle); } } else { rd.mouseReleased(e); } }