Java Code Examples for java.awt.geom.Dimension2D#getHeight()

The following examples show how to use java.awt.geom.Dimension2D#getHeight() . 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: ViewPoint3D.java    From orson-charts with GNU General Public License v3.0 6 votes vote down vote up
private double coverage(Dimension2D d, Dimension2D target) {
    double wpercent = d.getWidth() / target.getWidth();
    double hpercent = d.getHeight() / target.getHeight();
    if (wpercent <= 1.0 && hpercent <= 1.0) {
        return Math.max(wpercent, hpercent);
    } else {
        if (wpercent >= 1.0) {
            if (hpercent >= 1.0) {
                return Math.max(wpercent, hpercent);
            } else {
                return wpercent;
            }
        } else {
            return hpercent;  // don't think it will matter
        }
    }
}
 
Example 2
Source File: VerticalFlowElement.java    From orson-charts with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns info for as many elements as we can fit into one column.
 * 
 * @param first  the index of the first element.
 * @param g2  the graphics target.
 * @param bounds  the bounds.
 * 
 * @return A list of elements and dimensions. 
 */
private List<ElementInfo> columnOfElements(int first, 
        Graphics2D g2, Rectangle2D bounds) {
    List<ElementInfo> result = new ArrayList<>();
    int index = first;
    boolean full = false;
    double h = getInsets().top + getInsets().bottom;
    while (index < this.elements.size() && !full) {
        TableElement element = this.elements.get(index);
        Dimension2D dim = element.preferredSize(g2, bounds);
        if (h + dim.getHeight() <= bounds.getHeight() || index == first) {
            result.add(new ElementInfo(element, dim));
            h += dim.getHeight() + this.vgap;
            index++;
        } else {
            full = true;
        }
    }
    return result;
}
 
Example 3
Source File: TransformBoxAssert.java    From Pixelitor with GNU General Public License v3.0 6 votes vote down vote up
public TransformBoxAssert rotSizeIs(double w, double h) {
    isNotNull();

    Dimension2D size = actual.getRotatedImSize();
    double width = size.getWidth();
    if (Math.abs(width - w) > DOUBLE_TOLERANCE) {
        throw new AssertionError(format("Expected width %.2f, found %.2f", w, width));
    }

    double height = size.getHeight();
    if (Math.abs(height - h) > DOUBLE_TOLERANCE) {
        throw new AssertionError(format("Expected height %.2f, found %.2f", h, height));
    }

    return this;
}
 
