in kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/content/driver/tring/GenericParentTring.java [160:286]
private static Bounds computeCrackBounds(DesignHierarchyMask m, int childIndex) {
assert m != null;
assert m.isAcceptingSubComponent();
assert childIndex >= -1;
assert childIndex < m.getSubComponentCount();
final double crackX, crackY0, crackY1, crackWidth;
final int childCount = m.getSubComponentCount();
final Node child, skinParent;
if (childIndex == -1) {
child = getChildNode(m, childCount-1);
skinParent = child.getParent();
final Bounds cb = child.localToParent(child.getLayoutBounds());
crackX = cb.getMaxX();
crackY0 = cb.getMinY();
crackY1 = cb.getMaxY();
crackWidth = CRACK_MIN_WIDTH;
} else if (childIndex == 0) {
child = getChildNode(m, 0);
skinParent = child.getParent();
final Bounds cb = child.localToParent(child.getLayoutBounds());
crackX = cb.getMinX();
crackY0 = cb.getMinY();
crackY1 = cb.getMaxY();
crackWidth = CRACK_MIN_WIDTH;
} else {
/* child at child at
* targetIndex-1 targetIndex
*
* y0 +--------------+ crackY0
* y1 +---------------+ | |
* | | | |
* | prevBounds | | bounds |
* | | | |
* y2 +---------------+ | |
* | |
* y3 +--------------+ crackY1
* x0 crackX x1
*
*
*/
assert (1 <= childIndex) && (childIndex < childCount);
child = getChildNode(m, childIndex);
final Node prevChild = getChildNode(m, childIndex-1);
/*
* child and prevChild may or may not be visible.
* For example, when a ToolBar is shrinked, it automatically
* hides the rightmost children. Those nodes are disconnected
* from the skin and have a null parent.
*/
final double x0, x1, y0, y2, y1, y3;
if ((child.getParent() != null) && (prevChild.getParent() != null)) {
assert child.getParent() == prevChild.getParent();
skinParent = child.getParent();
final Bounds prevBounds = prevChild.getBoundsInParent();
final Bounds bounds = child.getBoundsInParent();
x0 = prevBounds.getMaxX();
x1 = bounds.getMinX();
y0 = bounds.getMinY();
y1 = prevBounds.getMinY();
y2 = prevBounds.getMaxY();
y3 = bounds.getMaxY();
} else if (child.getParent() != null) {
skinParent = child.getParent();
final Bounds bounds = child.getBoundsInParent();
x0 = x1 = bounds.getMinX();
y0 = y1 = bounds.getMinY();
y2 = y3 = bounds.getMaxY();
} else if (prevChild.getParent() != null) {
skinParent = prevChild.getParent();
final Bounds prevBounds = prevChild.getBoundsInParent();
x0 = x1 = prevBounds.getMaxX();
y0 = y1 = prevBounds.getMinY();
y2 = y3 = prevBounds.getMaxY();
} else {
// Both children are disconnect from the skin :(
x0 = x1 = y0 = y1 = y2 = y3 = 0.0; // To generate empty bounds
skinParent = null;
}
if (x0 <= x1) {
crackX = (x0 + x1) / 2.0;
crackY0 = Math.min(y0, y1);
crackY1 = Math.max(y2, y3);
crackWidth = Math.max(CRACK_MIN_WIDTH, x1 - x0);
} else {
crackX = x1;
crackY0 = y0;
crackY1 = y3;
crackWidth = CRACK_MIN_WIDTH;
}
}
assert m.getFxomObject().getSceneGraphObject() instanceof Parent;
final Parent parent = (Parent) m.getFxomObject().getSceneGraphObject();
final double pCrackX, pCrackY0, pCrackY1;
if (parent != skinParent) {
// m.getFxomObject() is a skinned component : so its fxom children
// are not the direct Node children.
if (skinParent != null) {
final Point2D p0 = Deprecation.localToLocal(skinParent, crackX, crackY0, parent);
final Point2D p1 = Deprecation.localToLocal(skinParent, crackX, crackY1, parent);
assert MathUtils.equals(p0.getX(), p1.getX());
pCrackX = p0.getX();
pCrackY0 = p0.getY();
pCrackY1 = p1.getY();
} else {
// Child at childIndex is inside a skin and is currently not
// visible : we generate and return empty bounds.
pCrackX = 0.0;
pCrackY0 = 0.0;
pCrackY1 = 0.0;
}
} else {
pCrackX = crackX;
pCrackY0 = crackY0;
pCrackY1 = crackY1;
}
return new BoundingBox(pCrackX - crackWidth /2, pCrackY0, crackWidth, pCrackY1 - pCrackY0);
}