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.SaturatedColorScheme;
033: import org.jvnet.substance.color.ShiftColorScheme;
034:
035: /**
036: * Saturated theme. This class is part of officially supported API.
037: *
038: * @author Kirill Grouchnikov
039: * @see ShiftColorScheme
040: */
041: public class SubstanceSaturatedTheme extends SubstanceWrapperTheme {
042: /**
043: * The saturation factor of <code>this</code> theme.
044: */
045: private double saturationFactor;
046:
047: /**
048: * If <code>true</code>, all visual components of the original theme will
049: * be saturated. If <code>false</code>, only the
050: * {@link #getActiveTheme()} will be saturated.
051: */
052: private boolean toSaturateEverything;
053:
054: /**
055: * Creates a new saturated theme. <b>Do not</b> use this constructor
056: * directly, use {@link SubstanceTheme#saturate(double)} instead.
057: *
058: * @param substanceTheme
059: * The original theme.
060: * @param saturationFactor
061: * Saturation factor.
062: * @param toSaturateEverything
063: * If <code>true</code>, all visual components of
064: * <code>this</code> theme will be saturated. If
065: * <code>false</code>, only the {@link #getActiveTheme()} will
066: * be saturated.
067: */
068: SubstanceSaturatedTheme(SubstanceTheme substanceTheme,
069: double saturationFactor, boolean toSaturateEverything) {
070: super (substanceTheme, new SaturatedColorScheme(substanceTheme
071: .getColorScheme(), saturationFactor), "Saturated "
072: + substanceTheme.getDisplayName() + " "
073: + (int) (100 * saturationFactor) + "% ["
074: + toSaturateEverything + "]", substanceTheme.getKind());
075: this .saturationFactor = saturationFactor;
076: this .toSaturateEverything = toSaturateEverything;
077: }
078:
079: /*
080: * (non-Javadoc)
081: *
082: * @see org.jvnet.substance.theme.SubstanceTheme#getBorderTheme()
083: */
084: @Override
085: public SubstanceTheme getBorderTheme() {
086: if (this .borderTheme == null)
087: this .borderTheme = this .originalTheme.getBorderTheme()
088: .saturate(this .saturationFactor);
089: return this .borderTheme;
090: }
091:
092: /*
093: * (non-Javadoc)
094: *
095: * @see org.jvnet.substance.theme.SubstanceTheme#getDefaultTheme()
096: */
097: @Override
098: public SubstanceTheme getDefaultTheme() {
099: if (this .toSaturateEverything) {
100: if (this .defaultTheme == null)
101: this .defaultTheme = this .originalTheme
102: .getDefaultTheme().saturate(
103: this .saturationFactor);
104: return this .defaultTheme;
105: } else {
106: return this .originalTheme.getDefaultTheme();
107: }
108: }
109:
110: /*
111: * (non-Javadoc)
112: *
113: * @see org.jvnet.substance.theme.SubstanceTheme#getDisabledTheme()
114: */
115: @Override
116: public SubstanceTheme getDisabledTheme() {
117: if (this.toSaturateEverything) {
118: if (this.disabledTheme == null)
119: this.disabledTheme = this.originalTheme
120: .getDisabledTheme().saturate(
121: this.saturationFactor);
122: return this.disabledTheme;
123: } else {
124: return this.originalTheme.getDisabledTheme();
125: }
126: }
127: }
|