List of usage examples for java.awt.geom GeneralPath moveTo
public abstract void moveTo(double x, double y);
From source file:org.jcurl.math.ShaperUtils.java
/** * Interpolate using <a/*w w w . ja v a 2s . c o m*/ * href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve">Linear Bezier * Curves</a>. * <p> * Computes the required intermediate <code>t</code> samples and delegates * to {@link #lineTo(R1RNFunction, double, GeneralPath, float)} to compute * the interpolating curve segments. * </p> * * @param src * the (at least 2-dimensional) curve. Higher dimensions are * ignored. * @param min * the min input <code>t</code> to * {@link R1RNFunction#at(double, int, int)} * @param max * the max input <code>t</code> to * {@link R1RNFunction#at(double, int, int)} * @param curves * the number of line segments - must be >= 1. * @param zoom * graphics zoom factor (typically 1) * @param ip * the {@link Interpolator} to get the intermediate sample * <code>t</code> values. * @see #lineTo(R1RNFunction, double, GeneralPath, float) */ public static Shape interpolateLinear(final R1RNFunction src, final double min, final double max, final int curves, final float zoom, final Interpolator ip) { // setup if (curves < 1) throw new IllegalArgumentException("Give me at least 1 (connect start + stop)"); final float d = (float) (max - min); final GeneralPath gp = new GeneralPath(GeneralPath.WIND_NON_ZERO, curves + 1); // +1 just to be sure... // start final float x = (float) src.at(min, 0, 0); final float y = (float) src.at(min, 0, 1); gp.moveTo(zoom * x, zoom * y); // intermediate final int n = curves; for (int i = 1; i < n; i++) { final double t = min + d * ip.interpolate((float) i / n); lineTo(src, t, gp, zoom); } // stop lineTo(src, max, gp, zoom); return gp; }
From source file:org.jcurl.math.ShaperUtils.java
/** * Interpolate using <a//from w ww . j a va 2 s . c o m * href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve">Quadratic Bezier * Curves</a>. * <p> * Computes the required intermediate <code>t</code> samples and delegates * to {@link #quadTo(R1RNFunction, double, double, GeneralPath, float)} to * compute the interpolating curve segments. * </p> * * @param src * the (2-dimensional) curve. Higher dimensions are ignored. * @param min * the min input <code>t</code> to * {@link R1RNFunction#at(double, int, int)} * @param max * the max input <code>t</code> to * {@link R1RNFunction#at(double, int, int)} * @param curves * the number of line segments - must be >= 1. * @param zoom * graphics zoom factor (typically 1) * @param ip * the {@link Interpolator} to get the intermediate sample * <code>t</code> values. * @see #quadTo(R1RNFunction, double, double, GeneralPath, float) */ public static Shape interpolateQuadratic(final R1RNFunction src, final double min, final double max, final int curves, final float zoom, final Interpolator ip) { // setup if (curves < 1) throw new IllegalArgumentException("Give me at least 1 (connect start + stop)"); final float d = (float) (max - min); final GeneralPath gp = new GeneralPath(GeneralPath.WIND_NON_ZERO, 2 * curves + 1); // +1 just to be sure... // start final float x = (float) src.at(min, 0, 0); final float y = (float) src.at(min, 0, 1); gp.moveTo(zoom * x, zoom * y); double told = min; // intermediate final int n = curves; for (int i = 1; i < n; i++) { final double t = min + d * ip.interpolate((float) i / n); quadTo(src, told, t, gp, zoom); told = t; } // stop quadTo(src, told, max, gp, zoom); return gp; }
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 ww w . j a va 2 s . com 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.squidy.designer.util.ImageUtils.java
public static Shape getShapeOfImage(BufferedImage image) { // Get the data Raster data = image.getData(); ///* w ww . j a v a 2 s .c o m*/ // System.out.println("num of bands = " + data.getNumBands()); // The colour of the pixel looking at // Shoulld have length of 4 (RGBA) int[] lookAt = null; // The map of all the points Point2D[][] pointMap = new Point2D[data.getWidth()][data.getHeight()]; // The from point Point2D from = null; // The general path GeneralPath path = new GeneralPath(); // Go round height for (int y = 0; y < data.getHeight(); y++) { // Go round width for (int x = 0; x < data.getWidth(); x++) { // Get the colour lookAt = data.getPixel(x, y, lookAt); // The alpha int a = lookAt[3]; // If > then 0 if (a > 0) { // Output 1 //System.out.print(1); // Save point pointMap[x][y] = new Point2D.Double(x, y); if (from == null) { from = pointMap[x][y]; } } // 0 else { // Output 0 //System.out.print(0); // Nothing her pointMap[x][y] = null; } } // New line //System.out.println(); } // Move it to the from if (from != null) { path.moveTo(from.getX(), from.getY()); /* * Make the shape */ // Go round height for (int y = 0; y < data.getHeight(); y++) { // Go round width for (int x = 0; x < data.getWidth(); x++) { // If the point is not null if (pointMap[x][y] != null) { // Draw a line to path.append(new Rectangle2D.Double(pointMap[x][y].getX(), pointMap[x][y].getY(), 1, 1), true); // path.lineTo(pointMap[x][y].getX(), pointMap[x][y].getY()); } } } path.closePath(); // TODO: Put in the middle return path; } return null; }
From source file:savant.view.tracks.ContinuousTrackRenderer.java
@Override public void render(Graphics2D g2, GraphPaneAdapter gp) throws RenderingException { renderPreCheck();/*from w w w . ja va2 s . c o m*/ AxisRange axisRange = (AxisRange) instructions.get(DrawingInstruction.AXIS_RANGE); gp.setXRange(axisRange.getXRange()); gp.setYRange(axisRange.getYRange()); if (gp.needsToResize()) return; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME); Color fillcolor = cs.getColor(ColourKey.CONTINUOUS_FILL); Color linecolor = cs.getColor(ColourKey.CONTINUOUS_LINE); GeneralPath path = new GeneralPath(); double xFormXPos = Double.NaN, xFormYPos = Double.NaN; double yPixel0 = gp.transformYPos(0.0); LOG.debug("h=" + gp.getHeight() + ", yMin=" + gp.getYRange().getFrom() + ", unitHeight=" + gp.getUnitHeight() + " \u27A4 yPixel0=" + yPixel0); double maxData = 0; boolean haveOpenPath = false; boolean haveData = false; if (data != null) { for (int i = 0; i < data.size(); i++) { ContinuousRecord continuousRecord = (ContinuousRecord) data.get(i); int xPos = continuousRecord.getPosition(); float yPos = continuousRecord.getValue(); if (Float.isNaN(yPos)) { // Hit a position with no data. May need to close off the current path. if (haveOpenPath) { path.lineTo(xFormXPos, yPixel0); path.closePath(); haveOpenPath = false; } } else { haveData = true; xFormXPos = gp.transformXPos(xPos);//+gp.getUnitWidth()/2; xFormYPos = gp.transformYPos(yPos); if (!haveOpenPath) { // Start our path off with a vertical line. path.moveTo(xFormXPos, yPixel0); haveOpenPath = true; } path.lineTo(xFormXPos, xFormYPos); Rectangle2D rec = new Rectangle2D.Double( xFormXPos - ((xFormXPos - path.getCurrentPoint().getX()) / 2), 0, Math.max(xFormXPos - path.getCurrentPoint().getX(), 1), gp.getHeight()); recordToShapeMap.put(continuousRecord, rec); xFormXPos = gp.transformXPos(xPos + 1); path.lineTo(xFormXPos, xFormYPos); } if (yPos > maxData) { maxData = yPos; } } } if (!haveData) { throw new RenderingException("No data in range", RenderingException.INFO_PRIORITY); } if (haveOpenPath) { // Path needs to be closed. path.lineTo(xFormXPos, yPixel0); path.closePath(); } g2.setColor(fillcolor); g2.fill(path); g2.setColor(linecolor); g2.draw(path); if (axisRange.getYRange().getFrom() < 0) { g2.setColor(Color.darkGray); g2.draw(new Line2D.Double(0.0, yPixel0, gp.getWidth(), yPixel0)); } }