Java Code Examples for java.awt.geom.NoninvertibleTransformException

The following examples show how to use java.awt.geom.NoninvertibleTransformException. These examples are extracted from open source projects. 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 Project: darklaf   Source File: ColorTriangle.java    License: MIT License 6 votes vote down vote up
public void createShapes(final float x, final float y, final int size) {
    int outerSize = 15;
    AffineTransform rotationTransform = AffineTransform.getRotateInstance(rotation, centerX, centerY);

    circleShape = calculateCircleShape(x, y, size, outerSize);
    triangleShape = calculateTriangleShape(x, y, size, outerSize, rotationTransform);
    outerIndicator = createOuterIndicator(centerX, centerY, (innerRadius + outerRadius) / 2.0,
                                          rotationTransform, outerIndicatorRadius);
    innerIndicator = createInnerIndicator(rotationTransform, innerIndicatorRadius);

    invalid = false;
    try {
        // For calculating pick location. MouseEvents already respect the ui scaling.
        triangleInverse = rotationTransform.createInverse();
    } catch (NoninvertibleTransformException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source Project: darklaf   Source File: ColorTriangle.java    License: MIT License 6 votes vote down vote up
@Override
public Raster getRaster(final int x, final int y, final int w, final int h) {
    WritableRaster raster = getColorModel().createCompatibleWritableRaster(w, h);
    for (int j = 0; j < h; j++) {
        for (int i = 0; i < w; i++) {
            dummy.setLocation((x + i), (y + j));
            try {
                transform.inverseTransform(dummy, dummy);
                triangleInverse.transform(dummy, dummy);
                Point2D sv = getSaturationAndValue(dummy.getX(), dummy.getY());
                setPixel(raster, i, j, getColorRGB(getHue(), sv.getX(), sv.getY()));
            } catch (NoninvertibleTransformException ignored) {}
        }
    }
    return raster;
}
 
Example 3
Source Project: jdk8u-jdk   Source File: AttributeValues.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static AffineTransform extractRotation(Point2D.Double pt,
    AffineTransform tx, boolean andTranslation) {

    tx.deltaTransform(pt, pt);
    AffineTransform rtx = AffineTransform.getRotateInstance(pt.x, pt.y);

    try {
        AffineTransform rtxi = rtx.createInverse();
        double dx = tx.getTranslateX();
        double dy = tx.getTranslateY();
        tx.preConcatenate(rtxi);
        if (andTranslation) {
            if (dx != 0 || dy != 0) {
                tx.setTransform(tx.getScaleX(), tx.getShearY(),
                                tx.getShearX(), tx.getScaleY(), 0, 0);
                rtx.setTransform(rtx.getScaleX(), rtx.getShearY(),
                                 rtx.getShearX(), rtx.getScaleY(), dx, dy);
            }
        }
    }
    catch (NoninvertibleTransformException e) {
        return null;
    }
    return rtx;
}
 
Example 4
/**
 * Change the dtx for the strike refs we use.  Keeps a reference to the at.  At
 * must not contain translation.
 * Called by setRenderTransform, setDTX, initFontData.
 */
private final void resetDTX(AffineTransform at) {
    fsref = null;
    dtx = at;
    invdtx = null;
    if (!dtx.isIdentity()) {
        try {
            invdtx = dtx.createInverse();
        }
        catch (NoninvertibleTransformException e) {
            // we needn't care for rendering
        }
    }
    if (gti != null) {
        gti.strikesRef = null;
    }
}
 
Example 5
private static AffineTransform extractRotation(Point2D.Double pt,
    AffineTransform tx, boolean andTranslation) {

    tx.deltaTransform(pt, pt);
    AffineTransform rtx = AffineTransform.getRotateInstance(pt.x, pt.y);

    try {
        AffineTransform rtxi = rtx.createInverse();
        double dx = tx.getTranslateX();
        double dy = tx.getTranslateY();
        tx.preConcatenate(rtxi);
        if (andTranslation) {
            if (dx != 0 || dy != 0) {
                tx.setTransform(tx.getScaleX(), tx.getShearY(),
                                tx.getShearX(), tx.getScaleY(), 0, 0);
                rtx.setTransform(rtx.getScaleX(), rtx.getShearY(),
                                 rtx.getShearX(), rtx.getScaleY(), dx, dy);
            }
        }
    }
    catch (NoninvertibleTransformException e) {
        return null;
    }
    return rtx;
}
 
Example 6
/**
 * !!! not used currently, but might be by getPixelbounds?
 */
public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) {
    if (renderFRC == null) {
        renderFRC = frc;
    }

    // it is a total pain that you have to copy the transform.

    AffineTransform at = renderFRC.getTransform();
    at.transform(loc, loc);
    pxResult.x = (int)loc.getX(); // but must not behave oddly around zero
    pxResult.y = (int)loc.getY();
    loc.setLocation(pxResult.x, pxResult.y);
    try {
        at.inverseTransform(loc, loc);
    }
    catch (NoninvertibleTransformException e) {
        throw new IllegalArgumentException("must be able to invert frc transform");
    }
}
 
Example 7
/**
 * Change the dtx for the strike refs we use.  Keeps a reference to the at.  At
 * must not contain translation.
 * Called by setRenderTransform, setDTX, initFontData.
 */
private final void resetDTX(AffineTransform at) {
    fsref = null;
    dtx = at;
    invdtx = null;
    if (!dtx.isIdentity()) {
        try {
            invdtx = dtx.createInverse();
        }
        catch (NoninvertibleTransformException e) {
            // we needn't care for rendering
        }
    }
    if (gti != null) {
        gti.strikesRef = null;
    }
}
 
Example 8
Source Project: pumpernickel   Source File: AbstractGraphics2D.java    License: MIT License 6 votes vote down vote up
@Override
public Shape getClip() {
	if (clipping == null)
		return null;

	try {
		Area area = new Area(clipping);
		area.transform(transform.createInverse());
		if (area.isRectangular())
			return area.getBounds2D();
		return area;
	} catch (NoninvertibleTransformException t) {
		RuntimeException e2 = new RuntimeException();
		e2.initCause(t);
		throw e2;
	}
}
 
Example 9
/**
 * Change the dtx for the strike refs we use.  Keeps a reference to the at.  At
 * must not contain translation.
 * Called by setRenderTransform, setDTX, initFontData.
 */
private final void resetDTX(AffineTransform at) {
    fsref = null;
    dtx = at;
    invdtx = null;
    if (!dtx.isIdentity()) {
        try {
            invdtx = dtx.createInverse();
        }
        catch (NoninvertibleTransformException e) {
            // we needn't care for rendering
        }
    }
    if (gti != null) {
        gti.strikesRef = null;
    }
}
 
Example 10
/**
 * !!! not used currently, but might be by getPixelbounds?
 */
public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) {
    if (renderFRC == null) {
        renderFRC = frc;
    }

    // it is a total pain that you have to copy the transform.

    AffineTransform at = renderFRC.getTransform();
    at.transform(loc, loc);
    pxResult.x = (int)loc.getX(); // but must not behave oddly around zero
    pxResult.y = (int)loc.getY();
    loc.setLocation(pxResult.x, pxResult.y);
    try {
        at.inverseTransform(loc, loc);
    }
    catch (NoninvertibleTransformException e) {
        throw new IllegalArgumentException("must be able to invert frc transform");
    }
}
 
