List of usage examples for java.awt Graphics2D setStroke
public abstract void setStroke(Stroke s);
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 w w w.jav a2s . c om*/ 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:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int cx = getSize().width / 2; int cy = getSize().height / 2; g2.translate(cx, cy);/*from w w w .ja v a 2s . c o m*/ g2.rotate(theta * Math.PI / 180); Shape oldClip = g2.getClip(); Shape e = new Ellipse2D.Float(-cx, -cy, cx * 2, cy * 2); g2.clip(e); Shape c = new Ellipse2D.Float(-cx, -cy, cx * 3 / 4, cy * 2); g2.setPaint(new GradientPaint(40, 40, Color.blue, 60, 50, Color.white, true)); g2.fill(c); g2.setPaint(Color.yellow); g2.fillOval(cx / 4, 0, cx, cy); g2.setClip(oldClip); g2.setFont(new Font("Times New Roman", Font.PLAIN, 64)); g2.setPaint(new GradientPaint(-cx, 0, Color.red, cx, 0, Color.black, false)); g2.drawString("Hello, 2D!", -cx * 3 / 4, cy / 4); AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) .75); g2.setComposite(ac); Shape r = new RoundRectangle2D.Float(0, -cy * 3 / 4, cx * 3 / 4, cy * 3 / 4, 20, 20); g2.setStroke(new BasicStroke(4)); g2.setPaint(Color.magenta); g2.fill(r); g2.setPaint(Color.green); g2.draw(r); g2.drawImage(image, -cx / 2, -cy / 2, this); }
From source file:org.oscarehr.common.web.PregnancyAction.java
public ActionForward getFundalImage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { List<Point2D.Double> points = new ArrayList<Point2D.Double>(); int index = 1; while (true) { String ga = request.getParameter("ga" + index); String cm = request.getParameter("fh" + index); if (ga == null || cm == null) break; String weeks = null;// w ww.j a v a 2 s.co m String offset = null; try { weeks = ga.substring(0, ga.indexOf("w")); offset = "0"; if (ga.indexOf("+") != -1) offset = ga.substring(ga.indexOf("+") + 1); } catch (Exception e) { MiscUtils.getLogger().warn("Error", e); } if (weeks != null && offset != null) { try { double gaa = Integer.parseInt(weeks) + (Integer.parseInt(offset) / 7); double cma = Double.parseDouble(cm); Point2D.Double p = new Point2D.Double(gaa, cma); points.add(p); } catch (NumberFormatException e) { MiscUtils.getLogger().warn("Error", e); } } index++; } File file = new File(request.getSession().getServletContext().getRealPath("/") + "WEB-INF/classes/oscar/form/prop/fundal_graph.png"); BufferedImage bufferedImage = ImageIO.read(file); Graphics2D g = bufferedImage.createGraphics(); g.setColor(Color.black); g.setStroke(new BasicStroke(2)); int xStart = 23; //each week is 10.25pixels int yStart = 318; //each height is 10.6pixels int width = 7; int height = 7; int startingWeek = 20; int startingHeight = 15; Point2D.Double lastPoint = null; for (Point2D.Double p : points) { if (p.x < startingWeek || p.x > 42) continue; if (p.y < startingHeight || p.y > 45) continue; Rectangle r = new Rectangle((int) (xStart + (10.25 * (p.x - startingWeek)) - (width / 2)), (int) (yStart - (10.60 * (p.y - startingHeight)) - (height / 2)), width, height); g.fill(r); if (lastPoint != null) { g.drawLine((int) (xStart + (10.25 * (lastPoint.x - startingWeek))), (int) (yStart - (10.60 * (lastPoint.y - startingHeight))), (int) (xStart + (10.25 * (p.x - startingWeek))), (int) (yStart - (10.60 * (p.y - startingHeight)))); } lastPoint = p; } g.dispose(); response.setContentType("image/png"); OutputStream outputStream = response.getOutputStream(); ImageIO.write(bufferedImage, "png", outputStream); outputStream.close(); return null; }
From source file:org.openmeetings.app.data.record.BatikMethods.java
public void drawThickLine2DPaint(Graphics2D g2d, double x1, double y1, double x2, double y2, int width, Color c, double xObj, double yObj, float alpha) throws Exception { g2d.setPaint(c);/*from w w w .ja va 2 s. c o m*/ int[] rules = new int[8]; //all possible Compositing Rules: rules[0] = AlphaComposite.SRC_OVER; rules[1] = AlphaComposite.DST_OVER; rules[2] = AlphaComposite.CLEAR; rules[3] = AlphaComposite.SRC; rules[4] = AlphaComposite.SRC_IN; rules[5] = AlphaComposite.DST_IN; rules[6] = AlphaComposite.SRC_OUT; rules[7] = AlphaComposite.DST_OUT; g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha)); g2d.setStroke(new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); Line2D line = new Line2D.Double(x1, y1, x2, y2); g2d.draw(line); }
From source file:org.openmeetings.app.data.record.BatikMethods.java
public void drawThickLine2D(Graphics2D g2d, double x1, double y1, double x2, double y2, int width, Color c, double xObj, double yObj, float alpha) throws Exception { g2d.setPaint(c);/* w w w . ja va 2s . c om*/ int[] rules = new int[8]; //all possible Compositing Rules: rules[0] = AlphaComposite.SRC_OVER; rules[1] = AlphaComposite.DST_OVER; rules[2] = AlphaComposite.CLEAR; rules[3] = AlphaComposite.SRC; rules[4] = AlphaComposite.SRC_IN; rules[5] = AlphaComposite.DST_IN; rules[6] = AlphaComposite.SRC_OUT; rules[7] = AlphaComposite.DST_OUT; g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha)); g2d.setStroke(new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); Line2D line = new Line2D.Double(x1 + xObj, y1 + yObj, x2 + xObj, y2 + yObj); g2d.draw(line); }
From source file:org.squidy.designer.model.PipeShape.java
@Override protected void paintShape(PPaintContext paintContext) { super.paintShape(paintContext); Graphics2D g = paintContext.getGraphics(); boolean processing = getPipe().getSource().isProcessing(); boolean hasFailure = getSource().hasFailure(); if (selected) { g.setColor(hasFailure ? COLOR_FAILURE_SELECTED : (processing ? COLOR_PROCESSING_SELECTED : COLOR_NORMAL_SELECTED)); } else {/*w ww .j av a 2s. co m*/ g.setColor(hasFailure ? COLOR_FAILURE : (processing ? COLOR_PROCESSING : COLOR_NORMAL)); } for (int i = 0; i < 3; i++) { g.setStroke(STROKE_SHAPE[i]); g.draw(shape); } }
From source file:net.sf.fspdfs.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 . j a v a2 s .c o m*/ 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: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). */// www . ja va 2 s . 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:ucar.unidata.idv.control.chart.MyTimeSeriesPlot.java
/** * draw//from w w w. j a va 2 s. c om * * @param g2 the graphics * @param dataArea where the data area is * @param index which data set * @param info info * @param crosshairState crosshairState * * @return any drawn */ public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info, CrosshairState crosshairState) { XYDataset dataset = getDataset(index); if (DatasetUtilities.isEmptyOrNull(dataset)) { return false; } ValueAxis rangeAxis = getRangeAxisForDataset(index); ValueAxis domainAxis = getDomainAxisForDataset(index); AxisLocation rangeAxisLocation = getRangeAxisLocation(index); AxisLocation domainAxisLocation = getDomainAxisLocation(index); RectangleEdge rangeEdge = getRangeAxisEdge(); RectangleEdge domainEdge = getDomainAxisEdge(); int seriesCount = dataset.getSeriesCount(); // System.out.println ("********************************"); for (int series = seriesCount - 1; series >= 0; series--) { int itemCount = dataset.getItemCount(series); int[] xs = new int[itemCount]; int[] ys = new int[itemCount]; g2.setStroke(getRendererForDataset(dataset).getSeriesStroke(series)); g2.setPaint(getRendererForDataset(dataset).getSeriesPaint(series)); int pointCnt = 0; for (int item = 0; item < itemCount; item++) { double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (!timeseries.valuesOk(index, x1, y1)) { if (pointCnt > 0) { g2.drawPolyline(xs, ys, pointCnt); pointCnt = 0; } continue; } double transX = domainAxis.valueToJava2D(x1, dataArea, domainEdge); double transY = rangeAxis.valueToJava2D(y1, dataArea, rangeEdge); if (!dataArea.contains(transX, transY)) { continue; } xs[pointCnt] = (int) (transX + 0.5); ys[pointCnt] = (int) (transY + 0.5); pointCnt++; if (pointCnt > 10) { g2.drawPolyline(xs, ys, pointCnt); xs[0] = xs[pointCnt - 1]; ys[0] = ys[pointCnt - 1]; pointCnt = 1; } } if (pointCnt > 1) { g2.drawPolyline(xs, ys, pointCnt); } long t2 = System.currentTimeMillis(); // System.err.println("time:" + (t2 - t1) + "ms #" + itemCount); } return true; }
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;//from w w w .j ava2s .com 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); } }