List of usage examples for java.awt.geom AffineTransform scale
@SuppressWarnings("fallthrough") public void scale(double sx, double sy)
From source file:org.apache.pdfbox.rendering.PageDrawer.java
private void drawBufferedImage(BufferedImage image, AffineTransform at) throws IOException { graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite()); setClip();//from ww w . j a v a 2 s . c o m PDSoftMask softMask = getGraphicsState().getSoftMask(); if (softMask != null) { AffineTransform imageTransform = new AffineTransform(at); imageTransform.scale(1, -1); imageTransform.translate(0, -1); Paint awtPaint = new TexturePaint(image, new Rectangle2D.Double(imageTransform.getTranslateX(), imageTransform.getTranslateY(), imageTransform.getScaleX(), imageTransform.getScaleY())); awtPaint = applySoftMaskToPaint(awtPaint, softMask); graphics.setPaint(awtPaint); Rectangle2D unitRect = new Rectangle2D.Float(0, 0, 1, 1); graphics.fill(at.createTransformedShape(unitRect)); } else { int width = image.getWidth(null); int height = image.getHeight(null); AffineTransform imageTransform = new AffineTransform(at); imageTransform.scale(1.0 / width, -1.0 / height); imageTransform.translate(0, -height); graphics.drawImage(image, imageTransform, null); } }
From source file:net.sf.ginp.browser.FolderManagerImpl.java
void makeThumbImage(final File origPicture, final String thumbFileName, final int maxThumbSize) { if (log.isDebugEnabled()) { log.debug("makeThumbImage: origFileName=" + origPicture.getAbsolutePath() + " thumbFileName=" + thumbFileName + " maxThumbSize=" + maxThumbSize); }//from w ww .ja v a 2 s. c o m // Only jpegs supported. if ((origPicture.getName().toLowerCase()).endsWith(".jpg") || (origPicture.getName().toLowerCase()).endsWith(".jpeg")) { try { // thumb it. JPEGImageDecoder dc = JPEGCodec.createJPEGDecoder((new FileInputStream(origPicture))); BufferedImage origImage = dc.decodeAsBufferedImage(); int origHeight = origImage.getHeight(null); int origWidth = origImage.getWidth(null); int scaledW = 0; int scaledH = 0; double scale = 1.0; if (origHeight < origWidth) { scale = (double) maxThumbSize / (double) origWidth; } else { scale = (double) maxThumbSize / (double) origHeight; } scaledW = (int) (scale * origWidth); scaledH = (int) (scale * origHeight); //AffineTransform at = new AffineTransform(); AffineTransform tx; AffineTransformOp af; JPEGImageEncoder encoder; BufferedImage outImage; outImage = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_INT_RGB); tx = new AffineTransform(); tx.scale(scale, scale); af = new AffineTransformOp(tx, null); af.filter(origImage, outImage); File ginpFolder = new File( thumbFileName.substring(0, thumbFileName.lastIndexOf("/.ginp")) + "/.ginp"); if (!(ginpFolder.exists())) { ginpFolder.mkdir(); } encoder = JPEGCodec.createJPEGEncoder(new FileOutputStream(thumbFileName)); encoder.encode(outImage); } catch (Exception e) { log.error("Error Makeing Thumb Image " + thumbFileName, e); } } }
From source file:org.apache.fop.render.pdf.pdfbox.PDFBoxAdapter.java
private void rotate(int rotation, PDRectangle viewBox, AffineTransform atdoc) { float x = viewBox.getWidth() + viewBox.getLowerLeftX(); float y = viewBox.getHeight() + viewBox.getLowerLeftY(); switch (rotation) { case 90://from www. j a va 2s. c o m atdoc.scale(viewBox.getWidth() / viewBox.getHeight(), viewBox.getHeight() / viewBox.getWidth()); atdoc.translate(0, viewBox.getWidth()); atdoc.rotate(-Math.PI / 2.0); atdoc.scale(viewBox.getWidth() / viewBox.getHeight(), viewBox.getHeight() / viewBox.getWidth()); break; case 180: atdoc.translate(x, y); atdoc.rotate(-Math.PI); atdoc.translate(-viewBox.getLowerLeftX(), -viewBox.getLowerLeftY()); break; case 270: atdoc.translate(viewBox.getLowerLeftX(), y); atdoc.rotate(Math.toRadians(270 + 180)); atdoc.translate(-x, -y); break; default: //no additional transformations necessary break; } }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java
private void createCategoricalLegendItems(PlotInstance plotInstance, Set<PlotDimension> dimensionSet, LegendItemCollection legendItemCollection, Iterable<Double> values) { createDimensionTitleLegendItem(plotInstance, dimensionSet, legendItemCollection); PlotConfiguration plotConfig = plotInstance.getCurrentPlotConfigurationClone(); Shape defaultShape = new Ellipse2D.Float(-5f, -5f, 10f, 10f); Color defaultOutlineColor = PlotConfiguration.DEFAULT_OUTLINE_COLOR; ColorProvider colorProvider = null;/* w ww.ja v a 2 s . c om*/ ShapeProvider shapeProvider = null; SizeProvider sizeProvider = null; DefaultDimensionConfig dimensionConfig = (DefaultDimensionConfig) plotConfig .getDimensionConfig(dimensionSet.iterator().next()); DimensionConfigData dimensionConfigData = plotInstance.getPlotData() .getDimensionConfigData(dimensionConfig); for (PlotDimension dimension : dimensionSet) { if (dimension == PlotDimension.COLOR) { colorProvider = dimensionConfigData.getColorProvider(); } else if (dimension == PlotDimension.SHAPE) { shapeProvider = dimensionConfigData.getShapeProvider(); } else if (dimension == PlotDimension.SIZE) { sizeProvider = dimensionConfigData.getSizeProvider(); } } // initialize size scale for legend ContinuousSizeProvider legendSizeProvider = null; if (sizeProvider != null) { double minScalingFactor = sizeProvider.getMinScalingFactor(); double maxScalingFactor = sizeProvider.getMaxScalingFactor(); double minLegendScalingFactor = MIN_LEGEND_ITEM_SCALING_FACTOR; double maxLegendScalingFactor = MAX_LEGEND_ITEM_SCALING_FACTOR; if (minScalingFactor > maxScalingFactor) { double tmp = minScalingFactor; minScalingFactor = maxScalingFactor; maxScalingFactor = tmp; minLegendScalingFactor = MAX_LEGEND_ITEM_SCALING_FACTOR; maxLegendScalingFactor = MIN_LEGEND_ITEM_SCALING_FACTOR; } legendSizeProvider = new ContinuousSizeProvider(minScalingFactor, maxScalingFactor, minLegendScalingFactor, maxLegendScalingFactor, false); } for (Double value : values) { // configure shape and stroke Shape shape = defaultShape; BasicStroke outlineStroke; Color outlineColor = new Color(0, 0, 0, 0); if (shapeProvider != null) { shape = shapeProvider.getShapeForCategory(value); outlineStroke = DEFAULT_OUTLINE_STROKE; outlineColor = defaultOutlineColor; } else { outlineStroke = new BasicStroke(); if (colorProvider != null) { shape = UNDEFINED_SHAPE; } else { shape = UNDEFINED_SHAPE_AND_COLOR; } } // configure fill paint Paint paint = UNDEFINED_COLOR_PAINT; if (colorProvider != null) { paint = colorProvider.getColorForValue(value); } double scalingFactor = 1; if (sizeProvider != null) { // scale shape according to sizeProvider scalingFactor = sizeProvider.getScalingFactorForValue(value); // scale shape to fit into legend scalingFactor = legendSizeProvider.getScalingFactorForValue(scalingFactor); AffineTransform transformation = new AffineTransform(); transformation.scale(scalingFactor, scalingFactor); shape = transformation.createTransformedShape(shape); } String label = dimensionConfigData.getStringForValue(value); if (label == null) { label = ""; } CustomLegendItem legendItem = new CustomLegendItem(label, null, null, null, shape, paint, outlineStroke, outlineColor); legendItemCollection.add(legendItem); } }
From source file:org.pentaho.di.core.gui.SwingDirectGC.java
public void setTransform(float translationX, float translationY, int shadowsize, float magnification) { AffineTransform transform = new AffineTransform(); transform.translate(translationX + shadowsize * magnification, translationY + shadowsize * magnification); transform.scale(magnification, magnification); gc.setTransform(transform);/* w w w .ja v a 2 s . c o m*/ }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java
/** * Creates a continuous legend item for one item in dimensionSet, i.e. dimensionSet must be a * set containing exactly one value./* w w w . j av a 2s . co m*/ * * @param dateFormat * format used to format minValue and maxValue as dates, or null if they should be * displayed numerically instead of as dates * @throws ChartPlottimeException */ private LegendItem createContinuousLegendItem(PlotInstance plotInstance, Set<PlotDimension> dimensionSet, double minValue, double maxValue, DateFormat dateFormat) { PlotConfiguration plotConfiguration = plotInstance.getCurrentPlotConfigurationClone(); PlotDimension dimension = dimensionSet.iterator().next(); DefaultDimensionConfig dimensionConfig = (DefaultDimensionConfig) plotConfiguration .getDimensionConfig(dimension); DimensionConfigData dimensionConfigData = plotInstance.getPlotData() .getDimensionConfigData(dimensionConfig); // String label = dimensionConfig.getLabel(); // if(label == null) { // label = I18N.getGUILabel("plotter.unnamed_value_label"); // } String label = ""; if (dimension == PlotDimension.COLOR) { ColorProvider colorProvider = dimensionConfigData.getColorProvider(); if (!colorProvider.supportsNumericalValues()) { throw new RuntimeException( "Color provider for continuous legend item does not support numerical values."); } // shape dimensions final int width = 50; final int height = 10; // create item paint // first disable logarithmic scale on color provider ( -> linear gradient in legend) // ContinuousColorProvider continuousColorProvider = null; // if (dimensionConfig.isLogarithmic() && colorProvider instanceof // ContinuousColorProvider) { // continuousColorProvider = (ContinuousColorProvider)colorProvider; // continuousColorProvider.setLogarithmic(false); // } // calculate gradient float fractions[] = new float[width]; Color colors[] = new Color[width]; for (int i = 0; i < width; ++i) { float fraction = i / (width - 1.0f); double fractionValue; if (colorProvider instanceof ContinuousColorProvider && ((ContinuousColorProvider) colorProvider).isColorMinMaxValueDifferentFromOriginal( ((ContinuousColorProvider) colorProvider).getMinValue(), ((ContinuousColorProvider) colorProvider).getMaxValue())) { fractionValue = ((ContinuousColorProvider) colorProvider).getMinValue() + fraction * (((ContinuousColorProvider) colorProvider).getMaxValue() - ((ContinuousColorProvider) colorProvider).getMinValue()); } else { fractionValue = minValue + fraction * (maxValue - minValue); } colors[i] = colorProvider.getColorForValue(fractionValue); fractions[i] = fraction; } LinearGradientPaint shapeFillPaint = new LinearGradientPaint(new Point(0, 0), new Point(width, 0), fractions, colors, CycleMethod.REPEAT); // reset color provider to logarithmic if necessary // if (continuousColorProvider != null && dimensionConfig.isLogarithmic()) { // continuousColorProvider.setLogarithmic(true); // } // create item shape Rectangle itemShape = new Rectangle(width, height); if (colorProvider instanceof ContinuousColorProvider) { return createFlankedShapeLegendItem(label, ((ContinuousColorProvider) colorProvider).getMinValue(), ((ContinuousColorProvider) colorProvider).getMaxValue(), itemShape, shapeFillPaint, true, dateFormat); } else { return createFlankedShapeLegendItem(label, minValue, maxValue, itemShape, shapeFillPaint, true, dateFormat); } } else if (dimension == PlotDimension.SHAPE) { // shape provider probably never supports numerical values return null; } else if (dimension == PlotDimension.SIZE) { SizeProvider sizeProvider = dimensionConfigData.getSizeProvider(); if (!sizeProvider.supportsNumericalValues()) { throw new RuntimeException( "Size provider for continuous legend item does not support numerical values."); } double minScalingFactor = sizeProvider.getMinScalingFactor(); double maxScalingFactor = sizeProvider.getMaxScalingFactor(); ContinuousSizeProvider legendSizeProvider = new ContinuousSizeProvider(minScalingFactor, maxScalingFactor, MIN_LEGEND_ITEM_SCALING_FACTOR, MAX_LEGEND_ITEM_SCALING_FACTOR, false); int legendItemCount = 4; Area composedShape = new Area(); Shape originalShape = UNDEFINED_SHAPE; if (dimensionSet.contains(PlotDimension.SIZE) && dimensionSet.size() == 1) { originalShape = UNDEFINED_SHAPE_AND_COLOR; } double maxHeight = originalShape.getBounds().getHeight() * MAX_LEGEND_ITEM_SCALING_FACTOR; for (int i = 0; i < legendItemCount; ++i) { double fraction = minScalingFactor + ((double) i / legendItemCount * (maxScalingFactor - minScalingFactor)); double legendScalingFactor = legendSizeProvider.getScalingFactorForValue(fraction); double composedWidth = composedShape.getBounds().getWidth(); AffineTransform t = new AffineTransform(); t.scale(legendScalingFactor, legendScalingFactor); Shape shape = t.createTransformedShape(originalShape); t = new AffineTransform(); double shapeWidth = shape.getBounds().getWidth(); double shapeHeight = shape.getBounds().getHeight(); t.translate(composedWidth + shapeWidth * .1, (maxHeight - shapeHeight) / 2.0); t.translate(-shape.getBounds().getMinX(), -shape.getBounds().getMinY()); shape = t.createTransformedShape(shape); composedShape.add(new Area(shape)); } return createFlankedShapeLegendItem(label, minValue, maxValue, composedShape, UNDEFINED_COLOR_PAINT, false, dateFormat); } else { throw new RuntimeException("Unsupported dimension. Execution path should never reach this line."); } }
From source file:edu.uci.ics.jung.visualization.picking.ShapePickSupport.java
/** * Retrieves the shape template for <code>e</code> and * transforms it according to the positions of its endpoints * in <code>layout</code>.// www . j a v a2 s. c o m * @param layout the <code>Layout</code> which specifies * <code>e</code>'s endpoints' positions * @param e the edge whose shape is to be returned * @return */ private Shape getTransformedEdgeShape(Layout<V, E> layout, E e) { Pair<V> pair = layout.getGraph().getEndpoints(e); V v1 = pair.getFirst(); V v2 = pair.getSecond(); boolean isLoop = v1.equals(v2); Point2D p1 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v1)); Point2D p2 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v2)); if (p1 == null || p2 == null) return null; float x1 = (float) p1.getX(); float y1 = (float) p1.getY(); float x2 = (float) p2.getX(); float y2 = (float) p2.getY(); // translate the edge to the starting vertex AffineTransform xform = AffineTransform.getTranslateInstance(x1, y1); Shape edgeShape = vv.getRenderContext().getEdgeShapeTransformer() .transform(Context.<Graph<V, E>, E>getInstance(vv.getGraphLayout().getGraph(), e)); if (isLoop) { // make the loops proportional to the size of the vertex Shape s2 = vv.getRenderContext().getVertexShapeTransformer().transform(v2); Rectangle2D s2Bounds = s2.getBounds2D(); xform.scale(s2Bounds.getWidth(), s2Bounds.getHeight()); // move the loop so that the nadir is centered in the vertex xform.translate(0, -edgeShape.getBounds2D().getHeight() / 2); } else { float dx = x2 - x1; float dy = y2 - y1; // rotate the edge to the angle between the vertices double theta = Math.atan2(dy, dx); xform.rotate(theta); // stretch the edge to span the distance between the vertices float dist = (float) Math.sqrt(dx * dx + dy * dy); xform.scale(dist, 1.0f); } // transform the edge to its location and dimensions edgeShape = xform.createTransformedShape(edgeShape); return edgeShape; }
From source file:org.pentaho.di.core.gui.SwingGC.java
public void setTransform(float translationX, float translationY, int shadowsize, float magnification) { // PDI-9953 - always use original GC's transform. AffineTransform transform = (AffineTransform) originalTransform.clone(); transform.translate(translationX + shadowsize * magnification, translationY + shadowsize * magnification); transform.scale(magnification, magnification); gc.setTransform(transform);/*from w w w .j a v a 2 s . c o m*/ }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java
private CustomLegendItem createValueSourceLegendItem(PlotConfiguration plotConfig, ValueSource valueSource) { Set<PlotDimension> dimensions = new HashSet<PlotDimension>(); for (PlotDimension dimension : PlotDimension.values()) { switch (dimension) { case DOMAIN: case VALUE: break; default:/* w w w . jav a2 s . c o m*/ if (valueSource.useSeriesFormatForDimension(plotConfig, dimension)) { dimensions.add(dimension); } } } if (dimensions.isEmpty()) { return null; } SeriesFormat format = valueSource.getSeriesFormat(); String description = ""; String toolTipText = ""; String urlText = ""; boolean shapeVisible = true; Shape shape; boolean shapeFilled = true; Paint fillPaint = UNDEFINED_COLOR_PAINT; boolean shapeOutlineVisible = true; Paint outlinePaint = PlotConfiguration.DEFAULT_OUTLINE_COLOR; Stroke outlineStroke = DEFAULT_OUTLINE_STROKE; boolean lineVisible = format.getLineStyle() != LineStyle.NONE && format.getSeriesType() == SeriesFormat.VisualizationType.LINES_AND_SHAPES; // configure fill paint and line paint Paint linePaint; String label = valueSource.toString(); if (label == null) { label = ""; } if (dimensions.contains(PlotDimension.COLOR)) { Color color = format.getItemColor(); fillPaint = format.getAreaFillPaint(color); linePaint = fillPaint; } else { if (format.getAreaFillStyle() == FillStyle.NONE) { fillPaint = new Color(0, 0, 0, 0); linePaint = fillPaint; } else if (format.getAreaFillStyle() == FillStyle.SOLID) { fillPaint = UNDEFINED_COLOR_PAINT; linePaint = UNDEFINED_LINE_COLOR; } else { fillPaint = format.getAreaFillPaint(UNDEFINED_COLOR); linePaint = fillPaint; } } VisualizationType seriesType = valueSource.getSeriesFormat().getSeriesType(); if (seriesType == VisualizationType.LINES_AND_SHAPES) { if (dimensions.contains(PlotDimension.SHAPE)) { shape = format.getItemShape().getShape(); } else if (dimensions.contains(PlotDimension.COLOR)) { shape = UNDEFINED_SHAPE; } else { shape = UNDEFINED_SHAPE_AND_COLOR; } if (dimensions.contains(PlotDimension.SIZE)) { AffineTransform transformation = new AffineTransform(); double scalingFactor = format.getItemSize(); transformation.scale(scalingFactor, scalingFactor); shape = transformation.createTransformedShape(shape); } } else if (seriesType == VisualizationType.BARS) { shape = BAR_SHAPE; } else if (seriesType == VisualizationType.AREA) { shape = AREA_SHAPE; } else { throw new RuntimeException("Unknown SeriesType. This should not happen."); } // configure line shape float lineLength = 0; if (lineVisible) { lineLength = format.getLineWidth(); if (lineLength < 1) { lineLength = 1; } if (lineLength > 1) { lineLength = 1 + (float) Math.log(lineLength) / 2; } // line at least 30 pixels long, and show at least 2 iterations of stroke lineLength = Math.max(lineLength * 30, format.getStrokeLength() * 2); // line at least 2x longer than shape width if (shape != null) { lineLength = Math.max(lineLength, (float) shape.getBounds().getWidth() * 2f); } } // now create line shape and stroke Shape line = new Line2D.Float(0, 0, lineLength, 0); BasicStroke lineStroke = format.getStroke(); if (lineStroke == null) { lineStroke = new BasicStroke(); } // unset line ending decoration to prevent drawing errors in legend { BasicStroke s = lineStroke; lineStroke = new BasicStroke(s.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, s.getMiterLimit(), s.getDashArray(), s.getDashPhase()); } return new CustomLegendItem(label, description, toolTipText, urlText, shapeVisible, shape, shapeFilled, fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke, lineVisible, line, lineStroke, linePaint); }
From source file:com.floreantpos.jasperreport.swing.JRViewerPanel.java
protected Image getPageErrorImage() { Image image = new BufferedImage((int) (viewerContext.getJasperPrint().getPageWidth() * realZoom) + 1, (int) (viewerContext.getJasperPrint().getPageHeight() * realZoom) + 1, BufferedImage.TYPE_INT_RGB); Graphics2D grx = (Graphics2D) image.getGraphics(); AffineTransform transform = new AffineTransform(); transform.scale(realZoom, realZoom); grx.transform(transform);/*from w w w.java2 s . c o m*/ drawPageError(grx); return image; }