unmodifiableManagedChildren = null;
/**
* Gets the list of children of this {@code Parent}.
*
*
* See the class documentation for {@link Node} for scene graph structure
* restrictions on setting a {@link Parent}'s children list.
* If these restrictions are violated by a change to the list of children,
* the change is ignored and the previous value of the children list is
* restored. An {@link IllegalArgumentException} is thrown in this case.
*
*
* If this {@link Parent} node is attached to a {@link Scene} attached to a {@link Window}
* that is showning ({@link javafx.stage.Window#isShowing()}), then its
* list of children must only be modified on the JavaFX Application Thread.
* An {@link IllegalStateException} is thrown if this restriction is
* violated.
*
*
* Note to subclasses: if you override this method, you must return from
* your implementation the result of calling this super method. The actual
* list instance returned from any getChildren() implementation must be
* the list owned and managed by this Parent. The only typical purpose
* for overriding this method is to promote the method to be public.
*
* @return the list of children of this {@code Parent}.
*/
protected ObservableList getChildren() {
return children;
}
/**
* Gets the list of children of this {@code Parent} as a read-only
* list.
*
* @return read-only access to this parent's children ObservableList
*/
public ObservableList getChildrenUnmodifiable() {
return unmodifiableChildren;
}
/**
* Gets the list of all managed children of this {@code Parent}.
*
* @param the type of the children nodes
* @return list of all managed children in this parent
*/
protected List getManagedChildren() {
if (unmodifiableManagedChildren == null) {
unmodifiableManagedChildren = new ArrayList();
for (int i=0, max=children.size(); i)unmodifiableManagedChildren;
}
/**
* Called by Node whenever its managed state may have changed, this
* method will cause the view of managed children to be updated
* such that it properly includes or excludes this child.
*/
final void managedChildChanged() {
requestLayout();
unmodifiableManagedChildren = null;
}
// implementation of Node.toFront function
final void toFront(Node node) {
if (Utils.assertionEnabled()) {
if (!childSet.contains(node)) {
throw new java.lang.AssertionError(
"specified node is not in the list of children");
}
}
if (children.get(children.size() - 1) != node) {
childrenTriggerPermutation = true;
try {
children.remove(node);
children.add(node);
} finally {
childrenTriggerPermutation = false;
}
}
}
// implementation of Node.toBack function
final void toBack(Node node) {
if (Utils.assertionEnabled()) {
if (!childSet.contains(node)) {
throw new java.lang.AssertionError(
"specified node is not in the list of children");
}
}
if (children.get(0) != node) {
childrenTriggerPermutation = true;
try {
children.remove(node);
children.add(0, node);
} finally {
childrenTriggerPermutation = false;
}
}
}
@Override
void scenesChanged(final Scene newScene, final SubScene newSubScene,
final Scene oldScene, final SubScene oldSubScene) {
if (oldScene != null && newScene == null) {
// RT-34863 - clean up CSS cache when Parent is removed from scene-graph
StyleManager.getInstance().forget(this);
// Clear removed list on parent who is no longer in a scene
if (removed != null) {
removed.clear();
}
}
for (int i=0; i orderedChildren = getOrderedChildren();
for (int i = orderedChildren.size() - 1; i >= 0; i--) {
orderedChildren.get(i).pickNode(pickRay, result);
if (result.isClosed()) {
return false;
}
}
return true;
}
/*
* Note: This method MUST only be called via its accessor method.
*/
private void doPickNodeLocal(PickRay pickRay, PickResultChooser result) {
double boundsDistance = intersectsBounds(pickRay);
if (!Double.isNaN(boundsDistance) && pickChildrenNode(pickRay, result)) {
if (isPickOnBounds()) {
result.offer(this, boundsDistance, PickResultChooser.computePoint(pickRay, boundsDistance));
}
}
}
@Override boolean isConnected() {
return super.isConnected() || sceneRoot;
}
@Override public Node lookup(String selector) {
Node n = super.lookup(selector);
if (n == null) {
for (int i=0, max=children.size(); i lookupAll(Selector selector, List results) {
results = super.lookupAll(selector, results);
for (int i=0, max=children.size(); i
* If this parent is either a layout root or unmanaged, then it will be
* added directly to the scene's dirty layout list, otherwise requestParentLayout
* will be invoked.
* @since JavaFX 8.0
*/
public void requestLayout() {
clearSizeCache();
markDirtyLayout(false, forceParentLayout);
}
private boolean forceParentLayout = false;
/**
* A package scope method used by Node and serves as a helper method for
* requestLayout() (see above). If forceParentLayout is true it will
* propagate this force layout flag to its parent.
*/
void requestLayout(boolean forceParentLayout) {
boolean savedForceParentLayout = this.forceParentLayout;
this.forceParentLayout = forceParentLayout;
requestLayout();
this.forceParentLayout = savedForceParentLayout;
}
/**
* Requests a layout pass of the parent to be performed before the next scene is
* rendered. This is batched up asynchronously to happen once per
* "pulse", or frame of animation.
*
* This may be used when the current parent have changed it's min/max/preferred width/height,
* but doesn't know yet if the change will lead to it's actual size change. This will be determined
* when it's parent recomputes the layout with the new hints.
*/
protected final void requestParentLayout() {
requestParentLayout(false);
}
/**
* A package scope method used by Node and serves as a helper method for
* requestParentLayout() (see above). If forceParentLayout is true it will
* force a request layout call on its parent if its parent is not null.
*/
void requestParentLayout(boolean forceParentLayout) {
if (!layoutRoot) {
final Parent p = getParent();
if (p != null && (!p.performingLayout || forceParentLayout)) {
p.requestLayout();
}
}
}
void clearSizeCache() {
if (sizeCacheClear) {
return;
}
sizeCacheClear = true;
prefWidthCache = -1;
prefHeightCache = -1;
minWidthCache = -1;
minHeightCache = -1;
}
@Override public double prefWidth(double height) {
if (height == -1) {
if (prefWidthCache == -1) {
prefWidthCache = computePrefWidth(-1);
if (Double.isNaN(prefWidthCache) || prefWidthCache < 0) prefWidthCache = 0;
sizeCacheClear = false;
}
return prefWidthCache;
} else {
double result = computePrefWidth(height);
return Double.isNaN(result) || result < 0 ? 0 : result;
}
}
@Override public double prefHeight(double width) {
if (width == -1) {
if (prefHeightCache == -1) {
prefHeightCache = computePrefHeight(-1);
if (Double.isNaN(prefHeightCache) || prefHeightCache < 0) prefHeightCache = 0;
sizeCacheClear = false;
}
return prefHeightCache;
} else {
double result = computePrefHeight(width);
return Double.isNaN(result) || result < 0 ? 0 : result;
}
}
@Override public double minWidth(double height) {
if (height == -1) {
if (minWidthCache == -1) {
minWidthCache = computeMinWidth(-1);
if (Double.isNaN(minWidthCache) || minWidthCache < 0) minWidthCache = 0;
sizeCacheClear = false;
}
return minWidthCache;
} else {
double result = computeMinWidth(height);
return Double.isNaN(result) || result < 0 ? 0 : result;
}
}
@Override public double minHeight(double width) {
if (width == -1) {
if (minHeightCache == -1) {
minHeightCache = computeMinHeight(-1);
if (Double.isNaN(minHeightCache) || minHeightCache < 0) minHeightCache = 0;
sizeCacheClear = false;
}
return minHeightCache;
} else {
double result = computeMinHeight(width);
return Double.isNaN(result) || result < 0 ? 0 : result;
}
}
// PENDING_DOC_REVIEW
/**
* Calculates the preferred width of this {@code Parent}. The default
* implementation calculates this width as the width of the area occupied
* by its managed children when they are positioned at their
* current positions at their preferred widths.
*
* @param height the height that should be used if preferred width depends
* on it
* @return the calculated preferred width
*/
protected double computePrefWidth(double height) {
double minX = 0;
double maxX = 0;
for (int i=0, max=children.size(); i
* Subclasses should override this function to layout content as needed.
*/
protected void layoutChildren() {
for (int i=0, max=children.size(); iCSS Reference
* Guide.
*/
private final ObservableList stylesheets = new TrackableObservableList() {
@Override
protected void onChanged(Change c) {
final Scene scene = getScene();
if (scene != null) {
// Notify the StyleManager if stylesheets change. This Parent's
// styleManager will get recreated in NodeHelper.processCSS.
StyleManager.getInstance().stylesheetsChanged(Parent.this, c);
// RT-9784 - if stylesheet is removed, reset styled properties to
// their initial value.
c.reset();
while(c.next()) {
if (c.wasRemoved() == false) {
continue;
}
break; // no point in resetting more than once...
}
reapplyCSS();
}
}
};
/**
* Gets an observable list of string URLs linking to the stylesheets to use
* with this Parent's contents. See {@link Scene#getStylesheets()} for details.
* For additional information about using CSS
* with the scene graph, see the CSS Reference
* Guide.
*
* @return the list of stylesheets to use with this Parent
* @since JavaFX 2.1
*/
public final ObservableList getStylesheets() { return stylesheets; }
/*
* This method recurses up the parent chain until parent is null. As the
* stack unwinds, if the Parent has stylesheets, they are added to the
* list.
*
* It is possible to override this method to stop the recursion. This allows
* a Parent to have a set of stylesheets distinct from its Parent.
*
* Note: This method MUST only be called via its accessor method.
*/
// SB-dependency: RT-21247 has been filed to track this
private List doGetAllParentStylesheets() {
List list = null;
final Parent myParent = getParent();
if (myParent != null) {
//
// recurse so that stylesheets of Parents closest to the root are
// added to the list first. The ensures that declarations for
// stylesheets further down the tree (closer to the leaf) have
// a higer ordinal in the cascade.
//
list = ParentHelper.getAllParentStylesheets(myParent);
}
if (stylesheets != null && stylesheets.isEmpty() == false) {
if (list == null) {
list = new ArrayList(stylesheets.size());
}
for (int n=0,nMax=stylesheets.size(); n 0) {
child.cssFlag = CssFlags.UPDATE;
}
NodeHelper.processCSS(child);
}
}
/***********************************************************************
* Misc *
* *
* Initialization and other functions *
* *
**********************************************************************/
{
// To initialize the class helper at the begining each constructor of this class
ParentHelper.initHelper(this);
}
/**
* Constructs a new {@code Parent}.
*/
protected Parent() {
layoutFlag = LayoutFlags.NEEDS_LAYOUT;
setAccessibleRole(AccessibleRole.PARENT);
}
private NGNode doCreatePeer() {
return new NGGroup();
}
@Override
void nodeResolvedOrientationChanged() {
for (int i = 0, max = children.size(); i < max; ++i) {
children.get(i).parentResolvedOrientationInvalidated();
}
}
/***************************************************************************
* *
* Bounds Computations *
* *
* This code originated in GroupBoundsHelper (part of javafx-sg-common) *
* but has been ported here to the FX side since we cannot rely on the PG *
* side for computing the bounds (due to the decoupling of the two *
* scenegraphs for threading and other purposes). *
* *
* Unfortunately, we cannot simply reuse GroupBoundsHelper without some *
* major (and hacky) modification due to the fact that GroupBoundsHelper *
* relies on PG state and we need to do similar things here that rely on *
* core scenegraph state. Unfortunately, that means we made a port. *
* *
**************************************************************************/
private BaseBounds tmp = new RectBounds();
/**
* The cached bounds for the Group. If the cachedBounds are invalid
* then we have no history of what the bounds are, or were.
*/
private BaseBounds cachedBounds = new RectBounds();
/**
* Indicates that the cachedBounds is invalid (or old) and need to be recomputed.
* If cachedBoundsInvalid is true and dirtyChildrenCount is non-zero,
* then when we recompute the cachedBounds we can consider the
* values in cachedBounds to represent the last valid bounds for the group.
* This is useful for several fast paths.
*/
private boolean cachedBoundsInvalid;
/**
* The number of dirty children which bounds haven't been incorporated
* into the cached bounds yet. Can be used even when dirtyChildren is null.
*/
private int dirtyChildrenCount;
/**
* This set is used to track all of the children of this group which are
* dirty. It is only used in cases where the number of children is > some
* value (currently 10). For very wide trees, this can provide a very
* important speed boost. For the sake of memory consumption, this is
* null unless the number of children ever crosses the threshold where
* it will be activated.
*/
private ArrayList dirtyChildren;
private Node top;
private Node left;
private Node bottom;
private Node right;
private Node near;
private Node far;
private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx) {
// If we have no children, our bounds are invalid
if (children.isEmpty()) {
return bounds.makeEmpty();
}
if (tx.isTranslateOrIdentity()) {
// this is a transform which is only doing translations, or nothing
// at all (no scales, rotates, or shears)
// so in this case we can easily use the cached bounds
if (cachedBoundsInvalid) {
recomputeBounds();
if (dirtyChildren != null) {
dirtyChildren.clear();
}
cachedBoundsInvalid = false;
dirtyChildrenCount = 0;
}
if (!tx.isIdentity()) {
bounds = bounds.deriveWithNewBounds((float)(cachedBounds.getMinX() + tx.getMxt()),
(float)(cachedBounds.getMinY() + tx.getMyt()),
(float)(cachedBounds.getMinZ() + tx.getMzt()),
(float)(cachedBounds.getMaxX() + tx.getMxt()),
(float)(cachedBounds.getMaxY() + tx.getMyt()),
(float)(cachedBounds.getMaxZ() + tx.getMzt()));
} else {
bounds = bounds.deriveWithNewBounds(cachedBounds);
}
return bounds;
} else {
// there is a scale, shear, or rotation happening, so need to
// do the full transform!
double minX = Double.MAX_VALUE, minY = Double.MAX_VALUE, minZ = Double.MAX_VALUE;
double maxX = Double.MIN_VALUE, maxY = Double.MIN_VALUE, maxZ = Double.MIN_VALUE;
boolean first = true;
for (int i=0, max=children.size(); i dirtyNodes,
int remainingDirtyNodes) {
// fast path for untransformed bounds calculation
if (cachedBounds.isEmpty()) {
createCachedBounds(dirtyNodes);
return true;
}
int invalidEdges = 0;
if ((left == null) || left.boundsChanged) {
invalidEdges |= LEFT_INVALID;
}
if ((top == null) || top.boundsChanged) {
invalidEdges |= TOP_INVALID;
}
if ((near == null) || near.boundsChanged) {
invalidEdges |= NEAR_INVALID;
}
if ((right == null) || right.boundsChanged) {
invalidEdges |= RIGHT_INVALID;
}
if ((bottom == null) || bottom.boundsChanged) {
invalidEdges |= BOTTOM_INVALID;
}
if ((far == null) || far.boundsChanged) {
invalidEdges |= FAR_INVALID;
}
// These indicate the bounds of the Group as computed by this
// function
float minX = cachedBounds.getMinX();
float minY = cachedBounds.getMinY();
float minZ = cachedBounds.getMinZ();
float maxX = cachedBounds.getMaxX();
float maxY = cachedBounds.getMaxY();
float maxZ = cachedBounds.getMaxZ();
// this checks the newly added nodes first, so if dirtyNodes is the
// whole children list, we can end early
for (int i = dirtyNodes.size() - 1; remainingDirtyNodes > 0; --i) {
final Node node = dirtyNodes.get(i);
if (node.boundsChanged) {
// assert node.isVisible();
node.boundsChanged = false;
--remainingDirtyNodes;
tmp = getChildTransformedBounds(node, BaseTransform.IDENTITY_TRANSFORM, tmp);
if (!tmp.isEmpty()) {
float tmpx = tmp.getMinX();
float tmpy = tmp.getMinY();
float tmpz = tmp.getMinZ();
float tmpx2 = tmp.getMaxX();
float tmpy2 = tmp.getMaxY();
float tmpz2 = tmp.getMaxZ();
// If this node forms an edge, then we will set it to be the
// node for this edge and update the min/max values
if (tmpx <= minX) {
minX = tmpx;
left = node;
invalidEdges &= ~LEFT_INVALID;
}
if (tmpy <= minY) {
minY = tmpy;
top = node;
invalidEdges &= ~TOP_INVALID;
}
if (tmpz <= minZ) {
minZ = tmpz;
near = node;
invalidEdges &= ~NEAR_INVALID;
}
if (tmpx2 >= maxX) {
maxX = tmpx2;
right = node;
invalidEdges &= ~RIGHT_INVALID;
}
if (tmpy2 >= maxY) {
maxY = tmpy2;
bottom = node;
invalidEdges &= ~BOTTOM_INVALID;
}
if (tmpz2 >= maxZ) {
maxZ = tmpz2;
far = node;
invalidEdges &= ~FAR_INVALID;
}
}
}
}
if (invalidEdges != 0) {
// failed to validate some edges
return false;
}
cachedBounds = cachedBounds.deriveWithNewBounds(minX, minY, minZ,
maxX, maxY, maxZ);
return true;
}
private void createCachedBounds(final List fromNodes) {
// These indicate the bounds of the Group as computed by this function
float minX, minY, minZ;
float maxX, maxY, maxZ;
final int nodeCount = fromNodes.size();
int i;
// handle first visible non-empty node
for (i = 0; i < nodeCount; ++i) {
final Node node = fromNodes.get(i);
node.boundsChanged = false;
if (node.isVisible()) {
tmp = node.getTransformedBounds(
tmp, BaseTransform.IDENTITY_TRANSFORM);
if (!tmp.isEmpty()) {
left = top = near = right = bottom = far = node;
break;
}
}
}
if (i == nodeCount) {
left = top = near = right = bottom = far = null;
cachedBounds.makeEmpty();
return;
}
minX = tmp.getMinX();
minY = tmp.getMinY();
minZ = tmp.getMinZ();
maxX = tmp.getMaxX();
maxY = tmp.getMaxY();
maxZ = tmp.getMaxZ();
// handle remaining visible non-empty nodes
for (++i; i < nodeCount; ++i) {
final Node node = fromNodes.get(i);
node.boundsChanged = false;
if (node.isVisible()) {
tmp = node.getTransformedBounds(
tmp, BaseTransform.IDENTITY_TRANSFORM);
if (!tmp.isEmpty()) {
final float tmpx = tmp.getMinX();
final float tmpy = tmp.getMinY();
final float tmpz = tmp.getMinZ();
final float tmpx2 = tmp.getMaxX();
final float tmpy2 = tmp.getMaxY();
final float tmpz2 = tmp.getMaxZ();
if (tmpx < minX) { minX = tmpx; left = node; }
if (tmpy < minY) { minY = tmpy; top = node; }
if (tmpz < minZ) { minZ = tmpz; near = node; }
if (tmpx2 > maxX) { maxX = tmpx2; right = node; }
if (tmpy2 > maxY) { maxY = tmpy2; bottom = node; }
if (tmpz2 > maxZ) { maxZ = tmpz2; far = node; }
}
}
}
cachedBounds = cachedBounds.deriveWithNewBounds(minX, minY, minZ,
maxX, maxY, maxZ);
}
/**
* Updates the bounds of this {@code Parent} and its children.
*/
@Override protected void updateBounds() {
for (int i=0, max=children.size(); i test_getRemoved() {
return removed;
}
/**
* Note: The only user of this method is in unit test:
* Parent_viewOrderChildren_sync_Test.
*/
List test_getViewOrderChildren() {
return viewOrderChildren;
}
}