/** * Creates the composition area. */ private void createCompositionArea() { synchronized(compositionAreaLock) { compositionArea = new CompositionArea(); if (compositionAreaOwner != null) { compositionArea.setHandlerInfo(compositionAreaOwner, inputMethodContext); } // If the client component is an active client using below-the-spot style, then // make the composition window undecorated without a title bar. Component client = clientComponent.get(); if(client != null){ InputMethodRequests req = client.getInputMethodRequests(); if (req != null && inputMethodContext.useBelowTheSpotInput()) { setCompositionAreaUndecorated(true); } } } }
public Rectangle getTextLocation(TextHitInfo offset) { synchronized (compositionAreaLock) { if (compositionAreaOwner == this && isCompositionAreaVisible()) { return compositionArea.getTextLocation(offset); } else if (composedText != null) { // there's composed text, but it's not displayed, so fake a rectangle return new Rectangle(0, 0, 0, 10); } else { InputMethodRequests requests = getClientInputMethodRequests(); if (requests != null) { return requests.getTextLocation(offset); } else { // passive client, no composed text, so fake a rectangle return new Rectangle(0, 0, 0, 10); } } } }
/** * Creates the composition area. */ private void createCompositionArea() { synchronized(compositionAreaLock) { compositionArea = new CompositionArea(); if (compositionAreaOwner != null) { compositionArea.setHandlerInfo(compositionAreaOwner, inputMethodContext); } // If the client component is an active client using below-the-spot style, then // make the composition window undecorated without a title bar. if(clientComponent!=null){ InputMethodRequests req = clientComponent.getInputMethodRequests(); if (req != null && inputMethodContext.useBelowTheSpotInput()) { setCompositionAreaUndecorated(true); } } } }
@Override public InputMethodRequests getInputMethodRequests() { try { return super.getInputMethodRequests(); } catch (NullPointerException ex) { return null; } }
/** * Positions the composition window near (usually below) the * insertion point in the client component if the client * component is an active client (below-the-spot input). */ void updateWindowLocation() { InputMethodRequests req = handler.getClientInputMethodRequests(); if (req == null) { // not an active client return; } Point windowLocation = new Point(); Rectangle caretRect = req.getTextLocation(null); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension windowSize = compositionWindow.getSize(); final int SPACING = 2; if (caretRect.x + windowSize.width > screenSize.width) { windowLocation.x = screenSize.width - windowSize.width; } else { windowLocation.x = caretRect.x; } if (caretRect.y + caretRect.height + SPACING + windowSize.height > screenSize.height) { windowLocation.y = caretRect.y - SPACING - windowSize.height; } else { windowLocation.y = caretRect.y + caretRect.height + SPACING; } compositionWindow.setLocation(windowLocation); }
/** * Returns the input method request handler of the client component. * When using the composition window for an active client (below-the-spot * input), input method requests that do not relate to the display of * the composed text are forwarded to the client component. */ InputMethodRequests getClientInputMethodRequests() { Component client = clientComponent.get(); if (client != null) { return client.getInputMethodRequests(); } return null; }
public int getInsertPositionOffset() { InputMethodRequests req = getClientInputMethodRequests(); if (req != null) { return req.getInsertPositionOffset(); } // we don't have access to the client component's text. return 0; }
public AttributedCharacterIterator getCommittedText(int beginIndex, int endIndex, Attribute[] attributes) { InputMethodRequests req = getClientInputMethodRequests(); if(req != null) { return req.getCommittedText(beginIndex, endIndex, attributes); } // we don't have access to the client component's text. return EMPTY_TEXT; }
public int getCommittedTextLength() { InputMethodRequests req = getClientInputMethodRequests(); if(req != null) { return req.getCommittedTextLength(); } // we don't have access to the client component's text. return 0; }
public AttributedCharacterIterator cancelLatestCommittedText(Attribute[] attributes) { InputMethodRequests req = getClientInputMethodRequests(); if(req != null) { return req.cancelLatestCommittedText(attributes); } // we don't have access to the client component's text. return null; }
public AttributedCharacterIterator getSelectedText(Attribute[] attributes) { InputMethodRequests req = getClientInputMethodRequests(); if(req != null) { return req.getSelectedText(attributes); } // we don't have access to the client component's text. return EMPTY_TEXT; }
/** * Dispatches committed text to a client component. * Called by composition window. * * @param client The component that the text should get dispatched to. * @param text The iterator providing access to the committed * (and possible composed) text. * @param committedCharacterCount The number of committed characters in the text. */ synchronized void dispatchCommittedText(Component client, AttributedCharacterIterator text, int committedCharacterCount) { // note that the client is not always the current client component - // some host input method adapters may dispatch input method events // through the Java event queue, and we may have switched clients while // the event was in the queue. if (committedCharacterCount == 0 || text.getEndIndex() <= text.getBeginIndex()) { return; } long time = System.currentTimeMillis(); dispatchingCommittedText = true; try { InputMethodRequests req = client.getInputMethodRequests(); if (req != null) { // active client -> send text as InputMethodEvent int beginIndex = text.getBeginIndex(); AttributedCharacterIterator toBeCommitted = (new AttributedString(text, beginIndex, beginIndex + committedCharacterCount)).getIterator(); InputMethodEvent inputEvent = new InputMethodEvent( client, InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, toBeCommitted, committedCharacterCount, null, null); client.dispatchEvent(inputEvent); } else { // passive client -> send text as KeyEvents char keyChar = text.first(); while (committedCharacterCount-- > 0 && keyChar != CharacterIterator.DONE) { KeyEvent keyEvent = new KeyEvent(client, KeyEvent.KEY_TYPED, time, 0, KeyEvent.VK_UNDEFINED, keyChar); client.dispatchEvent(keyEvent); keyChar = text.next(); } } } finally { dispatchingCommittedText = false; } }
private InputMethodRequests getReq() { if (haveActiveClient() && !useBelowTheSpotInput()) { return getClientComponent().getInputMethodRequests(); } else { return getCompositionAreaHandler(false); } }
public InputMethodRequests getInputMethodRequests() { if (inputMethodRequestsHandler == null) { inputMethodRequestsHandler = new InputMethodRequestsHandler(); Document doc = getDocument(); if (doc != null) { doc.addDocumentListener((DocumentListener)inputMethodRequestsHandler); } } return inputMethodRequestsHandler; }
/** * @see java.awt.peer.TextComponentPeer */ @Override public InputMethodRequests getInputMethodRequests() { if (xtext != null) return xtext.getInputMethodRequests(); else return null; }