List of usage examples for java.awt.geom AffineTransform concatenate
@SuppressWarnings("fallthrough") public void concatenate(AffineTransform Tx)
From source file:Main.java
static void drawArrow(Graphics g1, int x1, int y1, int x2, int y2) { // x1 and y1 are coordinates of circle or rectangle // x2 and y2 are coordinates of circle or rectangle, to this point is directed the arrow Graphics2D g = (Graphics2D) g1.create(); double dx = x2 - x1; double dy = y2 - y1; double angle = Math.atan2(dy, dx); int len = (int) Math.sqrt(dx * dx + dy * dy); AffineTransform t = AffineTransform.getTranslateInstance(x1, y1); t.concatenate(AffineTransform.getRotateInstance(angle)); g.transform(t);//from w ww. j av a 2 s . co m g.drawLine(0, 0, len, 0); int basePosition = len - ARROW_HEAD_SIZE.width; int height = ARROW_HEAD_SIZE.height; g.fillPolygon(new int[] { len, basePosition, basePosition, len }, new int[] { 0, -height, height, 0 }, 4); }
From source file:Main.java
public static BufferedImage getFlippedImage(BufferedImage bi) { BufferedImage flipped = new BufferedImage(bi.getWidth(), bi.getHeight(), bi.getType()); AffineTransform tran = AffineTransform.getTranslateInstance(0, bi.getHeight()); AffineTransform flip = AffineTransform.getScaleInstance(1d, -1d); tran.concatenate(flip); Graphics2D g = flipped.createGraphics(); g.setTransform(tran);//from w ww.j a v a2s . com g.drawImage(bi, 0, 0, null); g.dispose(); return flipped; }
From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java
/** * * @param s//ww w .j a v a 2s . c om * @param baseX * @param baseY * @param scalex * @param scaley * @return */ public static AffineTransform scaleAtOrigin(Shape s, double baseX, double baseY, float scalex, float scaley) { Point2D center = new Point2D.Double(baseX, baseY); //Affine transforms are applied from right to left AffineTransform at = getTranslateInstance(center.getX(), center.getY()); at.concatenate(getScaleInstance(scalex, scaley)); return at; }
From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java
/** * * @param chartPanel/* w w w . j ava 2 s.co m*/ * @param x1 * @param y1 * @return */ public static AffineTransform getModelToViewTransformXY(ChartPanel chartPanel, double x1, double y1) { double zoomX = chartPanel.getScaleX(); double zoomY = chartPanel.getScaleY(); Insets insets = chartPanel.getInsets(); AffineTransform at = getTranslateInstance(insets.left, insets.top); at.concatenate(getScaleInstance(zoomX, zoomY)); Plot plot = chartPanel.getChart().getPlot(); if (plot instanceof XYPlot) { XYPlot xyp = (XYPlot) plot; RectangleEdge xAxisLocation = xyp.getDomainAxisEdge(); RectangleEdge yAxisLocation = xyp.getRangeAxisEdge(); PlotOrientation orientation = xyp.getOrientation(); Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); double transX = xyp.getDomainAxis().valueToJava2D(x1, dataArea, xAxisLocation); double transY = xyp.getRangeAxis().valueToJava2D(y1, dataArea, yAxisLocation); if (orientation == PlotOrientation.HORIZONTAL) { double tmp = transX; transX = transY; transY = tmp; } at.concatenate(getTranslateInstance(transX, transY)); return at; } throw new IllegalArgumentException("Unsupported plot type: " + plot.getClass()); }
From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java
/** * * @param chartPanel//www . ja va 2 s . c o m * @param category * @param y * @return */ public static AffineTransform getModelToViewTransformCategory(ChartPanel chartPanel, int category, double y) { double zoomX = chartPanel.getScaleX(); double zoomY = chartPanel.getScaleY(); Insets insets = chartPanel.getInsets(); AffineTransform at = getTranslateInstance(insets.left, insets.top); at.concatenate(getScaleInstance(zoomX, zoomY)); Plot plot = chartPanel.getChart().getPlot(); if (plot instanceof CategoryPlot) { CategoryPlot xyp = (CategoryPlot) plot; CategoryDataset cds = xyp.getDataset(); RectangleEdge xAxisLocation = xyp.getDomainAxisEdge(); RectangleEdge yAxisLocation = xyp.getRangeAxisEdge(); PlotOrientation orientation = xyp.getOrientation(); Comparable<?> categoryKey = cds.getColumnKey(category); Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); double transX = xyp.getDomainAxis().getCategoryMiddle(categoryKey, cds.getColumnKeys(), dataArea, xAxisLocation); double transY = xyp.getRangeAxis().valueToJava2D(y, dataArea, yAxisLocation); if (orientation == PlotOrientation.HORIZONTAL) { double tmp = transX; transX = transY; transY = tmp; } at.concatenate(getTranslateInstance(transX, transY)); return at; } throw new IllegalArgumentException("Unsupported plot type: " + plot.getClass()); }
From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java
/** * * @param entity// w ww .j a va 2s. com * @param chartPanel * @param dataset * @param seriesIndex * @param itemIndex * @return */ public static Shape toView(Shape entity, ChartPanel chartPanel, Dataset dataset, int seriesIndex, int itemIndex) { if (dataset instanceof XYDataset) { XYDataset xyds = (XYDataset) dataset; double x1 = xyds.getXValue(seriesIndex, itemIndex); double y1 = xyds.getYValue(seriesIndex, itemIndex); AffineTransform toPosition = getModelToViewTransformXY(chartPanel, x1, y1); toPosition.concatenate( getTranslateInstance(-entity.getBounds2D().getCenterX(), -entity.getBounds2D().getCenterY())); return toPosition.createTransformedShape(entity); } else if (dataset instanceof CategoryDataset) { CategoryDataset cds = (CategoryDataset) dataset; double y1 = cds.getValue(seriesIndex, itemIndex).doubleValue(); AffineTransform toPosition = getModelToViewTransformCategory(chartPanel, itemIndex, y1); toPosition.concatenate( getTranslateInstance(-entity.getBounds2D().getCenterX(), -entity.getBounds2D().getCenterY())); return toPosition.createTransformedShape(entity); } throw new IllegalArgumentException("Unsupported dataset type: " + dataset.getClass()); }
From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java
/** * * @param entity/*from www . j a v a 2 s. c o m*/ * @param chartPanel * @return */ public static Point2D toViewXY(Point2D entity, ChartPanel chartPanel) { AffineTransform toPosition = getModelToViewTransformXY(chartPanel, entity.getX(), entity.getY()); toPosition.concatenate(getTranslateInstance(-entity.getX(), -entity.getY())); return toPosition.transform(entity, null); }
From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java
/** * * @param entity//from w ww . java2s. co m * @param chartPanel * @param center * @return */ public static Shape toViewXY(Shape entity, ChartPanel chartPanel, Point2D center) { AffineTransform toPosition = getModelToViewTransformXY(chartPanel, center.getX(), center.getY()); toPosition.concatenate(getTranslateInstance(-center.getX(), -center.getY())); return toPosition.createTransformedShape(entity); }
From source file:com.t_oster.visicut.misc.Helper.java
/** * Returns an AffineTransform, which transformes src to dest * and constists of a scale and translate component * @param src//from w w w. jav a2 s . com * @param dest * @return */ public static AffineTransform getTransform(Rectangle2D src, Rectangle2D dest) { AffineTransform scale = AffineTransform.getScaleInstance(dest.getWidth() / src.getWidth(), dest.getHeight() / src.getHeight()); Point2D scaled = scale.transform(new Point.Double(src.getX(), src.getY()), null); AffineTransform result = AffineTransform.getTranslateInstance(dest.getX() - scaled.getX(), dest.getY() - scaled.getY()); result.concatenate(scale); return result; }
From source file:net.sf.maltcms.chromaui.charts.overlay.Peak1DHeatmapOverlay.java
/** * * @param g2//from ww w. j ava 2 s .com * @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); } }