java.awt.geom.Dimension2D Java Examples
The following examples show how to use
java.awt.geom.Dimension2D.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JRWrappingSvgRenderer.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Dimension2D getDimension(JasperReportsContext jasperReportsContext) { Dimension2D imageDimension = null; try { // use original dimension if possible imageDimension = renderer.getDimension(jasperReportsContext); } catch (JRException e) { // ignore } if (imageDimension == null) { // fallback to element dimension imageDimension = elementDimension; } return imageDimension; }
Example #2
Source File: Group.java From ramus with GNU General Public License v3.0 | 6 votes |
public void applyTransforms() { double scaleX = getScaleX(); double scaleY = getScaleY(); for (Bounds bounds : this.bounds) { if (bounds instanceof QBounds) { QBounds qBounds = (QBounds) bounds; Point2D point = qBounds.getLocation(); qBounds.setLocation(new Point2D.Double(point.getX() + translate.getX(), point.getY() + translate.getY())); Dimension2D d = qBounds.getSize(); qBounds.setSize(new Dimension2DImpl(d.getWidth() * scaleX, d .getHeight() * scaleY)); } } clear(); }
Example #3
Source File: SwingUniversalImageSvg.java From hop with Apache License 2.0 | 6 votes |
public static void render( Graphics2D gc, GraphicsNode svgGraphicsNode, Dimension2D svgGraphicsSize, int centerX, int centerY, int width, int height, double angleRadians ) { double scaleX = width / svgGraphicsSize.getWidth(); double scaleY = height / svgGraphicsSize.getHeight(); AffineTransform affineTransform = new AffineTransform(); if ( centerX != 0 || centerY != 0 ) { affineTransform.translate( centerX, centerY ); } affineTransform.scale( scaleX, scaleY ); if ( angleRadians != 0 ) { affineTransform.rotate( angleRadians ); } affineTransform.translate( -svgGraphicsSize.getWidth() / 2, -svgGraphicsSize.getHeight() / 2 ); svgGraphicsNode.setTransform( affineTransform ); svgGraphicsNode.paint( gc ); }
Example #4
Source File: GridElement.java From orson-charts with GNU General Public License v3.0 | 6 votes |
/** * Returns the preferred size of the element (including insets). * * @param g2 the graphics target. * @param bounds the bounds. * @param constraints the constraints (ignored for now). * * @return The preferred size. */ @Override public Dimension2D preferredSize(Graphics2D g2, Rectangle2D bounds, Map<String, Object> constraints) { Insets insets = getInsets(); double[][] cellDimensions = findCellDimensions(g2, bounds); double[] widths = cellDimensions[0]; double[] heights = cellDimensions[1]; double w = insets.left + insets.right; for (int i = 0; i < widths.length; i++) { w = w + widths[i]; } double h = insets.top + insets.bottom; for (int i = 0; i < heights.length; i++) { h = h + heights[i]; } return new Dimension((int) w, (int) h); }
Example #5
Source File: FlowElement.java From orson-charts with GNU General Public License v3.0 | 6 votes |
/** * Returns the preferred size of the element (including insets). * * @param g2 the graphics target. * @param bounds the bounds. * @param constraints the constraints (ignored for now). * * @return The preferred size. */ @Override public Dimension2D preferredSize(Graphics2D g2, Rectangle2D bounds, Map<String, Object> constraints) { Insets insets = getInsets(); double width = insets.left + insets.right; double height = insets.top + insets.bottom; double maxRowWidth = 0.0; int elementCount = this.elements.size(); int i = 0; while (i < elementCount) { // get one row of elements... List<ElementInfo> elementsInRow = rowOfElements(i, g2, bounds); double rowHeight = calcRowHeight(elementsInRow); double rowWidth = calcRowWidth(elementsInRow, this.hgap); maxRowWidth = Math.max(rowWidth, maxRowWidth); height += rowHeight; i = i + elementsInRow.size(); } width += maxRowWidth; return new ElementDimension(width, height); }
Example #6
Source File: FlowElementTest.java From orson-charts with GNU General Public License v3.0 | 6 votes |
@Test public void testPreferredSize1() { BufferedImage img = new BufferedImage(100, 50, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = img.createGraphics(); FlowElement fe = new FlowElement(); ShapeElement se1 = new ShapeElement(new Rectangle(10, 5), Color.BLACK); se1.setInsets(new Insets(0, 0, 0, 0)); fe.addElement(se1); Dimension2D dim = fe.preferredSize(g2, new Rectangle(100, 50)); assertEquals(14.0, dim.getWidth(), EPSILON); assertEquals(9.0, dim.getHeight(), EPSILON); // although this element looks at the width of the bounds to determine // the layout, it will still return the minimum required size as the // preferred size, even if this exceeds the bounds dim = fe.preferredSize(g2, new Rectangle(10, 5)); assertEquals(14.0, dim.getWidth(), EPSILON); assertEquals(9.0, dim.getHeight(), EPSILON); }
Example #7
Source File: CImage.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** @return A MultiResolution image created from nsImagePtr, or null. */ private Image toImage() { if (ptr == 0) { return null; } AtomicReference<Dimension2D> sizeRef = new AtomicReference<>(); execute(ptr -> { sizeRef.set(nativeGetNSImageSize(ptr)); }); final Dimension2D size = sizeRef.get(); if (size == null) { return null; } final int w = (int)size.getWidth(); final int h = (int)size.getHeight(); AtomicReference<Dimension2D[]> repRef = new AtomicReference<>(); execute(ptr -> { repRef.set(nativeGetNSImageRepresentationSizes(ptr, size.getWidth(), size.getHeight())); }); Dimension2D[] sizes = repRef.get(); return sizes == null || sizes.length < 2 ? new MultiResolutionCachedImage(w, h, (width, height) -> toImage(w, h, width, height)) : new MultiResolutionCachedImage(w, h, sizes, (width, height) -> toImage(w, h, width, height)); }
Example #8
Source File: MindMapPanel.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
@Nullable public static BufferedImage renderMindMapAsImage(@Nonnull final MindMap model, @Nonnull final MindMapPanelConfig cfg, final boolean expandAll, @Nonnull final RenderQuality quality) { final MindMap workMap = new MindMap(model); workMap.resetPayload(); if (expandAll) { MindMapUtils.removeCollapseAttr(workMap); } final Dimension2D blockSize = calculateSizeOfMapInPixels(workMap, null, cfg, expandAll, quality); if (blockSize == null) { return null; } final BufferedImage img = new BufferedImage((int) blockSize.getWidth(), (int) blockSize.getHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D g = img.createGraphics(); final MMGraphics gfx = new MMGraphics2DWrapper(g); try { quality.prepare(g); gfx.setClip(0, 0, img.getWidth(), img.getHeight()); layoutFullDiagramWithCenteringToPaper(gfx, workMap, cfg, blockSize); drawOnGraphicsForConfiguration(gfx, cfg, workMap, false, null); } finally { gfx.dispose(); } return img; }
Example #9
Source File: ElementFactory.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Defines the top-right border-radius for this element. If the border radius has a non-zero width and height, the * element's border will have a rounded top-right corner. * * @param borderRadius * the defined border-radius for the top-right corner of this element or null, if this property should be * undefined. */ public void setBorderTopRightRadius( final Dimension2D borderRadius ) { if ( borderRadius == null ) { this.borderTopRightRadiusWidth = null; this.borderTopRightRadiusHeight = null; } else { this.borderTopRightRadiusWidth = new Float( borderRadius.getWidth() ); this.borderTopRightRadiusHeight = new Float( borderRadius.getHeight() ); } }
Example #10
Source File: CornerHandle.java From Pixelitor with GNU General Public License v3.0 | 5 votes |
public void drawWidthDisplay(DragDisplay dd, Dimension2D size) { Direction horEdgeDirection = getHorEdgeDirection(); String widthString = DragDisplay.getWidthDisplayString(size.getWidth()); Point2D horHalf = getHorHalfPoint(); float horX = (float) (horHalf.getX() + horEdgeDirection.dx); float horY = (float) (horHalf.getY() + horEdgeDirection.dy); dd.drawOneLine(widthString, horX, horY); }
Example #11
Source File: Panel3D.java From orson-charts with GNU General Public License v3.0 | 5 votes |
/** * Adjusts the viewing distance so that the chart fits the specified * size. A margin is left (see {@link #getMargin()} around the edges to * leave room for labels etc. * * @param size the target size ({@code null} not permitted). */ public void zoomToFit(Dimension2D size) { int w = (int) (size.getWidth() * (1.0 - this.margin)); int h = (int) (size.getHeight() * (1.0 - this.margin)); Dimension2D target = new Dimension(w, h); Dimension3D d3d = this.drawable.getDimensions(); float distance = this.drawable.getViewPoint().optimalDistance(target, d3d, this.drawable.getProjDistance()); this.drawable.getViewPoint().setRho(distance); repaint(); }
Example #12
Source File: CImage.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** @return A MultiResolution image created from nsImagePtr, or null. */ private Image toImage() { if (ptr == 0) { return null; } AtomicReference<Dimension2D> sizeRef = new AtomicReference<>(); execute(ptr -> { sizeRef.set(nativeGetNSImageSize(ptr)); }); final Dimension2D size = sizeRef.get(); if (size == null) { return null; } final int w = (int)size.getWidth(); final int h = (int)size.getHeight(); AtomicReference<Dimension2D[]> repRef = new AtomicReference<>(); execute(ptr -> { repRef.set(nativeGetNSImageRepresentationSizes(ptr, size.getWidth(), size.getHeight())); }); Dimension2D[] sizes = repRef.get(); return sizes == null || sizes.length < 2 ? new MultiResolutionCachedImage(w, h, (width, height) -> toImage(w, h, width, height)) : new MultiResolutionCachedImage(w, h, sizes, (width, height) -> toImage(w, h, width, height)); }
Example #13
Source File: ElementFactory.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Defines the element's minimum size. * * @param minimumSize * the element's minimum size. * @see ElementFactory#setMinimumWidth(Float) * @see ElementFactory#setMinimumHeight(Float) */ public void setMinimumSize( final Dimension2D minimumSize ) { if ( minimumSize == null ) { this.minimumWidth = null; this.minimumHeight = null; } else { this.minimumWidth = new Float( minimumSize.getWidth() ); this.minimumHeight = new Float( minimumSize.getHeight() ); } }
Example #14
Source File: CImage.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** @return A BufferedImage created from nsImagePtr, or null. */ public BufferedImage toImage() { if (ptr == 0) return null; final Dimension2D size = nativeGetNSImageSize(ptr); final int w = (int)size.getWidth(); final int h = (int)size.getHeight(); final BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE); final DataBufferInt dbi = (DataBufferInt)bimg.getRaster().getDataBuffer(); final int[] buffer = SunWritableRaster.stealData(dbi, 0); nativeCopyNSImageIntoArray(ptr, buffer, w, h); SunWritableRaster.markDirty(dbi); return bimg; }
Example #15
Source File: ElementFactory.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Defines the bottom-left border-radius for this element. If the border radius has a non-zero width and height, the * element's border will have a rounded bottom-left corner. * * @param borderRadius * the defined border-radius for the bottom-left corner of this element or null, if this property should be * undefined. */ public void setBorderBottomLeftRadius( final Dimension2D borderRadius ) { if ( borderRadius == null ) { this.borderBottomLeftRadiusWidth = null; this.borderBottomLeftRadiusHeight = null; } else { this.borderBottomLeftRadiusWidth = new Float( borderRadius.getWidth() ); this.borderBottomLeftRadiusHeight = new Float( borderRadius.getHeight() ); } }
Example #16
Source File: ColorScaleElement.java From orson-charts with GNU General Public License v3.0 | 5 votes |
@Override public List<Rectangle2D> layoutElements(Graphics2D g2, Rectangle2D bounds, Map<String, Object> constraints) { List<Rectangle2D> result = new ArrayList<>(1); Dimension2D prefDim = preferredSize(g2, bounds); Fit2D fitter = Fit2D.getNoScalingFitter(getRefPoint()); Rectangle2D dest = fitter.fit(prefDim, bounds); result.add(dest); return result; }
Example #17
Source File: TransformUtils.java From pumpernickel with MIT License | 5 votes |
/** * Create a simple scaling AffineTransform that transforms a rectangle * bounded by (0,0,d1.widthd,d2.height) to (0,0,d2.width,d2.height) */ public static AffineTransform createAffineTransform(Dimension2D d1, Dimension2D d2) { return createAffineTransform(new Rectangle2D.Double(0, 0, d1.getWidth(), d1.getHeight()), new Rectangle2D.Double(0, 0, d2.getWidth(), d2.getHeight())); }
Example #18
Source File: BatikRenderer.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Dimension2D getDimension(JasperReportsContext jasperReportsContext) { try { ensureSvg(jasperReportsContext); return documentSize; } catch (JRException e) { throw new JRRuntimeException(e); } }
Example #19
Source File: GEFComponent.java From ramus with GNU General Public License v3.0 | 5 votes |
public void setDiagramam(Diagram diagramam) { this.diagram = diagramam; Dimension2D size = diagramam.zoom(diagramam.getSize(), zoom); setSize((int) floor(size.getWidth()) + 2, (int) floor(size.getHeight()) + 2); setPreferredSize(getSize()); }
Example #20
Source File: Table.java From ramus with GNU General Public License v3.0 | 5 votes |
public void applyComlumnsSize(QBounds tableBound, Diagram diagram) { double width = getMinWidth(); double w = width / columns.length; double x = tableBound.getLocation().getX(); for (TableColumn tableColumn : columns) { QBounds bounds = (QBounds) diagram.getBounds(tableColumn); Dimension2D size = bounds.getSize(); size.setSize(w, size.getHeight()); bounds.setLocation(new Point2D.Double(x, getColumnYLocation( tableBound, size))); tableColumn.setWidth(w); x += w; } }
Example #21
Source File: PrintPreviewComponent.java From ramus with GNU General Public License v3.0 | 5 votes |
public void setFitZoom(double zoom, Dimension size) { if (zoom > 10) zoom = 10; if (zoom < 0.1) zoom = 0.1; int columnCount = 1; Dimension2D pageSize = getPageSize(); while (((pageSize.getWidth() + W_SPACE / zoom) * columnCount + pageSize .getWidth()) * zoom < size.getWidth()) { columnCount++; } setup(columnCount, zoom); }
Example #22
Source File: PrintPreviewComponent.java From ramus with GNU General Public License v3.0 | 5 votes |
public void setOnePageZoom(Dimension size) { Dimension2D pageSize = getPageSize(); int pageCount = printable.getPageCount(); if (pageCount == 0) return; double zoom = size.getWidth() / (pageSize.getWidth()); int columnCount = 1; setup(columnCount, zoom); }
Example #23
Source File: ExportToJPEGAction.java From orson-charts with GNU General Public License v3.0 | 5 votes |
/** * Writes the content of the panel to a PNG image, using Java's ImageIO. * * @param e the event. */ @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter( Resources.localString("JPG_FILE_FILTER_DESCRIPTION"), "jpg"); fileChooser.addChoosableFileFilter(filter); fileChooser.setFileFilter(filter); int option = fileChooser.showSaveDialog(this.panel); if (option == JFileChooser.APPROVE_OPTION) { String filename = fileChooser.getSelectedFile().getPath(); if (!filename.endsWith(".jpg")) { filename = filename + ".jpg"; } Dimension2D size = this.panel.getSize(); int w = (int) size.getWidth(); int h = (int) size.getHeight(); BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.panel.getDrawable().draw(g2, new Rectangle(w, h)); try { ImageIO.write(image, "jpeg", new File(filename)); } catch (IOException ex) { throw new RuntimeException(ex); } } }
Example #24
Source File: FlowElement.java From orson-charts with GNU General Public License v3.0 | 5 votes |
/** * Draws the element within the specified bounds. * * @param g2 the graphics target ({@code null} not permitted). * @param bounds the bounds ({@code null} not permitted). * @param onDrawHandler an object that will receive notification before * and after the element is drawn ({@code null} permitted). * * @since 1.3 */ @Override public void draw(Graphics2D g2, Rectangle2D bounds, TableElementOnDraw onDrawHandler) { if (onDrawHandler != null) { onDrawHandler.beforeDraw(this, g2, bounds); } Shape savedClip = g2.getClip(); g2.clip(bounds); // find the preferred size of the flow layout Dimension2D prefDim = preferredSize(g2, bounds); // fit a rectangle of this dimension to the bounds according to the // element anchor Fit2D fitter = Fit2D.getNoScalingFitter(getRefPoint()); Rectangle2D dest = fitter.fit(prefDim, bounds); // perform layout within this bounding rectangle List<Rectangle2D> layoutInfo = this.layoutElements(g2, dest, null); // draw the elements for (int i = 0; i < this.elements.size(); i++) { Rectangle2D rect = layoutInfo.get(i); TableElement element = this.elements.get(i); element.draw(g2, rect, onDrawHandler); } g2.setClip(savedClip); if (onDrawHandler != null) { onDrawHandler.afterDraw(this, g2, bounds); } }
Example #25
Source File: DimensionObjectDescription.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Creates an object based on the description. * * @return The object. */ public Object createObject() { final Dimension2D dim = new Dimension(); final float width = getFloatParameter("width"); final float height = getFloatParameter("height"); dim.setSize(width, height); return dim; }
Example #26
Source File: AbstractShapeCustomizer.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * Returns the width and height properties defined, if only one is defined it value will be used * also for the other, if they are both undefined it will return null. * * @return a size or null if it is undefined */ protected Dimension2D getSize() { Integer width = getWidth(); Integer height = getHeight(); if (width == null && height == null) { return null; } else if (width == null) { width = height; } else if (height == null) { height = width; } return new Dimension(width, height); }
Example #27
Source File: MultiResolutionCachedImage.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public MultiResolutionCachedImage(int baseImageWidth, int baseImageHeight, Dimension2D[] sizes, BiFunction<Integer, Integer, Image> mapper) { this.baseImageWidth = baseImageWidth; this.baseImageHeight = baseImageHeight; this.sizes = (sizes == null) ? null : Arrays.copyOf(sizes, sizes.length); this.mapper = mapper; }
Example #28
Source File: FlowElement.java From orson-charts with GNU General Public License v3.0 | 5 votes |
/** * Calculates the layout of the elements for the given bounds and * constraints. * * @param g2 the graphics target ({@code null} not permitted). * @param bounds the bounds ({@code null} not permitted). * @param constraints the constraints (not used here). * * @return A list of positions for the sub-elements. */ @Override public List<Rectangle2D> layoutElements(Graphics2D g2, Rectangle2D bounds, Map<String, Object> constraints) { int elementCount = this.elements.size(); List<Rectangle2D> result = new ArrayList<>(elementCount); int i = 0; double x = bounds.getX() + getInsets().left; double y = bounds.getY() + getInsets().top; while (i < elementCount) { // get one row of elements... List<ElementInfo> elementsInRow = rowOfElements(i, g2, bounds); double height = calcRowHeight(elementsInRow); double width = calcRowWidth(elementsInRow, this.hgap); if (this.horizontalAlignment == HAlign.CENTER) { x = bounds.getCenterX() - (width / 2.0); } else if (this.horizontalAlignment == HAlign.RIGHT) { x = bounds.getMaxX() - getInsets().right - width; } for (ElementInfo elementInfo : elementsInRow) { Dimension2D dim = elementInfo.getDimension(); Rectangle2D position = new Rectangle2D.Double(x, y, dim.getWidth(), height); result.add(position); x += position.getWidth() + this.hgap; } i = i + elementsInRow.size(); x = bounds.getX() + getInsets().left; y += height; } return result; }
Example #29
Source File: HtmlExporter.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
protected InternalImageProcessorResult( String imagePath, Dimension2D dimension, boolean isEmbededSvgData ) { this.imageSource = imagePath; this.dimension = dimension; this.isEmbededSvgData = isEmbededSvgData; }
Example #30
Source File: PositiveDimensionValidator.java From sejda with GNU Affero General Public License v3.0 | 5 votes |
@Override public boolean isValid(Dimension2D value, ConstraintValidatorContext context) { if (value != null) { return value.getWidth() > 0 && value.getHeight() > 0; } return true; }