List of usage examples for java.awt.geom Area Area
public Area(Shape s)
From source file:savant.view.swing.GraphPane.java
/** * Render the background of this GraphPane * * @param g The graphics object to use// w w w .j a v a 2s . com */ private void renderBackground(Graphics2D g2, boolean xGridOn, boolean yGridOn) { int h = getHeight(); int w = getWidth(); // Paint a gradient from top to bottom GradientPaint gp0 = new GradientPaint(0, 0, ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_TOP), 0, h, ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_BOTTOM)); g2.setPaint(gp0); g2.fillRect(0, 0, w, h); // We don't want the axes stomping on our labels, so make sure the clip excludes them. Area clipArea = new Area(new Rectangle(0, 0, w, h)); Color gridColor = ColourSettings.getColor(ColourKey.AXIS_GRID); if (yGridOn) { // Smallish font for tick labels. Font tickFont = g2.getFont().deriveFont(Font.PLAIN, 9); int[] yTicks = MiscUtils.getTickPositions(transformYPixel(getHeight()), transformYPixel(0.0)); g2.setColor(gridColor); g2.setFont(tickFont); for (int t : yTicks) { double y = transformYPos(t); // Skip labels at the top or bottom of the window because they look stupid. if (y != 0.0 && y != getHeight()) { String s = Integer.toString(t); Rectangle2D labelRect = tickFont.getStringBounds(s, g2.getFontRenderContext()); double baseline = y + labelRect.getHeight() * 0.5 - 2.0; g2.drawString(s, 4.0F, (float) baseline); clipArea.subtract(new Area(new Rectangle2D.Double(3.0, baseline - labelRect.getHeight() - 1.0, labelRect.getWidth() + 2.0, labelRect.getHeight() + 2.0))); } } g2.setClip(clipArea); for (int t2 : yTicks) { double y = transformYPos(t2); g2.draw(new Line2D.Double(0.0, y, w, y)); } } if (xGridOn) { Range r = LocationController.getInstance().getRange(); int[] xTicks = MiscUtils.getTickPositions(r); g2.setColor(gridColor); for (int t : xTicks) { double x = transformXPos(t); g2.draw(new Line2D.Double(x, 0, x, h)); } } g2.setClip(null); }
From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java
@Override public void fillPolygon(PolygonRenderEvent pre) throws ChartException { if (iv != null) { iv.modifyEvent(pre);/*w ww .j a v a 2 s . com*/ } final Fill flBackground = validateMultipleFill(pre.getBackground()); if (isFullTransparent(flBackground)) { return; } final Location[] loa = pre.getPoints(); final int[][] i2a = getCoordinatesAsInts(loa); if (flBackground instanceof ColorDefinition) { final ColorDefinition cd = (ColorDefinition) flBackground; _g2d.setColor((Color) _ids.getColor(cd)); _g2d.fill(getPolygon(loa)); } else if (flBackground instanceof Gradient) { final Gradient g = (Gradient) flBackground; final ColorDefinition cdStart = g.getStartColor(); final ColorDefinition cdEnd = g.getEndColor(); // final boolean bRadial = g.isCyclic(); final double dAngleInDegrees = g.getDirection(); final double dAngleInRadians = ((-dAngleInDegrees * Math.PI) / 180.0); // final int iAlpha = g.getTransparency(); final double dMinX = BaseRenderer.getX(loa, IConstants.MIN); final double dMaxX = BaseRenderer.getX(loa, IConstants.MAX); final double dMinY = BaseRenderer.getY(loa, IConstants.MIN); final double dMaxY = BaseRenderer.getY(loa, IConstants.MAX); if (dAngleInDegrees < -90 || dAngleInDegrees > 90) { throw new ChartException(ChartDeviceExtensionPlugin.ID, ChartException.RENDERING, "SwingRendererImpl.exception.gradient.angle", //$NON-NLS-1$ new Object[] { new Double(dAngleInDegrees) }, Messages.getResourceBundle(getULocale())); } Point2D.Double p2dStart, p2dEnd; if (dAngleInDegrees == 90) { p2dStart = new Point2D.Double(dMinX, dMaxY); p2dEnd = new Point2D.Double(dMinX, dMinY); } else if (dAngleInDegrees == -90) { p2dStart = new Point2D.Double(dMinX, dMinY); p2dEnd = new Point2D.Double(dMinX, dMaxY); } else if (dAngleInDegrees > 0) { p2dStart = new Point2D.Double(dMinX, dMaxY); p2dEnd = new Point2D.Double(dMaxX, dMaxY - (dMaxX - dMinX) * Math.abs(Math.tan(dAngleInRadians))); } else if (dAngleInDegrees < 0) { p2dStart = new Point2D.Double(dMinX, dMinY); p2dEnd = new Point2D.Double(dMaxX, dMinY + (dMaxX - dMinX) * Math.abs(Math.tan(dAngleInRadians))); } else { p2dStart = new Point2D.Double(dMinX, dMinY); p2dEnd = new Point2D.Double(dMaxX, dMinY); } _g2d.setPaint(new GradientPaint(p2dStart, (Color) _ids.getColor(cdStart), p2dEnd, (Color) _ids.getColor(cdEnd))); _g2d.fill(getPolygon(loa)); } else if (flBackground instanceof org.eclipse.birt.chart.model.attribute.Image) { Area ar2 = new Area(new Polygon(i2a[0], i2a[1], loa.length)); if (flBackground instanceof PatternImage) { fillWithPatternImage(ar2, flBackground); return; } java.awt.Image img = createImageFromModel(flBackground); if (img != null) { final Shape shClip = _g2d.getClip(); if (shClip != null) { Area ar1 = new Area(shClip); ar2.intersect(ar1); } _g2d.setClip(ar2); final double dMinX = BaseRenderer.getX(loa, IConstants.MIN); final double dMaxX = BaseRenderer.getX(loa, IConstants.MAX); final double dMinY = BaseRenderer.getY(loa, IConstants.MIN); final double dMaxY = BaseRenderer.getY(loa, IConstants.MAX); final Size szImage = _ids.getSize(img); final int iXRepeat = (int) (Math.ceil((dMaxX - dMinX) / szImage.getWidth())); final int iYRepeat = (int) (Math.ceil((dMaxY - dMinY) / szImage.getHeight())); final ImageObserver io = (ImageObserver) _ids.getObserver(); for (int i = 0; i < iXRepeat; i++) { for (int j = 0; j < iYRepeat; j++) { _g2d.drawImage(img, (int) (dMinX + i * szImage.getWidth()), (int) (dMinY + j * szImage.getHeight()), io); } } _g2d.setClip(shClip); // RESTORE } } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
/** * @see Graphics#create()/*from w ww . jav a 2 s . c o m*/ */ @Override public Graphics create() { final PdfGraphics2D g2 = new PdfGraphics2D(); g2.transform = new AffineTransform(this.transform); g2.metaData = this.metaData; g2.paint = this.paint; g2.fillGState = this.fillGState; g2.strokeGState = this.strokeGState; g2.background = this.background; g2.mediaTracker = this.mediaTracker; g2.setFont(this.font); g2.cb = this.cb.getDuplicate(); g2.cb.saveState(); g2.width = this.width; g2.height = this.height; g2.followPath(new Area(new Rectangle2D.Float(0, 0, width, height)), PdfGraphics2D.CLIP); if (this.clip != null) { g2.clip = new Area(this.clip); } g2.stroke = stroke; g2.originalStroke = originalStroke; g2.strokeOne = (BasicStroke) g2.transformStroke(g2.strokeOne); g2.oldStroke = g2.strokeOne; g2.setStrokeDiff(g2.oldStroke, null); g2.cb.saveState(); if (g2.clip != null) { g2.followPath(g2.clip, PdfGraphics2D.CLIP); } g2.parent = this; if (this.kids == null) { this.kids = new ArrayList(); } // This is disgusting. You really cant override the buffer on the fixed position. The way the dispose() code // handles the cleanup, this will create a huge mess ... // this.kids.add(new Integer(cb.getInternalBuffer().size())); this.kids.add(g2); return g2; }
From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java
@Override public void drawArc(ArcRenderEvent are) throws ChartException { if (iv != null) { iv.modifyEvent(are);//from w w w . j a va2s.c om } // CHECK IF THE LINE ATTRIBUTES ARE CORRECTLY DEFINED final LineAttributes lia = are.getOutline(); if (!validateLineAttributes(are.getSource(), lia)) { return; } // SETUP THE FOREGROUND COLOR (DARKER BACKGROUND IF DEFINED AS NULL) final Color cFG = (Color) validateEdgeColor(lia.getColor(), are.getBackground(), _ids); if (cFG == null || cFG.getAlpha() == 0) { return; } // DRAW THE ARC Stroke sPrevious = null; Stroke sCurrent = getCachedStroke(lia); if (sCurrent != null) // SOME STROKE DEFINED? { sPrevious = _g2d.getStroke(); _g2d.setStroke(sCurrent); } _g2d.setColor(cFG); if ((are.getInnerRadius() >= 0 && are.getOuterRadius() > 0 && are.getInnerRadius() < are.getOuterRadius()) || (are.getInnerRadius() > 0 && are.getOuterRadius() <= 0)) { Bounds rctOuter = getOuterRectangle(are); Bounds rctInner = getInnerRectangle(are); Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), rctOuter.getTop(), rctOuter.getWidth(), rctOuter.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.OPEN); Shape innerArc = new Arc2D.Double(rctInner.getLeft(), rctInner.getTop(), rctInner.getWidth(), rctInner.getHeight(), are.getStartAngle() + are.getAngleExtent(), -are.getAngleExtent(), Arc2D.OPEN); double startAngle = Math.toRadians(-are.getStartAngle()); double stopAngle = Math.toRadians(-are.getStartAngle() - are.getAngleExtent()); double xsOuter = (rctOuter.getLeft() + (Math.cos(startAngle) * 0.5 + 0.5) * rctOuter.getWidth()); double ysOuter = (rctOuter.getTop() + (Math.sin(startAngle) * 0.5 + 0.5) * rctOuter.getHeight()); double xeInner = (rctInner.getLeft() + (Math.cos(stopAngle) * 0.5 + 0.5) * rctInner.getWidth()); double yeInner = (rctInner.getTop() + (Math.sin(stopAngle) * 0.5 + 0.5) * rctInner.getHeight()); GeneralPath gp = new GeneralPath(); gp.append(outerArc, false); gp.lineTo((float) xeInner, (float) yeInner); gp.append(innerArc, false); gp.lineTo((float) xsOuter, (float) ysOuter); Area area = new Area(gp); Shape prevClip = _g2d.getClip(); Area ar2 = new Area(area); if (prevClip != null) { Area ar1 = new Area(prevClip); ar2.intersect(ar1); } _g2d.setClip(ar2); _g2d.draw(area); _g2d.setClip(prevClip); } else { _g2d.draw(new Arc2D.Double(are.getTopLeft().getX(), are.getTopLeft().getY(), are.getWidth(), are.getHeight(), are.getStartAngle(), are.getAngleExtent(), toG2dArcType(are.getStyle()))); } if (sPrevious != null) // RESTORE PREVIOUS STROKE { _g2d.setStroke(sPrevious); } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
/** * @see Graphics2D#clip(Shape)/* w w w . j a v a 2 s . com*/ */ @Override public void clip(Shape s) { if (s == null) { setClip(null); return; } s = transform.createTransformedShape(s); if (clip == null) { clip = new Area(s); } else { clip.intersect(new Area(s)); } followPath(s, PdfGraphics2D.CLIP); }
From source file:org.jfree.experimental.swt.SWTGraphics2D.java
/** * Returns <code>true</code> if the rectangle (in device space) intersects * with the shape (the interior, if <code>onStroke</code> is false, * otherwise the stroked outline of the shape). * // ww w . ja v a 2s.c o m * @param rect a rectangle (in device space). * @param s the shape. * @param onStroke test the stroked outline only? * * @return A boolean. */ @Override public boolean hit(Rectangle rect, Shape s, boolean onStroke) { AffineTransform transform = getTransform(); Shape ts; if (onStroke) { Stroke stroke = getStroke(); ts = transform.createTransformedShape(stroke.createStrokedShape(s)); } else { ts = transform.createTransformedShape(s); } if (!rect.getBounds2D().intersects(ts.getBounds2D())) { return false; } Area a1 = new Area(rect); Area a2 = new Area(ts); a1.intersect(a2); return !a1.isEmpty(); }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
/** * @see Graphics#setClip(Shape)/*from www .j a v a2s . co m*/ */ @Override public void setClip(Shape s) { cb.restoreState(); cb.saveState(); if (s != null) { s = transform.createTransformedShape(s); } if (s == null) { clip = null; } else { clip = new Area(s); followPath(s, PdfGraphics2D.CLIP); } paintFill = null; paintStroke = null; currentFillGState = 255; currentStrokeGState = 255; oldStroke = strokeOne; }
From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java
@Override public void fillArc(ArcRenderEvent are) throws ChartException { if (iv != null) { iv.modifyEvent(are);/*from w w w .j a va 2 s.com*/ } final Fill flBackground = validateMultipleFill(are.getBackground()); if (isFullTransparent(flBackground)) { return; } if (flBackground instanceof ColorDefinition) { final ColorDefinition cl = (ColorDefinition) flBackground; final Color clrPrevious = _g2d.getColor(); final Color currentColor = (Color) _ids.getColor(cl); _g2d.setColor(currentColor); if ((are.getInnerRadius() >= 0 && are.getOuterRadius() > 0 && are.getInnerRadius() < are.getOuterRadius()) || (are.getInnerRadius() > 0 && are.getOuterRadius() <= 0)) { Bounds rctOuter = getOuterRectangle(are); Bounds rctInner = getInnerRectangle(are); Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), rctOuter.getTop(), rctOuter.getWidth(), rctOuter.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE); Shape innerArc = new Arc2D.Double(rctInner.getLeft(), rctInner.getTop(), rctInner.getWidth(), rctInner.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE); Area fArea = new Area(outerArc); fArea.exclusiveOr(new Area(innerArc)); Shape prevClip = _g2d.getClip(); Area ar2 = new Area(fArea); if (prevClip != null) { Area ar1 = new Area(prevClip); ar2.intersect(ar1); } _g2d.setClip(ar2); _g2d.fill(fArea); _g2d.setClip(prevClip); } else { _g2d.fill(new Arc2D.Double(are.getTopLeft().getX(), are.getTopLeft().getY(), are.getWidth(), are.getHeight(), are.getStartAngle(), are.getAngleExtent(), toG2dArcType(are.getStyle()))); } _g2d.setColor(clrPrevious); // RESTORE } else if (flBackground instanceof Gradient) { final Gradient g = (Gradient) flBackground; final ColorDefinition cdStart = g.getStartColor(); final ColorDefinition cdEnd = g.getEndColor(); double dAngleInDegrees = g.getDirection(); final double dAngleInRadians = ((-dAngleInDegrees * Math.PI) / 180.0); Bounds bo = are.getBounds(); if (dAngleInDegrees < -90 || dAngleInDegrees > 90) { throw new ChartException(ChartDeviceExtensionPlugin.ID, ChartException.RENDERING, "SwingRendererImpl.exception.gradient.angle", //$NON-NLS-1$ new Object[] { new Double(dAngleInDegrees) }, Messages.getResourceBundle(getULocale())); } Point2D.Double p2dStart, p2dEnd; if (dAngleInDegrees == 90) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop()); } else if (dAngleInDegrees == -90) { p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); } else if (dAngleInDegrees > 0) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop() + bo.getHeight() - bo.getWidth() * Math.abs(Math.tan(dAngleInRadians))); } else if (dAngleInDegrees < 0) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop() + bo.getWidth() * Math.abs(Math.tan(dAngleInRadians))); } else { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop()); } final Paint pPrevious = _g2d.getPaint(); _g2d.setPaint(new GradientPaint(p2dStart, (Color) _ids.getColor(cdStart), p2dEnd, (Color) _ids.getColor(cdEnd))); if ((are.getInnerRadius() >= 0 && are.getOuterRadius() > 0 && are.getInnerRadius() < are.getOuterRadius()) || (are.getInnerRadius() > 0 && are.getOuterRadius() <= 0)) { Bounds rctOuter = getOuterRectangle(are); Bounds rctInner = getInnerRectangle(are); Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), rctOuter.getTop(), rctOuter.getWidth(), rctOuter.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE); Shape innerArc = new Arc2D.Double(rctInner.getLeft(), rctInner.getTop(), rctInner.getWidth(), rctInner.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE); Area fArea = new Area(outerArc); fArea.exclusiveOr(new Area(innerArc)); Shape prevClip = _g2d.getClip(); Area ar2 = new Area(fArea); if (prevClip != null) { Area ar1 = new Area(prevClip); ar2.intersect(ar1); } _g2d.setClip(ar2); _g2d.fill(fArea); _g2d.setClip(prevClip); } else { _g2d.fill(new Arc2D.Double(are.getTopLeft().getX(), are.getTopLeft().getY(), are.getWidth(), are.getHeight(), are.getStartAngle(), are.getAngleExtent(), toG2dArcType(are.getStyle()))); } _g2d.setPaint(pPrevious); // RESTORE } else if (flBackground instanceof org.eclipse.birt.chart.model.attribute.Image) { final Bounds bo = are.getBounds(); final Rectangle2D.Double r2d = new Rectangle2D.Double(bo.getLeft(), bo.getTop(), bo.getWidth(), bo.getHeight()); Shape shPreviousClip = _g2d.getClip(); Area ar = null; if ((are.getInnerRadius() >= 0 && are.getOuterRadius() > 0 && are.getInnerRadius() < are.getOuterRadius()) || (are.getInnerRadius() > 0 && are.getOuterRadius() <= 0)) { Bounds rctOuter = getOuterRectangle(are); Bounds rctInner = getInnerRectangle(are); Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), rctOuter.getTop(), rctOuter.getWidth(), rctOuter.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE); Shape innerArc = new Arc2D.Double(rctInner.getLeft(), rctInner.getTop(), rctInner.getWidth(), rctInner.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE); Area fArea = new Area(outerArc); fArea.exclusiveOr(new Area(innerArc)); if (shPreviousClip != null) { Area ar1 = new Area(shPreviousClip); fArea.intersect(ar1); } // _g2d.setClip( fArea ); ar = fArea; } else { // SETUP THE CLIPPING AREA final Shape shArc = new Arc2D.Double(are.getTopLeft().getX(), are.getTopLeft().getY(), are.getWidth(), are.getHeight(), are.getStartAngle(), are.getAngleExtent(), toG2dArcType(are.getStyle())); Area ar2 = new Area(shArc); if (shPreviousClip != null) { Area ar1 = new Area(shPreviousClip); ar2.intersect(ar1); } // _g2d.setClip( ar2 ); ar = ar2; } if (flBackground instanceof PatternImage) { fillWithPatternImage(new Area(ar), flBackground); return; } _g2d.setClip(ar); // LOAD THE IMAGE java.awt.Image img = createImageFromModel(flBackground); if (img != null) { // REPLICATE THE IMAGE AS NEEDED final Size szImage = _ids.getSize(img); int iXRepeat = (int) (Math.ceil(r2d.width / szImage.getWidth())); int iYRepeat = (int) (Math.ceil(r2d.height / szImage.getHeight())); ImageObserver io = (ImageObserver) _ids.getObserver(); for (int i = 0; i < iXRepeat; i++) { for (int j = 0; j < iYRepeat; j++) { _g2d.drawImage(img, (int) (r2d.x + i * szImage.getWidth()), (int) (r2d.y + j * szImage.getHeight()), io); } } } _g2d.setClip(shPreviousClip); // RESTORE } }
From source file:de.laures.cewolf.jfree.ThermometerPlot.java
/** * Draws the plot on a Java 2D graphics device (such as the screen or a printer). * * @param g2 the graphics device./* w w w . jav a 2 s . c o m*/ * @param area the area within which the plot should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing. */ public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { RoundRectangle2D outerStem = new RoundRectangle2D.Double(); RoundRectangle2D innerStem = new RoundRectangle2D.Double(); RoundRectangle2D mercuryStem = new RoundRectangle2D.Double(); Ellipse2D outerBulb = new Ellipse2D.Double(); Ellipse2D innerBulb = new Ellipse2D.Double(); String temp = null; FontMetrics metrics = null; if (info != null) { info.setPlotArea(area); } // adjust for insets... RectangleInsets insets = getInsets(); insets.trim(area); drawBackground(g2, area); // adjust for padding... Rectangle2D interior = (Rectangle2D) area.clone(); this.padding.trim(interior); int midX = (int) (interior.getX() + (interior.getWidth() / 2)); int midY = (int) (interior.getY() + (interior.getHeight() / 2)); int stemTop = (int) (interior.getMinY() + getBulbRadius()); int stemBottom = (int) (interior.getMaxY() - getBulbDiameter()); Rectangle2D dataArea = new Rectangle2D.Double(midX - getColumnRadius(), stemTop, getColumnRadius(), stemBottom - stemTop); outerBulb.setFrame(midX - getBulbRadius(), stemBottom, getBulbDiameter(), getBulbDiameter()); outerStem.setRoundRect(midX - getColumnRadius(), interior.getMinY(), getColumnDiameter(), stemBottom + getBulbDiameter() - stemTop, getColumnDiameter(), getColumnDiameter()); Area outerThermometer = new Area(outerBulb); Area tempArea = new Area(outerStem); outerThermometer.add(tempArea); innerBulb.setFrame(midX - getBulbRadius() + getGap(), stemBottom + getGap(), getBulbDiameter() - getGap() * 2, getBulbDiameter() - getGap() * 2); innerStem.setRoundRect(midX - getColumnRadius() + getGap(), interior.getMinY() + getGap(), getColumnDiameter() - getGap() * 2, stemBottom + getBulbDiameter() - getGap() * 2 - stemTop, getColumnDiameter() - getGap() * 2, getColumnDiameter() - getGap() * 2); Area innerThermometer = new Area(innerBulb); tempArea = new Area(innerStem); innerThermometer.add(tempArea); if ((this.dataset != null) && (this.dataset.getValue() != null)) { double current = this.dataset.getValue().doubleValue(); double ds = this.rangeAxis.valueToJava2D(current, dataArea, RectangleEdge.LEFT); int i = getColumnDiameter() - getGap() * 2; // already calculated int j = getColumnRadius() - getGap(); // already calculated int l = (i / 2); int k = (int) Math.round(ds); if (k < (getGap() + interior.getMinY())) { k = (int) (getGap() + interior.getMinY()); l = getBulbRadius(); } Area mercury = new Area(innerBulb); if (k < (stemBottom + getBulbRadius())) { mercuryStem.setRoundRect(midX - j, k, i, (stemBottom + getBulbRadius()) - k, l, l); tempArea = new Area(mercuryStem); mercury.add(tempArea); } g2.setPaint(getCurrentPaint()); g2.fill(mercury); // draw range indicators... if (this.subrangeIndicatorsVisible) { g2.setStroke(this.subrangeIndicatorStroke); Range range = this.rangeAxis.getRange(); // draw start of normal range double value = this.subrangeInfo[NORMAL][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[NORMAL]); g2.draw(line); } // draw start of warning range value = this.subrangeInfo[WARNING][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[WARNING]); g2.draw(line); } // draw start of critical range value = this.subrangeInfo[CRITICAL][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[CRITICAL]); g2.draw(line); } } // draw the axis... if ((this.rangeAxis != null) && (this.axisLocation != NONE)) { int drawWidth = AXIS_GAP; Rectangle2D drawArea; double cursor = 0; switch (this.axisLocation) { case RIGHT: cursor = midX + getColumnRadius(); drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1)); this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.RIGHT, null); break; case LEFT: default: //cursor = midX - COLUMN_RADIUS - AXIS_GAP; cursor = midX - getColumnRadius(); drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1)); this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.LEFT, null); break; } } // draw text value on screen g2.setFont(this.valueFont); g2.setPaint(this.valuePaint); metrics = g2.getFontMetrics(); switch (this.valueLocation) { case RIGHT: g2.drawString(this.valueFormat.format(current), midX + getColumnRadius() + getGap(), midY); break; case LEFT: String valueString = this.valueFormat.format(current); int stringWidth = metrics.stringWidth(valueString); g2.drawString(valueString, midX - getColumnRadius() - getGap() - stringWidth, midY); break; case BULB: temp = this.valueFormat.format(current); i = metrics.stringWidth(temp) / 2; g2.drawString(temp, midX - i, stemBottom + getBulbRadius() + getGap()); break; default: } /***/ } g2.setPaint(this.thermometerPaint); g2.setFont(this.valueFont); // draw units indicator metrics = g2.getFontMetrics(); int tickX1 = midX - getColumnRadius() - getGap() * 2 - metrics.stringWidth(UNITS[this.units]); if (tickX1 > area.getMinX()) { g2.drawString(UNITS[this.units], tickX1, (int) (area.getMinY() + 20)); } // draw thermometer outline g2.setStroke(this.thermometerStroke); g2.draw(outerThermometer); g2.draw(innerThermometer); drawOutline(g2, area); }
From source file:net.sf.maltcms.chromaui.charts.Chromatogram1DChartProvider.java
/** * * @param f//from w w w .jav a 2 s . c o m * @param useScanAcquisitionTime * @param outline * @param fill * @param valueVar * @return */ public static List<XYAnnotation> generatePeakShapes(IFileFragment f, boolean useScanAcquisitionTime, Color outline, Color fill, String valueVar) { List<XYAnnotation> l = new ArrayList<>(); try { IVariableFragment peakNames = f.getChild("peak_name"); IVariableFragment peakRT = f.getChild("peak_retention_time"); IVariableFragment peakStartRT = f.getChild("peak_start_time"); IVariableFragment peakStopRT = f.getChild("peak_end_time"); int peaks = peakRT.getArray().getShape()[0]; boolean baselineAvailable = true; IVariableFragment blStartRT = null; IVariableFragment blStopRT = null; IVariableFragment blStartValue = null; IVariableFragment blStopValue = null; try { blStartRT = f.getChild("baseline_start_time"); blStopRT = f.getChild("baseline_stop_time"); blStartValue = f.getChild("baseline_start_value"); blStopValue = f.getChild("baseline_stop_value"); } catch (ResourceNotAvailableException e) { baselineAvailable = false; } boolean andichromMode = valueVar.equals("ordinate_values"); Array ordinateValues = null; try { ordinateValues = f.getChild(valueVar).getArray(); } catch (ResourceNotAvailableException rne) { ordinateValues = f.getChild("total_intensity").getArray(); andichromMode = false; } Collection<String> peaknames = ArrayTools.getStringsFromArray(peakNames.getArray()); IndexIterator ii = peakRT.getArray().getIndexIterator(); Iterator<String> peaknamesIter = peaknames.iterator(); for (int i = 0; i < peaks; i++) { double sat = ii.getDoubleNext(); double peakStartTime = peakStartRT.getArray().getDouble(i); double peakStopTime = peakStopRT.getArray().getDouble(i); int scan = 0; int startIdx, stopIdx; if (andichromMode) { double delay = f.getChild("actual_delay_time").getArray().getDouble(0); double samplingRate = f.getChild("actual_sampling_interval").getArray().getDouble(0); scan = (int) (Math.floor(((sat - delay) / samplingRate))); startIdx = (int) (Math.floor(((peakStartTime - delay) / samplingRate))); stopIdx = (int) (Math.floor(((peakStopTime - delay) / samplingRate))); } else { Array satA = f.getChild("scan_acquisition_time").getArray(); double[] d = (double[]) satA.get1DJavaArray(double.class); scan = Arrays.binarySearch(d, sat); if (scan < 0) { scan = ((-1) * (scan + 1)); } startIdx = Arrays.binarySearch(d, peakStartTime); stopIdx = Arrays.binarySearch(d, peakStopTime); if (startIdx < 0) { startIdx = ((-1) * (startIdx + 1)); } if (stopIdx < 0) { stopIdx = ((-1) * (stopIdx + 1)); } } String name = peaknamesIter.next(); double blStartTime, blStopTime, blStartVal, blStopVal; if (baselineAvailable) { blStartTime = blStartRT.getArray().getDouble(i); blStopTime = blStopRT.getArray().getDouble(i); blStartVal = blStartValue.getArray().getDouble(i); blStopVal = blStopValue.getArray().getDouble(i); } else { blStartTime = peakStartTime; blStopTime = peakStopTime; blStartVal = ordinateValues.getDouble(startIdx); blStopVal = ordinateValues.getDouble(stopIdx); } if (name.trim().isEmpty()) { name = "NN"; } GeneralPath gp = new GeneralPath(); if (useScanAcquisitionTime) { Array sat2 = f.getChild("scan_acquisition_time").getArray(); gp.moveTo(peakStartTime, ordinateValues.getDouble(startIdx)); for (int j = startIdx + 1; j <= stopIdx + 1; j++) { gp.lineTo(sat2.getDouble(j), ordinateValues.getDouble(j)); } gp.lineTo(Math.max(blStopTime, peakStopTime), blStopVal); gp.lineTo(Math.min(blStartTime, peakStartTime), blStartVal); gp.closePath(); //gp.closePath(); Rectangle2D.Double bbox = new Rectangle2D.Double(peakStartTime, 0, peakStopTime - peakStartTime, ordinateValues.getDouble(scan)); Area a = new Area(bbox); a.intersect(new Area(gp)); XYShapeAnnotation xypa = new XYShapeAnnotation(a, new BasicStroke(), outline, fill); XYLineAnnotation xyla = new XYLineAnnotation(blStartTime, blStartVal, blStopTime, blStopVal, new BasicStroke(), Color.BLACK); l.add(xypa); l.add(xyla); // XYLineAnnotation baseline = new XYLineAnnotation(); } else { gp.moveTo(startIdx, ordinateValues.getDouble(startIdx)); for (int j = startIdx + 1; j <= stopIdx + 1; j++) { gp.lineTo(j, ordinateValues.getDouble(j)); } gp.closePath(); XYShapeAnnotation xypa = new XYShapeAnnotation(gp, new BasicStroke(), outline, fill); l.add(xypa); } } } catch (ResourceNotAvailableException rnae) { Logger.getLogger(Chromatogram1DChartProvider.class.getName()).info(rnae.getLocalizedMessage()); } return l; }