1 /*
2 * Copyright (c) 2002, 2008, 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
43 class ImagePainter extends SynthPainter {
44 private static final StringBuffer CACHE_KEY =
45 new StringBuffer("SynthCacheKey");
46
47 private Image image;
48 private Insets sInsets;
49 private Insets dInsets;
50 private URL path;
51 private boolean tiles;
52 private boolean paintCenter;
53 private Paint9Painter imageCache;
54 private boolean center;
55
56 private static Paint9Painter getPaint9Painter() {
57 // A SynthPainter is created per <imagePainter>. We want the
58 // cache to be shared by all, and we don't use a static because we
59 // don't want it to persist between look and feels. For that reason
60 // we use a AppContext specific Paint9Painter. It's backed via
61 // a WeakRef so that it can go away if the look and feel changes.
62 synchronized(CACHE_KEY) {
63 WeakReference<Paint9Painter> cacheRef =
64 (WeakReference<Paint9Painter>)AppContext.getAppContext().
65 get(CACHE_KEY);
66 Paint9Painter painter;
67 if (cacheRef == null || (painter = cacheRef.get()) == null) {
68 painter = new Paint9Painter(30);
69 cacheRef = new WeakReference<Paint9Painter>(painter);
70 AppContext.getAppContext().put(CACHE_KEY, cacheRef);
71 }
72 return painter;
73 }
74 }
75
76 ImagePainter(boolean tiles, boolean paintCenter,
77 Insets sourceInsets, Insets destinationInsets, URL path,
78 boolean center) {
79 if (sourceInsets != null) {
80 this.sInsets = (Insets)sourceInsets.clone();
81 }
82 if (destinationInsets == null) {
|
1 /*
2 * Copyright (c) 2002, 2014, 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
43 class ImagePainter extends SynthPainter {
44 private static final StringBuffer CACHE_KEY =
45 new StringBuffer("SynthCacheKey");
46
47 private Image image;
48 private Insets sInsets;
49 private Insets dInsets;
50 private URL path;
51 private boolean tiles;
52 private boolean paintCenter;
53 private Paint9Painter imageCache;
54 private boolean center;
55
56 private static Paint9Painter getPaint9Painter() {
57 // A SynthPainter is created per <imagePainter>. We want the
58 // cache to be shared by all, and we don't use a static because we
59 // don't want it to persist between look and feels. For that reason
60 // we use a AppContext specific Paint9Painter. It's backed via
61 // a WeakRef so that it can go away if the look and feel changes.
62 synchronized(CACHE_KEY) {
63 @SuppressWarnings("unchecked")
64 WeakReference<Paint9Painter> cacheRef =
65 (WeakReference<Paint9Painter>)AppContext.getAppContext().
66 get(CACHE_KEY);
67 Paint9Painter painter;
68 if (cacheRef == null || (painter = cacheRef.get()) == null) {
69 painter = new Paint9Painter(30);
70 cacheRef = new WeakReference<Paint9Painter>(painter);
71 AppContext.getAppContext().put(CACHE_KEY, cacheRef);
72 }
73 return painter;
74 }
75 }
76
77 ImagePainter(boolean tiles, boolean paintCenter,
78 Insets sourceInsets, Insets destinationInsets, URL path,
79 boolean center) {
80 if (sourceInsets != null) {
81 this.sInsets = (Insets)sourceInsets.clone();
82 }
83 if (destinationInsets == null) {
|