List of usage examples for java.awt Graphics2D getStroke
public abstract Stroke getStroke();
From source file:org.photovault.swingui.PhotoCollectionThumbView.java
private void paintThumbnail(Graphics2D g2, PhotoInfo photo, int startx, int starty, boolean isSelected) { log.debug("paintThumbnail entry " + photo.getUuid()); long startTime = System.currentTimeMillis(); long thumbReadyTime = 0; long thumbDrawnTime = 0; long endTime = 0; // Current position in which attributes can be drawn int ypos = starty + rowHeight / 2; boolean useOldThumbnail = false; Thumbnail thumbnail = null;/*from w w w . java 2 s . c o m*/ log.debug("finding thumb"); boolean hasThumbnail = photo.hasThumbnail(); log.debug("asked if has thumb"); if (hasThumbnail) { log.debug("Photo " + photo.getUuid() + " has thumbnail"); thumbnail = photo.getThumbnail(); log.debug("got thumbnail"); } else { /* Check if the thumbnail has been just invalidated. If so, use the old one until we get the new thumbnail created. */ thumbnail = photo.getOldThumbnail(); if (thumbnail != null) { useOldThumbnail = true; } else { // No success, use default thumnail. thumbnail = Thumbnail.getDefaultThumbnail(); } // Inform background task scheduler that we have some work to do ctrl.getBackgroundTaskScheduler().registerTaskProducer(this, TaskPriority.CREATE_VISIBLE_THUMBNAIL); } thumbReadyTime = System.currentTimeMillis(); log.debug("starting to draw"); // Find the position for the thumbnail BufferedImage img = thumbnail.getImage(); if (img == null) { thumbnail = Thumbnail.getDefaultThumbnail(); img = thumbnail.getImage(); } float scaleX = ((float) thumbWidth) / ((float) img.getWidth()); float scaleY = ((float) thumbHeight) / ((float) img.getHeight()); float scale = Math.min(scaleX, scaleY); int w = (int) (img.getWidth() * scale); int h = (int) (img.getHeight() * scale); int x = startx + (columnWidth - w) / (int) 2; int y = starty + (rowHeight - h) / (int) 2; log.debug("drawing thumbnail"); // Draw shadow int offset = isSelected ? 2 : 0; int shadowX[] = { x + 3 - offset, x + w + 1 + offset, x + w + 1 + offset }; int shadowY[] = { y + h + 1 + offset, y + h + 1 + offset, y + 3 - offset }; GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, shadowX.length); polyline.moveTo(shadowX[0], shadowY[0]); for (int index = 1; index < shadowX.length; index++) { polyline.lineTo(shadowX[index], shadowY[index]); } ; BasicStroke shadowStroke = new BasicStroke(4.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); Stroke oldStroke = g2.getStroke(); g2.setStroke(shadowStroke); g2.setColor(Color.DARK_GRAY); g2.draw(polyline); g2.setStroke(oldStroke); // Paint thumbnail g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.drawImage(img, new AffineTransform(scale, 0f, 0f, scale, x, y), null); if (useOldThumbnail) { creatingThumbIcon.paintIcon(this, g2, startx + (columnWidth - creatingThumbIcon.getIconWidth()) / (int) 2, starty + (rowHeight - creatingThumbIcon.getIconHeight()) / (int) 2); } log.debug("Drawn, drawing decorations"); if (isSelected) { Stroke prevStroke = g2.getStroke(); Color prevColor = g2.getColor(); g2.setStroke(new BasicStroke(3.0f)); g2.setColor(Color.BLUE); g2.drawRect(x, y, w, h); g2.setColor(prevColor); g2.setStroke(prevStroke); } thumbDrawnTime = System.currentTimeMillis(); boolean drawAttrs = (thumbWidth >= 100); if (drawAttrs) { // Increase ypos so that attributes are drawn under the image ypos += ((int) h) / 2 + 3; // Draw the attributes // Draw the qualoity icon to the upper left corner of the thumbnail int quality = photo.getQuality(); if (showQuality && quality != 0) { int qx = startx + (columnWidth - quality * starIcon.getIconWidth()) / (int) 2; for (int n = 0; n < quality; n++) { starIcon.paintIcon(this, g2, qx, ypos); qx += starIcon.getIconWidth(); } ypos += starIcon.getIconHeight(); } ypos += 6; if (photo.getRawSettings() != null) { // Draw the "RAW" icon int rx = startx + (columnWidth + w - rawIcon.getIconWidth()) / (int) 2 - 5; int ry = starty + (columnWidth - h - rawIcon.getIconHeight()) / (int) 2 + 5; rawIcon.paintIcon(this, g2, rx, ry); } if (photo.getHistory().getHeads().size() > 1) { // Draw the "unresolved conflicts" icon int rx = startx + (columnWidth + w - 10) / (int) 2 - 20; int ry = starty + (columnWidth - h - 10) / (int) 2; g2.setColor(Color.RED); g2.fillRect(rx, ry, 10, 10); } Color prevBkg = g2.getBackground(); if (isSelected) { g2.setBackground(Color.BLUE); } else { g2.setBackground(this.getBackground()); } Font attrFont = new Font("Arial", Font.PLAIN, 10); FontRenderContext frc = g2.getFontRenderContext(); if (showDate && photo.getShootTime() != null) { FuzzyDate fd = new FuzzyDate(photo.getShootTime(), photo.getTimeAccuracy()); String dateStr = fd.format(); TextLayout txt = new TextLayout(dateStr, attrFont, frc); // Calculate the position for the text Rectangle2D bounds = txt.getBounds(); int xpos = startx + ((int) (columnWidth - bounds.getWidth())) / 2 - (int) bounds.getMinX(); g2.clearRect(xpos - 2, ypos - 2, (int) bounds.getWidth() + 4, (int) bounds.getHeight() + 4); txt.draw(g2, xpos, (int) (ypos + bounds.getHeight())); ypos += bounds.getHeight() + 4; } String shootPlace = photo.getShootingPlace(); if (showPlace && shootPlace != null && shootPlace.length() > 0) { TextLayout txt = new TextLayout(photo.getShootingPlace(), attrFont, frc); // Calculate the position for the text Rectangle2D bounds = txt.getBounds(); int xpos = startx + ((int) (columnWidth - bounds.getWidth())) / 2 - (int) bounds.getMinX(); g2.clearRect(xpos - 2, ypos - 2, (int) bounds.getWidth() + 4, (int) bounds.getHeight() + 4); txt.draw(g2, xpos, (int) (ypos + bounds.getHeight())); ypos += bounds.getHeight() + 4; } g2.setBackground(prevBkg); } endTime = System.currentTimeMillis(); log.debug("paintThumbnail: exit " + photo.getUuid()); log.debug("Thumb fetch " + (thumbReadyTime - startTime) + " ms"); log.debug("Thumb draw " + (thumbDrawnTime - thumbReadyTime) + " ms"); log.debug("Deacoration draw " + (endTime - thumbDrawnTime) + " ms"); log.debug("Total " + (endTime - startTime) + " ms"); }
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 w w . jav a2s . 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:org.squidy.designer.zoom.impl.PortShape.java
/** * @param paintContext/*from ww w .j ava2s . c om*/ */ @Override protected void paintShape(PPaintContext paintContext) { super.paintShape(paintContext); Graphics2D g = paintContext.getGraphics(); PBounds bounds = getBoundsReference(); int x = (int) bounds.getX(); int y = (int) bounds.getY(); int width = (int) bounds.getWidth(); int height = (int) bounds.getHeight(); g.setColor(innerColor); g.fillOval(x, y, width, width); Stroke defaultStroke = g.getStroke(); g.setStroke(STROKE_PORT); g.setColor(Color.BLACK); g.drawOval(x, y, width, width); g.drawLine(x + 20, height - 20, x + width - 20, height - 20); g.drawLine(x + width - 50, height - 40, x + width - 20, height - 20); g.drawLine(x + width - 50, height + 0, x + width - 20, height - 20); g.setStroke(defaultStroke); // ////////////////// if (isCreatingEdge) { Graphics2D g2d = paintContext.getGraphics(); g2d.setColor(Color.GRAY); // // Paint label. // if (showLabel) { // paintLabel(paintContext); // Paint edge if is creating edge. if (isCreatingEdge) { paintCreatingEdge(paintContext); } } }
From source file:org.squidy.designer.zoom.impl.PortShape.java
/** * @param paintContext//from w w w .j a v a2 s .c o m */ private void paintCreatingEdge(PPaintContext paintContext) { // Get graphics to paint creating edge. Graphics2D g2d = paintContext.getGraphics(); Stroke defaultStroke = g2d.getStroke(); g2d.setColor(Color.GRAY); g2d.setStroke(STROKE_CREATING_EDGE); pointStart.setLocation(startX, startY); pointCurrent.setLocation(currentX, currentY); globalToLocal(pointStart); globalToLocal(pointCurrent); double x1 = pointStart.getX(); double y1 = pointStart.getY(); double x2 = pointCurrent.getX(); double y2 = pointCurrent.getY(); /* double width = Math.abs(x1 - x2); double height = Math.abs(y1 - y2); int division = 2; double middleLeftX = x1 + (width / division); double middleLeftY = y1 + (height / division); double middleRightX = x2 - (width / division); double middleRightY = y2 - (height / division); curve.setCurve(x1, y1, middleLeftX, middleLeftY, middleRightX, middleRightY, x2, y2); */ // double width = Math.abs(x1 - x2); // curve.setCurve(x1, y1, x1 + (width / 2), y1, x2 - (width / 2), y2, x2, y2); // g2d.draw(curve); g2d.drawLine((int) x1, (int) y1, (int) x2, (int) y2); g2d.setStroke(defaultStroke); }
From source file:savant.view.tracks.BAMTrackRenderer.java
/** * Connect intervals i1 and i2 with a dashed line to show mates. *//*from w w w . j a v a 2 s . c o m*/ private void connectPiledInterval(Graphics2D g2, GraphPaneAdapter gp, Interval i1, Interval i2, int level, Color linecolor, IntervalRecord ir1, IntervalRecord ir2) { Interval mateInterval = computeMateInterval(i1, i2); Stroke currentStroke = g2.getStroke(); //Stroke drawingStroke = new BasicStroke(3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{9}, 0); Stroke drawingStroke = new BasicStroke(1); double yPos = gp.transformYPos(0) - (level + 1) * gp.getUnitHeight() + gp.getUnitHeight() / 2.0 - gp.getOffset(); Line2D line = new Line2D.Double(gp.transformXPos(mateInterval.getStart()) + arrowWidth, yPos, gp.transformXPos(mateInterval.getEnd()) - arrowWidth, yPos); g2.setStroke(drawingStroke); g2.setColor(linecolor); g2.draw(line); g2.setStroke(currentStroke);//reset stroke Rectangle2D bound = new Rectangle2D.Double( Math.min(gp.transformXPos(mateInterval.getStart()), gp.transformXPos(mateInterval.getEnd())), yPos - gp.getUnitHeight() / 2.0, Math.abs(gp.transformXPos(mateInterval.getEnd()) - gp.transformXPos(mateInterval.getStart())), gp.getUnitHeight()); if (ir1 != null) { artifactMap.put(ir1, bound); } if (ir2 != null) { artifactMap.put(ir2, bound); } }
From source file:VASSAL.build.module.map.MapShader.java
public void draw(Graphics g, Map map) { if (shadingVisible) { double zoom = map.getZoom(); buildStroke(zoom);/*from ww w. j av a 2 s . co m*/ final Graphics2D g2 = (Graphics2D) g; final Composite oldComposite = g2.getComposite(); final Color oldColor = g2.getColor(); final Paint oldPaint = g2.getPaint(); final Stroke oldStroke = g2.getStroke(); g2.setComposite(getComposite()); g2.setColor(getColor()); g2.setPaint(scaleImage && pattern.equals(TYPE_IMAGE) && imageName != null ? getTexture(zoom) : getTexture()); Area area = getShadeShape(map); if (zoom != 1.0) { area = new Area(AffineTransform.getScaleInstance(zoom, zoom).createTransformedShape(area)); } g2.fill(area); if (border) { g2.setComposite(getBorderComposite()); g2.setStroke(getStroke(map.getZoom())); g2.setColor(getBorderColor()); g2.draw(area); } g2.setComposite(oldComposite); g2.setColor(oldColor); g2.setPaint(oldPaint); g2.setStroke(oldStroke); } }