src/java.desktop/share/classes/sun/font/AttributeMap.java
author adinn
Fri, 26 Jan 2018 16:38:21 +0000
changeset 48682 34e45260c040
parent 47216 71c04702a3d5
permissions -rw-r--r--
8196221: AArch64: Mistake in committed patch for JDK-8195859 Summary: The wrong patch was committed for JDK-8195859 Reviewed-by: aph
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2004, 2005, 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
  What is the dead simplest thing to do?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
  Extend AbstractMap and don't optimize for anything.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
  The only new api is 'getValues()' which returns the values struct as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
  long as no map api has been called.  If any map api is called,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
  create a real map and forward to it, and nuke values because of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  possibility that the map has been changed.  This is easier than
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  trying to create a map that only clears values if the map has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  changed, or implementing the map API directly on top of the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  struct.  We can always do that later if need be.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
package sun.font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.Paint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.font.GraphicAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.font.NumericShaper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.font.TextAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.font.TransformAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.im.InputMethodHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.text.AttributedCharacterIterator.Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.AbstractMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.util.Map.Entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import static sun.font.AttributeValues.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public final class AttributeMap extends AbstractMap<TextAttribute, Object> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private AttributeValues values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private Map<TextAttribute, Object> delegateMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public AttributeMap(AttributeValues values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        this.values = values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public Set<Entry<TextAttribute, Object>> entrySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        return delegate().entrySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public Object put(TextAttribute key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        return delegate().put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // internal API
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public AttributeValues getValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        return values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static boolean first = false; // debug
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private Map<TextAttribute, Object> delegate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (delegateMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            if (first) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                first = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                Thread.dumpStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            delegateMap = values.toMap(new HashMap<TextAttribute, Object>(27));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            // nuke values, once map is accessible it might be mutated and values would
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            // no longer reflect its contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            values = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return delegateMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (values != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            return "map of " + values.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return super.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
}