2658
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
|
2658
|
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
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2658
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2658
|
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 |
*
|
5506
|
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.
|
2658
|
24 |
*/
|
|
25 |
package javax.swing.plaf.nimbus;
|
|
26 |
|
|
27 |
import sun.awt.AppContext;
|
|
28 |
|
|
29 |
import java.awt.image.BufferedImage;
|
|
30 |
import java.lang.ref.SoftReference;
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Effect
|
|
34 |
*
|
|
35 |
* @author Created by Jasper Potts (Jun 18, 2007)
|
|
36 |
*/
|
|
37 |
abstract class Effect {
|
|
38 |
enum EffectType {
|
|
39 |
UNDER, BLENDED, OVER
|
|
40 |
}
|
|
41 |
|
|
42 |
// =================================================================================================================
|
|
43 |
// Abstract Methods
|
|
44 |
|
|
45 |
/**
|
|
46 |
* Get the type of this effect, one of UNDER,BLENDED,OVER. UNDER means the result of apply effect should be painted
|
|
47 |
* under the src image. BLENDED means the result of apply sffect contains a modified src image so just it should be
|
|
48 |
* painted. OVER means the result of apply effect should be painted over the src image.
|
|
49 |
*
|
|
50 |
* @return The effect type
|
|
51 |
*/
|
|
52 |
abstract EffectType getEffectType();
|
|
53 |
|
|
54 |
/**
|
|
55 |
* Get the opacity to use to paint the result effected image if the EffectType is UNDER or OVER.
|
|
56 |
*
|
|
57 |
* @return The opactity for the effect, 0.0f -> 1.0f
|
|
58 |
*/
|
|
59 |
abstract float getOpacity();
|
|
60 |
|
|
61 |
/**
|
|
62 |
* Apply the effect to the src image generating the result . The result image may or may not contain the source
|
|
63 |
* image depending on what the effect type is.
|
|
64 |
*
|
|
65 |
* @param src The source image for applying the effect to
|
|
66 |
* @param dst The dstination image to paint effect result into. If this is null then a new image will be created
|
|
67 |
* @param w The width of the src image to apply effect to, this allow the src and dst buffers to be bigger than
|
|
68 |
* the area the need effect applied to it
|
|
69 |
* @param h The height of the src image to apply effect to, this allow the src and dst buffers to be bigger than
|
|
70 |
* the area the need effect applied to it
|
|
71 |
* @return The result of appl
|
|
72 |
*/
|
|
73 |
abstract BufferedImage applyEffect(BufferedImage src, BufferedImage dst, int w, int h);
|
|
74 |
|
|
75 |
// =================================================================================================================
|
|
76 |
// Static data cache
|
|
77 |
|
|
78 |
protected static ArrayCache getArrayCache() {
|
|
79 |
ArrayCache cache = (ArrayCache)AppContext.getAppContext().get(ArrayCache.class);
|
|
80 |
if (cache == null){
|
|
81 |
cache = new ArrayCache();
|
|
82 |
AppContext.getAppContext().put(ArrayCache.class,cache);
|
|
83 |
}
|
|
84 |
return cache;
|
|
85 |
}
|
|
86 |
|
|
87 |
protected static class ArrayCache {
|
|
88 |
private SoftReference<int[]> tmpIntArray = null;
|
|
89 |
private SoftReference<byte[]> tmpByteArray1 = null;
|
|
90 |
private SoftReference<byte[]> tmpByteArray2 = null;
|
|
91 |
private SoftReference<byte[]> tmpByteArray3 = null;
|
|
92 |
|
|
93 |
protected int[] getTmpIntArray(int size) {
|
|
94 |
int[] tmp;
|
|
95 |
if (tmpIntArray == null || (tmp = tmpIntArray.get()) == null || tmp.length < size) {
|
|
96 |
// create new array
|
|
97 |
tmp = new int[size];
|
|
98 |
tmpIntArray = new SoftReference<int[]>(tmp);
|
|
99 |
}
|
|
100 |
return tmp;
|
|
101 |
}
|
|
102 |
|
|
103 |
protected byte[] getTmpByteArray1(int size) {
|
|
104 |
byte[] tmp;
|
|
105 |
if (tmpByteArray1 == null || (tmp = tmpByteArray1.get()) == null || tmp.length < size) {
|
|
106 |
// create new array
|
|
107 |
tmp = new byte[size];
|
|
108 |
tmpByteArray1 = new SoftReference<byte[]>(tmp);
|
|
109 |
}
|
|
110 |
return tmp;
|
|
111 |
}
|
|
112 |
|
|
113 |
protected byte[] getTmpByteArray2(int size) {
|
|
114 |
byte[] tmp;
|
|
115 |
if (tmpByteArray2 == null || (tmp = tmpByteArray2.get()) == null || tmp.length < size) {
|
|
116 |
// create new array
|
|
117 |
tmp = new byte[size];
|
|
118 |
tmpByteArray2 = new SoftReference<byte[]>(tmp);
|
|
119 |
}
|
|
120 |
return tmp;
|
|
121 |
}
|
|
122 |
|
|
123 |
protected byte[] getTmpByteArray3(int size) {
|
|
124 |
byte[] tmp;
|
|
125 |
if (tmpByteArray3 == null || (tmp = tmpByteArray3.get()) == null || tmp.length < size) {
|
|
126 |
// create new array
|
|
127 |
tmp = new byte[size];
|
|
128 |
tmpByteArray3 = new SoftReference<byte[]>(tmp);
|
|
129 |
}
|
|
130 |
return tmp;
|
|
131 |
}
|
|
132 |
}
|
|
133 |
}
|