Example 11
Source Project: jdk8u60   Source File: StandardGlyphVector.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Change the dtx for the strike refs we use.  Keeps a reference to the at.  At
 * must not contain translation.
 * Called by setRenderTransform, setDTX, initFontData.
 */
private final void resetDTX(AffineTransform at) {
    fsref = null;
    dtx = at;
    invdtx = null;
    if (!dtx.isIdentity()) {
        try {
            invdtx = dtx.createInverse();
        }
        catch (NoninvertibleTransformException e) {
            // we needn't care for rendering
        }
    }
    if (gti != null) {
        gti.strikesRef = null;
    }
}
 
Example 12
/**
 * !!! not used currently, but might be by getPixelbounds?
 */
public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) {
    if (renderFRC == null) {
        renderFRC = frc;
    }

    // it is a total pain that you have to copy the transform.

    AffineTransform at = renderFRC.getTransform();
    at.transform(loc, loc);
    pxResult.x = (int)loc.getX(); // but must not behave oddly around zero
    pxResult.y = (int)loc.getY();
    loc.setLocation(pxResult.x, pxResult.y);
    try {
        at.inverseTransform(loc, loc);
    }
    catch (NoninvertibleTransformException e) {
        throw new IllegalArgumentException("must be able to invert frc transform");
    }
}
 
