Source Code Cross Referenced for LightColorFactory.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) 2007 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.IConfigurationElement;
015:        import org.eclipse.core.runtime.IExecutableExtension;
016:        import org.eclipse.swt.graphics.RGB;
017:        import org.eclipse.swt.widgets.Display;
018:        import org.eclipse.ui.themes.ColorUtil;
019:        import org.eclipse.ui.themes.IColorFactory;
020:
021:        /**
022:         * LightColorFactory returns tab begin and end colours based on taking
023:         * a system color as input, analyzing it, and lightening it appropriately.
024:         * 
025:         * @since 3.3
026:         * 
027:         */
028:        public class LightColorFactory implements  IColorFactory,
029:                IExecutableExtension {
030:
031:            protected static final RGB white = ColorUtil
032:                    .getColorValue("COLOR_WHITE"); //$NON-NLS-1$
033:            protected static final RGB black = ColorUtil
034:                    .getColorValue("COLOR_BLACK"); //$NON-NLS-1$
035:
036:            String baseColorName;
037:            String definitionId;
038:
039:            /**
040:             * Return the highlight start (top of tab) color as an RGB
041:             * @return the highlight start RGB
042:             */
043:
044:            public static RGB createHighlightStartColor(RGB tabStartColor) {
045:                return ColorUtil.blend(white, tabStartColor);
046:            }
047:
048:            /**
049:             * This executable extension requires parameters to be explicitly declared
050:             * via the second method described in the <code>IExecutableExtension</code>
051:             * documentation. The following parameters are parsed:
052:             * <code>base</code>, describes the base color to produce all other colours from.
053:             * This value may either be an RGB triple or an SWT constant.
054:             * <code>definitionId</code>, describes the id of color we are looking for, one of
055:             * "org.eclipse.ui.workbench.ACTIVE_TAB_BG_START"
056:             * "org.eclipse.ui.workbench.ACTIVE_TAB_BG_END"
057:             * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement,
058:             *      java.lang.String, java.lang.Object)
059:             */
060:            public void setInitializationData(IConfigurationElement config,
061:                    String propertyName, Object data) {
062:
063:                if (data instanceof  Hashtable) {
064:                    Hashtable table = (Hashtable) data;
065:                    baseColorName = (String) table.get("base"); //$NON-NLS-1$
066:                    definitionId = (String) table.get("definitionId"); //$NON-NLS-1$
067:                }
068:            }
069:
070:            /* 
071:             * Return the number of RGB values in test that are
072:             * equal to or between lower and upper.
073:             */
074:            protected int valuesInRange(RGB test, int lower, int upper) {
075:                int hits = 0;
076:                if (test.red >= lower && test.red <= upper)
077:                    hits++;
078:                if (test.blue >= lower && test.blue <= upper)
079:                    hits++;
080:                if (test.green >= lower && test.green <= upper)
081:                    hits++;
082:
083:                return hits;
084:            }
085:
086:            /*
087:             * Return the RGB value for the bottom tab color
088:             * based on a blend of white and sample color
089:             */
090:            private RGB getLightenedColor(RGB sample) {
091:                //Group 1
092:                if (valuesInRange(sample, 180, 255) >= 2)
093:                    return sample;
094:
095:                //Group 2
096:                if (valuesInRange(sample, 100, 179) >= 2)
097:                    return ColorUtil.blend(white, sample, 40);
098:
099:                //Group 3
100:                if (valuesInRange(sample, 0, 99) >= 2)
101:                    return ColorUtil.blend(white, sample, 60);
102:
103:                //Group 4
104:                return ColorUtil.blend(white, sample, 30);
105:            }
106:
107:            /*
108:             * Return the Start (top of tab) color as an RGB
109:             */
110:            private RGB getActiveFocusStartColor() {
111:                if (Display.getCurrent().getDepth() < 15)
112:                    return getActiveFocusEndColor();
113:
114:                RGB startColor = ColorUtil.blend(white,
115:                        getActiveFocusEndColor(), 75);
116:                return startColor;
117:            }
118:
119:            /*
120:             * Return the End (top of tab) color as an RGB
121:             */
122:            private RGB getActiveFocusEndColor() {
123:                if (Display.getCurrent().getDepth() < 15)
124:                    return ColorUtil.getColorValue(baseColorName);
125:
126:                return getLightenedColor(ColorUtil.getColorValue(baseColorName));
127:            }
128:
129:            /*
130:             * Return the active focus tab text color as an RGB
131:             */
132:            private RGB getActiveFocusTextColor() {
133:                if (Display.getCurrent().getDepth() < 15)
134:                    return ColorUtil.getColorValue(baseColorName); //typically TITLE_FOREGROUND
135:
136:                return ColorUtil.getColorValue("COLOR_BLACK"); //$NON-NLS-1$
137:            }
138:
139:            /*
140:             * Return the RGB value for the top tab color.
141:             */
142:            private RGB getActiveNofocusStartColor() {
143:                RGB base = ColorUtil.getColorValue(baseColorName);
144:                if (Display.getCurrent().getDepth() < 15)
145:                    return base;
146:
147:                return ColorUtil.blend(white, base, 40);
148:            }
149:
150:            /*
151:             * (non-Javadoc)
152:             * 
153:             * @see org.eclipse.ui.themes.IColorFactory#createColor()
154:             */
155:            public RGB createColor() {
156:                //should have base, otherwise error in the xml
157:                if (baseColorName == null || definitionId == null)
158:                    return white;
159:
160:                if (definitionId
161:                        .equals("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START")) //$NON-NLS-1$
162:                    return getActiveFocusStartColor();
163:                if (definitionId
164:                        .equals("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END")) //$NON-NLS-1$
165:                    return getActiveFocusEndColor();
166:                if (definitionId
167:                        .equals("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR")) //$NON-NLS-1$
168:                    return getActiveFocusTextColor();
169:                if (definitionId
170:                        .equals("org.eclipse.ui.workbench.ACTIVE_NOFOCUS_TAB_BG_START")) //$NON-NLS-1$
171:                    return getActiveNofocusStartColor();
172:
173:                //should be one of start or end, otherwise error in the xml
174:                return white;
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.