< prev index next >

modules/graphics/src/main/java/com/sun/javafx/scene/KeyboardShortcutsHandler.java

Print this page




  82             }
  83         }
  84     }
  85 
  86     public ObservableMap<KeyCombination, ObservableList<Mnemonic>> getMnemonics() {
  87         if (mnemonics == null) {
  88             mnemonics = new ObservableMapWrapper<>(new HashMap<>());
  89         }
  90         return mnemonics;
  91     }
  92 
  93     public ObservableMap<KeyCombination, Runnable> getAccelerators() {
  94         if (accelerators == null) {
  95             acceleratorsBackingMap = new CopyOnWriteMap<>();
  96             accelerators = new ObservableMapWrapper<>(acceleratorsBackingMap);
  97         }
  98         return accelerators;
  99     }
 100 
 101     private void traverse(Event event, Node node, Direction dir) {
 102         if (node.impl_traverse(dir)) {
 103             event.consume();
 104         }
 105     }
 106 
 107     public void processTraversal(Event event) {
 108         if (event.getEventType() != KeyEvent.KEY_PRESSED) return;
 109         if (!(event instanceof KeyEvent)) return;
 110 
 111         KeyEvent keyEvent = (KeyEvent)event;
 112         if (!keyEvent.isMetaDown() && !keyEvent.isControlDown() && !keyEvent.isAltDown()) {
 113             Object obj = event.getTarget();
 114             if (!(obj instanceof Node)) return;
 115 
 116             Node node = (Node)obj;
 117             switch (keyEvent.getCode()) {
 118               case TAB :
 119                   if (keyEvent.isShiftDown()) {
 120                       traverse(event, node, Direction.PREVIOUS);
 121                   }
 122                   else {


 264         ** for mnemonics we need to check if visible and reachable....
 265         ** if a single Mnemonic on the keyCombo we
 266         ** fire the runnable in Mnemoninic, and transfer focus
 267         ** if there is more than one then we just
 268         ** transfer the focus
 269         **
 270         */
 271         boolean multipleNodes = false;
 272         Node firstNode = null;
 273         Mnemonic firstMnemonics = null;
 274         int focusedIndex = -1;
 275         int nextFocusable = -1;
 276 
 277         /*
 278         ** find first focusable node
 279         */
 280         for (int i = 0 ; i < mnemonicsList.size() ; i++) {
 281             Mnemonic mnemonic = mnemonicsList.get(i);
 282             Node currentNode = mnemonic.getNode();
 283 
 284             if (firstMnemonics == null && (currentNode.impl_isTreeVisible() && !currentNode.isDisabled())) {
 285                 firstMnemonics = mnemonic;
 286             }
 287 
 288             if (currentNode.impl_isTreeVisible() && (currentNode.isFocusTraversable() && !currentNode.isDisabled())) {
 289                 if (firstNode == null) {
 290                     firstNode = currentNode;
 291                 } else {
 292                     /*
 293                     ** there is more than one node on this keyCombo
 294                     */
 295                     multipleNodes = true;
 296                     if (focusedIndex != -1) {
 297                         if (nextFocusable == -1) {
 298                             nextFocusable = i;
 299                         }
 300                     }
 301                 }
 302             }
 303 
 304             /*
 305             ** one of our targets has the focus already
 306             */
 307             if (currentNode.isFocused()) {
 308                 focusedIndex = i;


 373                             acceleratorRunnable.run();
 374                             event.consume();
 375                         }
 376                     }
 377                 }
 378             } finally {
 379                 acceleratorsBackingMap.unlock();
 380             }
 381         }
 382     }
 383 
 384     private void processMnemonicsKeyDisplay() {
 385         ObservableList<Mnemonic> mnemonicsList = null;
 386         if (mnemonics != null) {
 387             for (Map.Entry<KeyCombination, ObservableList<Mnemonic>> mnemonic: mnemonics.entrySet()) {
 388                 mnemonicsList = (ObservableList) mnemonic.getValue();
 389 
 390                 if (mnemonicsList != null) {
 391                     for (int i = 0 ; i < mnemonicsList.size() ; i++) {
 392                         Node currentNode = (Node)mnemonicsList.get(i).getNode();
 393                         currentNode.impl_setShowMnemonics(mnemonicsDisplayEnabled);
 394                     }
 395                 }
 396             }
 397         }
 398     }
 399 
 400     /*
 401     ** remember if the alt key is being held
 402     */
 403     private boolean mnemonicsDisplayEnabled = false;
 404 
 405     public boolean isMnemonicsDisplayEnabled() {
 406         return mnemonicsDisplayEnabled;
 407     }
 408     public void setMnemonicsDisplayEnabled(boolean b) {
 409         if (b != mnemonicsDisplayEnabled) {
 410             mnemonicsDisplayEnabled = b;
 411             processMnemonicsKeyDisplay();
 412         }
 413     }




  82             }
  83         }
  84     }
  85 
  86     public ObservableMap<KeyCombination, ObservableList<Mnemonic>> getMnemonics() {
  87         if (mnemonics == null) {
  88             mnemonics = new ObservableMapWrapper<>(new HashMap<>());
  89         }
  90         return mnemonics;
  91     }
  92 
  93     public ObservableMap<KeyCombination, Runnable> getAccelerators() {
  94         if (accelerators == null) {
  95             acceleratorsBackingMap = new CopyOnWriteMap<>();
  96             accelerators = new ObservableMapWrapper<>(acceleratorsBackingMap);
  97         }
  98         return accelerators;
  99     }
 100 
 101     private void traverse(Event event, Node node, Direction dir) {
 102         if (NodeHelper.traverse(node, dir)) {
 103             event.consume();
 104         }
 105     }
 106 
 107     public void processTraversal(Event event) {
 108         if (event.getEventType() != KeyEvent.KEY_PRESSED) return;
 109         if (!(event instanceof KeyEvent)) return;
 110 
 111         KeyEvent keyEvent = (KeyEvent)event;
 112         if (!keyEvent.isMetaDown() && !keyEvent.isControlDown() && !keyEvent.isAltDown()) {
 113             Object obj = event.getTarget();
 114             if (!(obj instanceof Node)) return;
 115 
 116             Node node = (Node)obj;
 117             switch (keyEvent.getCode()) {
 118               case TAB :
 119                   if (keyEvent.isShiftDown()) {
 120                       traverse(event, node, Direction.PREVIOUS);
 121                   }
 122                   else {


 264         ** for mnemonics we need to check if visible and reachable....
 265         ** if a single Mnemonic on the keyCombo we
 266         ** fire the runnable in Mnemoninic, and transfer focus
 267         ** if there is more than one then we just
 268         ** transfer the focus
 269         **
 270         */
 271         boolean multipleNodes = false;
 272         Node firstNode = null;
 273         Mnemonic firstMnemonics = null;
 274         int focusedIndex = -1;
 275         int nextFocusable = -1;
 276 
 277         /*
 278         ** find first focusable node
 279         */
 280         for (int i = 0 ; i < mnemonicsList.size() ; i++) {
 281             Mnemonic mnemonic = mnemonicsList.get(i);
 282             Node currentNode = mnemonic.getNode();
 283 
 284             if (firstMnemonics == null && (NodeHelper.isTreeVisible(currentNode) && !currentNode.isDisabled())) {
 285                 firstMnemonics = mnemonic;
 286             }
 287 
 288             if (NodeHelper.isTreeVisible(currentNode) && (currentNode.isFocusTraversable() && !currentNode.isDisabled())) {
 289                 if (firstNode == null) {
 290                     firstNode = currentNode;
 291                 } else {
 292                     /*
 293                     ** there is more than one node on this keyCombo
 294                     */
 295                     multipleNodes = true;
 296                     if (focusedIndex != -1) {
 297                         if (nextFocusable == -1) {
 298                             nextFocusable = i;
 299                         }
 300                     }
 301                 }
 302             }
 303 
 304             /*
 305             ** one of our targets has the focus already
 306             */
 307             if (currentNode.isFocused()) {
 308                 focusedIndex = i;


 373                             acceleratorRunnable.run();
 374                             event.consume();
 375                         }
 376                     }
 377                 }
 378             } finally {
 379                 acceleratorsBackingMap.unlock();
 380             }
 381         }
 382     }
 383 
 384     private void processMnemonicsKeyDisplay() {
 385         ObservableList<Mnemonic> mnemonicsList = null;
 386         if (mnemonics != null) {
 387             for (Map.Entry<KeyCombination, ObservableList<Mnemonic>> mnemonic: mnemonics.entrySet()) {
 388                 mnemonicsList = (ObservableList) mnemonic.getValue();
 389 
 390                 if (mnemonicsList != null) {
 391                     for (int i = 0 ; i < mnemonicsList.size() ; i++) {
 392                         Node currentNode = (Node)mnemonicsList.get(i).getNode();
 393                         NodeHelper.setShowMnemonics(currentNode, mnemonicsDisplayEnabled);
 394                     }
 395                 }
 396             }
 397         }
 398     }
 399 
 400     /*
 401     ** remember if the alt key is being held
 402     */
 403     private boolean mnemonicsDisplayEnabled = false;
 404 
 405     public boolean isMnemonicsDisplayEnabled() {
 406         return mnemonicsDisplayEnabled;
 407     }
 408     public void setMnemonicsDisplayEnabled(boolean b) {
 409         if (b != mnemonicsDisplayEnabled) {
 410             mnemonicsDisplayEnabled = b;
 411             processMnemonicsKeyDisplay();
 412         }
 413     }


< prev index next >