Example 13
/**
 * !!! not used currently, but might be by getPixelbounds?
 */
public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) {
    if (renderFRC == null) {
        renderFRC = frc;
    }

    // it is a total pain that you have to copy the transform.

    AffineTransform at = renderFRC.getTransform();
    at.transform(loc, loc);
    pxResult.x = (int)loc.getX(); // but must not behave oddly around zero
    pxResult.y = (int)loc.getY();
    loc.setLocation(pxResult.x, pxResult.y);
    try {
        at.inverseTransform(loc, loc);
    }
    catch (NoninvertibleTransformException e) {
        throw new IllegalArgumentException("must be able to invert frc transform");
    }
}
 
Example 14
/**
 * Change the dtx for the strike refs we use.  Keeps a reference to the at.  At
 * must not contain translation.
 * Called by setRenderTransform, setDTX, initFontData.
 */
private final void resetDTX(AffineTransform at) {
    fsref = null;
    dtx = at;
    invdtx = null;
    if (!dtx.isIdentity()) {
        try {
            invdtx = dtx.createInverse();
        }
        catch (NoninvertibleTransformException e) {
            // we needn't care for rendering
        }
    }
    if (gti != null) {
        gti.strikesRef = null;
    }
}
 
Example 15
Source Project: jdk8u_jdk   Source File: AttributeValues.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static AffineTransform extractRotation(Point2D.Double pt,
    AffineTransform tx, boolean andTranslation) {

    tx.deltaTransform(pt, pt);
    AffineTransform rtx = AffineTransform.getRotateInstance(pt.x, pt.y);

    try {
        AffineTransform rtxi = rtx.createInverse();
        double dx = tx.getTranslateX();
        double dy = tx.getTranslateY();
        tx.preConcatenate(rtxi);
        if (andTranslation) {
            if (dx != 0 || dy != 0) {
                tx.setTransform(tx.getScaleX(), tx.getShearY(),
                                tx.getShearX(), tx.getScaleY(), 0, 0);
                rtx.setTransform(rtx.getScaleX(), rtx.getShearY(),
                                 rtx.getShearX(), rtx.getScaleY(), dx, dy);
            }
        }
    }
    catch (NoninvertibleTransformException e) {
        return null;
    }
    return rtx;
}
 
Example 16
/**
 * Change the dtx for the strike refs we use.  Keeps a reference to the at.  At
 * must not contain translation.
 * Called by setRenderTransform, setDTX, initFontData.
 */
private final void resetDTX(AffineTransform at) {
    fsref = null;
    dtx = at;
    invdtx = null;
    if (!dtx.isIdentity()) {
        try {
            invdtx = dtx.createInverse();
        }
        catch (NoninvertibleTransformException e) {
            // we needn't care for rendering
        }
    }
    if (gti != null) {
        gti.strikesRef = null;
    }
}
 
Example 17
/**
 * Change the dtx for the strike refs we use.  Keeps a reference to the at.  At
 * must not contain translation.
 * Called by setRenderTransform, setDTX, initFontData.
 */
private final void resetDTX(AffineTransform at) {
    fsref = null;
    dtx = at;
    invdtx = null;
    if (!dtx.isIdentity()) {
        try {
            invdtx = dtx.createInverse();
        }
        catch (NoninvertibleTransformException e) {
            // we needn't care for rendering
        }
    }
    if (gti != null) {
        gti.strikesRef = null;
    }
}
 
Example 18
Source Project: hottub   Source File: StandardGlyphVector.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * !!! not used currently, but might be by getPixelbounds?
 */
public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) {
    if (renderFRC == null) {
        renderFRC = frc;
    }

    // it is a total pain that you have to copy the transform.

    AffineTransform at = renderFRC.getTransform();
    at.transform(loc, loc);
    pxResult.x = (int)loc.getX(); // but must not behave oddly around zero
    pxResult.y = (int)loc.getY();
    loc.setLocation(pxResult.x, pxResult.y);
    try {
        at.inverseTransform(loc, loc);
    }
    catch (NoninvertibleTransformException e) {
        throw new IllegalArgumentException("must be able to invert frc transform");
    }
}
 
