List of usage examples for java.awt Graphics2D draw
public abstract void draw(Shape s);
From source file:org.springframework.cloud.stream.app.pose.estimation.processor.PoseEstimateOutputMessageBuilder.java
private byte[] drawPoses(byte[] imageBytes, List<Body> bodies) throws IOException { if (bodies != null) { BufferedImage originalImage = ImageIO.read(new ByteArrayInputStream(imageBytes)); Graphics2D g = originalImage.createGraphics(); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Stroke stroke = g.getStroke(); g.setStroke(new BasicStroke(this.poseProperties.getDrawLineWidth())); for (Body body : bodies) { for (Limb limb : body.getLimbs()) { Color limbColor = findLimbColor(body, limb); Part from = limb.getFromPart(); Part to = limb.getToPart(); if (limb.getLimbType() != Model.LimbType.limb17 && limb.getLimbType() != Model.LimbType.limb18) { g.setColor(limbColor); g.draw(new Line2D.Double(from.getNormalizedX(), from.getNormalizedY(), to.getNormalizedX(), to.getNormalizedY())); }//from w ww . j av a 2s . co m g.setStroke(new BasicStroke(1)); drawPartOval(from, this.poseProperties.getDrawPartRadius(), g); drawPartOval(to, this.poseProperties.getDrawPartRadius(), g); g.setStroke(new BasicStroke(this.poseProperties.getDrawLineWidth())); } } g.setStroke(stroke); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(originalImage, IMAGE_FORMAT, baos); baos.flush(); imageBytes = baos.toByteArray(); baos.close(); g.dispose(); } return imageBytes; }
From source file:MyCanvas.java
public void paint(Graphics g) { Graphics2D g2D = (Graphics2D) g; Point2D.Float point = new Point2D.Float(100, 100); // store start point GeneralPath p = new GeneralPath(GeneralPath.WIND_NON_ZERO); p.moveTo(point.x, point.y);/*from w w w . j av a2 s .c om*/ p.lineTo(point.x + 20.0f, point.y - 5.0f); // Line from start to A point = (Point2D.Float) p.getCurrentPoint(); p.lineTo(point.x + 5.0f, point.y - 20.0f); // Line from A to B point = (Point2D.Float) p.getCurrentPoint(); p.lineTo(point.x + 5.0f, point.y + 20.0f); // Line from B to C point = (Point2D.Float) p.getCurrentPoint(); p.lineTo(point.x + 20.0f, point.y + 5.0f); // Line from C to D point = (Point2D.Float) p.getCurrentPoint(); p.lineTo(point.x - 20.0f, point.y + 5.0f); // Line from D to E point = (Point2D.Float) p.getCurrentPoint(); p.lineTo(point.x - 5.0f, point.y + 20.0f); // Line from E to F point = (Point2D.Float) p.getCurrentPoint(); p.lineTo(point.x - 5.0f, point.y - 20.0f); // Line from F to g p.closePath(); // Line from G to start g2D.draw(p); }
From source file:gov.nih.nci.caintegrator.application.graphing.BoxAndWhiskerDotsRenderer.java
/** * Draws two dots to represent the average value of more than one outlier. * /* ww w . j a va2 s.c o m*/ * @param point the location * @param boxWidth the box width. * @param oRadius the radius. * @param g2 the graphics device. */ private void drawMultipleEllipse(Point2D point, double boxWidth, double oRadius, Graphics2D g2) { Ellipse2D dot1 = new Ellipse2D.Double(point.getX() - (boxWidth / 2) + oRadius, point.getY(), oRadius, oRadius); Ellipse2D dot2 = new Ellipse2D.Double(point.getX() + (boxWidth / 2), point.getY(), oRadius, oRadius); g2.draw(dot1); g2.draw(dot2); }
From source file:ScribbleDragAndDrop.java
/** * This method implements the DragGestureListener interface. It will be * invoked when the DragGestureRecognizer thinks that the user has initiated * a drag. If we're not in drawing mode, then this method will try to figure * out which Scribble object is being dragged, and will initiate a drag on * that object./*from w w w. j av a2 s . c o m*/ */ public void dragGestureRecognized(DragGestureEvent e) { // Don't drag if we're not in drag mode if (!dragMode) return; // Figure out where the drag started MouseEvent inputEvent = (MouseEvent) e.getTriggerEvent(); int x = inputEvent.getX(); int y = inputEvent.getY(); // Figure out which scribble was clicked on, if any by creating a // small rectangle around the point and testing for intersection. Rectangle r = new Rectangle(x - LINEWIDTH, y - LINEWIDTH, LINEWIDTH * 2, LINEWIDTH * 2); int numScribbles = scribbles.size(); for (int i = 0; i < numScribbles; i++) { // Loop through the scribbles Scribble s = (Scribble) scribbles.get(i); if (s.intersects(r)) { // The user started the drag on top of this scribble, so // start to drag it. // First, remember which scribble is being dragged, so we can // delete it later (if this is a move rather than a copy) beingDragged = s; // Next, create a copy that will be the one dragged Scribble dragScribble = (Scribble) s.clone(); // Adjust the origin to the point the user clicked on. dragScribble.translate(-x, -y); // Choose a cursor based on the type of drag the user initiated Cursor cursor; switch (e.getDragAction()) { case DnDConstants.ACTION_COPY: cursor = DragSource.DefaultCopyDrop; break; case DnDConstants.ACTION_MOVE: cursor = DragSource.DefaultMoveDrop; break; default: return; // We only support move and copys } // Some systems allow us to drag an image along with the // cursor. If so, create an image of the scribble to drag if (dragSource.isDragImageSupported()) { Rectangle scribbleBox = dragScribble.getBounds(); Image dragImage = this.createImage(scribbleBox.width, scribbleBox.height); Graphics2D g = (Graphics2D) dragImage.getGraphics(); g.setColor(new Color(0, 0, 0, 0)); // transparent background g.fillRect(0, 0, scribbleBox.width, scribbleBox.height); g.setColor(Color.black); g.setStroke(linestyle); g.translate(-scribbleBox.x, -scribbleBox.y); g.draw(dragScribble); Point hotspot = new Point(-scribbleBox.x, -scribbleBox.y); // Now start dragging, using the image. e.startDrag(cursor, dragImage, hotspot, dragScribble, this); } else { // Or start the drag without an image e.startDrag(cursor, dragScribble, this); } // After we've started dragging one scribble, stop looking return; } } }
From source file:org.amanzi.awe.render.network.NetworkRenderer.java
/** * Draw black border around selected sector * // ww w . j av a 2s . c om * @param destination * @param point * @param model * @param sector */ private void renderSelectionBorder(Graphics2D destination, Point point, ISectorElement sector, int index, int count) { Pair<Double, Double> sectorParameters = getSectorParameters(sector, index, count); int size = getSize(); double azimuth = sectorParameters.getLeft(); double beamwidth = sectorParameters.getRight(); GeneralPath path = new GeneralPath(); path.moveTo(getSectorXCoordinate(point, size), getSectorYCoordinate(point, size)); Arc2D a = createSector(point, networkRendererStyle.getLargeElementSize(), getAngle(azimuth, beamwidth), beamwidth); path.append(a.getPathIterator(null), true); path.closePath(); destination .setColor(networkRendererStyle.changeColor(SELECTED_SECTOR_COLOR, networkRendererStyle.getAlpha())); destination.draw(path); destination.drawString(sector.getName(), (int) a.getEndPoint().getX() + 10, (int) a.getEndPoint().getY()); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.ProfilesComparisonReportChartCanvas.java
protected void paintComponent(Graphics g) { // prepare graphic object Graphics2D g2d = (Graphics2D) g.create(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // set clipping area if (is_printing) { g2d.translate(-draw_area.x, -draw_area.y); g2d.setClip(draw_area);/* w w w .j a v a 2 s.c o m*/ } //paint canvas background if (!is_printing) { g2d.setColor(getBackground()); g2d.fillRect(0, 0, getWidth(), getHeight()); } // paint white background on drawing area g2d.setColor(Color.white); g2d.fillRect(draw_area.x, draw_area.y, draw_area.width, draw_area.height); if (!is_printing) { g2d.setColor(Color.black); g2d.draw(draw_area); } // paint paintChart(g2d); // dispose graphic object g2d.dispose(); revalidate(); }
From source file:TextLayoutWithCarets.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); if (mInitialized == false) initialize(g2);// w ww . j a v a 2 s . com float x = 20, y = 80; mLayout.draw(g2, x, y); // Create a plain stroke and a dashed stroke. Stroke[] caretStrokes = new Stroke[2]; caretStrokes[0] = new BasicStroke(); caretStrokes[1] = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 0, new float[] { 4, 4 }, 0); // Now draw the carets Shape[] carets = mLayout.getCaretShapes(mHit.getInsertionIndex()); for (int i = 0; i < carets.length; i++) { if (carets[i] != null) { AffineTransform at = AffineTransform.getTranslateInstance(x, y); Shape shape = at.createTransformedShape(carets[i]); g2.setStroke(caretStrokes[i]); g2.draw(shape); } } }
From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialRange.java
/** * Draws the range./*from w w w .j av a 2s .c o m*/ * * @param g2 the graphics target. * @param plot the plot. * @param frame the dial's reference frame (in Java2D space). * @param view the dial's view rectangle (in Java2D space). */ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame, this.getInnerRadius(), this.getInnerRadius()); Rectangle2D arcRectOuter = DialPlot.rectangleByRadius(frame, this.getOuterRadius(), this.getOuterRadius()); DialScale scale = plot.getScale(this.getScaleIndex()); if (scale == null) { throw new RuntimeException("No scale for scaleIndex = " + this.getScaleIndex()); } double angleMin = scale.valueToAngle(this.getLowerBound()); double angleMax = scale.valueToAngle(this.getUpperBound()); Arc2D arcInner = new Arc2D.Double(arcRectInner, angleMin, angleMax - angleMin, Arc2D.OPEN); Arc2D arcOuter = new Arc2D.Double(arcRectOuter, angleMax, angleMin - angleMax, Arc2D.OPEN); g2.setPaint(this.getPaint()); g2.setStroke(new BasicStroke(this.lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); g2.draw(arcInner); g2.draw(arcOuter); }
From source file:net.sf.jasperreports.chartthemes.spring.ScaledDialRange.java
/** * Draws the range./*from w w w . j a v a 2s . c o m*/ * * @param g2 the graphics target. * @param plot the plot. * @param frame the dial's reference frame (in Java2D space). * @param view the dial's view rectangle (in Java2D space). */ @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame, this.getInnerRadius(), this.getInnerRadius()); Rectangle2D arcRectOuter = DialPlot.rectangleByRadius(frame, this.getOuterRadius(), this.getOuterRadius()); DialScale scale = plot.getScale(this.getScaleIndex()); if (scale == null) { throw new RuntimeException("No scale for scaleIndex = " + this.getScaleIndex()); } double angleMin = scale.valueToAngle(this.getLowerBound()); double angleMax = scale.valueToAngle(this.getUpperBound()); Arc2D arcInner = new Arc2D.Double(arcRectInner, angleMin, angleMax - angleMin, Arc2D.OPEN); Arc2D arcOuter = new Arc2D.Double(arcRectOuter, angleMax, angleMin - angleMax, Arc2D.OPEN); g2.setPaint(this.getPaint()); g2.setStroke(new BasicStroke(this.lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); g2.draw(arcInner); g2.draw(arcOuter); }
From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java
private void drawItemShape(Graphics2D g2, int series, int item, Shape entityShape) { if (getItemShapeFilled(series, item)) { g2.setPaint(getUseFillPaint() ? getItemFillPaint(series, item) : getItemPaint(series, item)); g2.fill(entityShape);//from w ww .j av a2 s. c o m } if (getDrawOutlines()) { g2.setPaint(getUseOutlinePaint() ? getItemOutlinePaint(series, item) : getItemPaint(series, item)); g2.setStroke(getItemOutlineStroke(series, item)); } g2.draw(entityShape); }