@Override public void hideComponents(boolean hide) { this.hideComponents = hide; if (componentsInHiearchy == null) return; for (Renderable r : componentsInHiearchy) { Node node = (Node) r; node.setIsVisible(!hide); if (r instanceof RenderableComplex) { ((RenderableComplex) r).hideComponents = hide; } } // The following statements are related to bounds. if (bounds == null) return; if (hide) { saveOldBounds(); copyBoundsToComponents(); } else { recoverOldBounds(); // Make sure a complex container has enough size Renderable container = this.container; Rectangle childBounds = this.bounds; while (container instanceof RenderableComplex) { Rectangle cBounds = container.getBounds(); if (!cBounds.contains(childBounds)) { ((RenderableComplex) container).layout(); } childBounds = container.getBounds(); container = container.getContainer(); } } }
/** * Check if a passed Renderable object can be a Complex's component. * * @param r * @return */ @Override public boolean isAssignable(Renderable r) { if (bounds == null || r == this) // Don't point it to itself return false; // This container has not be materialized if (r instanceof Node) { if (r instanceof RenderableCompartment || r instanceof RenderablePathway || r instanceof Note) return false; // Need to check based on bounds. Should have a full containing if (r.getBounds() == null) return bounds.contains(r.getPosition()); else return bounds.contains(r.getBounds()); } return false; }
private void saveOldBounds() { if (oldIdToBounds == null) oldIdToBounds = new HashMap<Integer, Rectangle>(); else oldIdToBounds.clear(); // Save the bounds for this RenderableComplex. This bounds // will be used as the reference for future recovering oldIdToBounds.put(getID(), new Rectangle(bounds)); for (Renderable r : componentsInHiearchy) { Rectangle rBounds = r.getBounds(); if (rBounds != null) { // Just in case oldIdToBounds.put(r.getID(), new Rectangle(rBounds)); } } }
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(); } }