History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/font/AttributeMap.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/font/AttributeMap.java+101−0
@@ -0,0 +1,101 @@
1+/*
2+ * Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+/*
27+ What is the dead simplest thing to do?
28+ Extend AbstractMap and don't optimize for anything.
29+
30+ The only new api is 'getValues()' which returns the values struct as
31+ long as no map api has been called. If any map api is called,
32+ create a real map and forward to it, and nuke values because of the
33+ possibility that the map has been changed. This is easier than
34+ trying to create a map that only clears values if the map has been
35+ changed, or implementing the map API directly on top of the values
36+ struct. We can always do that later if need be.
37+*/
38+
39+package sun.font;
40+
41+import java.awt.Paint;
42+import java.awt.font.GraphicAttribute;
43+import java.awt.font.NumericShaper;
44+import java.awt.font.TextAttribute;
45+import java.awt.font.TransformAttribute;
46+import java.awt.geom.AffineTransform;
47+import java.awt.im.InputMethodHighlight;
48+import java.text.AttributedCharacterIterator.Attribute;
49+import java.util.AbstractMap;
50+import java.util.HashMap;
51+import java.util.Map;
52+import java.util.Set;
53+import java.util.Map.Entry;
54+
55+import static sun.font.AttributeValues.*;
56+
57+public final class AttributeMap extends AbstractMap<TextAttribute, Object> {
58+ private AttributeValues values;
59+ private Map<TextAttribute, Object> delegateMap;
60+
61+ public AttributeMap(AttributeValues values) {
62+ this.values = values;
63+ }
64+
65+ public Set<Entry<TextAttribute, Object>> entrySet() {
66+ return delegate().entrySet();
67+ }
68+
69+ public Object put(TextAttribute key, Object value) {
70+ return delegate().put(key, value);
71+ }
72+
73+ // internal API
74+ public AttributeValues getValues() {
75+ return values;
76+ }
77+
78+ private static boolean first = false; // debug
79+ private Map<TextAttribute, Object> delegate() {
80+ if (delegateMap == null) {
81+ if (first) {
82+ first = false;
83+ Thread.dumpStack();
84+ }
85+ delegateMap = values.toMap(new HashMap<TextAttribute, Object>(27));
86+
87+ // nuke values, once map is accessible it might be mutated and values would
88+ // no longer reflect its contents
89+ values = null;
90+ }
91+
92+ return delegateMap;
93+ }
94+
95+ public String toString() {
96+ if (values != null) {
97+ return "map of " + values.toString();
98+ }
99+ return super.toString();
100+ }
101+}