/** This method is used to copy the bounds of this complex to all it contained components. */ public void copyBoundsToComponents() { if (componentsInHiearchy == null || componentsInHiearchy.size() == 0) return; for (Renderable r : componentsInHiearchy) { if (r.bounds == null) { r.bounds = new Rectangle(bounds); if (r.getPosition() == null) r.setPosition(new Point()); ((Node) r).validatePositionFromBounds(); } else { r.bounds.x = bounds.x; r.bounds.y = bounds.y; r.bounds.width = bounds.width; r.bounds.height = bounds.height; } ((Node) r).invalidateTextBounds(); } }
private void recoverOldBounds() { // Make sure it is recoverable. If not, just do a simple // layout if (!isOldBoundsRecoverable()) { // Copy any known bounds if (oldIdToBounds != null) { for (Renderable r : componentsInHiearchy) { Rectangle bounds = oldIdToBounds.get(r.getID()); if (bounds == null) continue; if (r.bounds != null) { r.bounds.width = bounds.width; r.bounds.height = bounds.height; } else r.bounds = new Rectangle(bounds); } } // Just do an auto layout. Should start from the smalled complexes for (Renderable r : componentsInHiearchy) { if (r instanceof RenderableComplex) ((RenderableComplex) r).layout(); } layout(); return; } Rectangle oldBounds = oldIdToBounds.get(getID()); int dx = bounds.x - oldBounds.x; int dy = bounds.y - oldBounds.y; bounds.width = oldBounds.width; bounds.height = oldBounds.height; invalidateTextBounds(); for (Renderable r : componentsInHiearchy) { oldBounds = oldIdToBounds.get(r.getID()); oldBounds.translate(dx, dy); Rectangle newBounds = r.getBounds(); if (newBounds == null) { newBounds = new Rectangle(oldBounds); r.setBounds(newBounds); } else { newBounds.x = oldBounds.x; newBounds.y = oldBounds.y; newBounds.width = oldBounds.width; newBounds.height = oldBounds.height; } ((Node) r).invalidateTextBounds(); } }