/** * Transforms the figure. * * @param tx the transformation. */ public void transform(AffineTransform tx) { if (TRANSFORM.get(this) != null || tx.getType() != (tx.getType() & AffineTransform.TYPE_TRANSLATION)) { if (TRANSFORM.get(this) == null) { TRANSFORM.basicSet(this, (AffineTransform) tx.clone()); } else { AffineTransform t = TRANSFORM.getClone(this); t.preConcatenate(tx); TRANSFORM.basicSet(this, t); } } else { for (int i = 0; i < coordinates.length; i++) { tx.transform(coordinates[i], coordinates[i]); } if (FILL_GRADIENT.get(this) != null && !FILL_GRADIENT.get(this).isRelativeToFigureBounds()) { Gradient g = FILL_GRADIENT.getClone(this); g.transform(tx); FILL_GRADIENT.basicSet(this, g); } if (STROKE_GRADIENT.get(this) != null && !STROKE_GRADIENT.get(this).isRelativeToFigureBounds()) { Gradient g = STROKE_GRADIENT.getClone(this); g.transform(tx); STROKE_GRADIENT.basicSet(this, g); } } invalidate(); }
/** * paintComponent which paints the component. Flips if Status is normalRotation. * * @param _graphics the graphics which are painted. */ @Override public final void paintComponent(final Graphics _graphics) { // initialize values Graphics2D g2d = (Graphics2D) _graphics; AffineTransform origXform = g2d.getTransform(); AffineTransform newXform = (AffineTransform) origXform.clone(); // center of rotation is center of the panel int xRot = this.getWidth() / 2; int yRot = this.getHeight() / 2; // fetch rotation from Status double rotation = 0; // if not normal rotation if (!State.isNormalRotation()) { final int filpRotation = 180; rotation = filpRotation; } // rotate the image and draw the image to panel newXform.rotate(Math.toRadians(rotation), xRot, yRot); g2d.setTransform(newXform); super.paintComponent(g2d); g2d.setTransform(origXform); }
private void createSceneTransformContext(Graphics g) { graph2D = (Graphics2D) getContext(); originalRenderingContext = graph2D.getTransform(); AffineTransform newRenderingContext = (AffineTransform) (originalRenderingContext.clone()); newRenderingContext.scale(widthRescale, heightRescale); newRenderingContext.translate(BORDER_X, BORDER_Y); graph2D.setTransform(newRenderingContext); }
/** * Constructor creates an instance to be used for fill operations. * * @param shading the shading type to be used * @param colorModel the color model to be used * @param xform transformation for user to device space * @param matrix the pattern matrix concatenated with that of the parent content stream * @param deviceBounds the bounds of the area to paint, in device units * @throws IOException if there is an error getting the color space or doing color conversion. */ public AxialShadingContext( PDShadingType2 shading, ColorModel colorModel, AffineTransform xform, Matrix matrix, Rectangle deviceBounds) throws IOException { super(shading, colorModel, xform, matrix); this.axialShadingType = shading; coords = shading.getCoords().toFloatArray(); // domain values if (shading.getDomain() != null) { domain = shading.getDomain().toFloatArray(); } else { // set default values domain = new float[] {0, 1}; } // extend values COSArray extendValues = shading.getExtend(); if (shading.getExtend() != null) { extend = new boolean[2]; extend[0] = ((COSBoolean) extendValues.get(0)).getValue(); extend[1] = ((COSBoolean) extendValues.get(1)).getValue(); } else { // set default values extend = new boolean[] {false, false}; } // calculate some constants to be used in getRaster x1x0 = coords[2] - coords[0]; y1y0 = coords[3] - coords[1]; d1d0 = domain[1] - domain[0]; denom = Math.pow(x1x0, 2) + Math.pow(y1y0, 2); try { // get inverse transform to be independent of current user / device space // when handling actual pixels in getRaster() rat = matrix.createAffineTransform().createInverse(); rat.concatenate(xform.createInverse()); } catch (NoninvertibleTransformException ex) { LOG.error(ex, ex); } // shading space -> device space AffineTransform shadingToDevice = (AffineTransform) xform.clone(); shadingToDevice.concatenate(matrix.createAffineTransform()); // worst case for the number of steps is opposite diagonal corners, so use that double dist = Math.sqrt( Math.pow(deviceBounds.getMaxX() - deviceBounds.getMinX(), 2) + Math.pow(deviceBounds.getMaxY() - deviceBounds.getMinY(), 2)); factor = (int) Math.ceil(dist); // build the color table for the given number of steps colorTable = calcColorTable(); }
/** Creates a new instance of JTransformSegmentsEdit */ public JTransformSegmentsEdit( JDocumentViewer v, JPathObject target, Vector<JSegment> segments, AffineTransform af) { super(v); this.segments = (Vector<JSegment>) segments.clone(); this.target = target; this.af = (AffineTransform) af.clone(); presentationName = "セグメント移動"; redo(); }
@Override public Object clone() { Point2D p = new Point2D.Double(boundRect.getX(), boundRect.getY()); JImageObject ret = new JImageObject(imageIcon.getImage(), p); ret.alpha = alpha; ret.totalTransform = (AffineTransform) totalTransform.clone(); ret.totalRotation = totalRotation; return ret; }
private AffineTransform makeTransform(Object o) { AffineTransform r = (AffineTransform) ((AffineTransform) o).clone(); // System.out.println("r:"+r); if (origTransform != null) { AffineTransform r2 = (AffineTransform) origTransform.clone(); // System.out.println("r2:"+r2); r2.concatenate(r); r = r2; } return r; }
private void inspectCoordinateReferenceSystems() throws DataSourceException { // get the crs for the requested bbox requestCRS = CRS.getHorizontalCRS(requestedBBox.getCoordinateReferenceSystem()); // // Check if the request CRS is different from the coverage native CRS // if (!CRS.equalsIgnoreMetadata(requestCRS, coverageProperties.crs2D)) try { destinationToSourceTransform = CRS.findMathTransform(requestCRS, coverageProperties.crs2D, true); } catch (FactoryException e) { throw new DataSourceException("Unable to inspect request CRS", e); } // now transform the requested envelope to source crs if (destinationToSourceTransform != null && destinationToSourceTransform.isIdentity()) { destinationToSourceTransform = null; // the CRS is basically the same } else if (destinationToSourceTransform instanceof AffineTransform) { needsReprojection = true; // // k, the transformation between the various CRS is not null or the // Identity, let's see if it is an affine transform, which case we // can incorporate it into the requested grid to world // // we should not have any problems with regards to BBOX reprojection // update the requested grid to world transformation by pre concatenating the destination to // source transform AffineTransform mutableTransform = (AffineTransform) requestedGridToWorld.clone(); mutableTransform.preConcatenate((AffineTransform) destinationToSourceTransform); // update the requested envelope try { final MathTransform tempTransform = PixelTranslation.translate( ProjectiveTransform.create(mutableTransform), PixelInCell.CELL_CENTER, PixelInCell.CELL_CORNER); requestedBBox = new ReferencedEnvelope( CRS.transform(tempTransform, new GeneralEnvelope(requestedRasterArea))); } catch (MismatchedDimensionException e) { throw new DataSourceException("Unable to inspect request CRS", e); } catch (TransformException e) { throw new DataSourceException("Unable to inspect request CRS", e); } // now clean up all the traces of the transformations destinationToSourceTransform = null; } }
private void drawString(String text, int x, int y, float angle, Color color) { Graphics2D localGraph = (Graphics2D) getContext(); final int BORDER = 10; Font font = new Font("SansSerif", Font.PLAIN, 25); localGraph.setFont(font); // parse lines String[] lines = text.trim().split("\n"); int longest = 0; int maxChar = 0; for (int k = 0; k < lines.length; k++) { if (lines[k].length() > maxChar) { maxChar = lines[k].length(); longest = k; } } // draw background AffineTransform origAt = localGraph.getTransform(); AffineTransform newAt = (AffineTransform) (origAt.clone()); Rectangle2D rect = localGraph.getFontMetrics().getStringBounds(lines[longest], localGraph); RoundRectangle2D round = new RoundRectangle2D.Double( rect.getX(), rect.getY(), rect.getWidth() + (BORDER * 2), (rect.getHeight() * lines.length) + (BORDER * 2), 25, 25); newAt.rotate(Math.toRadians(angle), x, y); localGraph.setTransform(newAt); Shape shape = getTranslatedShape(round, new Point(x, y)); Color transparent = new Color(color.getRed(), color.getGreen(), color.getBlue(), 190); localGraph.setColor(transparent); localGraph.fill(shape); // draw single lines y += (BORDER - 27); for (int j = 0; j < lines.length; j++) { if (!lines[j].trim().isEmpty()) { y += 27; localGraph.setColor(Color.white); localGraph.drawString(lines[j], x + BORDER, y); } } localGraph.setTransform(origAt); }
/** * @param obj * @return */ protected AffineTransform setTransformContextFor(EnvObject obj) { Graphics2D tmpGraph = (Graphics2D) getContext(); panelTransform = tmpGraph.getTransform(); AffineTransform newAt = (AffineTransform) (panelTransform.clone()); int x = (int) obj.getCurrentRepresentation().getOffset().getX(); int y = (int) obj.getCurrentRepresentation().getOffset().getY(); newAt.translate(x, y); newAt.rotate(Math.toRadians(obj.getCurrentRepresentation().getRotation())); tmpGraph.setTransform(newAt); objectTransform = newAt; return newAt; }
/** * Receives notification of a change to a GraphicsNode. * * @param gnce The event object describing the GraphicsNode change. */ public void changeStarted(GraphicsNodeChangeEvent gnce) { // System.out.println("A node has changed for: " + this); GraphicsNode gn = gnce.getGraphicsNode(); WeakReference gnWRef = gn.getWeakReference(); boolean doPut = false; if (dirtyNodes == null) { dirtyNodes = new HashMap(); doPut = true; } else if (!dirtyNodes.containsKey(gnWRef)) doPut = true; if (doPut) { AffineTransform at = gn.getTransform(); if (at != null) at = (AffineTransform) at.clone(); else at = new AffineTransform(); dirtyNodes.put(gnWRef, at); } GraphicsNode chngSrc = gnce.getChangeSrc(); Rectangle2D rgn = null; if (chngSrc != null) { // A child node is moving in the tree so assign it's dirty // regions to this node before it moves. Rectangle2D drgn = getNodeDirtyRegion(chngSrc); if (drgn != null) rgn = new ChngSrcRect(drgn); } else { // Otherwise just use gn's current region. rgn = gn.getBounds(); } // Add this dirty region to any existing dirty region. Rectangle2D r2d = (Rectangle2D) fromBounds.remove(gnWRef); if (rgn != null) { if ((r2d != null) && (r2d != NULL_RECT)) { // System.err.println("GN: " + gn); // System.err.println("R2d: " + r2d); // System.err.println("Rgn: " + rgn); r2d = r2d.createUnion(rgn); // System.err.println("Union: " + r2d); } else r2d = rgn; } // if ((gn instanceof CompositeGraphicsNode) && // (r2d.getWidth() > 200)) { // new Exception("Adding Large: " + gn).printStackTrace(); // } // Store the bounds for the future. if (r2d == null) r2d = NULL_RECT; fromBounds.put(gnWRef, r2d); }
/** * Instantiates a new AffineTransformOp with the specified AffineTransform and a specified * interpolation type from the list of predefined interpolation types. * * @param xform the AffineTransform. * @param interp the one of predefined interpolation types: TYPE_NEAREST_NEIGHBOR, TYPE_BILINEAR, * or TYPE_BICUBIC. */ public AffineTransformOp(AffineTransform xform, int interp) { if (Math.abs(xform.getDeterminant()) <= Double.MIN_VALUE) { // awt.24F=Unable to invert transform {0} throw new ImagingOpException(Messages.getString("awt.24F", xform)); // $NON-NLS-1$ } this.at = (AffineTransform) xform.clone(); if (interp != TYPE_NEAREST_NEIGHBOR && interp != TYPE_BILINEAR && interp != TYPE_BICUBIC) { // awt.250=Unknown interpolation type: {0} throw new IllegalArgumentException(Messages.getString("awt.250", interp)); // $NON-NLS-1$ } this.iType = interp; }
protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; AffineTransform origXform = g2d.getTransform(); AffineTransform newXform = (AffineTransform)(origXform.clone()); //center of rotation is center of the panel int xRot = this.getWidth()/2; int yRot = this.getHeight()/2; newXform.rotate(Math.toRadians(currentAngle), xRot, yRot); g2d.setTransform(newXform); //draw image centered in panel int x = (getWidth() - image.getWidth(this))/2; int y = (getHeight() - image.getHeight(this))/2; g2d.drawImage(image, x, y, this); g2d.setTransform(origXform); }
public void validateCompositeState( Composite comp, AffineTransform xform, Paint paint, SunGraphics2D sg2d) { boolean updatePaint = (paint != validatedPaint) || paint == null; // validate composite if ((comp != validatedComp)) { if (comp != null) { setComposite(comp); } else { comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER); setComposite(comp); } // the paint state is dependent on the composite state, so make // sure we update the color below updatePaint = true; validatedComp = comp; } if (sg2d != null && validatedPixel != sg2d.pixel) { validatedPixel = sg2d.pixel; setForeground(validatedPixel); } // validate paint if (updatePaint) { if (paint != null && sg2d != null && sg2d.paintState >= SunGraphics2D.PAINT_GRADIENT) { XRPaints.setPaint(sg2d, paint); } else { XRResetPaint(); } validatedPaint = paint; } if (src != solidSrcPict) { AffineTransform at = (AffineTransform) xform.clone(); try { at.invert(); } catch (NoninvertibleTransformException e) { at.setToIdentity(); } src.validateAsSource(at, -1, -1); } }
public void draw(Graphics2D g2, float x, float y) { AffineTransform transf = g2.getTransform(); Stroke oldStroke = g2.getStroke(); final double sx = transf.getScaleX(); final double sy = transf.getScaleY(); double s = 1; if (sx == sy) { // There are rounding problems due to scale factor: lines could have different // spacing... // So the increment (space+thickness) is done in using integer. s = sx; AffineTransform t = (AffineTransform) transf.clone(); t.scale(1 / sx, 1 / sy); g2.setTransform(t); } g2.setStroke( new BasicStroke((float) (s * thickness), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); float th = thickness / 2.f; final Line2D.Float line = new Line2D.Float(); float xx = x + space; xx = (float) (xx * s + (space / 2.f) * s); final int inc = (int) Math.round((space + thickness) * s); for (int i = 0; i < N; i++) { line.setLine(xx + th * s, (y - height) * s, xx + th * s, y * s); g2.draw(line); xx += inc; } if (strike) { line.setLine( (x + space) * s, (y - height / 2.f) * s, xx - s * space / 2, (y - height / 2.f) * s); g2.draw(line); } g2.setTransform(transf); g2.setStroke(oldStroke); }
public AffineTransform getTransform() { return (AffineTransform) src2me.clone(); }
/** * Gets the affine transform associated with this AffineTransformOp. * * @return the AffineTransform. */ public final AffineTransform getTransform() { return (AffineTransform) at.clone(); }
/** * Superclass constructor, typical user should never have to call this. * * @param fractions numbers ranging from 0.0 to 1.0 specifying the distribution of colors along * the gradient * @param colors array of colors corresponding to each fractional value * @param cycleMethod either NO_CYCLE, REFLECT, or REPEAT * @param colorSpace which colorspace to use for interpolation, either SRGB or LINEAR_RGB * @param gradientTransform transform to apply to the gradient * @throws NullPointerException if arrays are null, or gradientTransform is null * @throws IllegalArgumentException if fractions.length != colors.length, or if colors is less * than 2 in size, or if an enumerated value is bad. * @see java.awt.PaintContext */ public MultipleGradientPaint( float[] fractions, Color[] colors, CycleMethodEnum cycleMethod, ColorSpaceEnum colorSpace, AffineTransform gradientTransform) { if (fractions == null) { throw new IllegalArgumentException("Fractions array cannot be " + "null"); } if (colors == null) { throw new IllegalArgumentException("Colors array cannot be null"); } if (fractions.length != colors.length) { throw new IllegalArgumentException("Colors and fractions must " + "have equal size"); } if (colors.length < 2) { throw new IllegalArgumentException("User must specify at least " + "2 colors"); } if ((colorSpace != LINEAR_RGB) && (colorSpace != SRGB)) { throw new IllegalArgumentException("Invalid colorspace for " + "interpolation."); } if ((cycleMethod != NO_CYCLE) && (cycleMethod != REFLECT) && (cycleMethod != REPEAT)) { throw new IllegalArgumentException("Invalid cycle method."); } if (gradientTransform == null) { throw new IllegalArgumentException("Gradient transform cannot be " + "null."); } // copy the fractions array this.fractions = new float[fractions.length]; System.arraycopy(fractions, 0, this.fractions, 0, fractions.length); // copy the colors array this.colors = new Color[colors.length]; System.arraycopy(colors, 0, this.colors, 0, colors.length); // copy some flags this.colorSpace = colorSpace; this.cycleMethod = cycleMethod; // copy the gradient transform this.gradientTransform = (AffineTransform) gradientTransform.clone(); // Process transparency boolean opaque = true; for (int i = 0; i < colors.length; i++) { opaque = opaque && (colors[i].getAlpha() == 0xff); } if (opaque) { transparency = OPAQUE; } else { transparency = TRANSLUCENT; } }
/** * Returns a copy of the transform applied to the gradient. * * @return a copy of the transform applied to the gradient. */ public AffineTransform getTransform() { return (AffineTransform) gradientTransform.clone(); }
/** * 保持上传照片的图片方向不发生调整 * * @param filePath 图片的文件路径 */ public static void MaintainOrientation(String filePath) { try { File file = new File(filePath); if (!file.exists()) { logger.fatal(new FileNotFoundException()); return; } Metadata metadata = ImageMetadataReader.readMetadata(file); Directory directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class); int orientation = 0; if (null != directory && directory.containsTag(ExifSubIFDDirectory.TAG_ORIENTATION)) { orientation = directory.getInt(ExifSubIFDDirectory.TAG_ORIENTATION); logger.debug(filePath + " 's orientation is :" + orientation); } String format = FileUtil.getFileSuffix(filePath); switch (orientation) { // case 1: // return "Top, left side (Horizontal / normal)"; // case 2: // return "Top, right side (Mirror horizontal)"; case 3: // return "Bottom, right side (Rotate 180)"; BufferedImage old_img3 = (BufferedImage) ImageIO.read(file); int w3 = old_img3.getWidth(); int h3 = old_img3.getHeight(); BufferedImage new_img3 = new BufferedImage(w3, h3, BufferedImage.TYPE_INT_BGR); Graphics2D g2d3 = new_img3.createGraphics(); AffineTransform origXform3 = g2d3.getTransform(); AffineTransform newXform3 = (AffineTransform) (origXform3.clone()); // center of rotation is center of the panel // double xRot3 = w3/2.0; newXform3.rotate(Math.toRadians(180.0), w3 / 2.0, h3 / 2.0); // 旋转180度 g2d3.setTransform(newXform3); // draw image centered in panel g2d3.drawImage(old_img3, 0, 0, null); // Reset to Original g2d3.setTransform(origXform3); // 写到新的文件 FileOutputStream out3 = new FileOutputStream(file); try { ImageIO.write(new_img3, format, out3); } finally { out3.close(); } break; // case 4: // return "Bottom, left side (Mirror vertical)"; // case 5: // return "Left side, top (Mirror horizontal and rotate 270 // CW)"; case 6: // return "Right side, top (Rotate 90 CW)"; BufferedImage old_img6 = (BufferedImage) ImageIO.read(file); int w6 = old_img6.getWidth(); int h6 = old_img6.getHeight(); BufferedImage new_img6 = new BufferedImage(h6, w6, BufferedImage.TYPE_INT_BGR); Graphics2D g2d6 = new_img6.createGraphics(); AffineTransform origXform6 = g2d6.getTransform(); AffineTransform newXform6 = (AffineTransform) (origXform6.clone()); // center of rotation is center of the panel double xRot6 = h6 / 2.0; newXform6.rotate(Math.toRadians(90.0), xRot6, xRot6); // 旋转90度 g2d6.setTransform(newXform6); // draw image centered in panel g2d6.drawImage(old_img6, 0, 0, null); // Reset to Original g2d6.setTransform(origXform6); // 写到新的文件 FileOutputStream out6 = new FileOutputStream(file); try { ImageIO.write(new_img6, format, out6); } finally { out6.close(); } break; // case 7: // return "Right side, bottom (Mirror horizontal and rotate 90 // CW)"; case 8: // return "Left side, bottom (Rotate 270 CW)"; BufferedImage old_img8 = (BufferedImage) ImageIO.read(file); int w8 = old_img8.getWidth(); int h8 = old_img8.getHeight(); BufferedImage new_img8 = new BufferedImage(h8, w8, BufferedImage.TYPE_INT_BGR); Graphics2D g2d8 = new_img8.createGraphics(); AffineTransform origXform8 = g2d8.getTransform(); AffineTransform newXform8 = (AffineTransform) (origXform8.clone()); // center of rotation is center of the panel double xRot8 = w8 / 2.0; newXform8.rotate(Math.toRadians(270.0), xRot8, xRot8); // 旋转90度 g2d8.setTransform(newXform8); // draw image centered in panel g2d8.drawImage(old_img8, 0, 0, null); // Reset to Original g2d8.setTransform(origXform8); // 写到新的文件 FileOutputStream out8 = new FileOutputStream(file); try { ImageIO.write(new_img8, format, out8); } finally { out8.close(); } break; // default: // return String.valueOf(orientation); } } catch (Exception e) { e.printStackTrace(); logger.fatal(e); } }
private void calculatePreviewTranslation() { Point2D point = calculateInsertionPoint(previewPoint); previewTransform = (AffineTransform) transformCells.clone(); previewTransform.translate(point.getX(), point.getY()); previewTransform.rotate(previewRotation, 0, 0); }
public void genRect(WritableRaster wr) { if (me2src == null) return; Rectangle srcR = me2src.createTransformedShape(wr.getBounds()).getBounds(); // System.out.println("Affine wrR: " + wr.getBounds()); // System.out.println("Affine srcR: " + srcR); // Outset by two pixels so we get context for interpolation... srcR.setBounds(srcR.x - 1, srcR.y - 1, srcR.width + 2, srcR.height + 2); // Don't try and get data from src that it doesn't have... CachableRed src = (CachableRed) getSources().get(0); // Raster srcRas = src.getData(srcR); if (!srcR.intersects(src.getBounds())) return; Raster srcRas = src.getData(srcR.intersection(src.getBounds())); if (srcRas == null) return; // This works around the problem that the buffered ops // completely ignore the coords of the Rasters passed in. AffineTransform aff = (AffineTransform) src2me.clone(); // Translate what is at 0,0 (which will be what our current // minX/Y is) to our current minX,minY. aff.concatenate(AffineTransform.getTranslateInstance(srcRas.getMinX(), srcRas.getMinY())); Point2D srcPt = new Point2D.Float(wr.getMinX(), wr.getMinY()); srcPt = me2src.transform(srcPt, null); Point2D destPt = new Point2D.Double(srcPt.getX() - srcRas.getMinX(), srcPt.getY() - srcRas.getMinY()); destPt = aff.transform(destPt, null); // Translate what will be at minX,minY to zero, zero // which where java2d will think the real minX,minY is. aff.preConcatenate(AffineTransform.getTranslateInstance(-destPt.getX(), -destPt.getY())); AffineTransformOp op = new AffineTransformOp(aff, hints); BufferedImage srcBI, myBI; ColorModel srcCM = src.getColorModel(); ColorModel myCM = getColorModel(); WritableRaster srcWR = (WritableRaster) srcRas; // If the output buffer is not premultiplied in certain cases // it fails to properly divide out the Alpha (it always does // the affine on premultiplied data). We help it out by // premultiplying for it. srcCM = GraphicsUtil.coerceData(srcWR, srcCM, true); srcBI = new BufferedImage( srcCM, srcWR.createWritableTranslatedChild(0, 0), srcCM.isAlphaPremultiplied(), null); myBI = new BufferedImage( myCM, wr.createWritableTranslatedChild(0, 0), myCM.isAlphaPremultiplied(), null); op.filter(srcBI, myBI); // if ((count % 40) == 0) { // org.apache.batik.ImageDisplay.showImage("Src: " , srcBI); // org.apache.batik.ImageDisplay.showImage("Dst: " , myBI); // } // count++; }
protected void paintWidgetImplementation() { super.paintWidget(); Graphics2D gr = getScene().getGraphics(); // Java2DUtils.setClip(gr,getClientArea()); // Move the gfx 10 pixel ahead... Rectangle r = getPreferredBounds(); long t = new Date().getTime(); // if (getElement() instanceof JRDesignImage) return; AffineTransform af = gr.getTransform(); AffineTransform new_af = (AffineTransform) af.clone(); AffineTransform translate = AffineTransform.getTranslateInstance( getBorder().getInsets().left + r.x, getBorder().getInsets().top + r.y); new_af.concatenate(translate); gr.setTransform(new_af); JasperDesign jd = ((AbstractReportObjectScene) this.getScene()).getJasperDesign(); JRDesignElement e = this.getElement(); DrawVisitor dv = ((AbstractReportObjectScene) this.getScene()).getDrawVisitor(); if (dv == null) return; if (e instanceof JRDesignCrosstab) { Composite oldComposite = gr.getComposite(); gr.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); try { e.visit(dv); } catch (Exception ex) { } gr.setComposite(oldComposite); Shape oldClip = gr.getClip(); Shape rect = new Rectangle2D.Float(0, 0, element.getWidth(), element.getHeight()); gr.clip(rect); gr.drawImage(crosstabImage.getImage(), 4, 4, null); gr.setClip(oldClip); } // if (e instanceof JRDesignFrame) // { // Composite oldComposite = gr.getComposite(); // gr.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); // //try { // // e.visit( dv ); // //} catch (Exception ex){} // gr.setComposite(oldComposite); // Shape oldClip = gr.getClip(); // Shape rect = new Rectangle2D.Float(0,0,element.getWidth(), element.getHeight()); // // } else if (e instanceof JRDesignSubreport) { Composite oldComposite = gr.getComposite(); gr.fillRect(0, 0, element.getWidth(), element.getHeight()); gr.setComposite(oldComposite); Shape oldClip = gr.getClip(); Shape rect = new Rectangle2D.Float(0, 0, element.getWidth(), element.getHeight()); gr.clip(rect); gr.drawImage(subreportImage.getImage(), 4, 4, null); gr.setClip(oldClip); } else if (e instanceof JRDesignGenericElement) { // Composite oldComposite = gr.getComposite(); Paint oldPaint = gr.getPaint(); gr.setPaint(new Color(196, 200, 162, 64)); gr.fillRect(0, 0, element.getWidth(), element.getHeight()); gr.setPaint(oldPaint); // gr.setComposite(oldComposite); Shape oldClip = gr.getClip(); Shape rect = new Rectangle2D.Float(0, 0, element.getWidth(), element.getHeight()); gr.clip(rect); gr.drawImage(genericElementImage.getImage(), 4, 4, null); gr.setClip(oldClip); } else if (e instanceof JRDesignChart) { if (((JRDesignChart) e).getChartType() == JRDesignChart.CHART_TYPE_MULTI_AXIS) { Composite oldComposite = gr.getComposite(); gr.fillRect(0, 0, element.getWidth(), element.getHeight()); gr.setComposite(oldComposite); Shape oldClip = gr.getClip(); Shape rect = new Rectangle2D.Float(0, 0, element.getWidth(), element.getHeight()); gr.clip(rect); gr.drawImage(multiaxisImage.getImage(), 4, 4, null); gr.setClip(oldClip); } else { ClassLoader oldCL = null; dv.setGraphics2D(gr); oldCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(IReportManager.getJRExtensionsClassLoader()); try { e.visit(dv); } catch (Exception ex) { System.err.println( "iReport - Element rendering exception " + getElement() + " " + ex.getMessage()); // ex.printStackTrace(); } if (oldCL != null) { Thread.currentThread().setContextClassLoader(oldCL); } } } else { dv.setGraphics2D(gr); try { ClassLoader cl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(IReportManager.getJRExtensionsClassLoader()); e.visit(dv); Thread.currentThread().setContextClassLoader(cl); } catch (Exception ex) { System.err.println( "iReport - Element rendering exception " + getElement() + " " + ex.getMessage()); // ex.printStackTrace(); } } // show the element and parent coordinates... /* Point p = getParentElementModelLocation(); gr.setColor(Color.darkGray); gr.setFont(new Font("SansSerif",0,6)); gr.drawString( getElement().getX() + "," + getElement().getY() + " - " + p.x + "," + p.y, 2, 12); */ // gr.setTransform(af); // Java2DUtils.resetClip(gr); // System.out.println("Painted : " + (t - new Date().getTime()) + " " + getElement()); }