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) {
|
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) {
|