📄 inputcontext.java
字号:
InputMethodDescriptor d = (InputMethodDescriptor) descriptors.get(i); Locale[] list; try { list = d.getAvailableLocales(); } catch (AWTException ignored) { continue; } for (int j = list.length; --j >= 0; ) if (locale.equals(list[j])) { try { next = d.createInputMethod(); recent.put(locale, next); } catch (Exception ignored) { continue; } } } if (next == null) return false; // XXX I'm not sure if this does all the necessary steps in the switch. if (im != null) { try { next.setCompositionEnabled(im.isCompositionEnabled()); } catch (UnsupportedOperationException ignored) { } im.endComposition(); im.deactivate(false); im.hideWindows(); } im = next; im.setLocale(locale); im.setCharacterSubsets(subsets); return true; } /** * Returns the current locale of the current input method or keyboard * layout. Returns null if the input context does not have a current input * method or keyboard layout or if the current input method's * {@link InputMethod#getLocale()} method returns null. Not all host * operating systems provide API to determine the locale of the currently * selected native input method or keyboard layout. For host operating * systems that don't provide such API, getLocale assumes that the current * locale of all native input methods or keyboard layouts provided by the * host operating system is the system's default locale. * * @return the locale of the current input method, or null * @since 1.3 */ public Locale getLocale() { return im == null ? null : im.getLocale(); } /** * Sets the subsets of Unicode characters allowed to be input by the current * input method, as well as subsequent input methods. The value of null * implies all characters are legal. Applications should not rely on this * behavior, since native host input methods may not allow restrictions. * If no current input method is available, this has no immediate effect. * * @param subsets the set of Unicode subsets to accept, or null */ public void setCharacterSubsets(Character.Subset[] subsets) { this.subsets = subsets; if (im != null) im.setCharacterSubsets(subsets); } /** * Changes the enabled status of the current input method. An input method * that is enabled for composition interprets incoming events for both * composition and control purposes, while a disabled input method only * interprets control commands (including commands to enable itself). * * @param enable whether to enable the input method * @throws UnsupportedOperationException if there is no current input method, * or the input method does not support enabling * @see #isCompositionEnabled() * @since 1.3 */ public void setCompositionEnabled(boolean enable) { if (im == null) throw new UnsupportedOperationException(); im.setCompositionEnabled(enable); } /** * Find out if the current input method is enabled. * * @return true if the current input method is enabled * @throws UnsupportedOperationException if there is no current input method, * or the input method does not support enabling * @see #setCompositionEnabled(boolean) * @since 1.3 */ public boolean isCompositionEnabled() { if (im == null) throw new UnsupportedOperationException(); return im.isCompositionEnabled(); } /** * Starts a reconversion operation in the current input method. The input * method gets theh text to reconvert from the client component, using * {@link InputMethodRequests#getSelectedText(Attribute[])}. Then the * composed and committed text produced by the operation is sent back to * the client using a sequence of InputMethodRequests. * * @throws UnsupportedOperationException if there is no current input method, * or the input method does not support reconversion * @since 1.3 */ public void reconvert() { if (im == null) throw new UnsupportedOperationException(); im.reconvert(); } /** * Dispatches an event to the current input method. This is called * automatically by AWT. If no input method is available, then the event * will never be consumed. * * @param event the event to dispatch * @throws NullPointerException if event is null */ public void dispatchEvent(AWTEvent event) { if (im != null) im.dispatchEvent(event); } /** * Notifies the input context that a client component has been removed from * its containment hierarchy, or that input method support has been disabled * for the component. This method is usually called from the client * component's {@link Component#removeNotify()} method. Potentially pending * input from input methods for this component is discarded. If no input * methods are available, then this method has no effect. * * @param client the client component * @throws NullPointerException if client is null */ public void removeNotify(Component client) { // XXX What to do with client information? if (im != null) { im.deactivate(false); im.removeNotify(); } } /** * Ends any input composition that may currently be going on in this * context. Depending on the platform and possibly user preferences, this * may commit or delete uncommitted text. Any changes to the text are * communicated to the active component using an input method event. If no * input methods are available, then this method has no effect. This may * be called for a variety of reasons, such as when the user moves the * insertion point in the client text outside the range of the composed text, * or when text is saved to file. */ public void endComposition() { if (im != null) im.endComposition(); } /** * Disposes of the input context and release the resources used by it. * Called automatically by AWT for the default input context of each * Window. If no input methods are available, then this method has no * effect. */ public void dispose() { if (im != null) { im.deactivate(false); im.dispose(); } } /** * Returns a control object from the current input method, or null. A * control object provides implementation-dependent methods that control * the behavior of the input method or obtain information from the input * method. Clients have to compare the result against known input method * control object types. If no input methods are available or the current * input method does not provide an input method control object, then null * is returned. * * @return the control object, or null */ public Object getInputMethodControlObject() { return im == null ? null : im.getControlObject(); }} // class InputContext
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -