001: /*
002: * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of Substance Kirill Grouchnikov nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030: package org.jvnet.substance.painter;
031:
032: import java.awt.*;
033:
034: /**
035: * Constant-translucency {@link ControlBackgroundComposite} that paints all
036: * non-active components with translucent composite.
037: *
038: * @author Kirill Grouchnikov
039: */
040: public class AlphaControlBackgroundComposite extends
041: ControlBackgroundComposite {
042: /**
043: * Alpha value for <code>this</code> composite.
044: */
045: protected float alpha;
046:
047: /**
048: * Alpha value for <code>this</code> composite.
049: */
050: protected float alphaActive;
051:
052: /**
053: * Composite for active controls.
054: */
055: protected Composite active;
056:
057: /**
058: * Composite for non-active controls.
059: */
060: protected Composite nonActive;
061:
062: /**
063: * Creates the new constant-translucent composite.
064: *
065: * @param alpha
066: * Alpha value for <code>this</code> composite for controls in
067: * non-active state.
068: */
069: public AlphaControlBackgroundComposite(float alpha) {
070: this (alpha, 1.0f);
071: }
072:
073: /**
074: * Creates the new constant-translucenct composite.
075: *
076: * @param alpha
077: * Alpha value for <code>this</code> composite for controls in
078: * non-active state.
079: * @param alphaActive
080: * Alpha value for <code>this</code> composite for controls in
081: * active state.
082: */
083: public AlphaControlBackgroundComposite(float alpha,
084: float alphaActive) {
085: this .alpha = alpha;
086: this .alphaActive = alphaActive;
087: this .active = AlphaComposite.getInstance(
088: AlphaComposite.SRC_OVER, this .alphaActive);
089: this .nonActive = AlphaComposite.getInstance(
090: AlphaComposite.SRC_OVER, this .alpha);
091: }
092:
093: /*
094: * (non-Javadoc)
095: *
096: * @see org.jvnet.substance.painter.ControlBackgroundComposite#getBackgroundComposite(java.awt.Component,
097: * java.awt.Container, int, boolean)
098: */
099: public Composite getBackgroundComposite(Component component,
100: Container container, int componentIndex,
101: boolean isPaintedActive) {
102: return isPaintedActive ? this.active : this.nonActive;
103: }
104: }
|