Java Code Examples for java.awt.geom.AffineTransform#setToIdentity()
The following examples show how to use
java.awt.geom.AffineTransform#setToIdentity() .
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: DefaultProcessDiagramCanvas.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
public void drawDefaultSequenceFlowIndicator(Line2D.Double line, double scaleFactor) { double length = DEFAULT_INDICATOR_WIDTH / scaleFactor, halfOfLength = length/2, f = 8; Line2D.Double defaultIndicator = new Line2D.Double(-halfOfLength, 0, halfOfLength, 0); double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); double dx = f * Math.cos(angle), dy = f * Math.sin(angle), x1 = line.x1 + dx, y1 = line.y1 + dy; AffineTransform transformation = new AffineTransform(); transformation.setToIdentity(); transformation.translate(x1, y1); transformation.rotate((angle - 3 * Math.PI / 4)); AffineTransform originalTransformation = g.getTransform(); g.setTransform(transformation); g.draw(defaultIndicator); g.setTransform(originalTransformation); }
Example 2
Source File: ProcessDiagramCanvas.java From maven-framework-project with MIT License | 6 votes |
public void drawArrowHead(Line2D.Double line) { int doubleArrowWidth = 2 * ARROW_WIDTH; Polygon arrowHead = new Polygon(); arrowHead.addPoint(0, 0); arrowHead.addPoint(-ARROW_WIDTH, -doubleArrowWidth); arrowHead.addPoint(ARROW_WIDTH, -doubleArrowWidth); AffineTransform transformation = new AffineTransform(); transformation.setToIdentity(); double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); transformation.translate(line.x2, line.y2); transformation.rotate((angle - Math.PI / 2d)); AffineTransform originalTransformation = g.getTransform(); g.setTransform(transformation); g.fill(arrowHead); g.setTransform(originalTransformation); }
Example 3
Source File: clsUtilityCPOF.java From mil-sym-java with Apache License 2.0 | 6 votes |
private static ShapeInfo BuildDummyShapeSpec() { ShapeInfo shape = new ShapeInfo(null); try { AffineTransform tx = new AffineTransform(); tx.setToIdentity(); GeneralPath gp = new GeneralPath(); shape.setLineColor(Color.WHITE); shape.setFillColor(null); shape.setStroke(new BasicStroke()); shape.setTexturePaint(null); gp.moveTo(-1000, -1000); gp.lineTo(-1001, -1001); shape.setShape(gp); shape.setAffineTransform(tx); } catch (Exception exc) { ErrorLogger.LogException(_className, "BuidDummyShapeSpec", new RendererException("Failed inside BuildDummyShapeSpec", exc)); } return shape; }
Example 4
Source File: MatrixTestCase.java From sis with Apache License 2.0 | 6 votes |
/** * Tests {@link MatrixSIS#convertAfter(int, Number, Number)} using {@link AffineTransform} * as a reference implementation. This test can be run only with matrices of size 3×3. * Consequently it is sub-classes responsibility to add a {@code testConvertAfter()} method * which invoke this method. * * @param matrix the matrix of size 3×3 to test. * * @since 0.6 */ final void testConvertAfter(final MatrixSIS matrix) { initialize(6501103578268988251L); final AffineTransform pre = new AffineTransform(); final AffineTransform at = AffineTransform.getShearInstance(nextNonZeroRandom(), nextNonZeroRandom()); matrix.setElement(0, 1, at.getShearX()); matrix.setElement(1, 0, at.getShearY()); for (int i=0; i<NUMBER_OF_REPETITIONS; i++) { final Number scale = nextNonZeroRandom(); final Number offset = nextNonZeroRandom(); final int tgtDim = (i & 1); switch (tgtDim) { default: pre.setToIdentity(); break; case 0: pre.setToTranslation(offset.doubleValue(), 0); pre.scale(scale.doubleValue(), 1); break; case 1: pre.setToTranslation(0, offset.doubleValue()); pre.scale(1, scale.doubleValue()); break; } at.preConcatenate(pre); matrix.convertAfter(tgtDim, scale, offset); assertCoefficientsEqual(at, matrix); } }
Example 5
Source File: VisualContact.java From workcraft with MIT License | 6 votes |
public AffineTransform getTransform() { AffineTransform result = new AffineTransform(); switch (this) { case WEST: result.quadrantRotate(2); break; case NORTH: result.quadrantRotate(3); break; case EAST: result.setToIdentity(); break; case SOUTH: result.quadrantRotate(1); break; } return result; }
Example 6
Source File: VdGroup.java From SVG-Android with Apache License 2.0 | 6 votes |
private void updateLocalMatrix() { // The order we apply is the same as the // RenderNode.cpp::applyViewPropertyTransforms(). mLocalMatrix.setToIdentity(); // In Android framework, the transformation is applied in // VectorDrawable.java VGroup::updateLocalMatrix() AffineTransform tempTrans = new AffineTransform(); tempTrans.setToIdentity(); tempTrans.translate(-mPivotX, -mPivotY); androidPostTransform(mLocalMatrix, tempTrans); tempTrans.setToIdentity(); tempTrans.scale(mScaleX, mScaleY); androidPostTransform(mLocalMatrix, tempTrans); tempTrans.setToIdentity(); tempTrans.rotate(mRotate * 3.1415926 / 180, 0, 0); androidPostTransform(mLocalMatrix, tempTrans); tempTrans.setToIdentity(); tempTrans.translate(mTranslateX + mPivotX, mTranslateY + mPivotY); androidPostTransform(mLocalMatrix, tempTrans); }
Example 7
Source File: ProcessDiagramCanvas.java From maven-framework-project with MIT License | 5 votes |
public void drawConditionalSequenceFlowIndicator(Line2D.Double line) { int horizontal = (int) (CONDITIONAL_INDICATOR_WIDTH * 0.7); int halfOfHorizontal = horizontal / 2; int halfOfVertical = CONDITIONAL_INDICATOR_WIDTH / 2; Polygon conditionalIndicator = new Polygon(); conditionalIndicator.addPoint(0, 0); conditionalIndicator.addPoint(-halfOfHorizontal, halfOfVertical); conditionalIndicator.addPoint(0, CONDITIONAL_INDICATOR_WIDTH); conditionalIndicator.addPoint(halfOfHorizontal, halfOfVertical); AffineTransform transformation = new AffineTransform(); transformation.setToIdentity(); double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); transformation.translate(line.x1, line.y1); transformation.rotate((angle - Math.PI / 2d)); AffineTransform originalTransformation = g.getTransform(); g.setTransform(transformation); g.draw(conditionalIndicator); Paint originalPaint = g.getPaint(); g.setPaint(CONDITIONAL_INDICATOR_COLOR); g.fill(conditionalIndicator); g.setPaint(originalPaint); g.setTransform(originalTransformation); }
Example 8
Source File: Shape2.java From mil-sym-java with Apache License 2.0 | 5 votes |
public Shape2(int value) { setShapeType(value); _Shape=new GeneralPath(); AffineTransform tx=new AffineTransform(); tx.setToIdentity(); Stroke stroke=new BasicStroke(); this.setStroke(stroke); this.setAffineTransform(tx); }
Example 9
Source File: ProcessDiagramCanvas.java From maven-framework-project with MIT License | 5 votes |
public void drawConditionalSequenceFlowIndicator(Line2D.Double line) { int horizontal = (int) (CONDITIONAL_INDICATOR_WIDTH * 0.7); int halfOfHorizontal = horizontal / 2; int halfOfVertical = CONDITIONAL_INDICATOR_WIDTH / 2; Polygon conditionalIndicator = new Polygon(); conditionalIndicator.addPoint(0, 0); conditionalIndicator.addPoint(-halfOfHorizontal, halfOfVertical); conditionalIndicator.addPoint(0, CONDITIONAL_INDICATOR_WIDTH); conditionalIndicator.addPoint(halfOfHorizontal, halfOfVertical); AffineTransform transformation = new AffineTransform(); transformation.setToIdentity(); double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); transformation.translate(line.x1, line.y1); transformation.rotate((angle - Math.PI / 2d)); AffineTransform originalTransformation = g.getTransform(); g.setTransform(transformation); g.draw(conditionalIndicator); Paint originalPaint = g.getPaint(); g.setPaint(CONDITIONAL_INDICATOR_COLOR); g.fill(conditionalIndicator); g.setPaint(originalPaint); g.setTransform(originalTransformation); }
Example 10
Source File: DefaultCaseDiagramCanvas.java From flowable-engine with Apache License 2.0 | 5 votes |
public void drawArrowHead(Line2D.Double line, double scaleFactor) { int doubleArrowWidth = (int) (2 * ARROW_WIDTH / scaleFactor); if (doubleArrowWidth == 0) { doubleArrowWidth = 2; } Polygon arrowHead = new Polygon(); arrowHead.addPoint(0, 0); int arrowHeadPoint = (int) (-ARROW_WIDTH / scaleFactor); if (arrowHeadPoint == 0) { arrowHeadPoint = -1; } arrowHead.addPoint(arrowHeadPoint, -doubleArrowWidth); arrowHeadPoint = (int) (ARROW_WIDTH / scaleFactor); if (arrowHeadPoint == 0) { arrowHeadPoint = 1; } arrowHead.addPoint(arrowHeadPoint, -doubleArrowWidth); AffineTransform transformation = new AffineTransform(); transformation.setToIdentity(); double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); transformation.translate(line.x2, line.y2); transformation.rotate((angle - Math.PI / 2d)); AffineTransform originalTransformation = g.getTransform(); g.setTransform(transformation); g.fill(arrowHead); g.setTransform(originalTransformation); }
Example 11
Source File: DefaultProcessDiagramCanvas.java From flowable-engine with Apache License 2.0 | 5 votes |
public void drawPoolOrLane(String name, GraphicInfo graphicInfo, double scaleFactor) { int x = (int) graphicInfo.getX(); int y = (int) graphicInfo.getY(); int width = (int) graphicInfo.getWidth(); int height = (int) graphicInfo.getHeight(); g.drawRect(x, y, width, height); // Add the name as text, vertical if (scaleFactor == 1.0 && name != null && name.length() > 0) { // Include some padding int availableTextSpace = height - 6; // Create rotation for derived font AffineTransform transformation = new AffineTransform(); transformation.setToIdentity(); transformation.rotate(270 * Math.PI / 180); Font currentFont = g.getFont(); Font theDerivedFont = currentFont.deriveFont(transformation); g.setFont(theDerivedFont); String truncated = fitTextToWidth(name, availableTextSpace); int realWidth = fontMetrics.stringWidth(truncated); g.drawString(truncated, x + 2 + fontMetrics.getHeight(), 3 + y + availableTextSpace - (availableTextSpace - realWidth) / 2); g.setFont(currentFont); } }
Example 12
Source File: DefaultProcessDiagramCanvas.java From flowable-engine with Apache License 2.0 | 5 votes |
public void drawConditionalSequenceFlowIndicator(Line2D.Double line, double scaleFactor) { if (scaleFactor > 1.0) return; int horizontal = (int) (CONDITIONAL_INDICATOR_WIDTH * 0.7); int halfOfHorizontal = horizontal / 2; int halfOfVertical = CONDITIONAL_INDICATOR_WIDTH / 2; Polygon conditionalIndicator = new Polygon(); conditionalIndicator.addPoint(0, 0); conditionalIndicator.addPoint(-halfOfHorizontal, halfOfVertical); conditionalIndicator.addPoint(0, CONDITIONAL_INDICATOR_WIDTH); conditionalIndicator.addPoint(halfOfHorizontal, halfOfVertical); AffineTransform transformation = new AffineTransform(); transformation.setToIdentity(); double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); transformation.translate(line.x1, line.y1); transformation.rotate((angle - Math.PI / 2d)); AffineTransform originalTransformation = g.getTransform(); g.setTransform(transformation); g.draw(conditionalIndicator); Paint originalPaint = g.getPaint(); g.setPaint(CONDITIONAL_INDICATOR_COLOR); g.fill(conditionalIndicator); g.setPaint(originalPaint); g.setTransform(originalTransformation); }
Example 13
Source File: AbstractShapeTransition2D.java From pumpernickel with MIT License | 5 votes |
@Override public Transition2DInstruction[] getInstructions(float progress, Dimension size) { Number multiplier = multipliers.get(size); if (multiplier == null) { multiplier = new Float(calculateMultiplier(size)); multipliers.put(size, multiplier); } if (type == IN) { progress = 1 - progress; } Shape clipping = getShape(); Rectangle2D r = ShapeBounds.getBounds(clipping); AffineTransform transform = new AffineTransform(); transform.setToIdentity(); transform.translate(size.width / 2, size.height / 2); transform.scale(progress * multiplier.floatValue(), progress * multiplier.floatValue()); transform.translate(-size.width / 2, -size.height / 2); transform.translate(-r.getCenterX() + size.width / 2f, -r.getCenterY() + size.height / 2f); clipping = transform.createTransformedShape(clipping); return new Transition2DInstruction[] { new ImageInstruction(type == OUT), new ImageInstruction(type != OUT, null, clipping) }; }
Example 14
Source File: TestRotateMethods.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static AffineTransform makeQuadAT(Mode mode, Point2D txpt, int quads) { AffineTransform at; double tx = (txpt == null) ? 0.0 : txpt.getX(); double ty = (txpt == null) ? 0.0 : txpt.getY(); switch (mode) { case GET: if (txpt != null) { at = AffineTransform.getQuadrantRotateInstance(quads, tx, ty); } else { at = AffineTransform.getQuadrantRotateInstance(quads); } break; case SET: at = makeRandomAT(); if (txpt != null) { at.setToQuadrantRotation(quads, tx, ty); } else { at.setToQuadrantRotation(quads); } break; case MOD: at = makeRandomAT(); at.setToIdentity(); if (txpt != null) { at.quadrantRotate(quads, tx, ty); } else { at.quadrantRotate(quads); } break; default: throw new InternalError("unrecognized mode: "+mode); } return at; }
Example 15
Source File: TestRotateMethods.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static AffineTransform makeAT(Mode mode, Point2D txpt, double vx, double vy) { AffineTransform at; double tx = (txpt == null) ? 0.0 : txpt.getX(); double ty = (txpt == null) ? 0.0 : txpt.getY(); switch (mode) { case GET: if (txpt != null) { at = AffineTransform.getRotateInstance(vx, vy, tx, ty); } else { at = AffineTransform.getRotateInstance(vx, vy); } break; case SET: at = makeRandomAT(); if (txpt != null) { at.setToRotation(vx, vy, tx, ty); } else { at.setToRotation(vx, vy); } break; case MOD: at = makeRandomAT(); at.setToIdentity(); if (txpt != null) { at.rotate(vx, vy, tx, ty); } else { at.rotate(vx, vy); } break; default: throw new InternalError("unrecognized mode: "+mode); } return at; }
Example 16
Source File: TestRotateMethods.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static AffineTransform makeAT(Mode mode, Point2D txpt, double radians) { AffineTransform at; double tx = (txpt == null) ? 0.0 : txpt.getX(); double ty = (txpt == null) ? 0.0 : txpt.getY(); switch (mode) { case GET: if (txpt != null) { at = AffineTransform.getRotateInstance(radians, tx, ty); } else { at = AffineTransform.getRotateInstance(radians); } break; case SET: at = makeRandomAT(); if (txpt != null) { at.setToRotation(radians, tx, ty); } else { at.setToRotation(radians); } break; case MOD: at = makeRandomAT(); at.setToIdentity(); if (txpt != null) { at.rotate(radians, tx, ty); } else { at.rotate(radians); } break; default: throw new InternalError("unrecognized mode: "+mode); } return at; }
Example 17
Source File: DefaultProcessDiagramCanvas.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void drawPoolOrLane(String name, GraphicInfo graphicInfo) { int x = (int) graphicInfo.getX(); int y = (int) graphicInfo.getY(); int width = (int) graphicInfo.getWidth(); int height = (int) graphicInfo.getHeight(); g.drawRect(x, y, width, height); // Add the name as text, vertical if(name != null && name.length() > 0) { // Include some padding int availableTextSpace = height - 6; // Create rotation for derived font AffineTransform transformation = new AffineTransform(); transformation.setToIdentity(); transformation.rotate(270 * Math.PI/180); Font currentFont = g.getFont(); Font theDerivedFont = currentFont.deriveFont(transformation); g.setFont(theDerivedFont); String truncated = fitTextToWidth(name, availableTextSpace); int realWidth = fontMetrics.stringWidth(truncated); g.drawString(truncated, x + 2 + fontMetrics.getHeight(), 3 + y + availableTextSpace - (availableTextSpace - realWidth) / 2); g.setFont(currentFont); } }
Example 18
Source File: DefaultProcessDiagramCanvas.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void drawConditionalSequenceFlowIndicator(Line2D.Double line, double scaleFactor) { if (scaleFactor > 1.0) return; int horizontal = (int) (CONDITIONAL_INDICATOR_WIDTH * 0.7); int halfOfHorizontal = horizontal / 2; int halfOfVertical = CONDITIONAL_INDICATOR_WIDTH / 2; Polygon conditionalIndicator = new Polygon(); conditionalIndicator.addPoint(0, 0); conditionalIndicator.addPoint(-halfOfHorizontal, halfOfVertical); conditionalIndicator.addPoint(0, CONDITIONAL_INDICATOR_WIDTH); conditionalIndicator.addPoint(halfOfHorizontal, halfOfVertical); AffineTransform transformation = new AffineTransform(); transformation.setToIdentity(); double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); transformation.translate(line.x1, line.y1); transformation.rotate((angle - Math.PI / 2d)); AffineTransform originalTransformation = g.getTransform(); g.setTransform(transformation); g.draw(conditionalIndicator); Paint originalPaint = g.getPaint(); g.setPaint(CONDITIONAL_INDICATOR_COLOR); g.fill(conditionalIndicator); g.setPaint(originalPaint); g.setTransform(originalTransformation); }
Example 19
Source File: clsUtilityGE.java From mil-sym-java with Apache License 2.0 | 4 votes |
/** * @deprecated * use cheap algorithm to expand polygons, works best on regular 4+ sided convex polygons * used primarily for expanding the original clipping areas. After clipping a tactical line against * the expanded clipping area, the original clipping area can be used to drop the clip lines * @param pts points to expand, usually a clipping area * @param expandX X expansion factor, e.g 10% growth would be 1.1 * @param expandY Y expansion factor * @return points for the expanded polygon */ protected static ArrayList<Point2D>expandPolygon2(ArrayList<Point2D>pts, double expandX, double expandY) { ArrayList<Point2D>lgPoly=null; try { AffineTransform at=new AffineTransform(); at.setToIdentity(); //get the center of the pts using an average double avgX=0,avgY=0,totalX=0,totalY=0; int j=0; boolean isClosed=false; //open the array, remove the last point if necessary if(pts.get(pts.size()-1).getX()==pts.get(0).getX() && pts.get(pts.size()-1).getY()==pts.get(0).getY()) { pts.remove(pts.size()-1); isClosed=true; } //asumes open array for(j=0;j<pts.size();j++) { totalX+=pts.get(j).getX(); totalY+=pts.get(j).getY(); } avgX=totalX/pts.size(); avgY=totalY/pts.size(); Point2D.Double[]srcPts=new Point2D.Double[pts.size()]; for(j=0;j<pts.size();j++) { srcPts[j]=new Point2D.Double(pts.get(j).getX(),pts.get(j).getY()); } Point2D[]destPts=new Point2D[pts.size()]; //translate the points to crcumscribe 0,0 at.translate(-avgY, -avgY);//ideally would be close to 0 at.transform(srcPts, 0, destPts, 0, srcPts.length); at.setToIdentity(); //scale the points by 10% at.scale(expandX, expandY); at.transform(destPts, 0, destPts, 0, destPts.length); at.setToIdentity(); at.translate(avgY, avgY); at.transform(destPts, 0, destPts, 0, destPts.length); lgPoly=new ArrayList<Point2D>(); for(j=0;j<destPts.length;j++) { lgPoly.add(destPts[j]); } //close the aray if the original clipping array was closed if(isClosed) lgPoly.add(new Point2D.Double(destPts[0].getX(),destPts[0].getY())); } catch (Exception exc) { ErrorLogger.LogException(_className, "expandPolygon", new RendererException("Failed inside expandPolygon", exc)); } return lgPoly; }
Example 20
Source File: VisualContact.java From workcraft with MIT License | 4 votes |
@Override public void draw(DrawRequest r) { Graphics2D g = r.getGraphics(); Decoration d = r.getDecoration(); Color colorisation = d.getColorisation(); Color fillColor = d.getBackground(); if (fillColor == null) { fillColor = getFillColor(); } AffineTransform savedTransform = g.getTransform(); AffineTransform rotateTransform = getDirection() != null ? getDirection().getTransform() : new AffineTransform(); if (isInput()) { rotateTransform.quadrantRotate(2); } g.transform(rotateTransform); boolean showContact = CircuitSettings.getShowContacts() || (d instanceof StateDecoration) || (d.getColorisation() != null) || (d.getBackground() != null); if (showContact || isPort()) { boolean showForcedInit = (d instanceof StateDecoration) && ((StateDecoration) d).showForcedInit(); Shape shape = showForcedInit && isForcedDriver() ? getForcedShape() : getShape(); float width = (float) CircuitSettings.getBorderWidth(); g.setStroke(new BasicStroke(width)); g.setColor(fillColor); g.fill(shape); g.setColor(ColorUtils.colorise(getForegroundColor(), colorisation)); g.draw(shape); } else if (r.getModel().getConnections(this).size() > 1) { g.setColor(ColorUtils.colorise(getForegroundColor(), colorisation)); g.fill(VisualJoint.shape); } if (!(getParent() instanceof VisualCircuitComponent)) { g.setTransform(savedTransform); rotateTransform.setToIdentity(); if (getDirection() == Direction.NORTH || getDirection() == Direction.SOUTH) { rotateTransform.quadrantRotate(-1); } g.transform(rotateTransform); drawNameInLocalSpace(r); } g.setTransform(savedTransform); d.decorate(g); }