Search in sources :

Example 1 with Annotation

use of java.text.Annotation in project jdk8u_jdk by JetBrains.

the class AttributeValues method applyIMHighlight.

/**
     * If this has an imHighlight, create copy of this with those attributes
     * applied to it.  Otherwise return this unchanged.
     */
public AttributeValues applyIMHighlight() {
    if (imHighlight != null) {
        InputMethodHighlight hl = null;
        if (imHighlight instanceof InputMethodHighlight) {
            hl = (InputMethodHighlight) imHighlight;
        } else {
            hl = (InputMethodHighlight) ((Annotation) imHighlight).getValue();
        }
        Map imStyles = hl.getStyle();
        if (imStyles == null) {
            Toolkit tk = Toolkit.getDefaultToolkit();
            imStyles = tk.mapInputMethodHighlight(hl);
        }
        if (imStyles != null) {
            return clone().merge(imStyles);
        }
    }
    return this;
}
Also used : Toolkit(java.awt.Toolkit) InputMethodHighlight(java.awt.im.InputMethodHighlight) HashMap(java.util.HashMap) Map(java.util.Map) Annotation(java.text.Annotation)

Example 2 with Annotation

use of java.text.Annotation in project jdk8u_jdk by JetBrains.

the class StyledParagraph method addInputMethodAttrs.

/**
     * Return a Map with entries from oldStyles, as well as input
     * method entries, if any.
     */
static Map<? extends Attribute, ?> addInputMethodAttrs(Map<? extends Attribute, ?> oldStyles) {
    Object value = oldStyles.get(TextAttribute.INPUT_METHOD_HIGHLIGHT);
    try {
        if (value != null) {
            if (value instanceof Annotation) {
                value = ((Annotation) value).getValue();
            }
            InputMethodHighlight hl;
            hl = (InputMethodHighlight) value;
            Map<? extends Attribute, ?> imStyles = null;
            try {
                imStyles = hl.getStyle();
            } catch (NoSuchMethodError e) {
            }
            if (imStyles == null) {
                Toolkit tk = Toolkit.getDefaultToolkit();
                imStyles = tk.mapInputMethodHighlight(hl);
            }
            if (imStyles != null) {
                HashMap<Attribute, Object> newStyles = new HashMap<>(5, (float) 0.9);
                newStyles.putAll(oldStyles);
                newStyles.putAll(imStyles);
                return newStyles;
            }
        }
    } catch (ClassCastException e) {
    }
    return oldStyles;
}
Also used : HashMap(java.util.HashMap) Attribute(java.text.AttributedCharacterIterator.Attribute) Toolkit(java.awt.Toolkit) InputMethodHighlight(java.awt.im.InputMethodHighlight) Annotation(java.text.Annotation)

Aggregations

Toolkit (java.awt.Toolkit)2 InputMethodHighlight (java.awt.im.InputMethodHighlight)2 Annotation (java.text.Annotation)2 HashMap (java.util.HashMap)2 Attribute (java.text.AttributedCharacterIterator.Attribute)1 Map (java.util.Map)1