Example 19
Source Project: pumpernickel   Source File: CurvedPolylineCreationUI.java    License: MIT License 6 votes vote down vote up
private Selection getSelection(MouseEvent evt)
		throws NoninvertibleTransformException {
	ShapeCreationPanel scp = (ShapeCreationPanel) evt.getComponent();
	AffineTransform tx = scp.getTransform();
	double r = scp.getHandleSize() / 2;
	Point2D mouseLoc = new Point2D.Float(evt.getX(), evt.getY());
	CurvedPolyline[] shapes = getMirror(scp);
	for (int shapeIndex = 0; shapeIndex < shapes.length; shapeIndex++) {
		if (scp.getHandlesActive().supports(scp, shapeIndex)) {
			for (int b = shapes[shapeIndex].getPointCount() - 1; b >= 0; b--) {
				Point2D p = tx.transform(
						shapes[shapeIndex].getPoint(b), null);
				Ellipse2D e = new Ellipse2D.Double(p.getX() - r,
						p.getY() - r, 2 * r, 2 * r);
				if (e.contains(mouseLoc))
					return new Selection(shapeIndex, b, null);
			}
		}
	}
	return getSelectedShape(scp, evt.getPoint());
}
 
Example 20
/**
 * !!! not used currently, but might be by getPixelbounds?
 */
public void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult) {
    if (renderFRC == null) {
        renderFRC = frc;
    }

    // it is a total pain that you have to copy the transform.

    AffineTransform at = renderFRC.getTransform();
    at.transform(loc, loc);
    pxResult.x = (int)loc.getX(); // but must not behave oddly around zero
    pxResult.y = (int)loc.getY();
    loc.setLocation(pxResult.x, pxResult.y);
    try {
        at.inverseTransform(loc, loc);
    }
    catch (NoninvertibleTransformException e) {
        throw new IllegalArgumentException("must be able to invert frc transform");
    }
}
 
Example 21
Source Project: openstock   Source File: FXGraphics2D.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the user clipping region.  The initial default value is 
 * {@code null}.
 * 
 * @return The user clipping region (possibly {@code null}).
 * 
 * @see #setClip(java.awt.Shape)
 */
@Override
public Shape getClip() {
    if (this.clip == null) {
        return null;
    }
    AffineTransform inv;
    try {
        inv = this.transform.createInverse();
        return inv.createTransformedShape(this.clip);
    } catch (NoninvertibleTransformException ex) {
        return null;
    }
}
 
Example 22
Source Project: darklaf   Source File: MouseEventUI.java    License: MIT License 5 votes vote down vote up
private Point transformPoint(final JXLayer<? extends V> layer, final Point point) {
    AffineTransform transform = this.getTransform(layer);
    if (transform != null) {
        try {
            transform.inverseTransform(point, point);
        } catch (NoninvertibleTransformException e) {
            e.printStackTrace();
        }
    }
    return point;
}
 
Example 23
@Override
protected void saveTransformForUndo() {
  try {
    AffineTransform inverse = bufferedTransform.createInverse();
    bufferedFigure.willChange();
    bufferedFigure.transform(inverse);
    bufferedFigure.changed();
  }
  catch (NoninvertibleTransformException e) {
    LOG.warn("Exception inverting transform.", e);
  }
}
 
Example 24
Source Project: hottub   Source File: MultiGradientTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void updatePoints(int x, int y) {
    Point2D inv = new Point2D.Double(x, y);

    try {
        inv = transform.inverseTransform(inv, null);
    } catch (NoninvertibleTransformException e) {
        e.printStackTrace();
    }

    x = (int)inv.getX();
    y = (int)inv.getY();

    switch (paintType) {
    default:
    case BASIC:
    case LINEAR:
        // pick the closest point to move
        if (inv.distance(startX, startY) < inv.distance(endX, endY)) {
            startX = x;
            startY = y;
        } else {
            endX = x;
            endY = y;
        }
        break;

    case RADIAL:
        // pick the closest point to move
        if (inv.distance(ctrX, ctrY) < inv.distance(focusX, focusY)) {
            ctrX = x;
            ctrY = y;
        } else {
            focusX = x;
            focusY = y;
        }
        break;
    }

    updatePaint();
}
 
