Path: blob/master/src/java.desktop/share/classes/sun/font/AttributeMap.java
41155 views
/*1* Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26What is the dead simplest thing to do?27Extend AbstractMap and don't optimize for anything.2829The only new api is 'getValues()' which returns the values struct as30long as no map api has been called. If any map api is called,31create a real map and forward to it, and nuke values because of the32possibility that the map has been changed. This is easier than33trying to create a map that only clears values if the map has been34changed, or implementing the map API directly on top of the values35struct. We can always do that later if need be.36*/3738package sun.font;3940import java.awt.Paint;41import java.awt.font.GraphicAttribute;42import java.awt.font.NumericShaper;43import java.awt.font.TextAttribute;44import java.awt.font.TransformAttribute;45import java.awt.geom.AffineTransform;46import java.awt.im.InputMethodHighlight;47import java.text.AttributedCharacterIterator.Attribute;48import java.util.AbstractMap;49import java.util.HashMap;50import java.util.Map;51import java.util.Set;52import java.util.Map.Entry;5354import static sun.font.AttributeValues.*;5556public final class AttributeMap extends AbstractMap<TextAttribute, Object> {57private AttributeValues values;58private Map<TextAttribute, Object> delegateMap;5960public AttributeMap(AttributeValues values) {61this.values = values;62}6364public Set<Entry<TextAttribute, Object>> entrySet() {65return delegate().entrySet();66}6768public Object put(TextAttribute key, Object value) {69return delegate().put(key, value);70}7172// internal API73public AttributeValues getValues() {74return values;75}7677private static boolean first = false; // debug78private Map<TextAttribute, Object> delegate() {79if (delegateMap == null) {80if (first) {81first = false;82Thread.dumpStack();83}84delegateMap = values.toMap(new HashMap<TextAttribute, Object>(27));8586// nuke values, once map is accessible it might be mutated and values would87// no longer reflect its contents88values = null;89}9091return delegateMap;92}9394public String toString() {95if (values != null) {96return "map of " + values.toString();97}98return super.toString();99}100}101102103