📄 uivisualizer.java
字号:
1. Locate a sibling, say <a>, that already exists. 2. Then, use AuInsertBefore for all sibling before <a>, and AuInsertAfter for all after anchor. 3. If anchor is not found, use AuAppendChild for the first and INSERT_AFTER for the rest */ final List before = new LinkedList(); Component anchor = null; final ComponentCtrl ntparentCtrl = (ComponentCtrl)ntparent; final Object ntparentxc = ntparentCtrl != null ? ntparentCtrl.getExtraCtrl(): null; for (Iterator it = sibs.iterator(); it.hasNext();) { final Component comp = (Component)it.next(); if ((ntparentxc instanceof MultiBranch) && ((MultiBranch)ntparentxc).inDifferentBranch(comp)) continue; if (anchor != null) { if (newsibs.remove(comp)) { responses.add(new AuInsertAfter(anchor, drawNew(comp))); if (newsibs.isEmpty()) return; //done (all newsibs are processed) anchor = comp; } else { anchor = comp; } } else if (newsibs.remove(comp)) { before.add(comp); } else { //Generate before in the reverse order and INSERT_BEFORE anchor = comp; for (ListIterator i2 = before.listIterator(before.size()); i2.hasPrevious();) { final Component c = (Component)i2.previous(); responses.add(new AuInsertBefore(anchor, drawNew(c))); anchor = c; } if (newsibs.isEmpty()) return; //done (all newsibs are processed) anchor = comp; } } assert D.OFF || (anchor == null && newsibs.isEmpty()): "anchor="+anchor+" newsibs="+newsibs+" sibs="+sibs; //all siblings are changed (and none of them is processed) final Iterator it = before.iterator(); anchor = (Component)it.next(); responses.add( ntparent != null ? new AuAppendChild(ntparent, drawNew(anchor)): new AuAppendChild(page, drawNew(anchor))); while (it.hasNext()) { final Component comp = (Component)it.next(); responses.add(new AuInsertAfter(anchor, drawNew(comp))); anchor = comp; } } /** Removes redundant components (i.e., an descendant of another). */ private static void removeRedundant(Set comps) { rudLoop: for (Iterator j = comps.iterator(); j.hasNext();) { final Component cj = (Component)j.next(); for (Iterator k = comps.iterator(); k.hasNext();) { final Component ck = (Component)k.next(); if (ck != cj && Components.isAncestor(ck, cj)) { j.remove(); continue rudLoop; } } } } /** Removes redundant components cross _invalidate, _smartUpdate * and _attached. */ private void removeCrossRedundant() { invLoop: for (Iterator j = _invalidated.iterator(); j.hasNext();) { final Component cj = (Component)j.next(); for (Iterator k = _attached.iterator(); k.hasNext();) { final Component ck = (Component)k.next(); if (Components.isAncestor(ck, cj)) { //includes ck == cj j.remove(); continue invLoop; } else if (Components.isAncestor(cj, ck)) { k.remove(); } } } suLoop: for (Iterator j = _smartUpdated.keySet().iterator(); j.hasNext();) { final Component cj = (Component)j.next(); if (isTransparent(cj)) { j.remove(); continue; } for (Iterator k = _invalidated.iterator(); k.hasNext();) { final Component ck = (Component)k.next(); if (Components.isAncestor(ck, cj)) { j.remove(); continue suLoop; } } for (Iterator k = _attached.iterator(); k.hasNext();) { final Component ck = (Component)k.next(); if (Components.isAncestor(ck, cj)) { j.remove(); continue suLoop; } } } } /** Resolve the transpancy of _invalidated and _attached by replacing * transparent components with their non-transparent children. * <p>Reason: a transparent component is not available at the client. */ private void resolveDirtyTransparent(List responses) { //resolves transprent components. List comps = null; for (Iterator it = _invalidated.iterator(); it.hasNext();) { final Component comp = (Component)it.next(); if (isTransparent(comp)) { if (comps == null) comps = new LinkedList(); comps.add(comp); it.remove(); responses.add(new AuRemove(comp)); //yes, we have to remove it because it might change from //non-transparent to transparent (and there is counterpart //in the client to remove) } } if (comps != null) { resolveTransparent(comps, _invalidated); comps = null; } for (Iterator it = _attached.iterator(); it.hasNext();) { final Component comp = (Component)it.next(); if (isTransparent(comp)) { if (comps == null) comps = new LinkedList(); comps.add(comp); it.remove(); responses.add(new AuRemove(comp)); //yes, we have to remove it because it might change from //non-transparent to transparent (and there is counterpart //in the client to remove) } } if (comps != null) resolveTransparent(comps, _attached); } /** Copies comps to result, and resolves comps by replacing transparent * components with their non-transparent children. */ private static void resolveTransparent(List comps, Collection result) { if (comps.isEmpty()) return; for (Iterator it = comps.iterator(); it.hasNext();) { final Component comp = (Component)it.next(); if (isTransparent(comp)) { resolveTransparent(comp.getChildren(), result); //recursive } else { result.add(comp); //either _invalidated.add or _attached.add } } } /** Clones comps and resolves comps by replacing transparent * components with their non-transparent children (right at the same place). */ private static List resolveTransparent(List comps) { if (comps.isEmpty()) return comps; final List cloned = new LinkedList(comps); for (ListIterator it = cloned.listIterator(); it.hasNext();) { final Component comp = (Component)it.next(); if (isTransparent(comp)) { it.remove(); for (Iterator it2 = resolveTransparent(comp.getChildren()) .iterator(); it2.hasNext();) it.add(it2.next()); } } return cloned; } private static Component getNonTransparentParent(Component comp) { for (;;) { comp = comp.getParent(); if (comp == null || !isTransparent(comp)) return comp; } } /** Draws a new attached component into a string. */ private static String drawNew(Component comp) throws IOException { final StringWriter out = new StringWriter(1024*8); comp.redraw(out); final StringBuffer buf = out.getBuffer(); final Component parent = comp.getParent(); if (parent != null) parent.onDrawNewChild(comp, buf); return buf.toString(); } /** Redraw the specified component into a string. */ private static String redraw(Component comp) throws IOException { final StringWriter out = new StringWriter(1024*8); comp.redraw(out); return out.toString(); } /** Redraws the whole page. */ private static String redraw(Page page) throws IOException { final StringWriter out = new StringWriter(1024*8); ((PageCtrl)page).redraw(null, out); return out.toString(); } /** Called before a component redraws itself if the component might * include another page. */ public void pushOwner(Component comp) { _1stec._owners.add(0, comp); } /** Called after a component redraws itself if it ever calls * {@link #pushOwner}. */ public void popOwner() { _1stec._owners.remove(0); } /** Sets the owner of the specified page. * The owner is the top of the stack pushed by {@link #pushOwner}. */ public void setOwner(Page page) { if (_1stec._owners.isEmpty()) { log.warning("No owner available for "+page); } else { final Component owner = (Component)_1stec._owners.get(0); ((PageCtrl)page).setOwner(owner); if (D.ON && log.finerable()) log.finer("Set owner of "+page+" to "+owner); } } /** Used to hold smart update and response with a time stamp. */ private static class TimedValue implements Comparable { private final int _timed; private final AuResponse _response; private TimedValue(int timed, AuResponse response) { _timed = timed; _response = response; } private TimedValue(int timed, Component comp, String name, String value) { _timed = timed; if (value != null) _response = new AuSetAttribute(comp, name, value); else _response = new AuRemoveAttribute(comp, name); } public String toString() { return '(' + _timed + ":" + _response + ')'; } public int compareTo(Object o) { final int t = ((TimedValue)o)._timed; return _timed > t ? 1: _timed == t ? 0: -1; } /** Returns the response representing this object. */ private AuResponse getResponse() { return _response; } }; /** Sets the reason to abort the current execution. * if not null, it means the current execution is aborting * and the specified argument is the reason to aborting. * Its interpretation depends on {@link org.zkoss.zk.ui.sys.UiEngine}. * * <p>Note: if setAbortingReason is ever set with non-null, you * CANNOT set it back to null. * * <p>The aborting flag means no more processing, i.e., dropping pending * requests, events, and rendering. * * <p>After call this method, you shall not keep processing the page * because the rendering is dropped and the client is out-of-sync * with the server. * * <p>This method doesn't really abort pending events and requests. * It just set a flag, {@link #getAbortingReason}, and it is * {@link org.zkoss.zk.ui.sys.UiEngine}'s job to detect this flag * and handling it properly. */ public void setAbortingReason(AbortingReason reason) { if (_aborting != null && reason == null) throw new IllegalStateException("Aborting reason is set and you cannot clear it"); //Reason: some event or request might be skipped //so clearing it might cause unexpected results _aborting = reason; } /** Returns the reason to aborting, or null if no aborting at all. * * @see #setAbortingReason */ public AbortingReason getAbortingReason() { return _aborting; } /** Returns whether it is aborting. * <p>The execution is aborting if {@link #getAbortingReason} returns * not null and the returned reason's {@link AbortingReason#isAborting} * is true. */ public boolean isAborting() { return _aborting != null && _aborting.isAborting(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -