1173N/A/*
2362N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
1173N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1173N/A *
1173N/A * This code is free software; you can redistribute it and/or modify it
1173N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
1173N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
1173N/A *
1173N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1173N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1173N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1173N/A * version 2 for more details (a copy is included in the LICENSE file that
1173N/A * accompanied this code).
1173N/A *
1173N/A * You should have received a copy of the GNU General Public License version
1173N/A * 2 along with this work; if not, write to the Free Software Foundation,
1173N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1173N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1173N/A */
1173N/Apackage javax.swing.plaf.nimbus;
1173N/A
1173N/Aimport sun.awt.AppContext;
1173N/A
1173N/Aimport java.awt.image.BufferedImage;
1173N/Aimport java.lang.ref.SoftReference;
1173N/A
1173N/A/**
1173N/A * Effect
1173N/A *
1173N/A * @author Created by Jasper Potts (Jun 18, 2007)
1173N/A */
1173N/Aabstract class Effect {
1173N/A enum EffectType {
1173N/A UNDER, BLENDED, OVER
1173N/A }
1173N/A
1173N/A // =================================================================================================================
1173N/A // Abstract Methods
1173N/A
1173N/A /**
1173N/A * Get the type of this effect, one of UNDER,BLENDED,OVER. UNDER means the result of apply effect should be painted
1173N/A * under the src image. BLENDED means the result of apply sffect contains a modified src image so just it should be
1173N/A * painted. OVER means the result of apply effect should be painted over the src image.
1173N/A *
1173N/A * @return The effect type
1173N/A */
1173N/A abstract EffectType getEffectType();
1173N/A
1173N/A /**
1173N/A * Get the opacity to use to paint the result effected image if the EffectType is UNDER or OVER.
1173N/A *
1173N/A * @return The opactity for the effect, 0.0f -> 1.0f
1173N/A */
1173N/A abstract float getOpacity();
1173N/A
1173N/A /**
1173N/A * Apply the effect to the src image generating the result . The result image may or may not contain the source
1173N/A * image depending on what the effect type is.
1173N/A *
1173N/A * @param src The source image for applying the effect to
1173N/A * @param dst The dstination image to paint effect result into. If this is null then a new image will be created
1173N/A * @param w The width of the src image to apply effect to, this allow the src and dst buffers to be bigger than
1173N/A * the area the need effect applied to it
1173N/A * @param h The height of the src image to apply effect to, this allow the src and dst buffers to be bigger than
1173N/A * the area the need effect applied to it
1173N/A * @return The result of appl
1173N/A */
1173N/A abstract BufferedImage applyEffect(BufferedImage src, BufferedImage dst, int w, int h);
1173N/A
1173N/A // =================================================================================================================
1173N/A // Static data cache
1173N/A
1173N/A protected static ArrayCache getArrayCache() {
1173N/A ArrayCache cache = (ArrayCache)AppContext.getAppContext().get(ArrayCache.class);
1173N/A if (cache == null){
1173N/A cache = new ArrayCache();
1173N/A AppContext.getAppContext().put(ArrayCache.class,cache);
1173N/A }
1173N/A return cache;
1173N/A }
1173N/A
1173N/A protected static class ArrayCache {
1173N/A private SoftReference<int[]> tmpIntArray = null;
1173N/A private SoftReference<byte[]> tmpByteArray1 = null;
1173N/A private SoftReference<byte[]> tmpByteArray2 = null;
1173N/A private SoftReference<byte[]> tmpByteArray3 = null;
1173N/A
1173N/A protected int[] getTmpIntArray(int size) {
1173N/A int[] tmp;
1173N/A if (tmpIntArray == null || (tmp = tmpIntArray.get()) == null || tmp.length < size) {
1173N/A // create new array
1173N/A tmp = new int[size];
1173N/A tmpIntArray = new SoftReference<int[]>(tmp);
1173N/A }
1173N/A return tmp;
1173N/A }
1173N/A
1173N/A protected byte[] getTmpByteArray1(int size) {
1173N/A byte[] tmp;
1173N/A if (tmpByteArray1 == null || (tmp = tmpByteArray1.get()) == null || tmp.length < size) {
1173N/A // create new array
1173N/A tmp = new byte[size];
1173N/A tmpByteArray1 = new SoftReference<byte[]>(tmp);
1173N/A }
1173N/A return tmp;
1173N/A }
1173N/A
1173N/A protected byte[] getTmpByteArray2(int size) {
1173N/A byte[] tmp;
1173N/A if (tmpByteArray2 == null || (tmp = tmpByteArray2.get()) == null || tmp.length < size) {
1173N/A // create new array
1173N/A tmp = new byte[size];
1173N/A tmpByteArray2 = new SoftReference<byte[]>(tmp);
1173N/A }
1173N/A return tmp;
1173N/A }
1173N/A
1173N/A protected byte[] getTmpByteArray3(int size) {
1173N/A byte[] tmp;
1173N/A if (tmpByteArray3 == null || (tmp = tmpByteArray3.get()) == null || tmp.length < size) {
1173N/A // create new array
1173N/A tmp = new byte[size];
1173N/A tmpByteArray3 = new SoftReference<byte[]>(tmp);
1173N/A }
1173N/A return tmp;
1173N/A }
1173N/A }
1173N/A}