jdk/src/java.desktop/share/classes/java/awt/font/StyledParagraph.java
author serb
Wed, 17 Sep 2014 16:14:12 +0400
changeset 26749 b6598aa90114
parent 25859 3317bb8137f4
permissions -rw-r--r--
8055326: Fix typos in client-related packages Reviewed-by: prr, azvegint, alexsch Contributed-by: pavel.rappo@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21957
diff changeset
     2
 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1999,  All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
package java.awt.font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.im.InputMethodHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.text.Annotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.text.AttributedCharacterIterator;
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
    37
import java.text.AttributedCharacterIterator.Attribute;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Map;
25111
080de8ffa3f6 8035301: Eliminate dependency on sun.text from font code
prr
parents: 23010
diff changeset
    41
import sun.font.CodePointIterator;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.font.Decoration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.font.FontResolver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * This class stores Font, GraphicAttribute, and Decoration intervals
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * on a paragraph of styled text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Currently, this class is optimized for a small number of intervals
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
    50
 * (preferably 1).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
final class StyledParagraph {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // the length of the paragraph
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private int length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    // If there is a single Decoration for the whole paragraph, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // is stored here.  Otherwise this field is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private Decoration decoration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    // If there is a single Font or GraphicAttribute for the whole
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // paragraph, it is stored here.  Otherwise this field is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private Object font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // If there are multiple Decorations in the paragraph, they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // stored in this Vector, in order.  Otherwise this vector and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // the decorationStarts array are null.
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
    69
    private Vector<Decoration> decorations;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // If there are multiple Decorations in the paragraph,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // decorationStarts[i] contains the index where decoration i
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    // starts.  For convenience, there is an extra entry at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // end of this array with the length of the paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    int[] decorationStarts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // If there are multiple Fonts/GraphicAttributes in the paragraph,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    // stored in this Vector, in order.  Otherwise this vector and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    // the fontStarts array are null.
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
    80
    private Vector<Object> fonts;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // If there are multiple Fonts/GraphicAttributes in the paragraph,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // fontStarts[i] contains the index where decoration i
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // starts.  For convenience, there is an extra entry at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // end of this array with the length of the paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    int[] fontStarts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private static int INITIAL_SIZE = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Create a new StyledParagraph over the given styled text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param aci an iterator over the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param chars the characters extracted from aci
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public StyledParagraph(AttributedCharacterIterator aci,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                           char[] chars) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        int start = aci.getBeginIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        int end = aci.getEndIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        length = end - start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        int index = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        aci.first();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            final int nextRunStart = aci.getRunLimit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            final int localIndex = index-start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   108
            Map<? extends Attribute, ?> attributes = aci.getAttributes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            attributes = addInputMethodAttrs(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            Decoration d = Decoration.getDecoration(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            addDecoration(d, localIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            Object f = getGraphicOrFont(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                addFonts(chars, attributes, localIndex, nextRunStart-start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                addFont(f, localIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            aci.setIndex(nextRunStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            index = nextRunStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        } while (index < end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        // Add extra entries to starts arrays with the length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        // of the paragraph.  'this' is used as a dummy value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        // in the Vector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (decorations != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            decorationStarts = addToVector(this, length, decorations, decorationStarts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (fonts != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            fontStarts = addToVector(this, length, fonts, fontStarts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Adjust indices in starts to reflect an insertion after pos.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Any index in starts greater than pos will be increased by 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private static void insertInto(int pos, int[] starts, int numStarts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        while (starts[--numStarts] > pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            starts[numStarts] += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Return a StyledParagraph reflecting the insertion of a single character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * into the text.  This method will attempt to reuse the given paragraph,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * but may create a new paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param aci an iterator over the text.  The text should be the same as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *     text used to create (or most recently update) oldParagraph, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *     the exception of inserting a single character at insertPos.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param chars the characters in aci
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param insertPos the index of the new character in aci
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param oldParagraph a StyledParagraph for the text in aci before the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *     insertion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public static StyledParagraph insertChar(AttributedCharacterIterator aci,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                             char[] chars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                             int insertPos,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                                             StyledParagraph oldParagraph) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        // If the styles at insertPos match those at insertPos-1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        // oldParagraph will be reused.  Otherwise we create a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        // paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        char ch = aci.setIndex(insertPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        int relativePos = Math.max(insertPos - aci.getBeginIndex() - 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   172
        Map<? extends Attribute, ?> attributes =
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   173
            addInputMethodAttrs(aci.getAttributes());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        Decoration d = Decoration.getDecoration(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (!oldParagraph.getDecorationAt(relativePos).equals(d)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            return new StyledParagraph(aci, chars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        Object f = getGraphicOrFont(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            FontResolver resolver = FontResolver.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            int fontIndex = resolver.getFontIndex(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            f = resolver.getFont(fontIndex, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (!oldParagraph.getFontOrGraphicAt(relativePos).equals(f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            return new StyledParagraph(aci, chars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        // insert into existing paragraph
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        oldParagraph.length += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (oldParagraph.decorations != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            insertInto(relativePos,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                       oldParagraph.decorationStarts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                       oldParagraph.decorations.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (oldParagraph.fonts != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            insertInto(relativePos,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                       oldParagraph.fontStarts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                       oldParagraph.fonts.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return oldParagraph;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Adjust indices in starts to reflect a deletion after deleteAt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Any index in starts greater than deleteAt will be increased by 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * It is the caller's responsibility to make sure that no 0-length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * runs result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    private static void deleteFrom(int deleteAt, int[] starts, int numStarts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        while (starts[--numStarts] > deleteAt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            starts[numStarts] -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Return a StyledParagraph reflecting the insertion of a single character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * into the text.  This method will attempt to reuse the given paragraph,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * but may create a new paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param aci an iterator over the text.  The text should be the same as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *     text used to create (or most recently update) oldParagraph, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *     the exception of deleting a single character at deletePos.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @param chars the characters in aci
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param deletePos the index where a character was removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param oldParagraph a StyledParagraph for the text in aci before the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *     insertion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public static StyledParagraph deleteChar(AttributedCharacterIterator aci,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                                             char[] chars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                                             int deletePos,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                                             StyledParagraph oldParagraph) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        // We will reuse oldParagraph unless there was a length-1 run
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        // at deletePos.  We could do more work and check the individual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        // Font and Decoration runs, but we don't right now...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        deletePos -= aci.getBeginIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (oldParagraph.decorations == null && oldParagraph.fonts == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            oldParagraph.length -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            return oldParagraph;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (oldParagraph.getRunLimit(deletePos) == deletePos+1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            if (deletePos == 0 || oldParagraph.getRunLimit(deletePos-1) == deletePos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                return new StyledParagraph(aci, chars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        oldParagraph.length -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if (oldParagraph.decorations != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            deleteFrom(deletePos,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                       oldParagraph.decorationStarts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                       oldParagraph.decorations.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (oldParagraph.fonts != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            deleteFrom(deletePos,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                       oldParagraph.fontStarts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                       oldParagraph.fonts.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return oldParagraph;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Return the index at which there is a different Font, GraphicAttribute, or
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
   265
     * Decoration than at the given index.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @param index a valid index in the paragraph
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @return the first index where there is a change in attributes from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *      those at index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public int getRunLimit(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if (index < 0 || index >= length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            throw new IllegalArgumentException("index out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        int limit1 = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if (decorations != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            int run = findRunContaining(index, decorationStarts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            limit1 = decorationStarts[run+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        int limit2 = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (fonts != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            int run = findRunContaining(index, fontStarts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            limit2 = fontStarts[run+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        return Math.min(limit1, limit2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * Return the Decoration in effect at the given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @param index a valid index in the paragraph
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @return the Decoration at index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public Decoration getDecorationAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (index < 0 || index >= length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            throw new IllegalArgumentException("index out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (decorations == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            return decoration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        int run = findRunContaining(index, decorationStarts);
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   302
        return decorations.elementAt(run);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Return the Font or GraphicAttribute in effect at the given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * The client must test the type of the return value to determine what
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * it is.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @param index a valid index in the paragraph
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @return the Font or GraphicAttribute at index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public Object getFontOrGraphicAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (index < 0 || index >= length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            throw new IllegalArgumentException("index out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (fonts == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        int run = findRunContaining(index, fontStarts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        return fonts.elementAt(run);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    /**
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 11081
diff changeset
   325
     * Return i such that starts[i] &lt;= index &lt; starts[i+1].  starts
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * must be in increasing order, with at least one element greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * than index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    private static int findRunContaining(int index, int[] starts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        for (int i=1; true; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            if (starts[i] > index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                return i-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * Append the given Object to the given Vector.  Add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * the given index to the given starts array.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * starts array does not have room for the index, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * new array is created and returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   344
    @SuppressWarnings({"rawtypes", "unchecked"})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    private static int[] addToVector(Object obj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                                     int index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                                     Vector v,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                                     int[] starts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if (!v.lastElement().equals(obj)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            v.addElement(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            int count = v.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            if (starts.length == count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                int[] temp = new int[starts.length*2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                System.arraycopy(starts, 0, temp, 0, starts.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                starts = temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            starts[count-1] = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        return starts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * Add a new Decoration run with the given Decoration at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    private void addDecoration(Decoration d, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (decorations != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            decorationStarts = addToVector(d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                                           index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                                           decorations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                                           decorationStarts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        else if (decoration == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            decoration = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            if (!decoration.equals(d)) {
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   380
                decorations = new Vector<Decoration>(INITIAL_SIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                decorations.addElement(decoration);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                decorations.addElement(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                decorationStarts = new int[INITIAL_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                decorationStarts[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                decorationStarts[1] = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * Add a new Font/GraphicAttribute run with the given object at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    private void addFont(Object f, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        if (fonts != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            fontStarts = addToVector(f, index, fonts, fontStarts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        else if (font == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            font = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            if (!font.equals(f)) {
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   404
                fonts = new Vector<Object>(INITIAL_SIZE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                fonts.addElement(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                fonts.addElement(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                fontStarts = new int[INITIAL_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                fontStarts[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                fontStarts[1] = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * Resolve the given chars into Fonts using FontResolver, then add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * font runs for each.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     */
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   418
    private void addFonts(char[] chars, Map<? extends Attribute, ?> attributes,
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   419
                          int start, int limit) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        FontResolver resolver = FontResolver.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        CodePointIterator iter = CodePointIterator.create(chars, start, limit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        for (int runStart = iter.charIndex(); runStart < limit; runStart = iter.charIndex()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            int fontIndex = resolver.nextFontRunIndex(iter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            addFont(resolver.getFont(fontIndex, attributes), runStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * Return a Map with entries from oldStyles, as well as input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * method entries, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     */
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   433
    static Map<? extends Attribute, ?>
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   434
           addInputMethodAttrs(Map<? extends Attribute, ?> oldStyles) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        Object value = oldStyles.get(TextAttribute.INPUT_METHOD_HIGHLIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                if (value instanceof Annotation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    value = ((Annotation)value).getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                InputMethodHighlight hl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                hl = (InputMethodHighlight) value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   447
                Map<? extends Attribute, ?> imStyles = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    imStyles = hl.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                } catch (NoSuchMethodError e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                if (imStyles == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    Toolkit tk = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                    imStyles = tk.mapInputMethodHighlight(hl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                if (imStyles != null) {
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   459
                    HashMap<Attribute, Object>
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   460
                        newStyles = new HashMap<>(5, (float)0.9);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    newStyles.putAll(oldStyles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    newStyles.putAll(imStyles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                    return newStyles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        catch(ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        return oldStyles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * Extract a GraphicAttribute or Font from the given attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * If attributes does not contain a GraphicAttribute, Font, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * Font family entry this method returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     */
11081
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   480
    private static Object getGraphicOrFont(
4a18889223e4 7117199: Fix javac warnings in src/share/classes/java/awt/font
prr
parents: 5506
diff changeset
   481
            Map<? extends Attribute, ?> attributes) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        Object value = attributes.get(TextAttribute.CHAR_REPLACEMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        value = attributes.get(TextAttribute.FONT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (attributes.get(TextAttribute.FAMILY) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            return Font.getFont(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
}