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.theme;
031:
032: import org.jvnet.substance.color.BlendBiColorScheme;
033:
034: /**
035: * Blend theme. Blend theme is based on two original themes and the blend
036: * factor, blending the colors from both themes for the painting. Here is how
037: * you can create and set a blend theme:<br>
038: * <br>
039: *
040: * <code>
041: * SubstanceTheme blend = new SubstanceBlendBiTheme(<br>
042: * SubstanceAquaTheme(), SubstanceBottleGreenTheme(), 0.4);<br>
043: * SubstanceLookAndFeel.setCurrentTheme(blend);<br>
044: * for (Frame frame : Frame.getFrames()) {<br>
045: * SwingUtilities.updateComponentTreeUI(frame);<br>
046: * }
047: * </code> <br>
048: * This class is part of officially supported API.
049: *
050: * @author Kirill Grouchnikov
051: */
052: public class SubstanceBlendBiTheme extends SubstanceTheme {
053: /**
054: * The first original theme.
055: */
056: private SubstanceTheme originalFirstTheme;
057:
058: /**
059: * The second original theme.
060: */
061: private SubstanceTheme originalSecondTheme;
062:
063: /**
064: * Likeness to the {@link #originalFirstTheme}. Values close to 0.0 will
065: * create theme that closely matches the {@link #originalSecondTheme}.
066: * Values close to 1.0 will create theme that closely matches the
067: * {@link #originalFirstTheme}.
068: */
069: private double firstThemeLikeness;
070:
071: /**
072: * Creates a new blended theme.
073: *
074: * @param originalFirstTheme
075: * The first original theme.
076: * @param originalSecondTheme
077: * The second original theme.
078: * @param firstThemeLikeness
079: * Likeness to the first theme. Values close to 0.0 will create
080: * theme that closely matches the second original theme. Values
081: * close to 1.0 will create theme that closely matches the first
082: * original scheme.
083: */
084: public SubstanceBlendBiTheme(SubstanceTheme originalFirstTheme,
085: SubstanceTheme originalSecondTheme,
086: double firstThemeLikeness) {
087: super (new BlendBiColorScheme(originalFirstTheme
088: .getColorScheme(),
089: originalSecondTheme.getColorScheme(),
090: firstThemeLikeness), "Blended "
091: + originalFirstTheme.getDisplayName() + " & "
092: + originalSecondTheme.getDisplayName() + " "
093: + firstThemeLikeness,
094: (firstThemeLikeness >= 0.5) ? originalFirstTheme
095: .getKind() : originalSecondTheme.getKind());
096: this .originalFirstTheme = originalFirstTheme;
097: this .originalSecondTheme = originalSecondTheme;
098: this .firstThemeLikeness = firstThemeLikeness;
099: }
100:
101: /*
102: * (non-Javadoc)
103: *
104: * @see org.jvnet.substance.theme.SubstanceTheme#tint(double)
105: */
106: @Override
107: public SubstanceTheme tint(double tintFactor) {
108: return new SubstanceBlendBiTheme(this .originalFirstTheme
109: .tint(tintFactor), this .originalSecondTheme
110: .tint(tintFactor), this .firstThemeLikeness);
111: }
112:
113: /*
114: * (non-Javadoc)
115: *
116: * @see org.jvnet.substance.theme.SubstanceTheme#tone(double)
117: */
118: @Override
119: public SubstanceTheme tone(double toneFactor) {
120: return new SubstanceBlendBiTheme(this .originalFirstTheme
121: .tone(toneFactor), this .originalSecondTheme
122: .tone(toneFactor), this .firstThemeLikeness);
123: }
124:
125: /*
126: * (non-Javadoc)
127: *
128: * @see org.jvnet.substance.theme.SubstanceTheme#shade(double)
129: */
130: @Override
131: public SubstanceTheme shade(double shadeFactor) {
132: return new SubstanceBlendBiTheme(this .originalFirstTheme
133: .shade(shadeFactor), this .originalSecondTheme
134: .shade(shadeFactor), this .firstThemeLikeness);
135: }
136:
137: /*
138: * (non-Javadoc)
139: *
140: * @see org.jvnet.substance.theme.SubstanceTheme#saturate(double, boolean)
141: */
142: @Override
143: public SubstanceTheme saturate(double saturateFactor,
144: boolean toSaturateEverything) {
145: return new SubstanceBlendBiTheme(this .originalFirstTheme
146: .saturate(saturateFactor, toSaturateEverything),
147: this .originalSecondTheme.saturate(saturateFactor,
148: toSaturateEverything), this .firstThemeLikeness);
149: }
150:
151: /*
152: * (non-Javadoc)
153: *
154: * @see org.jvnet.substance.theme.SubstanceTheme#invert()
155: */
156: @Override
157: public SubstanceTheme invert() {
158: return new SubstanceBlendBiTheme(this .originalFirstTheme
159: .invert(), this .originalSecondTheme.invert(),
160: this .firstThemeLikeness);
161: }
162:
163: /*
164: * (non-Javadoc)
165: *
166: * @see org.jvnet.substance.theme.SubstanceTheme#negate()
167: */
168: @Override
169: public SubstanceTheme negate() {
170: return new SubstanceBlendBiTheme(this .originalFirstTheme
171: .negate(), this .originalSecondTheme.negate(),
172: this .firstThemeLikeness);
173: }
174:
175: /*
176: * (non-Javadoc)
177: *
178: * @see org.jvnet.substance.theme.SubstanceTheme#hueShift(double)
179: */
180: @Override
181: public SubstanceTheme hueShift(double hueShiftFactor) {
182: return new SubstanceBlendBiTheme(this .originalFirstTheme
183: .hueShift(hueShiftFactor), this .originalSecondTheme
184: .hueShift(hueShiftFactor), this .firstThemeLikeness);
185: }
186:
187: /**
188: * Returns the first original theme.
189: *
190: * @return The first original theme.
191: */
192: public SubstanceTheme getOriginalFirstTheme() {
193: return this .originalFirstTheme;
194: }
195:
196: /**
197: * Returns the second original theme.
198: *
199: * @return The second original theme.
200: */
201: public SubstanceTheme getOriginalSecondTheme() {
202: return this.originalSecondTheme;
203: }
204: }
|