List of usage examples for java.awt.geom GeneralPath GeneralPath
public GeneralPath(int rule, int initialCapacity)
From source file:org.jcurl.math.helpers.CurveShape.java
public static Shape approximateQuadratic(final CurveGhost c, final double[] sections) throws FunctionEvaluationException { final double[] p0 = { c.getC(0, 0, sections[0]), c.getC(1, 0, sections[0]) }; final double[] v0 = { c.getC(0, 1, sections[0]), c.getC(1, 1, sections[0]) }; final double[] p1 = { 0, 0 }; final double[] v1 = { 0, 0 }; final GeneralPath gp = new GeneralPath(GeneralPath.WIND_NON_ZERO, sections.length + 1); gp.moveTo((float) p0[0], (float) p0[1]); final double tmp_a[][] = { { 0, 0 }, { 0, 0 } }; final double tmp_b[] = { 0, 0 }; final double pc[] = { 0, 0 }; for (int i = 1; i < sections.length; i++) { p1[0] = c.getC(0, 0, sections[i]); p1[1] = c.getC(1, 0, sections[i]); v1[0] = c.getC(0, 1, sections[i]); v1[1] = c.getC(1, 1, sections[i]); computeControlPoint(p0, v0, p1, v1, tmp_a, tmp_b, pc); gp.quadTo((float) pc[0], (float) pc[1], (float) p1[0], (float) p1[1]); p0[0] = p1[0];//w ww. j a v a 2 s . co m p0[1] = p1[1]; v0[0] = v1[0]; v0[1] = v1[1]; } return gp; }
From source file:org.jcurl.math.ShaperUtils.java
/** * Interpolate using <a/* w w w .j a va 2 s . co m*/ * href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve">Cubic Bezier Curves</a>. * <p> * Computes the required intermediate <code>t</code> samples and delegates * to {@link #curveTo(R1RNFunction, double, 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 interpolating cubic bezier curves - must be * >= 1. * @param zoom * graphics zoom factor (typically 1) * @param ip * the {@link Interpolator} to get the intermediate * <code>t</code> sample values. * @see #curveTo(R1RNFunction, double, double, GeneralPath, float) */ public static Shape interpolateCubic(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, 3 * 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); curveTo(src, told, t, gp, zoom); told = t; } // stop curveTo(src, told, max, gp, zoom); return gp; }
From source file:org.jcurl.math.ShaperUtils.java
/** * Interpolate using <a/*from w ww . j av 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 w w . j ava 2 s. c om * 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 w ww . j av a 2 s . c om*/ 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"); }