src/java.desktop/macosx/classes/sun/lwawt/macosx/CInputMethod.java

Print this page


   1 /*
   2  * Copyright (c) 2011, 2014, 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
  23  * questions.
  24  */
  25 
  26 package sun.lwawt.macosx;
  27 
  28 import java.awt.im.spi.*;
  29 import java.util.*;
  30 import java.awt.*;
  31 import java.awt.peer.*;
  32 import java.awt.event.*;
  33 import java.awt.im.*;
  34 import java.awt.font.*;
  35 import java.lang.Character.Subset;
  36 import java.lang.reflect.InvocationTargetException;
  37 import java.text.AttributedCharacterIterator.Attribute;
  38 import java.text.*;
  39 import javax.swing.text.JTextComponent;
  40 

  41 import sun.awt.im.InputMethodAdapter;
  42 import sun.lwawt.*;
  43 


  44 public class CInputMethod extends InputMethodAdapter {
  45     private InputMethodContext fIMContext;
  46     private Component fAwtFocussedComponent;
  47     private LWComponentPeer<?, ?> fAwtFocussedComponentPeer;
  48     private boolean isActive;
  49 
  50     private static Map<TextAttribute, Integer>[] sHighlightStyles;
  51 
  52     // Intitalize highlight mapping table and its mapper.
  53     static {
  54         @SuppressWarnings({"rawtypes", "unchecked"})
  55         Map<TextAttribute, Integer> styles[] = new Map[4];
  56         HashMap<TextAttribute, Integer> map;
  57 
  58         // UNSELECTED_RAW_TEXT_HIGHLIGHT
  59         map = new HashMap<TextAttribute, Integer>(1);
  60         map.put(TextAttribute.INPUT_METHOD_UNDERLINE,
  61                 TextAttribute.UNDERLINE_LOW_GRAY);
  62         styles[0] = Collections.unmodifiableMap(map);
  63 


 368     /**
 369         * Returns a control object from this input method, or null. A
 370      * control object provides methods that control the behavior of the
 371      * input method or obtain information from the input method. The type
 372      * of the object is an input method specific class. Clients have to
 373      * compare the result against known input method control object
 374      * classes and cast to the appropriate class to invoke the methods
 375      * provided.
 376      * <p>
 377      * This method is called by
 378      * {@link java.awt.im.InputContext#getInputMethodControlObject InputContext.getInputMethodControlObject}.
 379      *
 380      * @return a control object from this input method, or null
 381      */
 382     public Object getControlObject() {
 383         return null;
 384     }
 385 
 386     // java.awt.Toolkit#getNativeContainer() is not available
 387     //    from this package
 388     @SuppressWarnings("deprecation")
 389     private LWComponentPeer<?, ?> getNearestNativePeer(Component comp) {
 390         if (comp==null)
 391             return null;
 392 
 393         ComponentPeer peer = comp.getPeer();
 394         if (peer==null)
 395             return null;
 396 
 397         while (peer instanceof java.awt.peer.LightweightPeer) {
 398             comp = comp.getParent();
 399             if (comp==null)
 400                 return null;
 401             peer = comp.getPeer();
 402             if (peer==null)
 403                 return null;
 404         }
 405 
 406         if (peer instanceof LWComponentPeer)
 407             return (LWComponentPeer)peer;
 408 
 409         return null;
 410     }
 411 
 412     // =========================== NSTextInput callbacks ===========================
 413     // The 'marked text' that we get from Cocoa.  We need to track this separately, since
 414     // Java doesn't let us ask the IM context for it.
 415     private AttributedString fCurrentText = null;
 416     private String fCurrentTextAsString = null;
 417     private int fCurrentTextLength = 0;
 418 
 419     /**
 420      * Tell the component to commit all of the characters in the string to the current
 421      * text view. This effectively wipes out any text in progress.


   1 /*
   2  * Copyright (c) 2011, 2015, 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
  23  * questions.
  24  */
  25 
  26 package sun.lwawt.macosx;
  27 
  28 import java.awt.im.spi.*;
  29 import java.util.*;
  30 import java.awt.*;
  31 import java.awt.peer.*;
  32 import java.awt.event.*;
  33 import java.awt.im.*;
  34 import java.awt.font.*;
  35 import java.lang.Character.Subset;
  36 import java.lang.reflect.InvocationTargetException;
  37 import java.text.AttributedCharacterIterator.Attribute;
  38 import java.text.*;
  39 import javax.swing.text.JTextComponent;
  40 
  41 import sun.awt.AWTAccessor;
  42 import sun.awt.im.InputMethodAdapter;
  43 import sun.lwawt.*;
  44 
  45 import static sun.awt.AWTAccessor.ComponentAccessor;
  46 
  47 public class CInputMethod extends InputMethodAdapter {
  48     private InputMethodContext fIMContext;
  49     private Component fAwtFocussedComponent;
  50     private LWComponentPeer<?, ?> fAwtFocussedComponentPeer;
  51     private boolean isActive;
  52 
  53     private static Map<TextAttribute, Integer>[] sHighlightStyles;
  54 
  55     // Intitalize highlight mapping table and its mapper.
  56     static {
  57         @SuppressWarnings({"rawtypes", "unchecked"})
  58         Map<TextAttribute, Integer> styles[] = new Map[4];
  59         HashMap<TextAttribute, Integer> map;
  60 
  61         // UNSELECTED_RAW_TEXT_HIGHLIGHT
  62         map = new HashMap<TextAttribute, Integer>(1);
  63         map.put(TextAttribute.INPUT_METHOD_UNDERLINE,
  64                 TextAttribute.UNDERLINE_LOW_GRAY);
  65         styles[0] = Collections.unmodifiableMap(map);
  66 


 371     /**
 372         * Returns a control object from this input method, or null. A
 373      * control object provides methods that control the behavior of the
 374      * input method or obtain information from the input method. The type
 375      * of the object is an input method specific class. Clients have to
 376      * compare the result against known input method control object
 377      * classes and cast to the appropriate class to invoke the methods
 378      * provided.
 379      * <p>
 380      * This method is called by
 381      * {@link java.awt.im.InputContext#getInputMethodControlObject InputContext.getInputMethodControlObject}.
 382      *
 383      * @return a control object from this input method, or null
 384      */
 385     public Object getControlObject() {
 386         return null;
 387     }
 388 
 389     // java.awt.Toolkit#getNativeContainer() is not available
 390     //    from this package

 391     private LWComponentPeer<?, ?> getNearestNativePeer(Component comp) {
 392         if (comp==null)
 393             return null;
 394         final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
 395         ComponentPeer peer = acc.getPeer(comp);
 396         if (peer==null)
 397             return null;
 398 
 399         while (peer instanceof java.awt.peer.LightweightPeer) {
 400             comp = comp.getParent();
 401             if (comp==null)
 402                 return null;
 403             peer = acc.getPeer(comp);
 404             if (peer==null)
 405                 return null;
 406         }
 407 
 408         if (peer instanceof LWComponentPeer)
 409             return (LWComponentPeer)peer;
 410 
 411         return null;
 412     }
 413 
 414     // =========================== NSTextInput callbacks ===========================
 415     // The 'marked text' that we get from Cocoa.  We need to track this separately, since
 416     // Java doesn't let us ask the IM context for it.
 417     private AttributedString fCurrentText = null;
 418     private String fCurrentTextAsString = null;
 419     private int fCurrentTextLength = 0;
 420 
 421     /**
 422      * Tell the component to commit all of the characters in the string to the current
 423      * text view. This effectively wipes out any text in progress.