List of usage examples for java.awt.geom AffineTransform getTranslateInstance
public static AffineTransform getTranslateInstance(double tx, double ty)
From source file:PrintTest.java
/** * This method draws the page both on the screen and the printer graphics context. * @param g2 the graphics context/*from w ww. ja v a2 s .com*/ */ public void drawPage(Graphics2D g2) { FontRenderContext context = g2.getFontRenderContext(); Font f = new Font("Serif", Font.PLAIN, 72); GeneralPath clipShape = new GeneralPath(); TextLayout layout = new TextLayout("Hello", f, context); AffineTransform transform = AffineTransform.getTranslateInstance(0, 72); Shape outline = layout.getOutline(transform); clipShape.append(outline, false); layout = new TextLayout("World", f, context); transform = AffineTransform.getTranslateInstance(0, 144); outline = layout.getOutline(transform); clipShape.append(outline, false); g2.draw(clipShape); g2.clip(clipShape); final int NLINES = 50; Point2D p = new Point2D.Double(0, 0); for (int i = 0; i < NLINES; i++) { double x = (2 * getWidth() * i) / NLINES; double y = (2 * getHeight() * (NLINES - 1 - i)) / NLINES; Point2D q = new Point2D.Double(x, y); g2.draw(new Line2D.Double(p, q)); } }
From source file:com.t3.model.LightSource.java
private Area getArea(Token token, Zone zone, Direction position, Area area) { Grid grid = zone.getGrid();/*from w w w . j av a2 s. co m*/ Rectangle footprintBounds = token.getFootprint(grid).getBounds(grid, grid.convert(new ZonePoint(token.getX(), token.getY()))); int tx = 0; int ty = 0; switch (position) { case NW: tx -= footprintBounds.width / 2; ty -= footprintBounds.height / 2; break; case N: ty -= footprintBounds.height / 2; break; case NE: tx += footprintBounds.width / 2; ty -= footprintBounds.height / 2; break; case W: tx -= footprintBounds.width / 2; break; case CENTER: break; case E: tx += footprintBounds.width / 2; break; case SW: tx -= footprintBounds.width / 2; ty += footprintBounds.height / 2; break; case S: ty += footprintBounds.height / 2; break; case SE: tx += footprintBounds.width / 2; ty += footprintBounds.height / 2; break; } area.transform(AffineTransform.getTranslateInstance(tx, ty)); return area; }
From source file:net.sf.maltcms.chromaui.charts.overlay.Peak1DHeatmapOverlay.java
/** * * @param g2/*from ww w. jav a 2 s .co 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:com.t_oster.visicut.misc.Helper.java
/** * Compute the rotation angle of an affine transformation. * Counter-clockwise rotation is considered positive. * * method taken from http://javagraphics.blogspot.com/ * * @return rotation angle in radians (beween -pi and pi), * or NaN if the transformation is bogus. *//*from w w w . j a va 2 s. c o m*/ public static double getRotationAngle(AffineTransform transform) { transform = (AffineTransform) transform.clone(); // Eliminate any post-translation transform.preConcatenate( AffineTransform.getTranslateInstance(-transform.getTranslateX(), -transform.getTranslateY())); Point2D p1 = new Point2D.Double(1, 0); p1 = transform.transform(p1, p1); return Math.atan2(p1.getY(), p1.getX()); }
From source file:edu.uci.ics.jung.algorithms.layout.AggregateLayout.java
/** * @param v/*from w w w. j a v a 2 s. c o m*/ * @param location * @see edu.uci.ics.jung.algorithms.layout.Layout#setLocation(java.lang.Object, java.awt.geom.Point2D) */ public void setLocation(V v, Point2D location) { boolean wasInSublayout = false; for (Layout<V, E> layout : layouts.keySet()) { if (layout.getGraph().getVertices().contains(v)) { Point2D center = layouts.get(layout); // transform by the layout itself, but offset to the // center of the sublayout Dimension d = layout.getSize(); AffineTransform at = AffineTransform.getTranslateInstance(-center.getX() + d.width / 2, -center.getY() + d.height / 2); Point2D localLocation = at.transform(location, null); layout.setLocation(v, localLocation); wasInSublayout = true; } } if (wasInSublayout == false && getGraph().getVertices().contains(v)) { delegate.setLocation(v, location); } }
From source file:de.bund.bfr.jung.JungUtils.java
static <V, E> Shape getTransformedEdgeShape(RenderContext<V, E> rc, Layout<V, E> layout, E e) { Graph<V, E> graph = layout.getGraph(); edu.uci.ics.jung.graph.util.Pair<V> endpoints = graph.getEndpoints(e); V v1 = endpoints.getFirst();//from w w w .ja v a 2s. c o m V v2 = endpoints.getSecond(); if (!rc.getEdgeIncludePredicate().evaluate(Context.<Graph<V, E>, E>getInstance(graph, e)) || !rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V>getInstance(graph, v1)) || !rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V>getInstance(graph, v2))) { return null; } Point2D p1 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v1)); Point2D p2 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v2)); float x1 = (float) p1.getX(); float y1 = (float) p1.getY(); float x2 = (float) p2.getX(); float y2 = (float) p2.getY(); Shape edgeShape = rc.getEdgeShapeTransformer().transform(Context.getInstance(graph, e)); AffineTransform edgeShapeTransform = AffineTransform.getTranslateInstance(x1, y1); if (v1.equals(v2)) { Rectangle2D bounds = rc.getVertexShapeTransformer().transform(v1).getBounds2D(); edgeShapeTransform.scale(bounds.getWidth(), bounds.getHeight()); edgeShapeTransform.translate(0, -edgeShape.getBounds2D().getWidth() / 2); } else { float dx = x2 - x1; float dy = y2 - y1; edgeShapeTransform.rotate(Math.atan2(dy, dx)); edgeShapeTransform.scale(Math.sqrt(dx * dx + dy * dy), 1.0); } return edgeShapeTransform.createTransformedShape(edgeShape); }
From source file:es.ucm.fdi.edd.ui.views.utils.SWTImageCanvas.java
private void scrollHorizontally(ScrollBar scrollBar) { if (sourceImage == null) return;/*ww w . j ava 2s .c o m*/ AffineTransform af = transform; double tx = af.getTranslateX(); double select = -scrollBar.getSelection(); af.preConcatenate(AffineTransform.getTranslateInstance(select - tx, 0)); transform = af; syncScrollBars(); }
From source file:ImageBouncer.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; setTransform(g2);/* w w w . j av a2s . co m*/ setBilinear(g2); // Draw the image. g2.drawImage(image, AffineTransform.getTranslateInstance(mX, mY), null); }
From source file:es.ucm.fdi.edd.ui.views.utils.SWTImageCanvas.java
private void scrollVertically(ScrollBar scrollBar) { if (sourceImage == null) return;/*ww w. java 2 s . c om*/ AffineTransform af = transform; double ty = af.getTranslateY(); double select = -scrollBar.getSelection(); af.preConcatenate(AffineTransform.getTranslateInstance(0, select - ty)); transform = af; syncScrollBars(); }
From source file:BookTest.java
public void drawPage(Graphics2D g2, PageFormat pf, int page) { if (message.equals("")) return;/*w ww . ja v a2s . c o m*/ page--; // account for cover page drawCropMarks(g2, pf); g2.clip(new Rectangle2D.Double(0, 0, pf.getImageableWidth(), pf.getImageableHeight())); g2.translate(-page * pf.getImageableWidth(), 0); g2.scale(scale, scale); FontRenderContext context = g2.getFontRenderContext(); Font f = new Font("Serif", Font.PLAIN, 72); TextLayout layout = new TextLayout(message, f, context); AffineTransform transform = AffineTransform.getTranslateInstance(0, layout.getAscent()); Shape outline = layout.getOutline(transform); g2.draw(outline); }