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.awt.im; 27 28 import java.awt.Component; 29 import java.awt.Container; 30 import java.awt.Rectangle; 31 import java.awt.event.InputMethodEvent; 32 import java.awt.event.InputMethodListener; 33 import java.awt.font.TextAttribute; 34 import java.awt.font.TextHitInfo; 35 import java.awt.im.InputMethodRequests; 36 import java.text.AttributedCharacterIterator; 37 import java.text.AttributedCharacterIterator.Attribute; 38 import java.text.AttributedString; 39 40 /** 41 * A composition area handler handles events and input method requests for 42 * the composition area. Typically each input method context has its own 43 * composition area handler if it supports passive clients or below-the-spot 44 * input, but all handlers share a single composition area. 45 * 46 * @author JavaSoft International 47 */ 48 49 class CompositionAreaHandler implements InputMethodListener, 50 InputMethodRequests { 51 52 private static CompositionArea compositionArea; 53 private static Object compositionAreaLock = new Object(); 54 private static CompositionAreaHandler compositionAreaOwner; // synchronized through compositionArea 55 56 private AttributedCharacterIterator composedText; 57 private TextHitInfo caret = null; 58 private Component clientComponent = null; 59 private InputMethodContext inputMethodContext; 60 61 /** 62 * Constructs the composition area handler. 63 */ 64 CompositionAreaHandler(InputMethodContext context) { 65 inputMethodContext = context; 66 } 67 68 /** 69 * Creates the composition area. 70 */ 71 private void createCompositionArea() { 72 synchronized(compositionAreaLock) { 73 compositionArea = new CompositionArea(); 74 if (compositionAreaOwner != null) { 75 compositionArea.setHandlerInfo(compositionAreaOwner, inputMethodContext); 76 } 77 // If the client component is an active client using below-the-spot style, then 78 // make the composition window undecorated without a title bar. 79 if(clientComponent!=null){ 80 InputMethodRequests req = clientComponent.getInputMethodRequests(); 81 if (req != null && inputMethodContext.useBelowTheSpotInput()) { 82 setCompositionAreaUndecorated(true); 83 } 84 } 85 } 86 } 87 88 void setClientComponent(Component clientComponent) { 89 this.clientComponent = clientComponent; 90 } 91 92 /** 93 * Grabs the composition area, makes this handler its owner, and installs 94 * the handler and its input context into the composition area for event 95 * and input method request handling. 96 * If doUpdate is true, updates the composition area with previously sent 97 * composed text. 98 */ 99 100 void grabCompositionArea(boolean doUpdate) { 101 synchronized (compositionAreaLock) { 102 if (compositionAreaOwner != this) { 103 compositionAreaOwner = this; 104 if (compositionArea != null) { 105 compositionArea.setHandlerInfo(this, inputMethodContext); 106 } 107 if (doUpdate) { 108 // Create the composition area if necessary 109 if ((composedText != null) && (compositionArea == null)) { 239 public void caretPositionChanged(InputMethodEvent event) { 240 if (compositionArea != null) { 241 compositionArea.setCaret(event.getCaret()); 242 } 243 244 // event has been handled, so consume it 245 event.consume(); 246 } 247 248 // 249 // InputMethodRequests methods 250 // 251 252 /** 253 * Returns the input method request handler of the client component. 254 * When using the composition window for an active client (below-the-spot 255 * input), input method requests that do not relate to the display of 256 * the composed text are forwarded to the client component. 257 */ 258 InputMethodRequests getClientInputMethodRequests() { 259 if (clientComponent != null) { 260 return clientComponent.getInputMethodRequests(); 261 } 262 263 return null; 264 } 265 266 public Rectangle getTextLocation(TextHitInfo offset) { 267 synchronized (compositionAreaLock) { 268 if (compositionAreaOwner == this && isCompositionAreaVisible()) { 269 return compositionArea.getTextLocation(offset); 270 } else if (composedText != null) { 271 // there's composed text, but it's not displayed, so fake a rectangle 272 return new Rectangle(0, 0, 0, 10); 273 } else { 274 InputMethodRequests requests = getClientInputMethodRequests(); 275 if (requests != null) { 276 return requests.getTextLocation(offset); 277 } else { 278 // passive client, no composed text, so fake a rectangle 279 return new Rectangle(0, 0, 0, 10); 280 } | 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.awt.im; 27 28 import java.awt.Component; 29 import java.awt.Container; 30 import java.awt.Rectangle; 31 import java.awt.event.InputMethodEvent; 32 import java.awt.event.InputMethodListener; 33 import java.awt.font.TextAttribute; 34 import java.awt.font.TextHitInfo; 35 import java.awt.im.InputMethodRequests; 36 import java.lang.ref.WeakReference; 37 import java.text.AttributedCharacterIterator; 38 import java.text.AttributedCharacterIterator.Attribute; 39 import java.text.AttributedString; 40 41 /** 42 * A composition area handler handles events and input method requests for 43 * the composition area. Typically each input method context has its own 44 * composition area handler if it supports passive clients or below-the-spot 45 * input, but all handlers share a single composition area. 46 * 47 * @author JavaSoft International 48 */ 49 50 class CompositionAreaHandler implements InputMethodListener, 51 InputMethodRequests { 52 53 private static CompositionArea compositionArea; 54 private static Object compositionAreaLock = new Object(); 55 private static CompositionAreaHandler compositionAreaOwner; // synchronized through compositionArea 56 57 private AttributedCharacterIterator composedText; 58 private TextHitInfo caret = null; 59 private WeakReference<Component> clientComponent = new WeakReference<>(null); 60 private InputMethodContext inputMethodContext; 61 62 /** 63 * Constructs the composition area handler. 64 */ 65 CompositionAreaHandler(InputMethodContext context) { 66 inputMethodContext = context; 67 } 68 69 /** 70 * Creates the composition area. 71 */ 72 private void createCompositionArea() { 73 synchronized(compositionAreaLock) { 74 compositionArea = new CompositionArea(); 75 if (compositionAreaOwner != null) { 76 compositionArea.setHandlerInfo(compositionAreaOwner, inputMethodContext); 77 } 78 // If the client component is an active client using below-the-spot style, then 79 // make the composition window undecorated without a title bar. 80 Component client = clientComponent.get(); 81 if(client != null){ 82 InputMethodRequests req = client.getInputMethodRequests(); 83 if (req != null && inputMethodContext.useBelowTheSpotInput()) { 84 setCompositionAreaUndecorated(true); 85 } 86 } 87 } 88 } 89 90 void setClientComponent(Component clientComponent) { 91 this.clientComponent = new WeakReference<>(clientComponent); 92 } 93 94 /** 95 * Grabs the composition area, makes this handler its owner, and installs 96 * the handler and its input context into the composition area for event 97 * and input method request handling. 98 * If doUpdate is true, updates the composition area with previously sent 99 * composed text. 100 */ 101 102 void grabCompositionArea(boolean doUpdate) { 103 synchronized (compositionAreaLock) { 104 if (compositionAreaOwner != this) { 105 compositionAreaOwner = this; 106 if (compositionArea != null) { 107 compositionArea.setHandlerInfo(this, inputMethodContext); 108 } 109 if (doUpdate) { 110 // Create the composition area if necessary 111 if ((composedText != null) && (compositionArea == null)) { 241 public void caretPositionChanged(InputMethodEvent event) { 242 if (compositionArea != null) { 243 compositionArea.setCaret(event.getCaret()); 244 } 245 246 // event has been handled, so consume it 247 event.consume(); 248 } 249 250 // 251 // InputMethodRequests methods 252 // 253 254 /** 255 * Returns the input method request handler of the client component. 256 * When using the composition window for an active client (below-the-spot 257 * input), input method requests that do not relate to the display of 258 * the composed text are forwarded to the client component. 259 */ 260 InputMethodRequests getClientInputMethodRequests() { 261 Component client = clientComponent.get(); 262 if (client != null) { 263 return client.getInputMethodRequests(); 264 } 265 266 return null; 267 } 268 269 public Rectangle getTextLocation(TextHitInfo offset) { 270 synchronized (compositionAreaLock) { 271 if (compositionAreaOwner == this && isCompositionAreaVisible()) { 272 return compositionArea.getTextLocation(offset); 273 } else if (composedText != null) { 274 // there's composed text, but it's not displayed, so fake a rectangle 275 return new Rectangle(0, 0, 0, 10); 276 } else { 277 InputMethodRequests requests = getClientInputMethodRequests(); 278 if (requests != null) { 279 return requests.getTextLocation(offset); 280 } else { 281 // passive client, no composed text, so fake a rectangle 282 return new Rectangle(0, 0, 0, 10); 283 } |