< prev index next >

modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TwoLevelFocusBehavior.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.control.behavior;
  27 

  28 import javafx.css.PseudoClass;
  29 import javafx.scene.Node;
  30 import javafx.scene.control.Control;
  31 import javafx.scene.control.PopupControl;
  32 
  33 import javafx.scene.Scene;
  34 import javafx.scene.input.KeyEvent;
  35 
  36 import javafx.beans.value.ChangeListener;
  37 import javafx.event.Event;
  38 import javafx.event.EventDispatcher;
  39 import javafx.event.EventHandler;
  40 import javafx.scene.input.MouseEvent;
  41 
  42 /**
  43  * A two level focus handler allows a Control to behave as if it
  44  * has three focus states :
  45  *  - not focused
  46  *  - focused with internal focus
  47  *  - focused with external focus


  86 
  87     /**
  88      * Don't allow the Node to handle a key event if it is in externalFocus mode.
  89      * the only keyboard actions allowed are the navigation keys......
  90      */
  91     final EventDispatcher preemptiveEventDispatcher = (event, tail) -> {
  92 
  93         // block the event from being passed down to children
  94         if (event instanceof KeyEvent && event.getEventType() == KeyEvent.KEY_PRESSED) {
  95             if (!((KeyEvent)event).isMetaDown() && !((KeyEvent)event).isControlDown()  && !((KeyEvent)event).isAltDown()) {
  96                 if (isExternalFocus()) {
  97                     //
  98                     // don't let the behaviour leak any navigation keys when
  99                     // we're not in blocking mode....
 100                     //
 101                     Object obj = event.getTarget();
 102 
 103                     switch (((KeyEvent)event).getCode()) {
 104                       case TAB :
 105                           if (((KeyEvent)event).isShiftDown()) {
 106                               ((Node)obj).impl_traverse(com.sun.javafx.scene.traversal.Direction.PREVIOUS);
 107                           }
 108                           else {
 109                               ((Node)obj).impl_traverse(com.sun.javafx.scene.traversal.Direction.NEXT);
 110                           }
 111                           event.consume();
 112                           break;
 113                       case UP :
 114                           ((Node)obj).impl_traverse(com.sun.javafx.scene.traversal.Direction.UP);
 115                           event.consume();
 116                           break;
 117                       case DOWN :
 118                           ((Node)obj).impl_traverse(com.sun.javafx.scene.traversal.Direction.DOWN);
 119                           event.consume();
 120                           break;
 121                       case LEFT :
 122                           ((Node)obj).impl_traverse(com.sun.javafx.scene.traversal.Direction.LEFT);
 123                           event.consume();
 124                           break;
 125                       case RIGHT :
 126                           ((Node)obj).impl_traverse(com.sun.javafx.scene.traversal.Direction.RIGHT);
 127                           event.consume();
 128                           break;
 129                       case ENTER :
 130                           setExternalFocus(false);
 131                           event.consume();
 132                           break;
 133                       default :
 134                           // this'll kill mnemonics.... unless!
 135                           Scene s = tlNode.getScene();
 136                           Event.fireEvent(s, event);
 137                           event.consume();
 138                           break;
 139                     }
 140                 }
 141             }
 142         }
 143 
 144         return event;
 145     };
 146 




   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.control.behavior;
  27 
  28 import com.sun.javafx.scene.NodeHelper;
  29 import javafx.css.PseudoClass;
  30 import javafx.scene.Node;
  31 import javafx.scene.control.Control;
  32 import javafx.scene.control.PopupControl;
  33 
  34 import javafx.scene.Scene;
  35 import javafx.scene.input.KeyEvent;
  36 
  37 import javafx.beans.value.ChangeListener;
  38 import javafx.event.Event;
  39 import javafx.event.EventDispatcher;
  40 import javafx.event.EventHandler;
  41 import javafx.scene.input.MouseEvent;
  42 
  43 /**
  44  * A two level focus handler allows a Control to behave as if it
  45  * has three focus states :
  46  *  - not focused
  47  *  - focused with internal focus
  48  *  - focused with external focus


  87 
  88     /**
  89      * Don't allow the Node to handle a key event if it is in externalFocus mode.
  90      * the only keyboard actions allowed are the navigation keys......
  91      */
  92     final EventDispatcher preemptiveEventDispatcher = (event, tail) -> {
  93 
  94         // block the event from being passed down to children
  95         if (event instanceof KeyEvent && event.getEventType() == KeyEvent.KEY_PRESSED) {
  96             if (!((KeyEvent)event).isMetaDown() && !((KeyEvent)event).isControlDown()  && !((KeyEvent)event).isAltDown()) {
  97                 if (isExternalFocus()) {
  98                     //
  99                     // don't let the behaviour leak any navigation keys when
 100                     // we're not in blocking mode....
 101                     //
 102                     Object obj = event.getTarget();
 103 
 104                     switch (((KeyEvent)event).getCode()) {
 105                       case TAB :
 106                           if (((KeyEvent)event).isShiftDown()) {
 107                               NodeHelper.traverse((Node) obj, com.sun.javafx.scene.traversal.Direction.PREVIOUS);
 108                           }
 109                           else {
 110                               NodeHelper.traverse((Node) obj, com.sun.javafx.scene.traversal.Direction.NEXT);
 111                           }
 112                           event.consume();
 113                           break;
 114                       case UP :
 115                           NodeHelper.traverse((Node) obj, com.sun.javafx.scene.traversal.Direction.UP);
 116                           event.consume();
 117                           break;
 118                       case DOWN :
 119                           NodeHelper.traverse((Node) obj, com.sun.javafx.scene.traversal.Direction.DOWN);
 120                           event.consume();
 121                           break;
 122                       case LEFT :
 123                           NodeHelper.traverse((Node) obj, com.sun.javafx.scene.traversal.Direction.LEFT);
 124                           event.consume();
 125                           break;
 126                       case RIGHT :
 127                           NodeHelper.traverse((Node) obj, com.sun.javafx.scene.traversal.Direction.RIGHT);
 128                           event.consume();
 129                           break;
 130                       case ENTER :
 131                           setExternalFocus(false);
 132                           event.consume();
 133                           break;
 134                       default :
 135                           // this'll kill mnemonics.... unless!
 136                           Scene s = tlNode.getScene();
 137                           Event.fireEvent(s, event);
 138                           event.consume();
 139                           break;
 140                     }
 141                 }
 142             }
 143         }
 144 
 145         return event;
 146     };
 147 


< prev index next >