private void organizeCellElements(JRDesignCellContents cell, CrosstabObjectScene sc) { int cW = cell.getWidth(); int cH = cell.getHeight(); List children = cell.getChildren(); int y = 0; if (children.size() == 0) return; int h = cH / children.size(); SceneAnimator animator = new SceneAnimator(sc); CellAnimatorListener listener = new CellAnimatorListener(); animator.getPreferredBoundsAnimator().addAnimatorListener(listener); animator.getPreferredLocationAnimator().addAnimatorListener(listener); listener.addAnimation(); // bounds listener.addAnimation(); // location // 1 Calculate new elements size and location.. for (int i = 0; i < children.size(); ++i) { if (children.get(i) instanceof JRDesignElement) { JRDesignElement element = (JRDesignElement) children.get(i); listener.getNewSizes().put(element, new Rectangle(0, i * h, cW, h)); } } for (Iterator iter = listener.getNewSizes().keySet().iterator(); iter.hasNext(); ) { JRDesignElement element = (JRDesignElement) iter.next(); Rectangle rectangle = listener.getNewSizes().get(element); Widget w = sc.findWidget(element); if (w != null) { Rectangle r = w.getPreferredBounds(); r.width = rectangle.width; r.height = rectangle.height; animator.animatePreferredBounds(w, r); Point p = new Point(w.getLocation()); p.x -= element.getX() + rectangle.x; p.y += -(element.getY()) + rectangle.y; animator.animatePreferredLocation(w, p); } } }
public void updateBounds() { JasperDesign jd = ((AbstractReportObjectScene) this.getScene()).getJasperDesign(); // Point p = // JRBand band = ModelUtils.bandOfElement(element, jd); // int bandYLocation = ModelUtils.getBandLocation(band, jd); // setPreferredLocation(new Point( jd.getLeftMargin() + element.getX()-5, bandYLocation + // element.getY() -5) ); // setPreferredBounds(new Rectangle(0,0,element.getWidth()+10, element.getHeight()+10)); Point location = convertModelToLocalLocation(new Point(element.getX(), element.getY())); location.x -= getBorder().getInsets().left; location.y -= getBorder().getInsets().top; setPreferredLocation(location); setPreferredBounds( new Rectangle( 0, 0, element.getWidth() + getBorder().getInsets().left + getBorder().getInsets().right, element.getHeight() + getBorder().getInsets().top + getBorder().getInsets().bottom)); }