< prev index next >

src/java.desktop/share/classes/sun/awt/im/ExecutableInputMethodManager.java

Print this page


   1 /*
   2  * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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


 552         if (preferredLocale.equals(new Locale("th", "TH"))) {
 553             preferredLocale = new Locale("th");
 554         }
 555 
 556         // obtain node
 557         String path = preferredIMNode + "/" + createLocalePath(preferredLocale);
 558 
 559         // write in the preference tree
 560         writePreferredInputMethod(path, descriptor.getClass().getName());
 561         preferredLocatorCache.put(preferredLocale.toString().intern(),
 562             locator.deriveLocator(preferredLocale));
 563 
 564         return;
 565     }
 566 
 567     private String createLocalePath(Locale locale) {
 568         String language = locale.getLanguage();
 569         String country = locale.getCountry();
 570         String variant = locale.getVariant();
 571         String localePath = null;
 572         if (!variant.equals("")) {
 573             localePath = "_" + language + "/_" + country + "/_" + variant;
 574         } else if (!country.equals("")) {
 575             localePath = "_" + language + "/_" + country;
 576         } else {
 577             localePath = "_" + language;
 578         }
 579 
 580         return localePath;
 581     }
 582 
 583     private void writePreferredInputMethod(String path, String descriptorName) {
 584         if (userRoot != null) {
 585             Preferences node = userRoot.node(path);
 586 
 587             // record it
 588             if (descriptorName != null) {
 589                 node.put(descriptorKey, descriptorName);
 590             } else {
 591                 node.remove(descriptorKey);
 592             }
 593         }
 594     }


   1 /*
   2  * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   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


 552         if (preferredLocale.equals(new Locale("th", "TH"))) {
 553             preferredLocale = new Locale("th");
 554         }
 555 
 556         // obtain node
 557         String path = preferredIMNode + "/" + createLocalePath(preferredLocale);
 558 
 559         // write in the preference tree
 560         writePreferredInputMethod(path, descriptor.getClass().getName());
 561         preferredLocatorCache.put(preferredLocale.toString().intern(),
 562             locator.deriveLocator(preferredLocale));
 563 
 564         return;
 565     }
 566 
 567     private String createLocalePath(Locale locale) {
 568         String language = locale.getLanguage();
 569         String country = locale.getCountry();
 570         String variant = locale.getVariant();
 571         String localePath = null;
 572         if (!variant.isEmpty()) {
 573             localePath = "_" + language + "/_" + country + "/_" + variant;
 574         } else if (!country.isEmpty()) {
 575             localePath = "_" + language + "/_" + country;
 576         } else {
 577             localePath = "_" + language;
 578         }
 579 
 580         return localePath;
 581     }
 582 
 583     private void writePreferredInputMethod(String path, String descriptorName) {
 584         if (userRoot != null) {
 585             Preferences node = userRoot.node(path);
 586 
 587             // record it
 588             if (descriptorName != null) {
 589                 node.put(descriptorKey, descriptorName);
 590             } else {
 591                 node.remove(descriptorKey);
 592             }
 593         }
 594     }


< prev index next >