Example 4
Source File: CImage.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/** @return A MultiResolution image created from nsImagePtr, or null. */
private Image toImage() {
    if (ptr == 0) return null;

    final Dimension2D size = nativeGetNSImageSize(ptr);
    final int w = (int)size.getWidth();
    final int h = (int)size.getHeight();

    Dimension2D[] sizes
            = nativeGetNSImageRepresentationSizes(ptr,
                    size.getWidth(), size.getHeight());

    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 5
Source File: AbstractShapeCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Builds an ellipse shape.
 * 
 * @return the ellipse or null if its size is not specified
 */
protected Shape buildEllipse()
{
	Ellipse2D ellipse = null;
	Dimension2D size = getSize();
	if (size != null)
	{
		Point offset = getOffset(size);
		ellipse = 
			new Ellipse2D.Float(
				-offset.getX(), 
				-offset.getY(), 
				(float)size.getWidth(), 
				(float)size.getHeight()
				);
	}
	return ellipse;
}
 
Example 6
Source File: CImage.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/** @return A MultiResolution image created from nsImagePtr, or null. */
private Image toImage() {
    if (ptr == 0) return null;

    final Dimension2D size = nativeGetNSImageSize(ptr);
    final int w = (int)size.getWidth();
    final int h = (int)size.getHeight();

    Dimension2D[] sizes
            = nativeGetNSImageRepresentationSizes(ptr,
                    size.getWidth(), size.getHeight());

    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 7
Source File: CImage.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/** @return A MultiResolution image created from nsImagePtr, or null. */
private Image toImage() {
    if (ptr == 0) return null;

    final Dimension2D size = nativeGetNSImageSize(ptr);
    final int w = (int)size.getWidth();
    final int h = (int)size.getHeight();

    Dimension2D[] sizes
            = nativeGetNSImageRepresentationSizes(ptr,
                    size.getWidth(), size.getHeight());

    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: SwingUniversalImageSvg.java    From hop with Apache License 2.0 6 votes vote down vote up
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 9
Source File: CImage.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/** @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 10
Source File: ElementFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 11
Source File: CImage.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/** @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 12
Source File: Dimension2DObjectDescription.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the parameters of this description object to match the supplied object.
 *
 * @param o  the object (should be an instance of <code>Dimension2D</code>).
 *
 * @throws ObjectFactoryException if the object is not an instance of <code>Point2D</code>.
 */
public void setParameterFromObject(final Object o) throws ObjectFactoryException {
    if (!(o instanceof Dimension2D)) {
        throw new ObjectFactoryException("The given object is no java.awt.geom.Dimension2D.");
    }

    final Dimension2D dim = (Dimension2D) o;
    final float width = (float) dim.getWidth();
    final float height = (float) dim.getHeight();

    setParameter("width", new Float(width));
    setParameter("height", new Float(height));
}
 
Example 13
Source File: Dimension2DObjectDescription.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Sets the parameters of this description object to match the supplied object.
 *
 * @param o
 *          the object (should be an instance of <code>Dimension2D</code>).
 * @throws ObjectFactoryException
 *           if the object is not an instance of <code>Point2D</code>.
 */
public void setParameterFromObject( final Object o ) throws ObjectFactoryException {
  if ( !( o instanceof Dimension2D ) ) {
    throw new ObjectFactoryException( "The given object is no java.awt.geom.Dimension2D." );
  }

  final Dimension2D dim = (Dimension2D) o;
  final float width = (float) dim.getWidth();
  final float height = (float) dim.getHeight();

  setParameter( "width", new Float( width ) );
  setParameter( "height", new Float( height ) );
}
 
Example 14
Source File: AbstractCollapsableElement.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void alignElementAndChildren(@Nonnull final MindMapPanelConfig cfg, final boolean leftSide, final double leftX, final double topY) {
  super.alignElementAndChildren(cfg, leftSide, leftX, topY);

  final double horzInset = cfg.getOtherLevelHorizontalInset() * cfg.getScale();

  double childrenX;

  final double COLLAPSATORSIZE = cfg.getCollapsatorSize() * cfg.getScale();
  final double COLLAPSATORDISTANCE = cfg.getCollapsatorSize() * 0.1d * cfg.getScale();

  final double collapsatorX;

  if (leftSide) {
    childrenX = leftX + this.blockSize.getWidth() - this.bounds.getWidth();
    this.moveTo(childrenX, topY + (this.blockSize.getHeight() - this.bounds.getHeight()) / 2);
    childrenX -= horzInset;
    collapsatorX = -COLLAPSATORSIZE - COLLAPSATORDISTANCE;
  } else {
    childrenX = leftX;
    this.moveTo(childrenX, topY + (this.blockSize.getHeight() - this.bounds.getHeight()) / 2);
    childrenX += this.bounds.getWidth() + horzInset;
    collapsatorX = this.bounds.getWidth() + COLLAPSATORDISTANCE;
  }

  this.collapsatorZone.setRect(collapsatorX, (this.bounds.getHeight() - COLLAPSATORSIZE) / 2, COLLAPSATORSIZE, COLLAPSATORSIZE);

  if (!this.isCollapsed()) {
    final double vertInset = cfg.getOtherLevelVerticalInset() * cfg.getScale();

    final Dimension2D childBlockSize = calcBlockSize(cfg, null, true);
    double currentY = topY + (this.blockSize.getHeight() - childBlockSize.getHeight()) / 2.0d;

    boolean notFirstChild = false;

    for (final Topic t : this.model.getChildren()) {
      if (notFirstChild) {
        currentY += vertInset;
      } else {
        notFirstChild = true;
      }
      final AbstractElement w = (AbstractElement) assertNotNull(t.getPayload());
      w.alignElementAndChildren(cfg, leftSide, leftSide ? childrenX - w.getBlockSize().getWidth() : childrenX, currentY);
      currentY += w.getBlockSize().getHeight();
    }
  }
}
 
Example 15
Source File: BoardRenderer.java    From SproutLife with MIT License 4 votes vote down vote up
public void setBounds(Dimension2D d) {
    this.bounds = new Rectangle2D.Double(-20,-20,d.getWidth(),d.getHeight());
}
 
Example 16
Source File: JRXlsExporter.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
private InternalImageProcessorResult processImageRetainShape(DataRenderable renderer) throws JRException
{
	float normalWidth = availableImageWidth;
	float normalHeight = availableImageHeight;
	
	DimensionRenderable dimensionRenderer = imageRenderersCache.getDimensionRenderable((Renderable)renderer);
	Dimension2D dimension = dimensionRenderer == null ? null :  dimensionRenderer.getDimension(jasperReportsContext);
	if (dimension != null)
	{
		normalWidth = (int) dimension.getWidth();
		normalHeight = (int) dimension.getHeight();
	}
	
	float ratioX = 1f;
	float ratioY = 1f;

	int imageWidth = 0;
	int imageHeight = 0;
	
	int topOffset = 0;
	int leftOffset = 0;
	int bottomOffset = 0;
	int rightOffset = 0;

	short angle = 0;
	
	switch (imageElement.getRotation())
	{
		case LEFT:
			ratioX = availableImageWidth / normalHeight;
			ratioY = availableImageHeight / normalWidth;
			ratioX = ratioX < ratioY ? ratioX : ratioY;
			ratioY = ratioX;
			imageWidth = (int)(normalHeight * ratioX);
			imageHeight = (int)(normalWidth * ratioY);
			topOffset = (int) ((1f - ImageUtil.getXAlignFactor(imageElement)) * (availableImageHeight - imageHeight));
			leftOffset = (int) (ImageUtil.getYAlignFactor(imageElement) * (availableImageWidth - imageWidth));
			bottomOffset = (int) (ImageUtil.getXAlignFactor(imageElement) * (availableImageHeight - imageHeight));
			rightOffset = (int) ((1f - ImageUtil.getYAlignFactor(imageElement)) * (availableImageWidth - imageWidth));
			angle = -90;
			break;
		case RIGHT:
			ratioX = availableImageWidth / normalHeight;
			ratioY = availableImageHeight / normalWidth;
			ratioX = ratioX < ratioY ? ratioX : ratioY;
			ratioY = ratioX;
			imageWidth = (int)(normalHeight * ratioX);
			imageHeight = (int)(normalWidth * ratioY);
			topOffset = (int) (ImageUtil.getXAlignFactor(imageElement) * (availableImageHeight - imageHeight));
			leftOffset = (int) ((1f - ImageUtil.getYAlignFactor(imageElement)) * (availableImageWidth - imageWidth));
			bottomOffset = (int) ((1f - ImageUtil.getXAlignFactor(imageElement)) * (availableImageHeight - imageHeight));
			rightOffset = (int) (ImageUtil.getYAlignFactor(imageElement) * (availableImageWidth - imageWidth));
			angle = 90;
			break;
		case UPSIDE_DOWN:
			ratioX = availableImageWidth / normalWidth;
			ratioY = availableImageHeight / normalHeight;
			ratioX = ratioX < ratioY ? ratioX : ratioY;
			ratioY = ratioX;
			imageWidth = (int)(normalWidth * ratioX);
			imageHeight = (int)(normalHeight * ratioY);
			topOffset = (int) ((1f - ImageUtil.getYAlignFactor(imageElement)) * (availableImageHeight - imageHeight));
			leftOffset = (int) ((1f - ImageUtil.getXAlignFactor(imageElement)) * (availableImageWidth - imageWidth));
			bottomOffset = (int) (ImageUtil.getYAlignFactor(imageElement) * (availableImageHeight - imageHeight));
			rightOffset = (int) (ImageUtil.getXAlignFactor(imageElement) * (availableImageWidth - imageWidth));
			angle = 180;
			break;
		case NONE:
		default:
			ratioX = availableImageWidth / normalWidth;
			ratioY = availableImageHeight / normalHeight;
			ratioX = ratioX < ratioY ? ratioX : ratioY;
			ratioY = ratioX;
			imageWidth = (int)(normalWidth * ratioX);
			imageHeight = (int)(normalHeight * ratioY);
			topOffset = (int) (ImageUtil.getYAlignFactor(imageElement) * (availableImageHeight - imageHeight));
			leftOffset = (int) (ImageUtil.getXAlignFactor(imageElement) * (availableImageWidth - imageWidth));
			bottomOffset = (int) ((1f - ImageUtil.getYAlignFactor(imageElement)) * (availableImageHeight - imageHeight));
			rightOffset = (int) ((1f - ImageUtil.getXAlignFactor(imageElement)) * (availableImageWidth - imageWidth));
			angle = 0;
			break;
	}
	
	return 
		new InternalImageProcessorResult(
			renderer.getData(jasperReportsContext), 
			topOffset, 
			leftOffset, 
			bottomOffset, 
			rightOffset,
			angle
			);
}
 
Example 17
Source File: JRXlsMetadataExporter.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
private InternalImageProcessorResult processImageRetainShape(DataRenderable renderer) throws JRException
{
	float normalWidth = availableImageWidth;
	float normalHeight = availableImageHeight;

	DimensionRenderable dimensionRenderer = imageRenderersCache.getDimensionRenderable((Renderable)renderer);
	Dimension2D dimension = dimensionRenderer == null ? null :  dimensionRenderer.getDimension(jasperReportsContext);
	if (dimension != null) {
		normalWidth = (int) dimension.getWidth();
		normalHeight = (int) dimension.getHeight();
	}

	float ratioX = 1f;
	float ratioY = 1f;

	int imageWidth = 0;
	int imageHeight = 0;
	
	int topOffset = 0;
	int leftOffset = 0;
	int bottomOffset = 0;
	int rightOffset = 0;

	short angle = 0;
	
	switch (imageElement.getRotation())
	{
		case LEFT:
			ratioX = availableImageWidth / normalHeight;
			ratioY = availableImageHeight / normalWidth;
			ratioX = ratioX < ratioY ? ratioX : ratioY;
			ratioY = ratioX;
			imageWidth = (int)(normalHeight * ratioX);
			imageHeight = (int)(normalWidth * ratioY);
			topOffset = (int) ((1f - ImageUtil.getXAlignFactor(imageElement)) * (availableImageHeight - imageHeight));
			leftOffset = (int) (ImageUtil.getYAlignFactor(imageElement) * (availableImageWidth - imageWidth));
			bottomOffset = (int) (ImageUtil.getXAlignFactor(imageElement) * (availableImageHeight - imageHeight));
			rightOffset = (int) ((1f - ImageUtil.getYAlignFactor(imageElement)) * (availableImageWidth - imageWidth));
			angle = -90;
			break;
		case RIGHT:
			ratioX = availableImageWidth / normalHeight;
			ratioY = availableImageHeight / normalWidth;
			ratioX = ratioX < ratioY ? ratioX : ratioY;
			ratioY = ratioX;
			imageWidth = (int)(normalHeight * ratioX);
			imageHeight = (int)(normalWidth * ratioY);
			topOffset = (int) (ImageUtil.getXAlignFactor(imageElement) * (availableImageHeight - imageHeight));
			leftOffset = (int) ((1f - ImageUtil.getYAlignFactor(imageElement)) * (availableImageWidth - imageWidth));
			bottomOffset = (int) ((1f - ImageUtil.getXAlignFactor(imageElement)) * (availableImageHeight - imageHeight));
			rightOffset = (int) (ImageUtil.getYAlignFactor(imageElement) * (availableImageWidth - imageWidth));
			angle = 90;
			break;
		case UPSIDE_DOWN:
			ratioX = availableImageWidth / normalWidth;
			ratioY = availableImageHeight / normalHeight;
			ratioX = ratioX < ratioY ? ratioX : ratioY;
			ratioY = ratioX;
			imageWidth = (int)(normalWidth * ratioX);
			imageHeight = (int)(normalHeight * ratioY);
			topOffset = (int) ((1f - ImageUtil.getYAlignFactor(imageElement)) * (availableImageHeight - imageHeight));
			leftOffset = (int) ((1f - ImageUtil.getXAlignFactor(imageElement)) * (availableImageWidth - imageWidth));
			bottomOffset = (int) (ImageUtil.getYAlignFactor(imageElement) * (availableImageHeight - imageHeight));
			rightOffset = (int) (ImageUtil.getXAlignFactor(imageElement) * (availableImageWidth - imageWidth));
			angle = 180;
			break;
		case NONE:
		default:
			ratioX = availableImageWidth / normalWidth;
			ratioY = availableImageHeight / normalHeight;
			ratioX = ratioX < ratioY ? ratioX : ratioY;
			ratioY = ratioX;
			imageWidth = (int)(normalWidth * ratioX);
			imageHeight = (int)(normalHeight * ratioY);
			topOffset = (int) (ImageUtil.getYAlignFactor(imageElement) * (availableImageHeight - imageHeight));
			leftOffset = (int) (ImageUtil.getXAlignFactor(imageElement) * (availableImageWidth - imageWidth));
			bottomOffset = (int) ((1f - ImageUtil.getYAlignFactor(imageElement)) * (availableImageHeight - imageHeight));
			rightOffset = (int) ((1f - ImageUtil.getXAlignFactor(imageElement)) * (availableImageWidth - imageWidth));
			angle = 0;
			break;
	}
	
	return 
		new InternalImageProcessorResult(
			renderer.getData(jasperReportsContext), 
			topOffset, 
			leftOffset, 
			bottomOffset, 
			rightOffset,
			angle
			);
}
 
Example 18
Source File: AbstractRenderToImageDataRenderer.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public byte[] getData(JasperReportsContext jasperReportsContext) throws JRException
{
	Dimension2D dimension = getDimension(jasperReportsContext);
	
	if (dimension == null)
	{
		throw 
			new JRException(
				EXCEPTION_MESSAGE_KEY_DIMENSION_NULL_NOT_ALLOWED, 
				(Object[])null
				);
	}

	int dpi = getImageDataDPI(jasperReportsContext);
	double scale = dpi/72d;
	
	BufferedImage bi =
		new BufferedImage(
			(int) (scale * dimension.getWidth()),
			(int) (scale * dimension.getHeight()),
			BufferedImage.TYPE_INT_ARGB // always produce PNGs with transparency
			);

	Graphics2D g = createGraphics(bi);
	try
	{
		g.scale(scale, scale);
		Color backcolor = getBackcolor();
		if (backcolor != null)
		{
			g.setColor(backcolor);
			g.fillRect(0, 0, (int)dimension.getWidth(), (int)dimension.getHeight());
		}
		render(jasperReportsContext, g, new Rectangle((int)dimension.getWidth(), (int)dimension.getHeight()));
	}
	finally
	{
		g.dispose();
	}
	
	return JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(bi, ImageTypeEnum.PNG); // always produce PNGs with transparency
}
 
Example 19
Source File: Fit2D.java    From orson-charts with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Fits a rectangle of the specified dimension to the target rectangle,
 * aligning and scaling according to the attributes of this instance.
 * 
 * @param srcDim  the dimensions of the source rectangle ({@code null}
 *     not permitted).
 * @param target  the target rectangle ({@code null} not permitted).
 * 
 * @return The bounds of the fitted rectangle (never {@code null}). 
 */
public Rectangle2D fit(Dimension2D srcDim, Rectangle2D target) {
    Rectangle2D result = new Rectangle2D.Double();
    if (this.scale == Scale2D.SCALE_BOTH) {
        result.setFrame(target);
        return result;
    }
    double width = srcDim.getWidth();
    if (this.scale == Scale2D.SCALE_HORIZONTAL) {
        width = target.getWidth();
        if (!this.anchor.getRefPt().isHorizontalCenter()) {
            width -= 2 * this.anchor.getOffset().getDX();
        }
    }
    double height = srcDim.getHeight();
    if (this.scale == Scale2D.SCALE_VERTICAL) {
        height = target.getHeight();
        if (!this.anchor.getRefPt().isVerticalCenter()) {
            height -= 2 * this.anchor.getOffset().getDY();
        }
    }
    Point2D pt = this.anchor.getAnchorPoint(target);
    double x = Double.NaN; 
    if (this.anchor.getRefPt().isLeft()) {
        x = pt.getX();
    } else if (this.anchor.getRefPt().isHorizontalCenter()) {
        x = target.getCenterX() - width / 2;
    } else if (this.anchor.getRefPt().isRight()) {
        x = pt.getX() - width;
    }
    double y = Double.NaN;
    if (this.anchor.getRefPt().isTop()) {
        y = pt.getY();
    } else if (this.anchor.getRefPt().isVerticalCenter()) {
        y = target.getCenterY() - height / 2;
    } else if (this.anchor.getRefPt().isBottom()) {
        y = pt.getY() - height;
    }
    result.setRect(x, y, width, height);
    return result;
}
 
Example 20
Source File: SECWebRenderer.java    From mil-sym-java with Apache License 2.0 3 votes vote down vote up
/**
 * Given a symbol code meant for a single point symbol, returns the
 * anchor point at which to display that image based off the image returned
 * from the URL of the SinglePointServer.
 *
 * @param symbolID - the 15 character symbolID of a single point MilStd2525
 * symbol.
 * @return A pixel coordinate of the format "anchorX,anchorY,SymbolBoundsX,
 * SymbolBoundsY,SymbolBoundsWidth,SymbolBoundsHeight,IconWidth,IconHeight".
 * Anchor, represents the center point of the core symbol within the image.
 * The image should be centered on this point.
 * Symbol bounds represents the bounding rectangle of the core symbol within
 * the image.
 * IconWidth/Height represents the height and width of the image in its
 * entirety.
 * Returns an empty string if an error occurs.
 */
public String getSinglePointInfo(String symbolID)
{
    String info = "";
    Point2D anchor = new Point2D.Double();
    Rectangle2D symbolBounds = new Rectangle2D.Double();
    Dimension2D iconSize = new Dimension();
    sps.getSinglePointDimensions(symbolID, anchor, symbolBounds, iconSize);
    info = anchor.getX() + "," + anchor.getY() + "," +
            symbolBounds.getX() + "," + symbolBounds.getY() + "," +
            symbolBounds.getWidth() + "," + symbolBounds.getHeight() + "," + 
            iconSize.getWidth() + "," + iconSize.getHeight();
    return info;
}