Source Code Cross Referenced for RGBContrastFactory.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » themes » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » ui workbench » org.eclipse.ui.internal.themes 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2004, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.internal.themes;
011:
012:        import java.util.Hashtable;
013:
014:        import org.eclipse.core.runtime.CoreException;
015:        import org.eclipse.core.runtime.IConfigurationElement;
016:        import org.eclipse.core.runtime.IExecutableExtension;
017:        import org.eclipse.swt.graphics.RGB;
018:        import org.eclipse.ui.themes.ColorUtil;
019:        import org.eclipse.ui.themes.IColorFactory;
020:
021:        /**
022:         * A <code>IColorFactory</code> that may be used to select a colour with
023:         * a higher contrast.  The colors to blend are specified as per method
024:         * number two in  {@link org.eclipse.core.runtime.IExecutableExtension}.
025:         * <p>
026:         * Example usage:
027:         * <br/>
028:         * <code>
029:         * &lt;colorDefinition
030:         *     label="Red/Blue Contrast"
031:         *     id="example.redblueblend"&gt;
032:         *     &lt;colorFactory 
033:         * 				plugin="org.eclipse.ui" 
034:         * 				class="org.eclipse.ui.internal.themes.RGBContrastFactory"&gt;
035:         *      	&lt;parameter name="foreground" value="0,0,0" /&gt;
036:         *  		&lt;parameter name="background1" value="COLOR_RED" /&gt;
037:         *          &lt;parameter name="background2" value="COLOR_BLUE" /&gt;
038:         *     &lt;/colorFactory&gt;
039:         * &lt;/colorDefinition&gt;
040:         * </code>
041:         * </p>
042:         * 
043:         * <p>
044:         * This will select whichever of Red or Blue has a higher contrst with black.
045:         * The color values may be specified as RGB triples or as SWT constants.
046:         * </p>
047:         * 
048:         * @see org.eclipse.swt.SWT
049:         * @since 3.0
050:         */
051:        public class RGBContrastFactory implements  IColorFactory,
052:                IExecutableExtension {
053:            private String fg, bg1, bg2;
054:
055:            /**
056:             * Returns the intensity of an RGB component using the
057:             * sRGB gamma function.
058:             * 
059:             * @param val Value to convert.
060:             * @return Light intensity of the component.
061:             */
062:            double voltage_to_intensity_srgb(double val) {
063:                /* Handle invalid values before doing a gamma transform. */
064:                if (val < 0.0) {
065:                    return 0.0;
066:                }
067:                if (val > 1.0) {
068:                    return 1.0;
069:                }
070:
071:                if (val <= 0.04045) {
072:                    return val / 12.92;
073:                }
074:                return Math.pow((val + 0.055) / 1.055, 2.4);
075:            }
076:
077:            /**
078:             * Returns a measure of the lightness in the perceptual colourspace
079:             * IPT.
080:             * 
081:             * @param color The colour in sRGB
082:             * @return Lightness in IPT space.
083:             */
084:            double lightness(RGB color) {
085:                double r = voltage_to_intensity_srgb(color.red / 255.0);
086:                double g = voltage_to_intensity_srgb(color.green / 255.0);
087:                double b = voltage_to_intensity_srgb(color.blue / 255.0);
088:                double l = (0.3139 * r) + (0.6395 * g) + (0.0466 * b);
089:                double m = (0.1516 * r) + (0.7482 * g) + (0.1000 * b);
090:                double s = (0.0177 * r) + (0.1095 * g) + (0.8729 * b);
091:                double lp, mp, sp;
092:
093:                if (l < 0.0) {
094:                    lp = -Math.pow(-l, 0.43);
095:                } else {
096:                    lp = Math.pow(l, 0.43);
097:                }
098:                if (m < 0.0) {
099:                    mp = -Math.pow(-m, 0.43);
100:                } else {
101:                    mp = Math.pow(m, 0.43);
102:                }
103:                if (s < 0.0) {
104:                    sp = -Math.pow(-s, 0.43);
105:                } else {
106:                    sp = Math.pow(s, 0.43);
107:                }
108:
109:                return (0.4000 * lp) + (0.4000 * mp) + (0.2000 * sp);
110:            }
111:
112:            public RGB createColor() {
113:                /**
114:                 * Determine which pair has a higher contrast by selecting
115:                 * the colour with the furthest distance in lightness.
116:                 */
117:                RGB cfg, cbg1, cbg2;
118:
119:                if (fg != null) {
120:                    cfg = ColorUtil.getColorValue(fg);
121:                } else {
122:                    cfg = new RGB(255, 255, 255);
123:                }
124:                if (bg1 != null) {
125:                    cbg1 = ColorUtil.getColorValue(bg1);
126:                } else {
127:                    cbg1 = new RGB(0, 0, 0);
128:                }
129:                if (bg2 != null) {
130:                    cbg2 = ColorUtil.getColorValue(bg2);
131:                } else {
132:                    cbg2 = new RGB(0, 0, 0);
133:                }
134:
135:                double lfg = lightness(cfg);
136:                double lbg1 = lightness(cbg1);
137:                double lbg2 = lightness(cbg2);
138:
139:                if (Math.abs(lbg1 - lfg) > Math.abs(lbg2 - lfg)) {
140:                    return cbg1;
141:                } else {
142:                    return cbg2;
143:                }
144:            }
145:
146:            /**
147:             * This executable extension requires parameters to be explicitly declared 
148:             * via the second method described in the <code>IExecutableExtension</code> 
149:             * documentation.  This class expects that there will be three parameters, 
150:             * <code>foreground</code>, <code>background1</code> and
151:             * <code>background2</code>, that describe the two colors to be blended.
152:             * These values may either be RGB triples or SWT constants.
153:             * 
154:             * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, java.lang.String, java.lang.Object)
155:             */
156:            public void setInitializationData(IConfigurationElement config,
157:                    String propertyName, Object data) throws CoreException {
158:                if (data instanceof  Hashtable) {
159:                    Hashtable table = (Hashtable) data;
160:                    fg = (String) table.get("foreground"); //$NON-NLS-1$
161:                    bg1 = (String) table.get("background1"); //$NON-NLS-1$
162:                    bg2 = (String) table.get("background2"); //$NON-NLS-1$
163:                }
164:
165:            }
166:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.