Java Code Examples for sun.font.Decoration

Following code examples demonstrate how to use sun.font.Decorationfrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use sun.font.Decorationand various code implementation of this class.

    
    public StyledParagraph(AttributedCharacterIterator aci,
                           char[] chars) {

        int start = aci.getBeginIndex();
        int end = aci.getEndIndex();
        length = end - start;

        int index = start;
        aci.first();

        do {
            final int nextRunStart = aci.getRunLimit();
            final int localIndex = index-start;

            Map<? extends Attribute, ?> attributes = aci.getAttributes();
            attributes = addInputMethodAttrs(attributes);
            Decoration d = Decoration.getDecoration(attributes);
            addDecoration(d, localIndex);

            Object f = getGraphicOrFont(attributes);
            if (f == null) {
                addFonts(chars, attributes, localIndex, nextRunStart-start);
            }
            else {
                addFont(f, localIndex);
            }

            aci.setIndex(nextRunStart);
            index = nextRunStart;

        } while (index < end);

        if (decorations != null) {
            decorationStarts = addToVector(this, length, decorations, decorationStarts);
        }
        if (fonts != null) {
            fontStarts = addToVector(this, length, fonts, fontStarts);
        }
    } 


    
    public static StyledParagraph insertChar(AttributedCharacterIterator aci,
                                             char[] chars,
                                             int insertPos,
                                             StyledParagraph oldParagraph) {


        char ch = aci.setIndex(insertPos);
        int relativePos = Math.max(insertPos - aci.getBeginIndex() - 1, 0);

        Map<? extends Attribute, ?> attributes =
            addInputMethodAttrs(aci.getAttributes());
        Decoration d = Decoration.getDecoration(attributes);
        if (!oldParagraph.getDecorationAt(relativePos).equals(d)) {
            return new StyledParagraph(aci, chars);
        }
        Object f = getGraphicOrFont(attributes);
        if (f == null) {
            FontResolver resolver = FontResolver.getInstance();
            int fontIndex = resolver.getFontIndex(ch);
            f = resolver.getFont(fontIndex, attributes);
        }
        if (!oldParagraph.getFontOrGraphicAt(relativePos).equals(f)) {
            return new StyledParagraph(aci, chars);
        }

        oldParagraph.length += 1;
        if (oldParagraph.decorations != null) {
            insertInto(relativePos,
                       oldParagraph.decorationStarts,
                       oldParagraph.decorations.size());
        }
        if (oldParagraph.fonts != null) {
            insertInto(relativePos,
                       oldParagraph.fontStarts,
                       oldParagraph.fonts.size());
        }
        return oldParagraph;
    } 

Advertisement
Javadoc
This class handles underlining, strikethrough, and foreground and background styles on text. Clients

simply acquire instances of this class and hand them off to ExtendedTextLabels or GraphicComponents.

Read More
Advertisement