Java Code Examples for java.awt.geom.GeneralPath#getBounds()

The following examples show how to use java.awt.geom.GeneralPath#getBounds() . 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: AbstractSearchHighlight.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * Repositions this component.
 */
protected void nudge() {
	Point topLeft = SwingUtilities.convertPoint(highlightInfo.jc, 0, 0,
			layeredPane);

	GeneralPath path = new GeneralPath();
	path.moveTo(0, 0);
	path.lineTo(image.getWidth(), 0);
	path.lineTo(image.getWidth(), image.getHeight());
	path.lineTo(0, image.getHeight());
	path.closePath();

	AffineTransform transform = AffineTransform
			.getTranslateInstance(-imageCenter.x, -imageCenter.y);
	AffineTransform hTransform = (AffineTransform) getClientProperty(
			"transform");
	if (hTransform != null) {
		transform.concatenate(hTransform);
	}
	path.transform(transform);
	Rectangle bounds = path.getBounds();
	setBounds(center.x + topLeft.x - bounds.width / 2,
			center.y + topLeft.y - bounds.height / 2, bounds.width,
			bounds.height);
}
 
Example 2
Source File: CollocationCrsForm.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean accept(Product collocationProduct) {
    final Product referenceProduct = getReferenceProduct();
    if (referenceProduct == collocationProduct ||
        collocationProduct.getSceneGeoCoding() == null) {
        return false;
    }
    if (referenceProduct == null) {
        return true;
    }
    final GeoCoding geoCoding = collocationProduct.getSceneGeoCoding();
    if (geoCoding.canGetGeoPos() && geoCoding.canGetPixelPos() && (geoCoding instanceof CrsGeoCoding)) {
        final GeneralPath[] sourcePath = ProductUtils.createGeoBoundaryPaths(referenceProduct);
        final GeneralPath[] collocationPath = ProductUtils.createGeoBoundaryPaths(collocationProduct);
        for (GeneralPath path : sourcePath) {
            Rectangle bounds = path.getBounds();
            for (GeneralPath colPath : collocationPath) {
                if (colPath.getBounds().intersects(bounds)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 3
Source File: TransferMaskDialog.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private static boolean intersectsWith(Product sourceProduct, Product targetProduct) {
    final GeoCoding srcGC = sourceProduct.getSceneGeoCoding();
    final GeoCoding targetGC = targetProduct.getSceneGeoCoding();
    if (srcGC != null && srcGC.canGetGeoPos() && targetGC != null && targetGC.canGetGeoPos()) {
        final GeneralPath[] sourcePath = ProductUtils.createGeoBoundaryPaths(sourceProduct);
        final GeneralPath[] targetPath = ProductUtils.createGeoBoundaryPaths(targetProduct);
        for (GeneralPath spath : sourcePath) {
            Rectangle bounds = spath.getBounds();
            for (GeneralPath tPath : targetPath) {
                if (tPath.getBounds().intersects(bounds)) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 4
Source File: StarsTransition2D.java    From pumpernickel with MIT License 5 votes vote down vote up
protected void fit(GeneralPath p, float length, float centerX,
		float centerY, GeneralPath path, Dimension size, float progress) {
	Rectangle2D r = p.getBounds2D();
	AffineTransform t = new AffineTransform();
	t.translate(-r.getX() - r.getWidth() / 2, -r.getY() - r.getHeight() / 2);
	t.rotate((1 - progress) * 1);
	double scaleProgress = Math.pow(progress, 3) * .75f;
	t.scale(length / r.getWidth() * (.02 + 1.8 * scaleProgress),
			length / r.getWidth() * (.02 + 1.8 * scaleProgress));
	p.transform(t);

	if (progress > 1)
		progress = 1;
	if (progress < 0)
		progress = 0;
	Point2D endPoint = ShapeUtils.getPoint(path, 1);
	Point2D startPoint = ShapeUtils.getPoint(path, progress);
	Rectangle2D pathBounds = ShapeBounds.getBounds(path);
	AffineTransform pathTransform = RectangularTransform.create(pathBounds,
			new Rectangle2D.Float(0, 0, size.width + 100, size.height));
	pathTransform.transform(endPoint, endPoint);
	pathTransform.transform(startPoint, startPoint);
	r = p.getBounds();
	t.setToTranslation(-r.getCenterX() + centerX - endPoint.getX()
			+ startPoint.getX(),
			-r.getCenterY() + centerY - endPoint.getY() + startPoint.getY());

	p.transform(t);
}
 
Example 5
Source File: StarsTransition2D.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
protected static void fit(GeneralPath p, float length, float centerX, float centerY, GeneralPath path, Dimension size, float progress) {
    Rectangle2D r = p.getBounds2D();
    AffineTransform t = new AffineTransform();
    t.translate(-r.getX() - r.getWidth() / 2, -r.getY() - r.getHeight() / 2);
    t.rotate((1 - progress) * 1);
    double scaleProgress = Math.pow(progress, 3) * 0.75f;
    t.scale(length / r.getWidth() * (0.02 + 1.8 * scaleProgress), length / r
            .getWidth() * (0.02 + 1.8 * scaleProgress));
    p.transform(t);

    if (progress > 1) {
        progress = 1;
    }
    if (progress < 0) {
        progress = 0;
    }
    Point2D endPoint = ShapeUtils.getPoint(path, 1);
    Point2D startPoint = ShapeUtils.getPoint(path, progress);
    Rectangle2D pathBounds = ShapeBounds.getBounds(path);
    AffineTransform pathTransform = RectangularTransform.create(
            pathBounds,
            new Rectangle2D.Float(0, 0, size.width + 100, size.height)
    );
    pathTransform.transform(endPoint, endPoint);
    pathTransform.transform(startPoint, startPoint);
    r = p.getBounds();
    t.setToTranslation(-r.getCenterX() + centerX - endPoint.getX() + startPoint.getX(),
            -r.getCenterY() + centerY - endPoint.getY() + startPoint.getY());

    p.transform(t);
}
 
Example 6
Source File: GUIHex.java    From Rails with GNU General Public License v2.0 4 votes vote down vote up
private double getStrokeWidth(GeneralPath hexagon) {
    return ( 1 - getHexDrawScale() ) *
            ( hexagon.getBounds().width + hexagon.getBounds().height ) / 2;
}
 
Example 7
Source File: FreeForm.java    From dsworkbench with Apache License 2.0 4 votes vote down vote up
@Override
public void renderForm(Graphics2D g2d) {
    if (points.size() < 1) {
        return;
    }
    //store properties
    Stroke sBefore = g2d.getStroke();
    Color cBefore = g2d.getColor();
    Composite coBefore = g2d.getComposite();
    Font fBefore = g2d.getFont();
    //draw
    g2d.setStroke(getStroke());
    checkShowMode(g2d, drawColor);
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, drawAlpha));

    Point2D.Double pp = MapPanel.getSingleton().virtualPosToSceenPosDouble(points.get(0).getX(), points.get(0).getY());
    GeneralPath p = new GeneralPath();
    p.moveTo(pp.x, pp.y);
    for (int i = 1; i < points.size(); i++) {
        pp = MapPanel.getSingleton().virtualPosToSceenPosDouble(points.get(i).getX(), points.get(i).getY());
        p.lineTo(pp.x, pp.y);
    }
    java.awt.Rectangle mapBounds = MapPanel.getSingleton().getBounds();
    if (mapBounds.intersects(p.getBounds())) {
        setVisibleOnMap(true);
    } else {
        setVisibleOnMap(false);
        return;
    }
    if (filled) {
        g2d.fill(p);
    } else {
        g2d.draw(p);
    }

    if (drawName) {
        g2d.setColor(getTextColor());
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getTextAlpha()));
        g2d.setFont(fBefore.deriveFont((float) getTextSize()));
        Rectangle2D textBounds = g2d.getFontMetrics().getStringBounds(getFormName(), g2d);
        java.awt.Rectangle bounds = p.getBounds();
        g2d.drawString(getFormName(), (int) Math.rint(bounds.getX() + bounds.getWidth() / 2 - textBounds.getWidth() / 2), (int) Math.rint(bounds.getY() + bounds.getHeight() / 2 + textBounds.getHeight() / 2));
    }

    //restore properties
    g2d.setStroke(sBefore);
    g2d.setColor(cBefore);
    g2d.setComposite(coBefore);
    g2d.setFont(fBefore);
}
 
Example 8
Source File: FreeForm.java    From dsworkbench with Apache License 2.0 4 votes vote down vote up
public void renderPreview(Graphics2D g2d) {
    if (points.size() < 1) {
        return;
    }
    //store properties
    Stroke sBefore = g2d.getStroke();
    Color cBefore = g2d.getColor();
    Composite coBefore = g2d.getComposite();
    Font fBefore = g2d.getFont();
    //draw
    g2d.setStroke(getStroke());
    g2d.setColor(drawColor);
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, drawAlpha));

    GeneralPath p = new GeneralPath();
    Point2D.Double pp = points.get(0);
    p.moveTo(pp.x, pp.y);
    for (int i = 0; i <= points.size() - 1; i++) {
        pp = points.get(i);
        p.lineTo(pp.x, pp.y);
    }

    if (filled) {
        g2d.fill(p);
    } else {
        g2d.draw(p);
    }

    if (drawName) {
        g2d.setColor(getTextColor());
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getTextAlpha()));
        g2d.setFont(fBefore.deriveFont((float) getTextSize()));
        Rectangle2D textBounds = g2d.getFontMetrics().getStringBounds(getFormName(), g2d);
        java.awt.Rectangle bounds = p.getBounds();
        g2d.drawString(getFormName(), (int) Math.rint(bounds.getX() + bounds.getWidth() / 2 - textBounds.getWidth() / 2), (int) Math.rint(bounds.getY() + bounds.getHeight() / 2 + textBounds.getHeight() / 2));
    }
    g2d.setStroke(sBefore);
    g2d.setColor(cBefore);
    g2d.setComposite(coBefore);
    g2d.setFont(fBefore);
}
 
Example 9
Source File: CurvesPanel.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License votes vote down vote up
protected void drawCurve(Graphics2D g2,
            float y1, float y1_offset,
            float y2, float y2_offset,
            float cx1, float cx1_offset,
            float cy1, float cy1_offset,
            float cx2, float cx2_offset,
            float cy2, float cy2_offset,
            float thickness,
            float speed,
            boolean invert) {
        float width = getWidth();
       
        float offset = (float) Math.sin(counter / (speed * Math.PI));
        
        float start_x = 0.0f;
        float start_y = offset * y1_offset + y1;
        float end_x = width;
        float end_y = offset * y2_offset + y2;
        
        float ctrl1_x = offset * cx1_offset + cx1;
        float ctrl1_y = offset * cy1_offset + cy1;
        float ctrl2_x = offset * cx2_offset + cx2;
        float ctrl2_y = offset * cy2_offset + cy2;
       
        GeneralPath thickCurve = new GeneralPath();
        thickCurve.moveTo(start_x, start_y);
        thickCurve.curveTo(ctrl1_x, ctrl1_y,
                ctrl2_x, ctrl2_y,
                end_x, end_y);
        thickCurve.lineTo(end_x, end_y + thickness);
        thickCurve.curveTo(ctrl2_x, ctrl2_y + thickness,
                ctrl1_x, ctrl1_y + thickness,
                start_x, start_y + thickness);
        thickCurve.lineTo(start_x, start_y);
       
        Rectangle bounds = thickCurve.getBounds();
        if (!bounds.intersects(g2.getClipBounds())) {
            return;
        }
      
        GradientPaint painter = new GradientPaint(0, bounds.y,
                invert ? end : start,
                0, bounds.y + bounds.height,
                invert ? start : end);

        Paint oldPainter = g2.getPaint();
        g2.setPaint(painter);
        g2.fill(thickCurve);
       
        g2.setPaint(oldPainter);
    }