src/solaris/classes/sun/awt/X11InputMethod.java

Print this page




  83 
  84     /*
  85      * visible position values
  86      */
  87     private static final int XIMVisibleToForward = (1<<8);
  88     private static final int XIMVisibleToBackward = (1<<9);
  89     private static final int XIMVisibleCenter = (1<<10);
  90     private static final int XIMVisibleMask = (XIMVisibleToForward|
  91                                                XIMVisibleToBackward|
  92                                                XIMVisibleCenter);
  93 
  94     private Locale locale;
  95     private static boolean isXIMOpened = false;
  96     protected Container clientComponentWindow = null;
  97     private Component awtFocussedComponent = null;
  98     private Component lastXICFocussedComponent = null;
  99     private boolean   isLastXICActive = false;
 100     private boolean   isLastTemporary = false;
 101     private boolean   isActive = false;
 102     private boolean   isActiveClient = false;
 103     private static Map[] highlightStyles;
 104     private boolean disposed = false;
 105 
 106     //reset the XIC if necessary
 107     private boolean   needResetXIC = false;
 108     private WeakReference<Component> needResetXICClient = new WeakReference<>(null);
 109 
 110     // The use of compositionEnableSupported is to reduce unnecessary
 111     // native calls if set/isCompositionEnabled
 112     // throws UnsupportedOperationException.
 113     // It is set to false if that exception is thrown first time
 114     // either of the two methods are called.
 115     private boolean compositionEnableSupported = true;
 116     // The savedCompositionState indicates the composition mode when
 117     // endComposition or setCompositionEnabled is called. It doesn't always
 118     // reflect the actual composition state because it doesn't get updated
 119     // when the user changes the composition state through direct interaction
 120     // with the input method. It is used to save the composition mode when
 121     // focus is traversed across different client components sharing the
 122     // same java input context. Also if set/isCompositionEnabled are not
 123     // supported, it remains false.
 124     private boolean savedCompositionState = false;
 125 
 126     // variables to keep track of preedit context.
 127     // these variables need to be accessed within AWT_LOCK/UNLOCK
 128     private String committedText = null;
 129     private StringBuffer composedText = null;
 130     private IntBuffer rawFeedbacks;
 131 
 132     // private data (X11InputMethodData structure defined in
 133     // awt_InputMethod.c) for native methods
 134     // this structure needs to be accessed within AWT_LOCK/UNLOCK
 135     transient private long pData = 0; // accessed by native
 136 
 137     // Initialize highlight mapping table
 138     static {
 139         Map styles[] = new Map[4];
 140         HashMap map;

 141 
 142         // UNSELECTED_RAW_TEXT_HIGHLIGHT
 143         map = new HashMap(1);
 144         map.put(TextAttribute.WEIGHT,
 145                   TextAttribute.WEIGHT_BOLD);
 146         styles[0] = Collections.unmodifiableMap(map);
 147 
 148         // SELECTED_RAW_TEXT_HIGHLIGHT
 149         map = new HashMap(1);
 150         map.put(TextAttribute.SWAP_COLORS,
 151                   TextAttribute.SWAP_COLORS_ON);
 152         styles[1] = Collections.unmodifiableMap(map);
 153 
 154         // UNSELECTED_CONVERTED_TEXT_HIGHLIGHT
 155         map = new HashMap(1);
 156         map.put(TextAttribute.INPUT_METHOD_UNDERLINE,
 157                   TextAttribute.UNDERLINE_LOW_ONE_PIXEL);
 158         styles[2] = Collections.unmodifiableMap(map);
 159 
 160         // SELECTED_CONVERTED_TEXT_HIGHLIGHT
 161         map = new HashMap(1);
 162         map.put(TextAttribute.SWAP_COLORS,
 163                   TextAttribute.SWAP_COLORS_ON);
 164         styles[3] = Collections.unmodifiableMap(map);
 165 
 166         highlightStyles = styles;
 167     }
 168 
 169     static {
 170         initIDs();
 171     }
 172 
 173     /**
 174      * Initialize JNI field and method IDs for fields that may be
 175        accessed from C.
 176      */
 177     private static native void initIDs();
 178 
 179     /**
 180      * Constructs an X11InputMethod instance. It initializes the XIM
 181      * environment if it's not done yet.
 182      *
 183      * @exception AWTException if XOpenIM() failed.


 416     public void disableInputMethod() {
 417         if (lastXICFocussedComponent != null) {
 418             setXICFocus(getPeer(lastXICFocussedComponent), false, isLastXICActive);
 419             lastXICFocussedComponent = null;
 420             isLastXICActive = false;
 421 
 422             resetXIC();
 423             needResetXICClient.clear();
 424             needResetXIC = false;
 425         }
 426     }
 427 
 428     // implements java.awt.im.spi.InputMethod.hideWindows
 429     public void hideWindows() {
 430         // ??? need real implementation
 431     }
 432 
 433     /**
 434      * @see java.awt.Toolkit#mapInputMethodHighlight
 435      */
 436     public static Map mapInputMethodHighlight(InputMethodHighlight highlight) {
 437         int index;
 438         int state = highlight.getState();
 439         if (state == InputMethodHighlight.RAW_TEXT) {
 440             index = 0;
 441         } else if (state == InputMethodHighlight.CONVERTED_TEXT) {
 442             index = 2;
 443         } else {
 444             return null;
 445         }
 446         if (highlight.isSelected()) {
 447             index += 1;
 448         }
 449         return highlightStyles[index];
 450     }
 451 
 452     /**
 453      * @see sun.awt.im.InputMethodAdapter#setAWTFocussedComponent
 454      */
 455     protected void setAWTFocussedComponent(Component component) {
 456         if (component == null) {




  83 
  84     /*
  85      * visible position values
  86      */
  87     private static final int XIMVisibleToForward = (1<<8);
  88     private static final int XIMVisibleToBackward = (1<<9);
  89     private static final int XIMVisibleCenter = (1<<10);
  90     private static final int XIMVisibleMask = (XIMVisibleToForward|
  91                                                XIMVisibleToBackward|
  92                                                XIMVisibleCenter);
  93 
  94     private Locale locale;
  95     private static boolean isXIMOpened = false;
  96     protected Container clientComponentWindow = null;
  97     private Component awtFocussedComponent = null;
  98     private Component lastXICFocussedComponent = null;
  99     private boolean   isLastXICActive = false;
 100     private boolean   isLastTemporary = false;
 101     private boolean   isActive = false;
 102     private boolean   isActiveClient = false;
 103     private static Map<TextAttribute, ?>[] highlightStyles;
 104     private boolean disposed = false;
 105 
 106     //reset the XIC if necessary
 107     private boolean   needResetXIC = false;
 108     private WeakReference<Component> needResetXICClient = new WeakReference<>(null);
 109 
 110     // The use of compositionEnableSupported is to reduce unnecessary
 111     // native calls if set/isCompositionEnabled
 112     // throws UnsupportedOperationException.
 113     // It is set to false if that exception is thrown first time
 114     // either of the two methods are called.
 115     private boolean compositionEnableSupported = true;
 116     // The savedCompositionState indicates the composition mode when
 117     // endComposition or setCompositionEnabled is called. It doesn't always
 118     // reflect the actual composition state because it doesn't get updated
 119     // when the user changes the composition state through direct interaction
 120     // with the input method. It is used to save the composition mode when
 121     // focus is traversed across different client components sharing the
 122     // same java input context. Also if set/isCompositionEnabled are not
 123     // supported, it remains false.
 124     private boolean savedCompositionState = false;
 125 
 126     // variables to keep track of preedit context.
 127     // these variables need to be accessed within AWT_LOCK/UNLOCK
 128     private String committedText = null;
 129     private StringBuffer composedText = null;
 130     private IntBuffer rawFeedbacks;
 131 
 132     // private data (X11InputMethodData structure defined in
 133     // awt_InputMethod.c) for native methods
 134     // this structure needs to be accessed within AWT_LOCK/UNLOCK
 135     transient private long pData = 0; // accessed by native
 136 
 137     // Initialize highlight mapping table
 138     static {
 139         @SuppressWarnings({"unchecked", "rawtypes"})
 140         Map<TextAttribute, ?> styles[] = new Map[4];
 141         HashMap<TextAttribute, Object> map;
 142 
 143         // UNSELECTED_RAW_TEXT_HIGHLIGHT
 144         map = new HashMap<>(1);
 145         map.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);

 146         styles[0] = Collections.unmodifiableMap(map);
 147 
 148         // SELECTED_RAW_TEXT_HIGHLIGHT
 149         map = new HashMap<>(1);
 150         map.put(TextAttribute.SWAP_COLORS, TextAttribute.SWAP_COLORS_ON);

 151         styles[1] = Collections.unmodifiableMap(map);
 152 
 153         // UNSELECTED_CONVERTED_TEXT_HIGHLIGHT
 154         map = new HashMap<>(1);
 155         map.put(TextAttribute.INPUT_METHOD_UNDERLINE,
 156                 TextAttribute.UNDERLINE_LOW_ONE_PIXEL);
 157         styles[2] = Collections.unmodifiableMap(map);
 158 
 159         // SELECTED_CONVERTED_TEXT_HIGHLIGHT
 160         map = new HashMap<>(1);
 161         map.put(TextAttribute.SWAP_COLORS, TextAttribute.SWAP_COLORS_ON);

 162         styles[3] = Collections.unmodifiableMap(map);
 163 
 164         highlightStyles = styles;
 165     }
 166 
 167     static {
 168         initIDs();
 169     }
 170 
 171     /**
 172      * Initialize JNI field and method IDs for fields that may be
 173        accessed from C.
 174      */
 175     private static native void initIDs();
 176 
 177     /**
 178      * Constructs an X11InputMethod instance. It initializes the XIM
 179      * environment if it's not done yet.
 180      *
 181      * @exception AWTException if XOpenIM() failed.


 414     public void disableInputMethod() {
 415         if (lastXICFocussedComponent != null) {
 416             setXICFocus(getPeer(lastXICFocussedComponent), false, isLastXICActive);
 417             lastXICFocussedComponent = null;
 418             isLastXICActive = false;
 419 
 420             resetXIC();
 421             needResetXICClient.clear();
 422             needResetXIC = false;
 423         }
 424     }
 425 
 426     // implements java.awt.im.spi.InputMethod.hideWindows
 427     public void hideWindows() {
 428         // ??? need real implementation
 429     }
 430 
 431     /**
 432      * @see java.awt.Toolkit#mapInputMethodHighlight
 433      */
 434     public static Map<TextAttribute, ?> mapInputMethodHighlight(InputMethodHighlight highlight) {
 435         int index;
 436         int state = highlight.getState();
 437         if (state == InputMethodHighlight.RAW_TEXT) {
 438             index = 0;
 439         } else if (state == InputMethodHighlight.CONVERTED_TEXT) {
 440             index = 2;
 441         } else {
 442             return null;
 443         }
 444         if (highlight.isSelected()) {
 445             index += 1;
 446         }
 447         return highlightStyles[index];
 448     }
 449 
 450     /**
 451      * @see sun.awt.im.InputMethodAdapter#setAWTFocussedComponent
 452      */
 453     protected void setAWTFocussedComponent(Component component) {
 454         if (component == null) {