1 /*
2 * Copyright (c) 1997, 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
657 * IM server or language service and we want to try our best to return as much
658 * information as possible.
659 *
660 * Note: This method could return null on Linux if XMODIFIERS is not set properly or
661 * if any IOException is thrown.
662 * See man page of XSetLocaleModifiers(3X11) for the usgae of XMODIFIERS,
663 * atok12setup(1) and wnn6setup(1) for the information written to
664 * $HOME/.dtprofile when you run these two commands.
665 *
666 */
667 public String getNativeInputMethodInfo() {
668 String xmodifiers = System.getenv("XMODIFIERS");
669 String imInfo = null;
670
671 // If XMODIFIERS is set, return the value
672 if (xmodifiers != null) {
673 int imIndex = xmodifiers.indexOf("@im=");
674 if (imIndex != -1) {
675 imInfo = xmodifiers.substring(imIndex + 4);
676 }
677 } else if (System.getProperty("os.name").startsWith("SunOS")) {
678 File dtprofile = new File(System.getProperty("user.home") +
679 "/.dtprofile");
680 String languageEngineInfo = null;
681 try {
682 BufferedReader br = new BufferedReader(new FileReader(dtprofile));
683 String line = null;
684
685 while ( languageEngineInfo == null && (line = br.readLine()) != null) {
686 if (line.contains("atok") || line.contains("wnn")) {
687 StringTokenizer tokens = new StringTokenizer(line);
688 while (tokens.hasMoreTokens()) {
689 String token = tokens.nextToken();
690 if (Pattern.matches("atok.*setup", token) ||
691 Pattern.matches("wnn.*setup", token)){
692 languageEngineInfo = token.substring(0, token.indexOf("setup"));
693 break;
694 }
695 }
696 }
697 }
698
699 br.close();
700 } catch(IOException ioex) {
701 // Since this method is provided for internal testing only,
702 // we dump the stack trace for the ease of debugging.
703 ioex.printStackTrace();
704 }
705
706 imInfo = "htt " + languageEngineInfo;
707 }
708
709 return imInfo;
710 }
711
712
713 /**
714 * Performs mapping from an XIM visible feedback value to Java IM highlight.
715 * @return Java input method highlight
716 */
717 protected InputMethodHighlight convertVisualFeedbackToHighlight(int feedback) {
718 InputMethodHighlight highlight;
719
720 switch (feedback) {
721 case XIMUnderline:
722 highlight = InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT;
723 break;
724 case XIMReverse:
725 highlight = InputMethodHighlight.SELECTED_CONVERTED_TEXT_HIGHLIGHT;
726 break;
|
1 /*
2 * Copyright (c) 1997, 2020, 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
657 * IM server or language service and we want to try our best to return as much
658 * information as possible.
659 *
660 * Note: This method could return null on Linux if XMODIFIERS is not set properly or
661 * if any IOException is thrown.
662 * See man page of XSetLocaleModifiers(3X11) for the usgae of XMODIFIERS,
663 * atok12setup(1) and wnn6setup(1) for the information written to
664 * $HOME/.dtprofile when you run these two commands.
665 *
666 */
667 public String getNativeInputMethodInfo() {
668 String xmodifiers = System.getenv("XMODIFIERS");
669 String imInfo = null;
670
671 // If XMODIFIERS is set, return the value
672 if (xmodifiers != null) {
673 int imIndex = xmodifiers.indexOf("@im=");
674 if (imIndex != -1) {
675 imInfo = xmodifiers.substring(imIndex + 4);
676 }
677 }
678
679 return imInfo;
680 }
681
682
683 /**
684 * Performs mapping from an XIM visible feedback value to Java IM highlight.
685 * @return Java input method highlight
686 */
687 protected InputMethodHighlight convertVisualFeedbackToHighlight(int feedback) {
688 InputMethodHighlight highlight;
689
690 switch (feedback) {
691 case XIMUnderline:
692 highlight = InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT;
693 break;
694 case XIMReverse:
695 highlight = InputMethodHighlight.SELECTED_CONVERTED_TEXT_HIGHLIGHT;
696 break;
|