< prev index next >

src/share/classes/sun/awt/im/InputContext.java

Print this page
rev 1571 : 8010297: Missing isLoggable() checks in logging code
Summary: Add isLoggable() checks
Reviewed-by: anthony, mchung, serb
Contributed-by: Laurent Bourges <bourges.laurent@gmail.com>


 369     private void activateInputMethod(boolean updateCompositionArea) {
 370         // call hideWindows() if this input context uses a different
 371         // input method than the previously activated one
 372         if (inputMethodWindowContext != null && inputMethodWindowContext != this &&
 373                 inputMethodWindowContext.inputMethodLocator != null &&
 374                 !inputMethodWindowContext.inputMethodLocator.sameInputMethod(inputMethodLocator) &&
 375                 inputMethodWindowContext.inputMethod != null) {
 376             inputMethodWindowContext.inputMethod.hideWindows();
 377         }
 378         inputMethodWindowContext = this;
 379 
 380         if (inputMethod != null) {
 381             if (previousInputMethod != inputMethod &&
 382                     previousInputMethod instanceof InputMethodAdapter) {
 383                 // let the host adapter pass through the input events for the
 384                 // new input method
 385                 ((InputMethodAdapter) previousInputMethod).stopListening();
 386             }
 387             previousInputMethod = null;
 388 



 389             if (log.isLoggable(Level.FINE)) log.fine("Current client component " + currentClientComponent);
 390             if (inputMethod instanceof InputMethodAdapter) {
 391                 ((InputMethodAdapter) inputMethod).setClientComponent(currentClientComponent);
 392             }
 393             inputMethod.activate();
 394             isInputMethodActive = true;
 395 
 396             if (perInputMethodState != null) {
 397                 Boolean state = (Boolean) perInputMethodState.remove(inputMethod);
 398                 if (state != null) {
 399                     clientWindowNotificationEnabled = state.booleanValue();
 400                 }
 401             }
 402             if (clientWindowNotificationEnabled) {
 403                 if (!addedClientWindowListeners()) {
 404                     addClientWindowListeners();
 405                 }
 406                 synchronized(this) {
 407                     if (clientWindowListened != null) {
 408                         notifyClientWindowChange(clientWindowListened);


 866             inputMethodCreationFailed = true;
 867 
 868             // if the instance has been created, then it means either
 869             // setLocale() or setInputMethodContext() failed.
 870             if (inputMethodInstance != null) {
 871                 inputMethodInstance = null;
 872             }
 873         } catch (LinkageError e) {
 874             logCreationFailed(e);
 875 
 876             // same as above
 877             inputMethodCreationFailed = true;
 878         }
 879         ((InputMethodContext) this).setInputMethodSupportsBelowTheSpot(
 880                 (!(inputMethodInstance instanceof InputMethodAdapter)) ||
 881                 ((InputMethodAdapter) inputMethodInstance).supportsBelowTheSpot());
 882         return inputMethodInstance;
 883     }
 884 
 885     private void logCreationFailed(Throwable throwable) {


 886         String errorTextFormat = Toolkit.getProperty("AWT.InputMethodCreationFailed",
 887                                                      "Could not create {0}. Reason: {1}");
 888         Object[] args =
 889             {inputMethodLocator.getDescriptor().getInputMethodDisplayName(null, Locale.getDefault()),
 890              throwable.getLocalizedMessage()};
 891         MessageFormat mf = new MessageFormat(errorTextFormat);
 892         Logger logger = Logger.getLogger("sun.awt.im");
 893         logger.config(mf.format(args));

 894     }
 895 
 896     InputMethodLocator getInputMethodLocator() {
 897         if (inputMethod != null) {
 898             return inputMethodLocator.deriveLocator(inputMethod.getLocale());
 899         }
 900         return inputMethodLocator;
 901     }
 902 
 903     /**
 904      * @see java.awt.im.InputContext#endComposition
 905      */
 906     public synchronized void endComposition() {
 907         if (inputMethod != null) {
 908             inputMethod.endComposition();
 909         }
 910     }
 911 
 912     /**
 913      * @see java.awt.im.spi.InputMethodContext#enableClientWindowNotification




 369     private void activateInputMethod(boolean updateCompositionArea) {
 370         // call hideWindows() if this input context uses a different
 371         // input method than the previously activated one
 372         if (inputMethodWindowContext != null && inputMethodWindowContext != this &&
 373                 inputMethodWindowContext.inputMethodLocator != null &&
 374                 !inputMethodWindowContext.inputMethodLocator.sameInputMethod(inputMethodLocator) &&
 375                 inputMethodWindowContext.inputMethod != null) {
 376             inputMethodWindowContext.inputMethod.hideWindows();
 377         }
 378         inputMethodWindowContext = this;
 379 
 380         if (inputMethod != null) {
 381             if (previousInputMethod != inputMethod &&
 382                     previousInputMethod instanceof InputMethodAdapter) {
 383                 // let the host adapter pass through the input events for the
 384                 // new input method
 385                 ((InputMethodAdapter) previousInputMethod).stopListening();
 386             }
 387             previousInputMethod = null;
 388 
 389             if (log.isLoggable(Level.FINE)) {
 390                 log.fine("Current client component " + currentClientComponent);
 391             }
 392             if (log.isLoggable(Level.FINE)) log.fine("Current client component " + currentClientComponent);
 393             if (inputMethod instanceof InputMethodAdapter) {
 394                 ((InputMethodAdapter) inputMethod).setClientComponent(currentClientComponent);
 395             }
 396             inputMethod.activate();
 397             isInputMethodActive = true;
 398 
 399             if (perInputMethodState != null) {
 400                 Boolean state = (Boolean) perInputMethodState.remove(inputMethod);
 401                 if (state != null) {
 402                     clientWindowNotificationEnabled = state.booleanValue();
 403                 }
 404             }
 405             if (clientWindowNotificationEnabled) {
 406                 if (!addedClientWindowListeners()) {
 407                     addClientWindowListeners();
 408                 }
 409                 synchronized(this) {
 410                     if (clientWindowListened != null) {
 411                         notifyClientWindowChange(clientWindowListened);


 869             inputMethodCreationFailed = true;
 870 
 871             // if the instance has been created, then it means either
 872             // setLocale() or setInputMethodContext() failed.
 873             if (inputMethodInstance != null) {
 874                 inputMethodInstance = null;
 875             }
 876         } catch (LinkageError e) {
 877             logCreationFailed(e);
 878 
 879             // same as above
 880             inputMethodCreationFailed = true;
 881         }
 882         ((InputMethodContext) this).setInputMethodSupportsBelowTheSpot(
 883                 (!(inputMethodInstance instanceof InputMethodAdapter)) ||
 884                 ((InputMethodAdapter) inputMethodInstance).supportsBelowTheSpot());
 885         return inputMethodInstance;
 886     }
 887 
 888     private void logCreationFailed(Throwable throwable) {
 889         Logger logger = Logger.getLogger("sun.awt.im");
 890         if (logger.isLoggable(Level.CONFIG)) {
 891             String errorTextFormat = Toolkit.getProperty("AWT.InputMethodCreationFailed",
 892                                                          "Could not create {0}. Reason: {1}");
 893             Object[] args =
 894                 {inputMethodLocator.getDescriptor().getInputMethodDisplayName(null, Locale.getDefault()),
 895                  throwable.getLocalizedMessage()};
 896             MessageFormat mf = new MessageFormat(errorTextFormat);

 897             logger.config(mf.format(args));
 898         }
 899     }
 900 
 901     InputMethodLocator getInputMethodLocator() {
 902         if (inputMethod != null) {
 903             return inputMethodLocator.deriveLocator(inputMethod.getLocale());
 904         }
 905         return inputMethodLocator;
 906     }
 907 
 908     /**
 909      * @see java.awt.im.InputContext#endComposition
 910      */
 911     public synchronized void endComposition() {
 912         if (inputMethod != null) {
 913             inputMethod.endComposition();
 914         }
 915     }
 916 
 917     /**
 918      * @see java.awt.im.spi.InputMethodContext#enableClientWindowNotification


< prev index next >