001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.lib.profiler.ui.components;
042:
043: import java.awt.AlphaComposite;
044: import java.awt.Color;
045: import java.awt.Graphics2D;
046: import java.awt.Image;
047: import java.awt.image.BufferedImage;
048: import javax.swing.UIManager;
049:
050: /**
051: *
052: * @author Jiri Sedlacek
053: */
054: public class ImageBlenderPanel extends ImagePanel {
055: //~ Instance fields ----------------------------------------------------------------------------------------------------------
056:
057: private Color background;
058: private Image image1;
059: private Image image2;
060: private float blendAlpha;
061:
062: //~ Constructors -------------------------------------------------------------------------------------------------------------
063:
064: public ImageBlenderPanel(Image image1, Image image2) {
065: this (image1, image2, UIManager.getColor("Panel.background"), 0); // NOI18N
066: }
067:
068: public ImageBlenderPanel(Image image1, Image image2,
069: Color background, float blendAlpha) {
070: super (
071: createBlendedImage(image1, image2, background,
072: blendAlpha));
073: this .background = background;
074: this .blendAlpha = blendAlpha;
075: this .image1 = image1;
076: this .image2 = image2;
077: }
078:
079: //~ Methods ------------------------------------------------------------------------------------------------------------------
080:
081: public void setBlendAlpha(float blendAlpha) {
082: setImage(createBlendedImage(image1, image2, background,
083: blendAlpha));
084: this .blendAlpha = blendAlpha;
085: }
086:
087: private static Image createBlendedImage(Image image1, Image image2,
088: Color background, float blendAlpha) {
089: Image i1 = loadImage(image1);
090: Image i2 = loadImage(image2);
091:
092: int blendedImageWidth = Math.max(i1.getWidth(null), i2
093: .getWidth(null));
094: int blendedImageHeight = Math.max(i1.getHeight(null), i2
095: .getHeight(null));
096:
097: BufferedImage blendedImage = new BufferedImage(
098: blendedImageWidth, blendedImageHeight,
099: BufferedImage.TYPE_INT_RGB);
100: Graphics2D blendedImageGraphics = (Graphics2D) blendedImage
101: .getGraphics();
102:
103: blendedImageGraphics.setColor(background);
104: blendedImageGraphics.fillRect(0, 0, blendedImageWidth,
105: blendedImageHeight);
106: blendedImageGraphics.drawImage(i1, 0, 0, null);
107: blendedImageGraphics.setComposite(AlphaComposite.getInstance(
108: AlphaComposite.SRC_OVER, blendAlpha));
109: blendedImageGraphics.drawImage(i2, 0, 0, null);
110:
111: return blendedImage;
112: }
113: }
|