< prev index next >

modules/graphics/src/main/java/com/sun/javafx/scene/traversal/TabOrderHelper.java

Print this page




   8  * particular file as subject to the "Classpath" exception as provided
   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.scene.ParentHelper;
  29 import javafx.collections.ObservableList;
  30 import javafx.scene.Node;
  31 import javafx.scene.Parent;
  32 
  33 import java.util.List;
  34 
  35 final class TabOrderHelper {
  36     private static Node findPreviousFocusableInList(List<Node> nodeList, int startIndex) {
  37         for (int i = startIndex ; i >= 0 ; i--) {
  38             Node prevNode = nodeList.get(i);
  39             // ParentTraverEngine can override traversability, so we need to check it first
  40             if (isDisabledOrInvisible(prevNode)) continue;
  41             final ParentTraversalEngine traversalEngine = prevNode instanceof Parent
  42                     ? ParentHelper.getTraversalEngine((Parent) prevNode) : null;
  43             if (prevNode instanceof Parent) {
  44                 if (traversalEngine != null && traversalEngine.canTraverse()) {
  45                     Node selected = traversalEngine.selectLast();
  46                     if (selected != null) {
  47                         return selected;


  49                 } else {
  50                     List<Node> prevNodesList = ((Parent) prevNode).getChildrenUnmodifiable();
  51                     if (prevNodesList.size() > 0) {
  52                         Node newNode = findPreviousFocusableInList(prevNodesList, prevNodesList.size() - 1);
  53                         if (newNode != null) {
  54                             return newNode;
  55                         }
  56                     }
  57                 }
  58             }
  59             if (traversalEngine != null
  60                     ? traversalEngine.isParentTraversable()
  61                     : prevNode.isFocusTraversable()) {
  62                 return prevNode;
  63             }
  64         }
  65         return null;
  66     }
  67 
  68     private static boolean isDisabledOrInvisible(Node prevNode) {
  69         return prevNode.isDisabled() || !prevNode.impl_isTreeVisible();
  70     }
  71 
  72     public static Node findPreviousFocusablePeer(Node node, Parent root) {
  73         Node startNode = node;
  74         Node newNode = null;
  75         List<Node> parentNodes = findPeers(startNode);
  76 
  77         if (parentNodes == null) {
  78             // We are at top level, so select the last focusable node
  79             ObservableList<Node> rootChildren = ((Parent) node).getChildrenUnmodifiable();
  80             return findPreviousFocusableInList(rootChildren, rootChildren.size() - 1);
  81         }
  82 
  83         int ourIndex = parentNodes.indexOf(startNode);
  84 
  85         // Start with the siblings "to the left"
  86         newNode = findPreviousFocusableInList(parentNodes, ourIndex - 1);
  87 
  88         /*
  89         ** we've reached the end of the peer nodes, and none have been selected,




   8  * particular file as subject to the "Classpath" exception as provided
   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.scene.NodeHelper;
  29 import com.sun.javafx.scene.ParentHelper;
  30 import javafx.collections.ObservableList;
  31 import javafx.scene.Node;
  32 import javafx.scene.Parent;
  33 
  34 import java.util.List;
  35 
  36 final class TabOrderHelper {
  37     private static Node findPreviousFocusableInList(List<Node> nodeList, int startIndex) {
  38         for (int i = startIndex ; i >= 0 ; i--) {
  39             Node prevNode = nodeList.get(i);
  40             // ParentTraverEngine can override traversability, so we need to check it first
  41             if (isDisabledOrInvisible(prevNode)) continue;
  42             final ParentTraversalEngine traversalEngine = prevNode instanceof Parent
  43                     ? ParentHelper.getTraversalEngine((Parent) prevNode) : null;
  44             if (prevNode instanceof Parent) {
  45                 if (traversalEngine != null && traversalEngine.canTraverse()) {
  46                     Node selected = traversalEngine.selectLast();
  47                     if (selected != null) {
  48                         return selected;


  50                 } else {
  51                     List<Node> prevNodesList = ((Parent) prevNode).getChildrenUnmodifiable();
  52                     if (prevNodesList.size() > 0) {
  53                         Node newNode = findPreviousFocusableInList(prevNodesList, prevNodesList.size() - 1);
  54                         if (newNode != null) {
  55                             return newNode;
  56                         }
  57                     }
  58                 }
  59             }
  60             if (traversalEngine != null
  61                     ? traversalEngine.isParentTraversable()
  62                     : prevNode.isFocusTraversable()) {
  63                 return prevNode;
  64             }
  65         }
  66         return null;
  67     }
  68 
  69     private static boolean isDisabledOrInvisible(Node prevNode) {
  70         return prevNode.isDisabled() || !NodeHelper.isTreeVisible(prevNode);
  71     }
  72 
  73     public static Node findPreviousFocusablePeer(Node node, Parent root) {
  74         Node startNode = node;
  75         Node newNode = null;
  76         List<Node> parentNodes = findPeers(startNode);
  77 
  78         if (parentNodes == null) {
  79             // We are at top level, so select the last focusable node
  80             ObservableList<Node> rootChildren = ((Parent) node).getChildrenUnmodifiable();
  81             return findPreviousFocusableInList(rootChildren, rootChildren.size() - 1);
  82         }
  83 
  84         int ourIndex = parentNodes.indexOf(startNode);
  85 
  86         // Start with the siblings "to the left"
  87         newNode = findPreviousFocusableInList(parentNodes, ourIndex - 1);
  88 
  89         /*
  90         ** we've reached the end of the peer nodes, and none have been selected,


< prev index next >