KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > nimbus > Effect


1 /*
2  * @(#)Effect.java 1.2 07/12/12
3  *
4  * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package com.sun.java.swing.plaf.nimbus;
8
9 import sun.awt.AppContext;
10
11 import java.awt.image.BufferedImage JavaDoc;
12 import java.lang.ref.SoftReference JavaDoc;
13
14 /**
15  * Effect
16  *
17  * @author Created by Jasper Potts (Jun 18, 2007)
18  * @version 1.0
19  */

20 abstract class Effect {
21     enum EffectType {
22         UNDER, BLENDED, OVER
23     }
24
25     // =================================================================================================================
26
// Abstract Methods
27

28     /**
29      * Get the type of this effect, one of UNDER,BLENDED,OVER. UNDER means the result of apply effect should be painted
30      * under the src image. BLENDED means the result of apply sffect contains a modified src image so just it should be
31      * painted. OVER means the result of apply effect should be painted over the src image.
32      *
33      * @return The effect type
34      */

35     abstract EffectType getEffectType();
36
37     /**
38      * Get the opacity to use to paint the result effected image if the EffectType is UNDER or OVER.
39      *
40      * @return The opactity for the effect, 0.0f -> 1.0f
41      */

42     abstract float getOpacity();
43
44     /**
45      * Apply the effect to the src image generating the result . The result image may or may not contain the source
46      * image depending on what the effect type is.
47      *
48      * @param src The source image for applying the effect to
49      * @param dst The dstination image to paint effect result into. If this is null then a new image will be created
50      * @param w The width of the src image to apply effect to, this allow the src and dst buffers to be bigger than
51      * the area the need effect applied to it
52      * @param h The height of the src image to apply effect to, this allow the src and dst buffers to be bigger than
53      * the area the need effect applied to it
54      * @return The result of appl
55      */

56     abstract BufferedImage JavaDoc applyEffect(BufferedImage JavaDoc src, BufferedImage JavaDoc dst, int w, int h);
57
58     // =================================================================================================================
59
// Static data cache
60

61     protected static ArrayCache getArrayCache() {
62         ArrayCache cache = (ArrayCache)AppContext.getAppContext().get(ArrayCache.class);
63         if (cache == null){
64             cache = new ArrayCache();
65             AppContext.getAppContext().put(ArrayCache.class,cache);
66         }
67         return cache;
68     }
69
70     protected static class ArrayCache {
71         private SoftReference JavaDoc<int[]> tmpIntArray = null;
72         private SoftReference JavaDoc<byte[]> tmpByteArray1 = null;
73         private SoftReference JavaDoc<byte[]> tmpByteArray2 = null;
74         private SoftReference JavaDoc<byte[]> tmpByteArray3 = null;
75
76         protected int[] getTmpIntArray(int size) {
77             int[] tmp;
78             if (tmpIntArray == null || (tmp = tmpIntArray.get()) == null || tmp.length < size) {
79                 // create new array
80
tmp = new int[size];
81                 tmpIntArray = new SoftReference JavaDoc<int[]>(tmp);
82             }
83             return tmp;
84         }
85
86         protected byte[] getTmpByteArray1(int size) {
87             byte[] tmp;
88             if (tmpByteArray1 == null || (tmp = tmpByteArray1.get()) == null || tmp.length < size) {
89                 // create new array
90
tmp = new byte[size];
91                 tmpByteArray1 = new SoftReference JavaDoc<byte[]>(tmp);
92             }
93             return tmp;
94         }
95
96         protected byte[] getTmpByteArray2(int size) {
97             byte[] tmp;
98             if (tmpByteArray2 == null || (tmp = tmpByteArray2.get()) == null || tmp.length < size) {
99                 // create new array
100
tmp = new byte[size];
101                 tmpByteArray2 = new SoftReference JavaDoc<byte[]>(tmp);
102             }
103             return tmp;
104         }
105
106         protected byte[] getTmpByteArray3(int size) {
107             byte[] tmp;
108             if (tmpByteArray3 == null || (tmp = tmpByteArray3.get()) == null || tmp.length < size) {
109                 // create new array
110
tmp = new byte[size];
111                 tmpByteArray3 = new SoftReference JavaDoc<byte[]>(tmp);
112             }
113             return tmp;
114         }
115     }
116 }
117
Popular Tags