## modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TextBinding.java

Print this page

    rev 4839 : RT-2529: Locale specific runtime errors (Turkish)

       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 java.util.StringTokenizer;
      29
      30 import javafx.scene.input.KeyCode;
      31
      32 /**
      33  * <p>
      34  * Provides support for embedding a mnemonic, accelerator and text in a single
      35  * string. A mnemonic is a single character that will either give a control
      36  * focus or activate it when pressed in conjunction with the base platform's
      37  * mnemonic modifier (typically the {@code Alt} key). An accelerator is a key
      38  * combination that will activate the object.
      39  * </p>
      40  *
      41  * <p>
      42  * The syntax of the string content is as follows:
      43  * </p>
      44  *
      45  * <ul>
      46  * <li>
      47  * <p>
     314      * Returns a KeyBinding for the given accelerator text or {@code null} if
     315      * the accelerator text cannot be parsed.
     316      *
     317      * @return a KeyBinding for the given accelerator text or {@code null} if
     318      *         the accelerator text cannot be parsed
     319      */
     320     private KeyBinding parseAcceleratorText(String s) {
     321         KeyBinding result = null;
     322         String text = null;
     323         boolean controlDown = false;
     324         boolean altDown = false;
     325         boolean shiftDown = false;
     326         boolean shortcutDown = false;
     327         boolean parseFail = false;
     328         StringTokenizer tokenizer = new StringTokenizer(s, "+");
     329         while (!parseFail && tokenizer.hasMoreTokens()) {
     330             String token = tokenizer.nextToken();
     331             if (!tokenizer.hasMoreTokens()) {
     332                 text = token;
     333             } else {
     334                 KeyCode code = KeyCode.getKeyCode(token.toUpperCase());
     335                 if (code != null) {
     336                     switch (code) {
     337                       case CONTROL:
     338                         controlDown = true;
     339                         break;
     340                       case ALT:
     341                         altDown = true;
     342                         break;
     343                       case SHIFT:
     344                         shiftDown = true;
     345                         break;
     346                       case SHORTCUT:
     347                         shortcutDown = true;
     348                         break;
     349                       default:
     350                         text = null;
     351                         parseFail = true;
     352                         break;
     353                     }
     354                 } else {
       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 java.util.Locale;
      29 import java.util.StringTokenizer;
      30
      31 import javafx.scene.input.KeyCode;
      32
      33 /**
      34  * <p>
      35  * Provides support for embedding a mnemonic, accelerator and text in a single
      36  * string. A mnemonic is a single character that will either give a control
      37  * focus or activate it when pressed in conjunction with the base platform's
      38  * mnemonic modifier (typically the {@code Alt} key). An accelerator is a key
      39  * combination that will activate the object.
      40  * </p>
      41  *
      42  * <p>
      43  * The syntax of the string content is as follows:
      44  * </p>
      45  *
      46  * <ul>
      47  * <li>
      48  * <p>
     315      * Returns a KeyBinding for the given accelerator text or {@code null} if
     316      * the accelerator text cannot be parsed.
     317      *
     318      * @return a KeyBinding for the given accelerator text or {@code null} if
     319      *         the accelerator text cannot be parsed
     320      */
     321     private KeyBinding parseAcceleratorText(String s) {
     322         KeyBinding result = null;
     323         String text = null;
     324         boolean controlDown = false;
     325         boolean altDown = false;
     326         boolean shiftDown = false;
     327         boolean shortcutDown = false;
     328         boolean parseFail = false;
     329         StringTokenizer tokenizer = new StringTokenizer(s, "+");
     330         while (!parseFail && tokenizer.hasMoreTokens()) {
     331             String token = tokenizer.nextToken();
     332             if (!tokenizer.hasMoreTokens()) {
     333                 text = token;
     334             } else {
     335                 KeyCode code = KeyCode.getKeyCode(token.toUpperCase(Locale.ROOT));
     336                 if (code != null) {
     337                     switch (code) {
     338                       case CONTROL:
     339                         controlDown = true;
     340                         break;
     341                       case ALT:
     342                         altDown = true;
     343                         break;
     344                       case SHIFT:
     345                         shiftDown = true;
     346                         break;
     347                       case SHORTCUT:
     348                         shortcutDown = true;
     349                         break;
     350                       default:
     351                         text = null;
     352                         parseFail = true;
     353                         break;
     354                     }
     355                 } else {