List of usage examples for java.awt.geom AffineTransform createTransformedShape
public Shape createTransformedShape(Shape pSrc)
From source file:edu.uci.ics.jung.visualization.util.VertexShapeFactory.java
/** * Returns a regular <code>Polygon</code> of <code>num_points</code> * points whose bounding /*from w w w . j a va2s. c o m*/ * box's width and height are defined by this instance's size and * aspect ratio functions for this vertex. * @param num_points the number of points of the polygon; must be >= 5. */ public Shape getRegularStar(V v, int num_points) { if (num_points < 5) throw new IllegalArgumentException("Number of sides must be >= 5"); Rectangle2D frame = getRectangle(v); float width = (float) frame.getWidth(); float height = (float) frame.getHeight(); // generate coordinates double theta = (2 * Math.PI) / num_points; double angle = -theta / 2; thePolygon.reset(); thePolygon.moveTo(0, 0); float delta_x = width * (float) Math.cos(angle); float delta_y = width * (float) Math.sin(angle); Point2D prev = thePolygon.getCurrentPoint(); thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y); for (int i = 1; i < num_points; i++) { angle += theta; delta_x = width * (float) Math.cos(angle); delta_y = width * (float) Math.sin(angle); prev = thePolygon.getCurrentPoint(); thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y); angle -= theta * 2; delta_x = width * (float) Math.cos(angle); delta_y = width * (float) Math.sin(angle); prev = thePolygon.getCurrentPoint(); thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y); } thePolygon.closePath(); // scale polygon to be right size, translate to center at (0,0) Rectangle2D r = thePolygon.getBounds2D(); double scale_x = width / r.getWidth(); double scale_y = height / r.getHeight(); float translationX = (float) (r.getMinX() + r.getWidth() / 2); float translationY = (float) (r.getMinY() + r.getHeight() / 2); AffineTransform at = AffineTransform.getScaleInstance(scale_x, scale_y); at.translate(-translationX, -translationY); Shape shape = at.createTransformedShape(thePolygon); return shape; }
From source file:lu.lippmann.cdb.graph.mouse.CadralEditingGraphMousePlugin.java
/** * Function to draw the arrow while drawing * @param down/* w w w . ja va 2 s. co m*/ * @param out */ private void transformArrowShape(Point2D down, Point2D out) { float x1 = (float) down.getX(); float y1 = (float) down.getY(); float x2 = (float) out.getX(); float y2 = (float) out.getY(); AffineTransform xform = AffineTransform.getTranslateInstance(x2, y2); float dx = x2 - x1; float dy = y2 - y1; float thetaRadians = (float) Math.atan2(dy, dx); xform.rotate(thetaRadians); arrowShape = xform.createTransformedShape(rawArrowShape); }
From source file:net.sf.maltcms.chromaui.charts.overlay.Peak1DHeatmapOverlay.java
/** * * @param g2//from w w w.j a va 2 s .c o m * @param chartPanel */ @Override public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) { if (isVisible()) { Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); g2.clip(dataArea); JFreeChart chart = chartPanel.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); RectangleEdge xAxisEdge = plot.getDomainAxisEdge(); ValueAxis yAxis = plot.getRangeAxis(); RectangleEdge yAxisEdge = plot.getRangeAxisEdge(); Color c = g2.getColor(); Color fillColor = peakAnnotations.getColor(); if (fillColor == null || fillColor.equals(Color.WHITE) || fillColor.equals(new Color(255, 255, 255, 0))) { Logger.getLogger(getClass().getName()) .info("Peak annotation color was null or white, using color from treatment group!"); fillColor = peakAnnotations.getChromatogram().getTreatmentGroup().getColor(); } g2.setColor(ChartCustomizer.withAlpha(fillColor, 0.5f)); for (IPeakAnnotationDescriptor descr : peakAnnotations.getMembers()) { double x = descr.getApexTime(); double xx = xAxis.valueToJava2D(x, dataArea, xAxisEdge); double width = xAxis.valueToJava2D(1, dataArea, xAxisEdge); double mzRange = (descr.getMassValues()[descr.getMassValues().length - 1] - descr.getMassValues()[0]); double y = mzRange / 2.0d; double yy = yAxis.valueToJava2D(y, dataArea, yAxisEdge); double height = yAxis.valueToJava2D(mzRange, dataArea, yAxisEdge); AffineTransform at = AffineTransform.getTranslateInstance(xx, yy); at.concatenate(AffineTransform.getTranslateInstance(-x, -y)); Rectangle2D.Double r = new Rectangle2D.Double(xx - (width / 2.0d), yy, width, height); g2.fill(at.createTransformedShape(r)); } g2.setColor(c); g2.setClip(savedClip); } }
From source file:lu.lippmann.cdb.graph.mouse.CadralEditingGraphMousePlugin.java
/** * Function to create the edge shape while drawing * @param down//w ww .j av a2s . c o m * @param out */ private void transformEdgeShape(Point2D down, Point2D out) { float x1 = (float) down.getX(); float y1 = (float) down.getY(); float x2 = (float) out.getX(); float y2 = (float) out.getY(); AffineTransform xform = AffineTransform.getTranslateInstance(x1, y1); float dx = x2 - x1; float dy = y2 - y1; float thetaRadians = (float) Math.atan2(dy, dx); xform.rotate(thetaRadians); float dist = (float) Math.sqrt(dx * dx + dy * dy); xform.scale((double) dist / rawEdge.getBounds().getWidth(), 1.0d); edgeShape = xform.createTransformedShape(rawEdge); }
From source file:Paints.java
/** Draw the example */ public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; // Paint the entire background using a GradientPaint. // The background color varies diagonally from deep red to pale blue g.setPaint(new GradientPaint(0, 0, new Color(150, 0, 0), WIDTH, HEIGHT, new Color(200, 200, 255))); g.fillRect(0, 0, WIDTH, HEIGHT); // fill the background // Use a different GradientPaint to draw a box. // This one alternates between deep opaque green and transparent green. // Note: the 4th arg to Color() constructor specifies color opacity g.setPaint(new GradientPaint(0, 0, new Color(0, 150, 0), 20, 20, new Color(0, 150, 0, 0), true)); g.setStroke(new BasicStroke(15)); // use wide lines g.drawRect(25, 25, WIDTH - 50, HEIGHT - 50); // draw the box // The glyphs of fonts can be used as Shape objects, which enables // us to use Java2D techniques with letters Just as we would with // any other shape. Here we get some letter shapes to draw. Font font = new Font("Serif", Font.BOLD, 10); // a basic font Font bigfont = // a scaled up version font.deriveFont(AffineTransform.getScaleInstance(30.0, 30.0)); GlyphVector gv = bigfont.createGlyphVector(g.getFontRenderContext(), "JAV"); Shape jshape = gv.getGlyphOutline(0); // Shape of letter J Shape ashape = gv.getGlyphOutline(1); // Shape of letter A Shape vshape = gv.getGlyphOutline(2); // Shape of letter V // We're going to outline the letters with a 5-pixel wide line g.setStroke(new BasicStroke(5.0f)); // We're going to fake shadows for the letters using the // following Paint and AffineTransform objects Paint shadowPaint = new Color(0, 0, 0, 100); // Translucent black AffineTransform shadowTransform = AffineTransform.getShearInstance(-1.0, 0.0); // Shear to the right shadowTransform.scale(1.0, 0.5); // Scale height by 1/2 // Move to the baseline of our first letter g.translate(65, 270);/*from w w w .j a v a2s . c om*/ // Draw the shadow of the J shape g.setPaint(shadowPaint); g.translate(15, 20); // Compensate for the descender of the J // transform the J into the shape of its shadow, and fill it g.fill(shadowTransform.createTransformedShape(jshape)); g.translate(-15, -20); // Undo the translation above // Now fill the J shape with a solid (and opaque) color g.setPaint(Color.blue); // Fill with solid, opaque blue g.fill(jshape); // Fill the shape g.setPaint(Color.black); // Switch to solid black g.draw(jshape); // And draw the outline of the J // Now draw the A shadow g.translate(75, 0); // Move to the right g.setPaint(shadowPaint); // Set shadow color g.fill(shadowTransform.createTransformedShape(ashape)); // draw shadow // Draw the A shape using a solid transparent color g.setPaint(new Color(0, 255, 0, 125)); // Transparent green as paint g.fill(ashape); // Fill the shape g.setPaint(Color.black); // Switch to solid back g.draw(ashape); // Draw the outline // Move to the right and draw the shadow of the letter V g.translate(175, 0); g.setPaint(shadowPaint); g.fill(shadowTransform.createTransformedShape(vshape)); // We're going to fill the next letter using a TexturePaint, which // repeatedly tiles an image. The first step is to obtain the image. // We could load it from an image file, but here we create it // ourselves by drawing a into an off-screen image. Note that we use // a GradientPaint to fill the off-screen image, so the fill pattern // combines features of both Paint classes. BufferedImage tile = // Create an image new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB); Graphics2D tg = tile.createGraphics(); // Get its Graphics for drawing tg.setColor(Color.pink); tg.fillRect(0, 0, 50, 50); // Fill tile background with pink tg.setPaint(new GradientPaint(40, 0, Color.green, // diagonal gradient 0, 40, Color.gray)); // green to gray tg.fillOval(5, 5, 40, 40); // Draw a circle with this gradient // Use this new tile to create a TexturePaint and fill the letter V g.setPaint(new TexturePaint(tile, new Rectangle(0, 0, 50, 50))); g.fill(vshape); // Fill letter shape g.setPaint(Color.black); // Switch to solid black g.draw(vshape); // Draw outline of letter // Move to the right and draw the shadow of the final A g.translate(160, 0); g.setPaint(shadowPaint); g.fill(shadowTransform.createTransformedShape(ashape)); g.fill(ashape); // Fill letter A g.setPaint(Color.black); // Revert to solid black g.draw(ashape); // Draw the outline of the A }
From source file:net.sf.maltcms.chromaui.annotations.XYSelectableShapeAnnotation.java
/** * * @param arg0/*from w w w . j a va 2 s .c om*/ * @param arg1 * @param arg2 * @param arg3 * @param arg4 * @param arg5 * @param arg6 */ @Override public void draw(Graphics2D arg0, XYPlot arg1, Rectangle2D arg2, ValueAxis arg3, ValueAxis arg4, int arg5, PlotRenderingInfo arg6) { //System.out.println("Annotation "+toString()+" is active: "+isActive()); PlotOrientation orientation = arg1.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(arg1.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(arg1.getRangeAxisLocation(), orientation); // compute transform matrix elements via sample points. Assume no // rotation or shear. Rectangle2D bounds = this.s.getBounds2D(); double x0 = bounds.getMinX(); double x1 = bounds.getMaxX(); double xx0 = arg3.valueToJava2D(x0, arg2, domainEdge); double xx1 = arg3.valueToJava2D(x1, arg2, domainEdge); double m00 = (xx1 - xx0) / (x1 - x0); double m02 = xx0 - x0 * m00; double y0 = bounds.getMaxY(); double y1 = bounds.getMinY(); double yy0 = arg4.valueToJava2D(y0, arg2, rangeEdge); double yy1 = arg4.valueToJava2D(y1, arg2, rangeEdge); double m11 = (yy1 - yy0) / (y1 - y0); double m12 = yy0 - m11 * y0; // create transform & transform shape Shape s = null, ch = null; if (orientation == PlotOrientation.HORIZONTAL) { AffineTransform t1 = new AffineTransform(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f); AffineTransform t2 = new AffineTransform(m11, 0.0f, 0.0f, m00, m12, m02); s = t1.createTransformedShape(this.s); s = t2.createTransformedShape(s); // ch = t1.createTransformedShape(this.ch); // ch = t2.createTransformedShape(ch); } else if (orientation == PlotOrientation.VERTICAL) { AffineTransform t = new AffineTransform(m00, 0, 0, m11, m02, m12); s = t.createTransformedShape(this.s); // ch = t.createTransformedShape(this.ch); } if (this.active) { arg0.setPaint(this.highlight); // double x = s.getBounds2D().getX(); // double y = s.getBounds2D().getY(); // double w = s.getBounds2D().getWidth(); // double h = s.getBounds2D().getHeight(); // Shape e = new Ellipse2D.Double(x, y, w, h); arg0.fill(s); arg0.setPaint(this.outline); arg0.draw(s); // arg0.setStroke(this.stroke); // arg0.draw(ch); } else { arg0.setPaint(this.fill); arg0.fill(s); arg0.setPaint(this.outline); arg0.draw(s); } addEntity(arg6, s, arg5, getToolTipText(), getURL()); this.xyta.draw(arg0, arg1, arg2, arg3, arg4, arg5, arg6); }
From source file:graph.eventhandlers.MyEditingGraphMousePlugin.java
private void transformArrowShape(Point2D down, Point2D out) { float x1 = (float) down.getX(); float y1 = (float) down.getY(); float x2 = (float) out.getX(); float y2 = (float) out.getY(); AffineTransform xform = AffineTransform.getTranslateInstance(x2, y2); float dx = x2 - x1; float dy = y2 - y1; float thetaRadians = (float) Math.atan2(dy, dx); xform.rotate(thetaRadians);// www .j av a2 s .c o m arrowShape = xform.createTransformedShape(rawArrowShape); }
From source file:business.ImageManager.java
public ImageIcon getArrow(double angle) { BufferedImage img = new BufferedImage(40, 40, BufferedImage.TRANSLUCENT); Graphics2D big = img.createGraphics(); //setup para os rastros big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); big.setStroke(/* w w w . jav a 2 s . c o m*/ new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] { 5f }, 0f)); big.setColor(Color.red); int cx = this.getYellowBall().getIconWidth() / 2; int cy = this.getYellowBall().getIconHeight() / 2; AffineTransform at = AffineTransform.getTranslateInstance(cx, cy); at.rotate(Math.toRadians(angle)); // at.scale(2.0, 2.0); Shape shape = at.createTransformedShape(createArrow()); big.setPaint(Color.red); big.draw(shape); ImageIcon ret = new ImageIcon(img); return (ret); // tenta com o icone...angle. }
From source file:graph.eventhandlers.MyEditingGraphMousePlugin.java
/** * code lifted from PluggableRenderer to move an edge shape into an * arbitrary position//from w ww .j av a 2 s . co m */ private void transformEdgeShape(Point2D down, Point2D out) { float x1 = (float) down.getX(); float y1 = (float) down.getY(); float x2 = (float) out.getX(); float y2 = (float) out.getY(); AffineTransform xform = AffineTransform.getTranslateInstance(x1, y1); float dx = x2 - x1; float dy = y2 - y1; float thetaRadians = (float) Math.atan2(dy, dx); xform.rotate(thetaRadians); float dist = (float) Math.sqrt(dx * dx + dy * dy); xform.scale(dist / rawEdge.getBounds().getWidth(), 1.0); edgeShape = xform.createTransformedShape(rawEdge); }
From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java
/** * Get the label shape for the given tree node * @param treeNode//w ww. j a v a 2s.c om * the tree node * @param frc * the font rendering context * @return * the label shape */ private Shape getLabelShape(VisualTreeNode treeNode, FontRenderContext frc) { // convert the strain list to a comma separated list then wrap it List<String> strainList = treeNode.getPhylogenyTreeNode().getStrains(); int strainCount = strainList.size(); StringBuffer commaSeparatedStrains = new StringBuffer(); for (int i = 0; i < strainCount; i++) { if (i >= 1) { commaSeparatedStrains.append(", "); } commaSeparatedStrains.append(strainList.get(i)); } String[] wrappedStrains = TextWrapper.wrapText(commaSeparatedStrains.toString(), NODE_LABEL_WRAP_LIMIT); Shape textShape = Java2DUtils.createCenteredMultilineTextShape(wrappedStrains, LABEL_FONT, frc); AffineTransform transform = new AffineTransform(); transform.translate(treeNode.getPosition().getX(), treeNode.getPosition().getY()); textShape = transform.createTransformedShape(textShape); return textShape; }