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.color;
031:
032: import java.awt.Color;
033:
034: import org.jvnet.substance.utils.SubstanceColorUtilities;
035:
036: /**
037: * Base class for color schemes simulating color-blind users.
038: *
039: * @author Kirill Grouchnikov
040: */
041: public class ColorBlindColorScheme extends BaseColorScheme {
042: /**
043: * Matrix for converting RGB to LMS.
044: */
045: public double[][] _rgbToLms = {
046: { 0.05059983, 0.08585369, 0.00952420 },
047: { 0.01893033, 0.08925308, 0.01370054 },
048: { 0.00292202, 0.00975732, 0.07145979 } };
049:
050: /**
051: * Matrix for converting LMS to RGB.
052: */
053: public double[][] _lmsToRgb = {
054: { 30.830854, -29.832659, 1.610474 },
055: { -6.481468, 17.715578, -2.532642 },
056: { -0.375690, -1.199062, 14.273846 } };
057:
058: /**
059: * The main ultra-light color.
060: */
061: private Color mainUltraLightColor;
062:
063: /**
064: * The main extra-light color.
065: */
066: private Color mainExtraLightColor;
067:
068: /**
069: * The main light color.
070: */
071: private Color mainLightColor;
072:
073: /**
074: * The main medium color.
075: */
076: private Color mainMidColor;
077:
078: /**
079: * The main dark color.
080: */
081: private Color mainDarkColor;
082:
083: /**
084: * The main ultra-dark color.
085: */
086: private Color mainUltraDarkColor;
087:
088: /**
089: * The foreground color.
090: */
091: private Color foregroundColor;
092:
093: /**
094: * The original color scheme.
095: */
096: private ColorScheme origScheme;
097:
098: /**
099: * Blindness kind.
100: *
101: * @author Kirill Grouchnikov
102: */
103: public enum BlindnessKind {
104: /**
105: * Protanopia color blindness.
106: */
107: PROTANOPIA,
108:
109: /**
110: * Deuteranopia color blindness.
111: */
112: DEUTERANOPIA,
113:
114: /**
115: * Tritanopia color blindness.
116: */
117: TRITANOPIA
118: }
119:
120: /**
121: * Creates a new color scheme that simulates color-blindness.
122: *
123: * @param origScheme
124: * Original color scheme.
125: * @param kind
126: * Color-blindness kind.
127: */
128: public ColorBlindColorScheme(ColorScheme origScheme,
129: BlindnessKind kind) {
130: this .origScheme = origScheme;
131: this .foregroundColor = SubstanceColorUtilities
132: .getColorBlindColor(origScheme.getForegroundColor(),
133: _rgbToLms, kind, _lmsToRgb);
134: this .mainUltraDarkColor = SubstanceColorUtilities
135: .getColorBlindColor(origScheme.getUltraDarkColor(),
136: _rgbToLms, kind, _lmsToRgb);
137: this .mainDarkColor = SubstanceColorUtilities
138: .getColorBlindColor(origScheme.getDarkColor(),
139: _rgbToLms, kind, _lmsToRgb);
140: this .mainMidColor = SubstanceColorUtilities.getColorBlindColor(
141: origScheme.getMidColor(), _rgbToLms, kind, _lmsToRgb);
142: this .mainLightColor = SubstanceColorUtilities
143: .getColorBlindColor(origScheme.getLightColor(),
144: _rgbToLms, kind, _lmsToRgb);
145: this .mainExtraLightColor = SubstanceColorUtilities
146: .getColorBlindColor(origScheme.getExtraLightColor(),
147: _rgbToLms, kind, _lmsToRgb);
148: this .mainUltraLightColor = SubstanceColorUtilities
149: .getColorBlindColor(origScheme.getUltraLightColor(),
150: _rgbToLms, kind, _lmsToRgb);
151: }
152:
153: /*
154: * (non-Javadoc)
155: *
156: * @see org.jvnet.substance.color.ColorScheme#getForegroundColor()
157: */
158: public Color getForegroundColor() {
159: return this .foregroundColor;
160: }
161:
162: /*
163: * (non-Javadoc)
164: *
165: * @see org.jvnet.substance.color.ColorScheme#getUltraLightColor()
166: */
167: public Color getUltraLightColor() {
168: return this .mainUltraLightColor;
169: }
170:
171: /*
172: * (non-Javadoc)
173: *
174: * @see org.jvnet.substance.color.ColorScheme#getExtraLightColor()
175: */
176: public Color getExtraLightColor() {
177: return this .mainExtraLightColor;
178: }
179:
180: /*
181: * (non-Javadoc)
182: *
183: * @see org.jvnet.substance.color.ColorScheme#getLightColor()
184: */
185: public Color getLightColor() {
186: return this .mainLightColor;
187: }
188:
189: /*
190: * (non-Javadoc)
191: *
192: * @see org.jvnet.substance.color.ColorScheme#getMidColor()
193: */
194: public Color getMidColor() {
195: return this .mainMidColor;
196: }
197:
198: /*
199: * (non-Javadoc)
200: *
201: * @see org.jvnet.substance.color.ColorScheme#getDarkColor()
202: */
203: public Color getDarkColor() {
204: return this .mainDarkColor;
205: }
206:
207: /*
208: * (non-Javadoc)
209: *
210: * @see org.jvnet.substance.color.ColorScheme#getUltraDarkColor()
211: */
212: public Color getUltraDarkColor() {
213: return this .mainUltraDarkColor;
214: }
215:
216: /**
217: * Returns the original color scheme.
218: *
219: * @return The original color scheme.
220: */
221: public ColorScheme getOrigScheme() {
222: return this.origScheme;
223: }
224: }
|