int passes = 0;
Duration totalDuration = new Duration();
ConnectorMap connectorMap = ConnectorMap.get(connection);
JsArrayString dump = needsHorizontalLayout.dump();
int dumpLength = dump.length();
for (int i = 0; i < dumpLength; i++) {
String layoutId = dump.get(i);
currentDependencyTree.setNeedsHorizontalLayout(layoutId, true);
}
dump = needsVerticalLayout.dump();
dumpLength = dump.length();
for (int i = 0; i < dumpLength; i++) {
String layoutId = dump.get(i);
currentDependencyTree.setNeedsVerticalLayout(layoutId, true);
}
needsHorizontalLayout = FastStringSet.create();
needsVerticalLayout = FastStringSet.create();
dump = needsMeasure.dump();
dumpLength = dump.length();
for (int i = 0; i < dumpLength; i++) {
String layoutId = dump.get(i);
currentDependencyTree.setNeedsMeasure(layoutId, true);
}
needsMeasure = FastStringSet.create();
measureNonConnectors();
Profiler.leave("LayoutManager phase init");
while (true) {
Profiler.enter("Layout pass");
passes++;
performBrowserLayoutHacks();
Profiler.enter("Layout measure connectors");
int measuredConnectorCount = measureConnectors(
currentDependencyTree, everythingNeedsMeasure);
Profiler.leave("Layout measure connectors");
everythingNeedsMeasure = false;
if (measuredConnectorCount == 0) {
VConsole.log("No more changes in pass " + passes);
Profiler.leave("Layout pass");
break;
}
int firedListeners = 0;
if (!listenersToFire.isEmpty()) {
firedListeners = listenersToFire.size();
Profiler.enter("Layout fire resize events");
for (Element element : listenersToFire) {
Collection<ElementResizeListener> listeners = elementResizeListeners
.get(element);
if (listeners != null) {
Profiler.enter("Layout fire resize events - listeners not null");
Profiler.enter("ElementResizeListener.onElementResize copy list");
ElementResizeListener[] array = listeners
.toArray(new ElementResizeListener[listeners
.size()]);
Profiler.leave("ElementResizeListener.onElementResize copy list");
ElementResizeEvent event = new ElementResizeEvent(this,
element);
for (ElementResizeListener listener : array) {
try {
String key = null;
if (Profiler.isEnabled()) {
Profiler.enter("ElementResizeListener.onElementResize construct profiler key");
key = "ElementResizeListener.onElementResize for "
+ Util.getSimpleName(listener);
Profiler.leave("ElementResizeListener.onElementResize construct profiler key");
Profiler.enter(key);
}
listener.onElementResize(event);
if (Profiler.isEnabled()) {
Profiler.leave(key);
}
} catch (RuntimeException e) {
VConsole.error(e);
}
}
Profiler.leave("Layout fire resize events - listeners not null");
}
}
listenersToFire.clear();
Profiler.leave("Layout fire resize events");
}
Profiler.enter("LayoutManager handle ManagedLayout");
FastStringSet updatedSet = FastStringSet.create();
int layoutCount = 0;
while (currentDependencyTree.hasHorizontalConnectorToLayout()
|| currentDependencyTree.hasVerticaConnectorToLayout()) {
JsArrayString layoutTargets = currentDependencyTree
.getHorizontalLayoutTargetsJsArray();
int length = layoutTargets.length();
for (int i = 0; i < length; i++) {
ManagedLayout layout = (ManagedLayout) connectorMap
.getConnector(layoutTargets.get(i));
if (layout instanceof DirectionalManagedLayout) {
currentDependencyTree
.markAsHorizontallyLayouted(layout);
DirectionalManagedLayout cl = (DirectionalManagedLayout) layout;
try {
String key = null;
if (Profiler.isEnabled()) {
key = "layoutHorizontally() for "
+ Util.getSimpleName(cl);
Profiler.enter(key);
}
cl.layoutHorizontally();
layoutCount++;
if (Profiler.isEnabled()) {
Profiler.leave(key);
}
} catch (RuntimeException e) {
VConsole.error(e);
}
countLayout(layoutCounts, cl);
} else {
currentDependencyTree
.markAsHorizontallyLayouted(layout);
currentDependencyTree.markAsVerticallyLayouted(layout);
SimpleManagedLayout rr = (SimpleManagedLayout) layout;
try {
String key = null;
if (Profiler.isEnabled()) {
key = "layout() for " + Util.getSimpleName(rr);
Profiler.enter(key);
}
rr.layout();
layoutCount++;
if (Profiler.isEnabled()) {
Profiler.leave(key);
}
} catch (RuntimeException e) {
VConsole.error(e);
}
countLayout(layoutCounts, rr);
}
if (debugLogging) {
updatedSet.add(layout.getConnectorId());
}
}
layoutTargets = currentDependencyTree
.getVerticalLayoutTargetsJsArray();
length = layoutTargets.length();
for (int i = 0; i < length; i++) {
ManagedLayout layout = (ManagedLayout) connectorMap
.getConnector(layoutTargets.get(i));
if (layout instanceof DirectionalManagedLayout) {
currentDependencyTree.markAsVerticallyLayouted(layout);
DirectionalManagedLayout cl = (DirectionalManagedLayout) layout;
try {
String key = null;
if (Profiler.isEnabled()) {
key = "layoutHorizontally() for "
+ Util.getSimpleName(cl);
Profiler.enter(key);
}
cl.layoutVertically();
layoutCount++;
if (Profiler.isEnabled()) {
Profiler.leave(key);
}
} catch (RuntimeException e) {
VConsole.error(e);
}
countLayout(layoutCounts, cl);
} else {
currentDependencyTree
.markAsHorizontallyLayouted(layout);
currentDependencyTree.markAsVerticallyLayouted(layout);
SimpleManagedLayout rr = (SimpleManagedLayout) layout;
try {
String key = null;
if (Profiler.isEnabled()) {
key = "layout() for " + Util.getSimpleName(rr);
Profiler.enter(key);
}
rr.layout();
layoutCount++;
if (Profiler.isEnabled()) {
Profiler.leave(key);
}
} catch (RuntimeException e) {
VConsole.error(e);
}
countLayout(layoutCounts, rr);
}
if (debugLogging) {
updatedSet.add(layout.getConnectorId());
}
}
}
Profiler.leave("LayoutManager handle ManagedLayout");
if (debugLogging) {
JsArrayString changedCids = updatedSet.dump();
StringBuilder b = new StringBuilder(" ");
b.append(changedCids.length());
b.append(" requestLayout invocations ");
if (changedCids.length() < 30) {
for (int i = 0; i < changedCids.length(); i++) {
if (i != 0) {
b.append(", ");
} else {
b.append(": ");
}
String connectorString = changedCids.get(i);
if (changedCids.length() < 10) {
ServerConnector connector = ConnectorMap.get(
connection).getConnector(connectorString);
connectorString = Util
.getConnectorString(connector);
}