/** * @return true iff this transform is the identity transform */ public boolean isIdentity() { return isIdentity(transformParameters); }
/** * Composes an <code>AffineTransform</code> object with the * <code>Transform</code> in this <code>Graphics2D</code> according * to the rule last-specified-first-applied. If the current * <code>Transform</code> is Cx, the result of composition * with Tx is a new <code>Transform</code> Cx'. Cx' becomes the * current <code>Transform</code> for this <code>Graphics2D</code>. * Transforming a point p by the updated <code>Transform</code> Cx' is * equivalent to first transforming p by Tx and then transforming * the result by the original <code>Transform</code> Cx. In other * words, Cx'(p) = Cx(Tx(p)). A copy of the Tx is made, if necessary, * so further modifications to Tx do not affect rendering. * @param Tx the <code>AffineTransform</code> object to be composed with * the current <code>Transform</code> * @see #setTransform * @see AffineTransform */ public void transform(AffineTransform Tx){ transform.concatenate(Tx); transformStack.add(TransformStackElement.createGeneralTransformElement(Tx)); }
/** * Concatenates the current <code>Graphics2D</code> * <code>Transform</code> with a translated rotation * transform. Subsequent rendering is transformed by a transform * which is constructed by translating to the specified location, * rotating by the specified radians, and translating back by the same * amount as the original translation. This is equivalent to the * following sequence of calls: * <pre> * translate(x, y); * rotate(theta); * translate(-x, -y); * </pre> * Rotating with a positive angle theta rotates points on the positive * x axis toward the positive y axis. * @param theta the angle of rotation in radians * @param x x coordinate of the origin of the rotation * @param y y coordinate of the origin of the rotation */ public void rotate(double theta, double x, double y){ transform.rotate(theta, x, y); transformStack.add(TransformStackElement.createTranslateElement(x, y)); transformStack.add(TransformStackElement.createRotateElement(theta)); transformStack.add(TransformStackElement.createTranslateElement(-x, -y)); }
double[] transformParameters = transformElement.getTransformParameters(); switch(transformElement.getType().toInt()){ case TransformType.TRANSFORM_TRANSLATE: if(!transformElement.isIdentity()) { transformString.append(TRANSFORM_TRANSLATE); transformString.append(OPEN_PARENTHESIS); if(!transformElement.isIdentity()) { transformString.append(TRANSFORM_ROTATE); transformString.append(OPEN_PARENTHESIS); if(!transformElement.isIdentity()) { transformString.append(TRANSFORM_SCALE); transformString.append(OPEN_PARENTHESIS); if(!transformElement.isIdentity()) { transformString.append(TRANSFORM_MATRIX); transformString.append(OPEN_PARENTHESIS); if(!transformElement.isIdentity()) { transformString.append(TRANSFORM_MATRIX); transformString.append(OPEN_PARENTHESIS);
element = (TransformStackElement) transformStack[i].clone(); next++; canConcatenate = element.concatenate(transformStack[j]); if(!canConcatenate) break;
TransformStackElement stackElement = (TransformStackElement)this.transformStack.get(i); copyGc.transformStack.add(stackElement.clone());
/** * Translates the origin of the graphics context to the point * (<i>x</i>, <i>y</i>) in the current coordinate system. * Modifies this graphics context so that its new origin corresponds * to the point (<i>x</i>, <i>y</i>) in this graphics context's * original coordinate system. All coordinates used in subsequent * rendering operations on this graphics context will be relative * to this new origin. * @param x the <i>x</i> coordinate. * @param y the <i>y</i> coordinate. */ public void translate(int x, int y){ if(x!=0 || y!=0){ transform.translate(x, y); transformStack.add(TransformStackElement.createTranslateElement(x, y)); } }
/** * Concatenates the current <code>Graphics2D</code> * <code>Transform</code> with a rotation transform. * Subsequent rendering is rotated by the specified radians relative * to the previous origin. * This is equivalent to calling <code>transform(R)</code>, where R is an * <code>AffineTransform</code> represented by the following matrix: * <pre> * [ cos(theta) -sin(theta) 0 ] * [ sin(theta) cos(theta) 0 ] * [ 0 0 1 ] * </pre> * Rotating with a positive angle theta rotates points on the positive * x axis toward the positive y axis. * @param theta the angle of rotation in radians */ public void rotate(double theta){ transform.rotate(theta); transformStack.add(TransformStackElement.createRotateElement(theta)); }
/** * Concatenates the current <code>Graphics2D</code> * <code>Transform</code> with a shearing transform. * Subsequent renderings are sheared by the specified * multiplier relative to the previous position. * This is equivalent to calling <code>transform(SH)</code>, where SH * is an <code>AffineTransform</code> represented by the following * matrix: * <pre> * [ 1 shx 0 ] * [ shy 1 0 ] * [ 0 0 1 ] * </pre> * @param shx the multiplier by which coordinates are shifted in * the positive X axis direction as a function of their Y coordinate * @param shy the multiplier by which coordinates are shifted in * the positive Y axis direction as a function of their X coordinate */ public void shear(double shx, double shy){ transform.shear(shx, shy); transformStack.add(TransformStackElement.createShearElement(shx, shy)); }
/** * Concatenates the current <code>Graphics2D</code> * <code>Transform</code> with a scaling transformation * Subsequent rendering is resized according to the specified scaling * factors relative to the previous scaling. * This is equivalent to calling <code>transform(S)</code>, where S is an * <code>AffineTransform</code> represented by the following matrix: * <pre> * [ sx 0 0 ] * [ 0 sy 0 ] * [ 0 0 1 ] * </pre> * @param sx the amount by which X coordinates in subsequent * rendering operations are multiplied relative to previous * rendering operations. * @param sy the amount by which Y coordinates in subsequent * rendering operations are multiplied relative to previous * rendering operations. */ public void scale(double sx, double sy){ transform.scale(sx, sy); transformStack.add(TransformStackElement.createScaleElement(sx, sy)); }
double[] transformParameters = transformElement.getTransformParameters(); switch(transformElement.getType().toInt()){ case TransformType.TRANSFORM_TRANSLATE: if(!transformElement.isIdentity()) { transformString.append(TRANSFORM_TRANSLATE); transformString.append(OPEN_PARENTHESIS); if(!transformElement.isIdentity()) { transformString.append(TRANSFORM_ROTATE); transformString.append(OPEN_PARENTHESIS); if(!transformElement.isIdentity()) { transformString.append(TRANSFORM_SCALE); transformString.append(OPEN_PARENTHESIS); if(!transformElement.isIdentity()) { transformString.append(TRANSFORM_MATRIX); transformString.append(OPEN_PARENTHESIS); if(!transformElement.isIdentity()) { transformString.append(TRANSFORM_MATRIX); transformString.append(OPEN_PARENTHESIS);
element = (TransformStackElement) transformStack[i].clone(); next++; canConcatenate = element.concatenate(transformStack[j]); if(!canConcatenate) break;
TransformStackElement stackElement = (TransformStackElement)this.transformStack.get(i); copyGc.transformStack.add(stackElement.clone());
/** * Translates the origin of the graphics context to the point * (<i>x</i>, <i>y</i>) in the current coordinate system. * Modifies this graphics context so that its new origin corresponds * to the point (<i>x</i>, <i>y</i>) in this graphics context's * original coordinate system. All coordinates used in subsequent * rendering operations on this graphics context will be relative * to this new origin. * @param x the <i>x</i> coordinate. * @param y the <i>y</i> coordinate. */ public void translate(int x, int y){ if(x!=0 || y!=0){ transform.translate(x, y); transformStack.add(TransformStackElement.createTranslateElement(x, y)); } }
/** * Concatenates the current <code>Graphics2D</code> * <code>Transform</code> with a rotation transform. * Subsequent rendering is rotated by the specified radians relative * to the previous origin. * This is equivalent to calling <code>transform(R)</code>, where R is an * <code>AffineTransform</code> represented by the following matrix: * <pre> * [ cos(theta) -sin(theta) 0 ] * [ sin(theta) cos(theta) 0 ] * [ 0 0 1 ] * </pre> * Rotating with a positive angle theta rotates points on the positive * x axis toward the positive y axis. * @param theta the angle of rotation in radians */ public void rotate(double theta){ transform.rotate(theta); transformStack.add(TransformStackElement.createRotateElement(theta)); }
/** * Concatenates the current <code>Graphics2D</code> * <code>Transform</code> with a shearing transform. * Subsequent renderings are sheared by the specified * multiplier relative to the previous position. * This is equivalent to calling <code>transform(SH)</code>, where SH * is an <code>AffineTransform</code> represented by the following * matrix: * <pre> * [ 1 shx 0 ] * [ shy 1 0 ] * [ 0 0 1 ] * </pre> * @param shx the multiplier by which coordinates are shifted in * the positive X axis direction as a function of their Y coordinate * @param shy the multiplier by which coordinates are shifted in * the positive Y axis direction as a function of their X coordinate */ public void shear(double shx, double shy){ transform.shear(shx, shy); transformStack.add(TransformStackElement.createShearElement(shx, shy)); }
/** * Concatenates the current <code>Graphics2D</code> * <code>Transform</code> with a scaling transformation * Subsequent rendering is resized according to the specified scaling * factors relative to the previous scaling. * This is equivalent to calling <code>transform(S)</code>, where S is an * <code>AffineTransform</code> represented by the following matrix: * <pre> * [ sx 0 0 ] * [ 0 sy 0 ] * [ 0 0 1 ] * </pre> * @param sx the amount by which X coordinates in subsequent * rendering operations are multiplied relative to previous * rendering operations. * @param sy the amount by which Y coordinates in subsequent * rendering operations are multiplied relative to previous * rendering operations. */ public void scale(double sx, double sy){ transform.scale(sx, sy); transformStack.add(TransformStackElement.createScaleElement(sx, sy)); }
/** * Concatenates the current <code>Graphics2D</code> * <code>Transform</code> with a translated rotation * transform. Subsequent rendering is transformed by a transform * which is constructed by translating to the specified location, * rotating by the specified radians, and translating back by the same * amount as the original translation. This is equivalent to the * following sequence of calls: * <pre> * translate(x, y); * rotate(theta); * translate(-x, -y); * </pre> * Rotating with a positive angle theta rotates points on the positive * x axis toward the positive y axis. * @param theta the angle of rotation in radians * @param x x coordinate of the origin of the rotation * @param y y coordinate of the origin of the rotation */ public void rotate(double theta, double x, double y){ transform.rotate(theta, x, y); transformStack.add(TransformStackElement.createTranslateElement(x, y)); transformStack.add(TransformStackElement.createRotateElement(theta)); transformStack.add(TransformStackElement.createTranslateElement(-x, -y)); }
/** * @return true iff this transform is the identity transform */ public boolean isIdentity() { return isIdentity(transformParameters); }
/** * Composes an <code>AffineTransform</code> object with the * <code>Transform</code> in this <code>Graphics2D</code> according * to the rule last-specified-first-applied. If the current * <code>Transform</code> is Cx, the result of composition * with Tx is a new <code>Transform</code> Cx'. Cx' becomes the * current <code>Transform</code> for this <code>Graphics2D</code>. * Transforming a point p by the updated <code>Transform</code> Cx' is * equivalent to first transforming p by Tx and then transforming * the result by the original <code>Transform</code> Cx. In other * words, Cx'(p) = Cx(Tx(p)). A copy of the Tx is made, if necessary, * so further modifications to Tx do not affect rendering. * @param Tx the <code>AffineTransform</code> object to be composed with * the current <code>Transform</code> * @see #setTransform * @see AffineTransform */ public void transform(AffineTransform Tx){ transform.concatenate(Tx); transformStack.add(TransformStackElement.createGeneralTransformElement(Tx)); }