List of usage examples for java.awt Graphics2D setPaint
public abstract void setPaint(Paint paint);
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). *///from w ww . ja v 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:edu.csun.ecs.cs.multitouchj.application.whiteboard.ui.InteractiveCanvas.java
protected void drawPoints() { synchronized (previousPoints) { synchronized (resizableBufferedImage) { // clear points for pen if it's been long since last changed long currentTime = new Date().getTime(); for (int id : pens.keySet()) { if (previousTimes.containsKey(id)) { long time = previousTimes.get(id); if ((currentTime - time) > POINT_CLEAR_DURATION) { previousPoints.remove(id); previousTimes.remove(id); }/*from w w w . ja v a 2 s .c o m*/ } } DisplayMode displayMode = getWindowManager().getDisplayManager().getCurrentDisplayMode(); BufferedImage bufferedImage = resizableBufferedImage.getBufferedImage(); Graphics2D graphics = bufferedImage.createGraphics(); for (int id : pens.keySet()) { Pen pen = pens.get(id); LinkedList<Point> points = previousPoints.get(id); if ((pen != null) && (points != null) && (points.size() > 1)) { log.debug("id: " + id + ", points: " + points.size()); Point previousPoint = points.removeFirst(); Iterator<Point> iterator = points.iterator(); while (iterator.hasNext()) { Point point = iterator.next(); if (iterator.hasNext()) { iterator.remove(); } graphics.setStroke(pen.getStroke()); graphics.setPaint(pen.getPaint()); graphics.drawLine((int) Math.floor(previousPoint.getX()), (displayMode.getHeight() - (int) Math.floor(previousPoint.getY())), (int) Math.floor(point.getX()), (displayMode.getHeight() - (int) Math.floor(point.getY()))); previousPoint = point; } setDirty(true); } } graphics.dispose(); } } }
From source file:de.berlios.statcvs.xml.chart.SymbolicNameAnnotation.java
/** * @see org.jfree.chart.annotations.XYAnnotation#draw(java.awt.Graphics2D, org.jfree.chart.plot.XYPlot, java.awt.geom.Rectangle2D, org.jfree.chart.axis.ValueAxis, org.jfree.chart.axis.ValueAxis) *///from ww w.j ava 2s. c o m public void draw(Graphics2D g2d, XYPlot xyPlot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis) { PlotOrientation orientation = xyPlot.getOrientation(); // don't draw the annotation if symbolic names date is out of axis' bounds. if (domainAxis.getUpperBound() < symbolicName.getDate().getTime() || domainAxis.getLowerBound() > symbolicName.getDate().getTime()) { return; } RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(xyPlot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(xyPlot.getRangeAxisLocation(), orientation); float x = (float) domainAxis.translateValueToJava2D(symbolicName.getDate().getTime(), dataArea, domainEdge); float y1 = (float) rangeAxis.translateValueToJava2D(rangeAxis.getUpperBound(), dataArea, rangeEdge); float y2 = (float) rangeAxis.translateValueToJava2D(rangeAxis.getLowerBound(), dataArea, rangeEdge); g2d.setPaint(linePaint); g2d.setStroke(stroke); Line2D line = new Line2D.Float(x, y1, x, y2); g2d.draw(line); float anchorX = x; float anchorY = y1 + 2; g2d.setFont(font); g2d.setPaint(textPaint); /*g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);*/ RefineryUtilities.drawRotatedString(symbolicName.getName(), g2d, anchorX, anchorY, TextAnchor.BOTTOM_RIGHT, TextAnchor.BOTTOM_RIGHT, -Math.PI / 2); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java
@Override public void paintComponent(Graphics g) { super.paintComponent(g); if (getChart() == null) { return;// w ww .ja v a 2 s . c om } Graphics2D g2 = (Graphics2D) g.create(); // first determine the size of the chart rendering area... Dimension size = getSize(); Insets insets = getInsets(); Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); // work out if scaling is required... boolean scale = false; double drawWidth = available.getWidth(); double drawHeight = available.getHeight(); setChartFieldValue(getChartFieldByName("scaleX"), 1.0); // this.scaleX = 1.0; setChartFieldValue(getChartFieldByName("scaleY"), 1.0); // this.scaleY = 1.0; if (drawWidth < getMinimumDrawWidth()) { setChartFieldValue(getChartFieldByName("scaleX"), drawWidth / getMinimumDrawWidth()); // this.scaleX = drawWidth / getMinimumDrawWidth(); drawWidth = getMinimumDrawWidth(); scale = true; } else if (drawWidth > getMaximumDrawWidth()) { setChartFieldValue(getChartFieldByName("scaleX"), drawWidth / getMaximumDrawWidth()); // this.scaleX = drawWidth / getMaximumDrawWidth(); drawWidth = getMaximumDrawWidth(); scale = true; } if (drawHeight < getMinimumDrawHeight()) { setChartFieldValue(getChartFieldByName("scaleY"), drawHeight / getMinimumDrawHeight()); // this.scaleY = drawHeight / getMinimumDrawHeight(); drawHeight = getMinimumDrawHeight(); scale = true; } else if (drawHeight > getMaximumDrawHeight()) { setChartFieldValue(getChartFieldByName("scaleY"), drawHeight / getMaximumDrawHeight()); // this.scaleY = drawHeight / getMaximumDrawHeight(); drawHeight = getMaximumDrawHeight(); scale = true; } Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight); // are we using the chart buffer? if ((Boolean) getChartFieldValueByName("useBuffer")) { // do we need to resize the buffer? if ((getChartFieldValueByName("chartBuffer") == null) || ((Integer) getChartFieldValueByName("chartBufferWidth") != available.getWidth()) || ((Integer) getChartFieldValueByName("chartBufferHeight") != available.getHeight())) { setChartFieldValue(getChartFieldByName("chartBufferWidth"), (int) available.getWidth()); // this.chartBufferWidth = (int) available.getWidth(); setChartFieldValue(getChartFieldByName("chartBufferHeight"), (int) available.getHeight()); // this.chartBufferHeight = (int) available.getHeight(); GraphicsConfiguration gc = g2.getDeviceConfiguration(); setChartFieldValue(getChartFieldByName("chartBuffer"), gc.createCompatibleImage((Integer) getChartFieldValueByName("chartBufferWidth"), (Integer) getChartFieldValueByName("chartBufferHeight"), Transparency.TRANSLUCENT)); // this.chartBuffer = gc.createCompatibleImage(this.chartBufferWidth, // this.chartBufferHeight, Transparency.TRANSLUCENT); setRefreshBuffer(true); } // do we need to redraw the buffer? if (getRefreshBuffer()) { setRefreshBuffer(false); // clear the flag Rectangle2D bufferArea = new Rectangle2D.Double(0, 0, (Integer) getChartFieldValueByName("chartBufferWidth"), (Integer) getChartFieldValueByName("chartBufferHeight")); Graphics2D bufferG2 = (Graphics2D) ((Image) getChartFieldValueByName("chartBuffer")).getGraphics(); Rectangle r = new Rectangle(0, 0, (Integer) getChartFieldValueByName("chartBufferWidth"), (Integer) getChartFieldValueByName("chartBufferHeight")); bufferG2.setPaint(getBackground()); bufferG2.fill(r); if (scale) { AffineTransform saved = bufferG2.getTransform(); AffineTransform st = AffineTransform.getScaleInstance( (Double) getChartFieldValueByName("scaleX"), (Double) getChartFieldValueByName("scaleY")); bufferG2.transform(st); getChart().draw(bufferG2, chartArea, getAnchor(), getChartRenderingInfo()); bufferG2.setTransform(saved); } else { getChart().draw(bufferG2, bufferArea, getAnchor(), getChartRenderingInfo()); } } // zap the buffer onto the panel... g2.drawImage((Image) getChartFieldValueByName("chartBuffer"), insets.left, insets.top, this); } // or redrawing the chart every time... else { AffineTransform saved = g2.getTransform(); g2.translate(insets.left, insets.top); if (scale) { AffineTransform st = AffineTransform.getScaleInstance((Double) getChartFieldValueByName("scaleX"), (Double) getChartFieldValueByName("scaleY")); g2.transform(st); } getChart().draw(g2, chartArea, getAnchor(), getChartRenderingInfo()); g2.setTransform(saved); } Iterator iterator = ((List) getChartFieldValueByName("overlays")).iterator(); while (iterator.hasNext()) { Overlay overlay = (Overlay) iterator.next(); overlay.paintOverlay(g2, this); } // redraw the zoom rectangle (if present) - if useBuffer is false, // we use XOR so we can XOR the rectangle away again without redrawing // the chart drawZoomRectangle(g2, !(Boolean) getChartFieldValueByName("useBuffer")); g2.dispose(); setAnchor(null); setVerticalTraceLine(null); setHorizontalTraceLine(null); }
From source file:org.openaltimeter.desktopapp.annotations.XYVarioAnnotation.java
@Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { // draw line/*from ww w.j a va2 s. c o m*/ super.draw(g2, plot, dataArea, domainAxis, rangeAxis, rendererIndex, info); // draw text PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation); float anchorX = (float) domainAxis.valueToJava2D((x1 + x2) / 2, dataArea, domainEdge); float anchorY = (float) rangeAxis.valueToJava2D((y1 + y2) / 2, dataArea, rangeEdge); if (orientation == PlotOrientation.HORIZONTAL) { float tempAnchor = anchorX; anchorX = anchorY; anchorY = tempAnchor; } g2.setFont(getFont()); g2.setPaint(getPaint()); TextUtilities.drawRotatedString(getText(), g2, anchorX + this.offset, anchorY - OFFSET_SIZE, getTextAnchor(), getRotationAngle(), getRotationAnchor()); g2.setPaint(Color.GRAY); int jx1 = (int) domainAxis.valueToJava2D(x1, dataArea, domainEdge); int jx2 = (int) domainAxis.valueToJava2D(x2, dataArea, domainEdge); int jy1 = (int) rangeAxis.valueToJava2D(y1, dataArea, rangeEdge); int jy2 = (int) rangeAxis.valueToJava2D(y2, dataArea, rangeEdge); TextUtilities.drawRotatedString(getText2(), g2, (jx1 + jx2) / 2, jy1 + LIMB_TEXT_OFFSET, getTextAnchor(), getRotationAngle(), getRotationAnchor()); g2.drawLine(jx1, jy1, jx2, jy1); g2.drawLine(jx2, jy1, jx2, jy2); }
From source file:org.pentaho.reporting.engine.classic.core.layout.output.RenderUtility.java
public static DefaultImageReference createImageFromDrawable(final DrawableWrapper drawable, final StrictBounds rect, final StyleSheet box, final OutputProcessorMetaData metaData) { final int imageWidth = (int) StrictGeomUtility.toExternalValue(rect.getWidth()); final int imageHeight = (int) StrictGeomUtility.toExternalValue(rect.getHeight()); if (imageWidth == 0 || imageHeight == 0) { return null; }/*from w w w .j a v a 2 s .c o m*/ final double scale = RenderUtility.getNormalizationScale(metaData); final Image image = ImageUtils.createTransparentImage((int) (imageWidth * scale), (int) (imageHeight * scale)); final Graphics2D g2 = (Graphics2D) image.getGraphics(); final Object attribute = box.getStyleProperty(ElementStyleKeys.ANTI_ALIASING); if (attribute != null) { if (Boolean.TRUE.equals(attribute)) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } else if (Boolean.FALSE.equals(attribute)) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } } if (RenderUtility.isFontSmooth(box, metaData)) { g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } else { g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } g2.scale(scale, scale); // the clipping bounds are a sub-area of the whole drawable // we only want to print a certain area ... final String fontName = (String) box.getStyleProperty(TextStyleKeys.FONT); final int fontSize = box.getIntStyleProperty(TextStyleKeys.FONTSIZE, 8); final boolean bold = box.getBooleanStyleProperty(TextStyleKeys.BOLD); final boolean italics = box.getBooleanStyleProperty(TextStyleKeys.ITALIC); if (bold && italics) { g2.setFont(new Font(fontName, Font.BOLD | Font.ITALIC, fontSize)); } else if (bold) { g2.setFont(new Font(fontName, Font.BOLD, fontSize)); } else if (italics) { g2.setFont(new Font(fontName, Font.ITALIC, fontSize)); } else { g2.setFont(new Font(fontName, Font.PLAIN, fontSize)); } g2.setStroke((Stroke) box.getStyleProperty(ElementStyleKeys.STROKE)); g2.setPaint((Paint) box.getStyleProperty(ElementStyleKeys.PAINT)); drawable.draw(g2, new Rectangle2D.Double(0, 0, imageWidth, imageHeight)); g2.dispose(); try { return new DefaultImageReference(image); } catch (final IOException e1) { logger.warn("Unable to fully load a given image. (It should not happen here.)", e1); return null; } }
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 ww.jav a2 s. c o 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); } }
From source file:org.rdv.viz.chart.FastXYItemRenderer.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) { boolean itemVisible = getItemVisible(series, item); // setup for collecting optional entity info... Shape entityArea = null;/*w w w . j av a2s .c o m*/ EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } PlotOrientation orientation = plot.getOrientation(); Paint paint = getItemPaint(series, item); Stroke seriesStroke = getItemStroke(series, item); g2.setPaint(paint); g2.setStroke(seriesStroke); // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(x1) || Double.isNaN(y1)) { itemVisible = false; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (getPlotLines()) { if (item == 0) { previousDrawnItem = 1; } if (getDrawSeriesLineAsPath()) { State s = (State) state; if (s.getSeriesIndex() != series) { // we are starting a new series path s.seriesPath.reset(); s.setLastPointGood(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.getSeriesIndex() == 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... double x0 = dataset.getXValue(series, item - previousDrawnItem); double y0 = dataset.getYValue(series, item - previousDrawnItem); 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 int numX = dataset.getItemCount(series); double minX = dataset.getXValue(series, 0); double maxX = dataset.getXValue(series, numX - 1); if (getGapThresholdType() == UnitType.ABSOLUTE) { drawLine = Math.abs(x1 - x0) <= getGapThreshold(); } else { drawLine = Math.abs(x1 - x0) <= ((maxX - minX) / numX * getGapThreshold()); } } if (drawLine) { double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); 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; } // Only draw line if it is more than a pixel away from the // previous one if ((transX1 - transX0 > 2 || transX1 - transX0 < -2 || transY1 - transY0 > 2 || transY1 - transY0 < -2)) { previousDrawnItem = 1; 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); } } else { // Increase counter for the previous drawn item. previousDrawnItem++; } } } } } // 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; } // add a cursor to indicate the position of the last data item if (getCursorVisible() && item == dataset.getItemCount(series) - 1) { Line2D cursorX = new Line2D.Double(transX1 - DEFAULT_CURSOR_SIZE, transY1, transX1 + DEFAULT_CURSOR_SIZE, transY1); g2.draw(cursorX); Line2D cursorY = new Line2D.Double(transX1, transY1 - DEFAULT_CURSOR_SIZE, transX1, transY1 + DEFAULT_CURSOR_SIZE); g2.draw(cursorY); } 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()) { Image image = getImage(plot, series, item, transX1, transY1); if (image != null) { 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)); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation); // add an entity for the item... if (entities != null && dataArea.contains(xx, yy)) { addEntity(entities, entityArea, dataset, series, item, xx, yy); } }
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 va2s.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.fhcrc.cpl.viewer.quant.gui.PanelWithSpectrumChart.java
License:asdf
/** * * @param imageWidthEachScan/* w ww . ja v a2 s . c om*/ * @param imageHeightEachScan * @param maxTotalImageHeight a hard boundary on the total image height. If imageHeightEachScan is too big, * given the total number of charts and this arg, it gets knocked down * @param outputFile * @throws java.io.IOException */ public void savePerScanSpectraImage(int imageWidthEachScan, int imageHeightEachScan, int maxTotalImageHeight, File outputFile) throws IOException { int numCharts = scanLineChartMap.size(); int widthPaddingForLabels = 50; imageHeightEachScan = Math.min(imageHeightEachScan, maxTotalImageHeight / numCharts); List<Integer> allScanNumbers = new ArrayList<Integer>(scanLineChartMap.keySet()); Collections.sort(allScanNumbers); List<PanelWithChart> allCharts = new ArrayList<PanelWithChart>(); for (int scanNumber : allScanNumbers) { PanelWithLineChart scanChart = scanLineChartMap.get(scanNumber); allCharts.add(scanChart); scanChart.setSize(imageWidthEachScan - widthPaddingForLabels, imageHeightEachScan); } BufferedImage perScanChartImage = MultiChartDisplayPanel.createImageForAllCharts(allCharts); BufferedImage perScanChartImageWithLabels = new BufferedImage(imageWidthEachScan, perScanChartImage.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D g = perScanChartImageWithLabels.createGraphics(); g.drawImage(perScanChartImage, widthPaddingForLabels, 0, null); g.setPaint(Color.WHITE); g.drawRect(0, 0, widthPaddingForLabels, perScanChartImage.getHeight()); for (int i = 0; i < allCharts.size(); i++) { int scanNumber = allScanNumbers.get(i); int chartTop = i * imageHeightEachScan; int chartMiddle = chartTop + (imageHeightEachScan / 2); if (lightFirstScanLine > 0 && lightLastScanLine > 0) { if (scanNumber >= lightFirstScanLine && scanNumber <= lightLastScanLine) g.setPaint(Color.GREEN); else g.setPaint(Color.RED); } else g.setPaint(Color.BLACK); g.drawString("" + scanNumber, 5, chartMiddle); } g.dispose(); ImageIO.write(perScanChartImageWithLabels, "png", outputFile); }