Example 25
TexturePaintContext(ColorModel cm, AffineTransform xform,
                    int bWidth, int bHeight, int maxw) {
    this.colorModel = getInternedColorModel(cm);
    this.bWidth = bWidth;
    this.bHeight = bHeight;
    this.maxWidth = maxw;

    try {
        xform = xform.createInverse();
    } catch (NoninvertibleTransformException e) {
        xform.setToScale(0, 0);
    }
    this.incXAcross = mod(xform.getScaleX(), bWidth);
    this.incYAcross = mod(xform.getShearY(), bHeight);
    this.incXDown = mod(xform.getShearX(), bWidth);
    this.incYDown = mod(xform.getScaleY(), bHeight);
    this.xOrg = xform.getTranslateX();
    this.yOrg = xform.getTranslateY();
    this.colincx = (int) incXAcross;
    this.colincy = (int) incYAcross;
    this.colincxerr = fractAsInt(incXAcross);
    this.colincyerr = fractAsInt(incYAcross);
    this.rowincx = (int) incXDown;
    this.rowincy = (int) incYDown;
    this.rowincxerr = fractAsInt(incXDown);
    this.rowincyerr = fractAsInt(incYDown);

}
 
Example 26
public Shape untransformShape(Shape s) {
    if (s == null) {
        return null;
    }
    if (transformState > TRANSFORM_INT_TRANSLATE) {
        try {
            return transformShape(transform.createInverse(), s);
        } catch (NoninvertibleTransformException e) {
            return null;
        }
    } else {
        return transformShape(-transX, -transY, s);
    }
}
 
Example 27
Source Project: coordination_oru   Source File: PathEditor2.java    License: GNU General Public License v3.0 5 votes vote down vote up
private Point2D getMousePositionInMap() {
	Point2D mousePositionInMap = null;
	AffineTransform geomToScreen = panel.getMapTransform();
	try {
		AffineTransform geomToScreenInv = geomToScreen.createInverse();
		mousePositionInMap = geomToScreenInv.transform(new Point2D.Double(panel.getMousePosition().x,panel.getMousePosition().y), null);
		//System.out.println(mousePosition);
	} catch (NoninvertibleTransformException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	return mousePositionInMap;
}
 
Example 28
public boolean pointToPath(Point2D pt, Point2D result) {
    result.setLocation(pt);
    if (tx != null) {
        try {
            tx.inverseTransform(pt, result);
        }
        catch (NoninvertibleTransformException ex) {
        }
    }
    return result.getX() > 0;
}
 
Example 29
TexturePaintContext(ColorModel cm, AffineTransform xform,
                    int bWidth, int bHeight, int maxw) {
    this.colorModel = getInternedColorModel(cm);
    this.bWidth = bWidth;
    this.bHeight = bHeight;
    this.maxWidth = maxw;

    try {
        xform = xform.createInverse();
    } catch (NoninvertibleTransformException e) {
        xform.setToScale(0, 0);
    }
    this.incXAcross = mod(xform.getScaleX(), bWidth);
    this.incYAcross = mod(xform.getShearY(), bHeight);
    this.incXDown = mod(xform.getShearX(), bWidth);
    this.incYDown = mod(xform.getScaleY(), bHeight);
    this.xOrg = xform.getTranslateX();
    this.yOrg = xform.getTranslateY();
    this.colincx = (int) incXAcross;
    this.colincy = (int) incYAcross;
    this.colincxerr = fractAsInt(incXAcross);
    this.colincyerr = fractAsInt(incYAcross);
    this.rowincx = (int) incXDown;
    this.rowincy = (int) incYDown;
    this.rowincxerr = fractAsInt(incXDown);
    this.rowincyerr = fractAsInt(incYDown);

}
 
Example 30
Source Project: dragonwell8_jdk   Source File: Test8004859.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args)
        throws NoninvertibleTransformException {
    final BufferedImage bi = new BufferedImage(300, 300,
                                               BufferedImage.TYPE_INT_RGB);
    final Graphics2D g = (Graphics2D) bi.getGraphics();
    test(g);
    g.translate(2.0, 2.0);
    test(g);
    g.translate(-4.0, -4.0);
    test(g);
    g.scale(2.0, 2.0);
    test(g);
    g.scale(-4.0, -4.0);
    test(g);
    g.rotate(Math.toRadians(90));
    test(g);
    g.rotate(Math.toRadians(90));
    test(g);
    g.rotate(Math.toRadians(90));
    test(g);
    g.rotate(Math.toRadians(90));
    test(g);
    g.dispose();
    if (!status) {
        throw new RuntimeException("Test failed");
    }
}