Parallel and Sequential transitions can have child animations. An animation can be added to more than one parent and all parents will have the child animation in their children list, but the animation's data structure can only hold one parent. This causes the following inconsistencies:
1. Adding an animation to 2 parents causes it to only treat the second parent as a parent.
2. Adding an animation to 2 parents, then removing it from one parent, causes it to have no parent.
If multiple parents is an intended state, the data structure needs to reflect this, and the public API method Transition#getParentTargetNode() needs to be updated.
The first solution that comes to mind is to hold a set of parents instead of a single one.
If multiple parents is not an intended state, adding an animation to a parent must remove the animation from the previous parent.
The following test code demonstrates the problem:
Animation child = new PauseTransition();
SequentialTransition parent1 = new SequentialTransition();
ParallelTransition parent2 = new ParallelTransition();
assertEquals("Animation should have no parent", null, AnimationShim.getParent(child));
parent1.getChildren().add(child);
assertTrue(parent1.getChildren().contains(child));
assertEquals("Animation should have a SequentialTransition parent", parent1, AnimationShim.getParent(child));
parent2.getChildren().add(child);
assertTrue(parent1.getChildren().contains(child));
assertTrue(parent2.getChildren().contains(child));
assertEquals("Animation should still have a SequentialTransition parent", parent1, AnimationShim.getParent(child)); // fails
parent2.getChildren().remove(child);
assertTrue(parent1.getChildren().contains(child));
assertTrue(!parent2.getChildren().contains(child));
assertEquals("Animation should still have a SequentialTransition parent", parent1, AnimationShim.getParent(child)); // fails
1. Adding an animation to 2 parents causes it to only treat the second parent as a parent.
2. Adding an animation to 2 parents, then removing it from one parent, causes it to have no parent.
If multiple parents is an intended state, the data structure needs to reflect this, and the public API method Transition#getParentTargetNode() needs to be updated.
The first solution that comes to mind is to hold a set of parents instead of a single one.
If multiple parents is not an intended state, adding an animation to a parent must remove the animation from the previous parent.
The following test code demonstrates the problem:
Animation child = new PauseTransition();
SequentialTransition parent1 = new SequentialTransition();
ParallelTransition parent2 = new ParallelTransition();
assertEquals("Animation should have no parent", null, AnimationShim.getParent(child));
parent1.getChildren().add(child);
assertTrue(parent1.getChildren().contains(child));
assertEquals("Animation should have a SequentialTransition parent", parent1, AnimationShim.getParent(child));
parent2.getChildren().add(child);
assertTrue(parent1.getChildren().contains(child));
assertTrue(parent2.getChildren().contains(child));
assertEquals("Animation should still have a SequentialTransition parent", parent1, AnimationShim.getParent(child)); // fails
parent2.getChildren().remove(child);
assertTrue(parent1.getChildren().contains(child));
assertTrue(!parent2.getChildren().contains(child));
assertEquals("Animation should still have a SequentialTransition parent", parent1, AnimationShim.getParent(child)); // fails
- relates to
-
JDK-8091669 Composite pattern in Animation API
- Open