/** * Sets the parent of the view. This is reimplemented to provide the superclass behavior as well * as calling the <code>loadChildren</code> method if this view does not already have children. * The children should not be loaded in the constructor because the act of setting the parent may * cause them to try to search up the hierarchy (to get the hosting <code>Container</code> for * example). If this view has children (the view is being moved from one place in the view * hierarchy to another), the <code>loadChildren</code> method will not be called. * * @param parent the parent of the view, <code>null</code> if none */ public void setParent(View parent) { super.setParent(parent); if ((parent != null) && (nchildren == 0)) { ViewFactory f = getViewFactory(); loadChildren(f); } }
/** * Update the flow on the given FlowView. By default, this causes all of the rows (child views) * to be rebuilt to match the given constraints for each row. This is called by a * FlowView.layout to update the child views in the flow. * * @param fv the view to reflow */ public void layout(FlowView fv) { int p0 = fv.getStartOffset(); int p1 = fv.getEndOffset(); // we want to preserve all views from the logicalView from being // removed View lv = getLogicalView(fv); int n = lv.getViewCount(); for (int i = 0; i < n; i++) { View v = lv.getView(i); v.setParent(lv); } fv.removeAll(); for (int rowIndex = 0; p0 < p1; rowIndex++) { View row = fv.createRow(); fv.append(row); // layout the row to the current span. If nothing fits, // force something. int next = layoutRow(fv, rowIndex, p0); if (row.getViewCount() == 0) { row.append(createView(fv, p0, Integer.MAX_VALUE, rowIndex)); next = row.getEndOffset(); } if (next <= p0) { throw new StateInvariantError("infinite loop in formatting"); } else { p0 = next; } } }
/** * Establishes the parent view for this view. Seize this moment to cache the AWT Container I'm in. */ public void setParent(View parent) { super.setParent(parent); fContainer = parent != null ? getContainer() : null; if (parent == null && fComponent != null) { fComponent.getParent().remove(fComponent); fComponent = null; } }
/** Returns the view to use for alternate text. This may be null. */ private View getAltView() { View view; synchronized (this) { view = altView; } if (view != null && view.getParent() == null) { view.setParent(getParent()); } return view; }
/** * Establishes the parent view for this view. Seize this moment to cache the AWT Container I'm in. */ @Override public void setParent(View parent) { View oldParent = getParent(); super.setParent(parent); container = (parent != null) ? getContainer() : null; if (oldParent != parent) { synchronized (this) { state |= RELOAD_FLAG; } } }
private void recursiveReparent(View v, View logicalView) { int n = v.getViewCount(); for (int i = 0; i < n; i++) { View tmpView = v.getView(i); if (contains(logicalView, tmpView)) { tmpView.setParent(logicalView); } else { recursiveReparent(tmpView, logicalView); } } }
/** * Adjusts the given row if possible to fit within the layout span. By default this will try to * find the highest break weight possible nearest the end of the row. If a forced break is * encountered, the break will be positioned there. * * @param rowIndex the row to adjust to the current layout span. * @param desiredSpan the current layout span >= 0 * @param x the location r starts at. */ protected void adjustRow(FlowView fv, int rowIndex, int desiredSpan, int x) { final int flowAxis = fv.getFlowAxis(); View r = fv.getView(rowIndex); int n = r.getViewCount(); int span = 0; int bestWeight = BadBreakWeight; int bestSpan = 0; int bestIndex = -1; int bestOffset = 0; View v; for (int i = 0; i < n; i++) { v = r.getView(i); int spanLeft = desiredSpan - span; int w = v.getBreakWeight(flowAxis, x + span, spanLeft); if ((w >= bestWeight) && (w > BadBreakWeight)) { bestWeight = w; bestIndex = i; bestSpan = span; if (w >= ForcedBreakWeight) { // it's a forced break, so there is // no point in searching further. break; } } span += v.getPreferredSpan(flowAxis); } if (bestIndex < 0) { // there is nothing that can be broken, leave // it in it's current state. return; } // Break the best candidate view, and patch up the row. int spanLeft = desiredSpan - bestSpan; v = r.getView(bestIndex); v = v.breakView(flowAxis, v.getStartOffset(), x + bestSpan, spanLeft); View[] va = new View[1]; va[0] = v; View lv = getLogicalView(fv); for (int i = bestIndex; i < n; i++) { View tmpView = r.getView(i); if (contains(lv, tmpView)) { tmpView.setParent(lv); } else if (tmpView.getViewCount() > 0) { recursiveReparent(tmpView, lv); } } r.replace(bestIndex, n - bestIndex, va); }
/** * Forward the DocumentEvent to the given child view. This is implemented to reparent the child * to the logical view (the children may have been parented by a row in the flow if they fit * without breaking) and then execute the superclass behavior. * * @param v the child view to forward the event to. * @param e the change information from the associated document * @param a the current allocation of the view * @param f the factory to use to rebuild if the view has children * @see #forwardUpdate * @since 1.3 */ protected void forwardUpdateToView(View v, DocumentEvent e, Shape a, ViewFactory f) { v.setParent(this); super.forwardUpdateToView(v, e, a, f); }