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.ColorScheme;
033: import org.jvnet.substance.color.MixColorScheme;
034:
035: /**
036: * Mixed theme. Mixed theme is based on two original themes, using the first
037: * theme for the left part of the painting, the second theme for the right part
038: * of the painting, and the theme blend gradient in the middle. Here is how you
039: * can create and set a mixed theme:<br>
040: * <br>
041: *
042: * <code>
043: * SubstanceTheme mixed = new SubstanceMixTheme(<br>
044: * SubstanceAquaTheme(), SubstanceBottleGreenTheme());<br>
045: * SubstanceLookAndFeel.setCurrentTheme(mixed);<br>
046: * for (Frame frame : Frame.getFrames()) {<br>
047: * SwingUtilities.updateComponentTreeUI(frame);<br>
048: * }
049: * </code><br>
050: * This class is part of officially supported API.
051: *
052: * @author Kirill Grouchnikov
053: */
054: public class SubstanceMixTheme extends SubstanceTheme {
055: /**
056: * The original themes.
057: */
058: private SubstanceTheme[] originalThemes;
059:
060: /**
061: * Creates a new mixed theme.
062: *
063: * @param originalThemes
064: * The original themes.
065: */
066: public SubstanceMixTheme(SubstanceTheme... originalThemes) {
067: super (new MixColorScheme(getSchemes(originalThemes)),
068: getName(originalThemes), ThemeKind.MIXED);
069: this .originalThemes = originalThemes;
070: }
071:
072: /**
073: * Returns the color schemes of the specified themes.
074: *
075: * @param themes
076: * Themes array.
077: * @return Color schemes array, each entry corresponding to an entry in the
078: * input theme array.
079: */
080: private static ColorScheme[] getSchemes(SubstanceTheme... themes) {
081: ColorScheme[] result = new ColorScheme[themes.length];
082: for (int i = 0; i < themes.length; i++) {
083: result[i] = themes[i].getColorScheme();
084: }
085: return result;
086: }
087:
088: /**
089: * Returns the name of a mixed theme that is based on the specified themes.
090: *
091: * @param themes
092: * Themes array.
093: * @return Name of a mixed theme that is based on the specified themes.
094: */
095: private static String getName(SubstanceTheme... themes) {
096: StringBuffer idBuf = new StringBuffer();
097: idBuf.append("Mixed ");
098: String delim = "";
099: for (SubstanceTheme theme : themes) {
100: idBuf.append(delim);
101: idBuf.append(theme.getDisplayName());
102: delim = " & ";
103: }
104: return idBuf.toString();
105: }
106:
107: /**
108: * Returns the original themes.
109: *
110: * @return The original themes.
111: */
112: public SubstanceTheme[] getOriginalThemes() {
113: return this .originalThemes;
114: }
115:
116: /*
117: * (non-Javadoc)
118: *
119: * @see org.jvnet.substance.theme.SubstanceTheme#tint(double)
120: */
121: @Override
122: public SubstanceTheme tint(double tintFactor) {
123: SubstanceTheme[] tinted = new SubstanceTheme[this .originalThemes.length];
124: for (int i = 0; i < this .originalThemes.length; i++)
125: tinted[i] = this .originalThemes[i].tint(tintFactor);
126: return new SubstanceMixTheme(tinted);
127: }
128:
129: /*
130: * (non-Javadoc)
131: *
132: * @see org.jvnet.substance.theme.SubstanceTheme#tone(double)
133: */
134: @Override
135: public SubstanceTheme tone(double toneFactor) {
136: SubstanceTheme[] toned = new SubstanceTheme[this .originalThemes.length];
137: for (int i = 0; i < this .originalThemes.length; i++)
138: toned[i] = this .originalThemes[i].tone(toneFactor);
139: return new SubstanceMixTheme(toned);
140: }
141:
142: /*
143: * (non-Javadoc)
144: *
145: * @see org.jvnet.substance.theme.SubstanceTheme#shade(double)
146: */
147: @Override
148: public SubstanceTheme shade(double shadeFactor) {
149: SubstanceTheme[] shaded = new SubstanceTheme[this .originalThemes.length];
150: for (int i = 0; i < this .originalThemes.length; i++)
151: shaded[i] = this .originalThemes[i].shade(shadeFactor);
152: return new SubstanceMixTheme(shaded);
153: }
154:
155: /*
156: * (non-Javadoc)
157: *
158: * @see org.jvnet.substance.theme.SubstanceTheme#saturate(double, boolean)
159: */
160: @Override
161: public SubstanceTheme saturate(double saturateFactor,
162: boolean toSaturateEverything) {
163: SubstanceTheme[] saturated = new SubstanceTheme[this .originalThemes.length];
164: for (int i = 0; i < this .originalThemes.length; i++)
165: saturated[i] = this .originalThemes[i].saturate(
166: saturateFactor, toSaturateEverything);
167: return new SubstanceMixTheme(saturated);
168: }
169:
170: /*
171: * (non-Javadoc)
172: *
173: * @see org.jvnet.substance.theme.SubstanceTheme#hueShift(double)
174: */
175: @Override
176: public SubstanceTheme hueShift(double hueShiftFactor) {
177: SubstanceTheme[] shaded = new SubstanceTheme[this .originalThemes.length];
178: for (int i = 0; i < this .originalThemes.length; i++)
179: shaded[i] = this .originalThemes[i].hueShift(hueShiftFactor);
180: return new SubstanceMixTheme(shaded);
181: }
182:
183: /*
184: * (non-Javadoc)
185: *
186: * @see org.jvnet.substance.theme.SubstanceTheme#invert()
187: */
188: @Override
189: public SubstanceTheme invert() {
190: SubstanceTheme[] inverted = new SubstanceTheme[this .originalThemes.length];
191: for (int i = 0; i < this .originalThemes.length; i++)
192: inverted[i] = this .originalThemes[i].invert();
193: return new SubstanceMixTheme(inverted);
194: }
195:
196: /*
197: * (non-Javadoc)
198: *
199: * @see org.jvnet.substance.theme.SubstanceTheme#negate()
200: */
201: @Override
202: public SubstanceTheme negate() {
203: SubstanceTheme[] negated = new SubstanceTheme[this .originalThemes.length];
204: for (int i = 0; i < this .originalThemes.length; i++)
205: negated[i] = this .originalThemes[i].negate();
206: return new SubstanceMixTheme(negated);
207: }
208:
209: //
210: /*
211: * (non-Javadoc)
212: *
213: * @see org.jvnet.substance.theme.SubstanceTheme#getFirstTheme()
214: */
215: @Override
216: public SubstanceTheme getFirstTheme() {
217: return this .getOriginalThemes()[0];
218: }
219:
220: /*
221: * (non-Javadoc)
222: *
223: * @see org.jvnet.substance.theme.SubstanceTheme#getSecondTheme()
224: */
225: @Override
226: public SubstanceTheme getSecondTheme() {
227: return this .getOriginalThemes()[this .getOriginalThemes().length - 1];
228: }
229:
230: /*
231: * (non-Javadoc)
232: *
233: * @see org.jvnet.substance.theme.SubstanceTheme#getDefaultTheme()
234: */
235: @Override
236: public SubstanceTheme getDefaultTheme() {
237: return this .getOriginalThemes()[0].getDefaultTheme();
238: }
239:
240: /*
241: * (non-Javadoc)
242: *
243: * @see org.jvnet.substance.theme.SubstanceTheme#getDisabledTheme()
244: */
245: @Override
246: public SubstanceTheme getDisabledTheme() {
247: return this .getOriginalThemes()[0].getDisabledTheme();
248: }
249: }
|