private AttributeSet translateAttributes(Map<AttributedCharacterIterator.Attribute, ?> source) { for(AttributedCharacterIterator.Attribute sourceKey : source.keySet()) { Object sourceValue = source.get(sourceKey); // Ignore any non-input method related highlights if (!(sourceValue instanceof InputMethodHighlight)) { continue; } InputMethodHighlight imh = (InputMethodHighlight) sourceValue; if (imh.isSelected()) { return highlightInverse; } else { return highlightUnderlined; } } LOG.fine("No translation for " + source); return SimpleAttributeSet.EMPTY; }
/** * @see java.awt.Toolkit#mapInputMethodHighlight */ public static Map mapInputMethodHighlight(InputMethodHighlight highlight) { int index; int state = highlight.getState(); if (state == InputMethodHighlight.RAW_TEXT) { index = 0; } else if (state == InputMethodHighlight.CONVERTED_TEXT) { index = 2; } else { return null; } if (highlight.isSelected()) { index += 1; } return highlightStyles[index]; }
/** * @see java.awt.Toolkit#mapInputMethodHighlight */ public static Map<TextAttribute, ?> mapInputMethodHighlight(InputMethodHighlight highlight) { int index; int state = highlight.getState(); if (state == InputMethodHighlight.RAW_TEXT) { index = 0; } else if (state == InputMethodHighlight.CONVERTED_TEXT) { index = 2; } else { return null; } if (highlight.isSelected()) { index += 1; } return highlightStyles[index]; }
public void mapInputMethodHighlight(InputMethodHighlight highlight, Map map) { TextAttribute key = TextAttribute.SWAP_COLORS; if (highlight.isSelected()) { map.put(key, TextAttribute.SWAP_COLORS_ON); return; } switch(highlight.getState()) { case InputMethodHighlight.RAW_TEXT: key = TextAttribute.WEIGHT; map.put(key, TextAttribute.WEIGHT_BOLD); break; case InputMethodHighlight.CONVERTED_TEXT: key = TextAttribute.INPUT_METHOD_UNDERLINE; map.put(key, TextAttribute.UNDERLINE_LOW_ONE_PIXEL); break; } }
@SuppressWarnings("unchecked") public void mapInputMethodHighlight(InputMethodHighlight highlight, Map<TextAttribute, ?> map) { Map<TextAttribute, Object> _map = (Map<TextAttribute, Object>)map; TextAttribute key = TextAttribute.INPUT_METHOD_UNDERLINE; boolean selected = highlight.isSelected(); switch(highlight.getState()) { case InputMethodHighlight.RAW_TEXT: _map.put(key, selected ? TextAttribute.UNDERLINE_LOW_GRAY : TextAttribute.UNDERLINE_LOW_DOTTED); break; case InputMethodHighlight.CONVERTED_TEXT: _map.put(key, selected ? TextAttribute.UNDERLINE_LOW_ONE_PIXEL : TextAttribute.UNDERLINE_LOW_DOTTED); if (selected) { // maybe get colors from system properties? key = TextAttribute.BACKGROUND; _map.put(key, Color.white); key = TextAttribute.FOREGROUND; _map.put(key, new Color(0, 0, 128)); key = TextAttribute.SWAP_COLORS; _map.put(key, TextAttribute.SWAP_COLORS_ON); } break; } }
/** * Send the composed text to the client. */ private void sendComposedText() { AttributedString as = new AttributedString(buffer.toString()); as.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT, InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT); context.dispatchInputMethodEvent( InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, as.getIterator(), 0, TextHitInfo.leading(insertionPoint), null); }
/** * Returns a style map for the input method highlight. */ @Override public Map<java.awt.font.TextAttribute,?> mapInputMethodHighlight( InputMethodHighlight highlight) { return WInputMethod.mapInputMethodHighlight(highlight); }
/** * Performs mapping from an XIM visible feedback value to Java IM highlight. * @return Java input method highlight */ private InputMethodHighlight convertVisualFeedbackToHighlight(int feedback) { InputMethodHighlight highlight; switch (feedback) { case XIMUnderline: highlight = InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT; break; case XIMReverse: highlight = InputMethodHighlight.SELECTED_CONVERTED_TEXT_HIGHLIGHT; break; case XIMHighlight: highlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT; break; case XIMPrimary: highlight = InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT; break; case XIMSecondary: highlight = InputMethodHighlight.SELECTED_CONVERTED_TEXT_HIGHLIGHT; break; case XIMTertiary: highlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT; break; default: highlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT; break; } return highlight; }