9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.javafx.scene.traversal;
27
28 import com.sun.javafx.application.PlatformImpl;
29 import javafx.geometry.BoundingBox;
30 import javafx.geometry.Bounds;
31 import javafx.scene.Node;
32 import javafx.scene.Parent;
33
34 import java.util.ArrayList;
35 import java.util.List;
36
37 /**
38 * This is abstract class for a traversal engine. There are 2 types : {@link com.sun.javafx.scene.traversal.ParentTraversalEngine}
39 * to be used in {@link Parent#setTraversalEngine(ParentTraversalEngine)} to override default behavior
40 * and {@link com.sun.javafx.scene.traversal.TopMostTraversalEngine} that is the default traversal engine for scene and subscene.
41 *
42 * Every engine is basically a wrapper of an algorithm + some specific parent (or scene/subscene), which define engine's root.
43 */
44 public abstract class TraversalEngine{
45
46 /**
47 * This is the default algorithm for the running platform. It's the algorithm that's used in TopMostTraversalEngine
48 */
187 private abstract class BaseEngineContext implements TraversalContext {
188
189 /**
190 * Returns all traversable nodes in the context's (engine's) root
191 */
192 @Override
193 public List<Node> getAllTargetNodes() {
194 final List<Node> targetNodes = new ArrayList<>();
195 addFocusableChildrenToList(targetNodes, getRoot());
196 return targetNodes;
197 }
198
199 @Override
200 public Bounds getSceneLayoutBounds(Node n) {
201 return getLayoutBounds(n, null);
202 }
203
204 private void addFocusableChildrenToList(List<Node> list, Parent parent) {
205 List<Node> parentsNodes = parent.getChildrenUnmodifiable();
206 for (Node n : parentsNodes) {
207 if (n.isFocusTraversable() && !n.isFocused() && n.impl_isTreeVisible() && !n.isDisabled()) {
208 list.add(n);
209 }
210 if (n instanceof Parent) {
211 addFocusableChildrenToList(list, (Parent)n);
212 }
213 }
214 }
215
216 // All of the methods below are callbacks from traversal context to the default algorithm.
217 // They can be used to obtain "default" result for the specified subtree.
218 // This is useful when there is some algorithm that overrides behavior for a Parent but parent's children
219 // should be again traversed by default algorithm.
220 @Override
221 public Node selectFirstInParent(Parent parent) {
222 tempEngineContext.setRoot(parent);
223 return DEFAULT_ALGORITHM.selectFirst(tempEngineContext);
224 }
225
226 @Override
227 public Node selectLastInParent(Parent parent) {
|
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.javafx.scene.traversal;
27
28 import com.sun.javafx.application.PlatformImpl;
29 import com.sun.javafx.scene.NodeHelper;
30 import javafx.geometry.BoundingBox;
31 import javafx.geometry.Bounds;
32 import javafx.scene.Node;
33 import javafx.scene.Parent;
34
35 import java.util.ArrayList;
36 import java.util.List;
37
38 /**
39 * This is abstract class for a traversal engine. There are 2 types : {@link com.sun.javafx.scene.traversal.ParentTraversalEngine}
40 * to be used in {@link Parent#setTraversalEngine(ParentTraversalEngine)} to override default behavior
41 * and {@link com.sun.javafx.scene.traversal.TopMostTraversalEngine} that is the default traversal engine for scene and subscene.
42 *
43 * Every engine is basically a wrapper of an algorithm + some specific parent (or scene/subscene), which define engine's root.
44 */
45 public abstract class TraversalEngine{
46
47 /**
48 * This is the default algorithm for the running platform. It's the algorithm that's used in TopMostTraversalEngine
49 */
188 private abstract class BaseEngineContext implements TraversalContext {
189
190 /**
191 * Returns all traversable nodes in the context's (engine's) root
192 */
193 @Override
194 public List<Node> getAllTargetNodes() {
195 final List<Node> targetNodes = new ArrayList<>();
196 addFocusableChildrenToList(targetNodes, getRoot());
197 return targetNodes;
198 }
199
200 @Override
201 public Bounds getSceneLayoutBounds(Node n) {
202 return getLayoutBounds(n, null);
203 }
204
205 private void addFocusableChildrenToList(List<Node> list, Parent parent) {
206 List<Node> parentsNodes = parent.getChildrenUnmodifiable();
207 for (Node n : parentsNodes) {
208 if (n.isFocusTraversable() && !n.isFocused() && NodeHelper.isTreeVisible(n) && !n.isDisabled()) {
209 list.add(n);
210 }
211 if (n instanceof Parent) {
212 addFocusableChildrenToList(list, (Parent)n);
213 }
214 }
215 }
216
217 // All of the methods below are callbacks from traversal context to the default algorithm.
218 // They can be used to obtain "default" result for the specified subtree.
219 // This is useful when there is some algorithm that overrides behavior for a Parent but parent's children
220 // should be again traversed by default algorithm.
221 @Override
222 public Node selectFirstInParent(Parent parent) {
223 tempEngineContext.setRoot(parent);
224 return DEFAULT_ALGORITHM.selectFirst(tempEngineContext);
225 }
226
227 @Override
228 public Node selectLastInParent(Parent parent) {
|