Source Code Cross Referenced for SharedStyleManager.java in  » IDE-Eclipse » ui » org » eclipse » ui » internal » intro » impl » swt » 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 » org.eclipse.ui.internal.intro.impl.swt 
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.intro.impl.swt;
011:
012:        import java.io.InputStream;
013:        import java.net.URL;
014:        import java.util.Properties;
015:
016:        import org.eclipse.core.runtime.IPath;
017:        import org.eclipse.core.runtime.Path;
018:        import org.eclipse.swt.graphics.Color;
019:        import org.eclipse.swt.graphics.Image;
020:        import org.eclipse.swt.graphics.RGB;
021:        import org.eclipse.ui.forms.FormColors;
022:        import org.eclipse.ui.forms.widgets.FormToolkit;
023:        import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot;
024:        import org.eclipse.ui.internal.intro.impl.util.ImageUtil;
025:        import org.eclipse.ui.internal.intro.impl.util.Log;
026:        import org.osgi.framework.Bundle;
027:
028:        public class SharedStyleManager {
029:
030:            protected Properties properties;
031:            protected StyleContext context;
032:
033:            class StyleContext {
034:                IPath path;
035:                Bundle bundle;
036:                boolean inTheme;
037:            }
038:
039:            SharedStyleManager() {
040:                // no-op
041:            }
042:
043:            /**
044:             * Constructor used when shared styles need to be loaded. The bundle is
045:             * retrieved from the model root.
046:             * 
047:             * @param modelRoot
048:             */
049:            public SharedStyleManager(IntroModelRoot modelRoot) {
050:                context = new StyleContext();
051:                context.bundle = modelRoot.getBundle();
052:                properties = new Properties();
053:                String[] sharedStyles = modelRoot.getPresentation()
054:                        .getImplementationStyles();
055:                if (sharedStyles != null) {
056:                    for (int i = 0; i < sharedStyles.length; i++)
057:                        load(properties, sharedStyles[i], context);
058:                }
059:            }
060:
061:            protected void load(Properties properties, String style,
062:                    StyleContext context) {
063:                if (style == null)
064:                    return;
065:                try {
066:                    URL styleURL = new URL(style);
067:                    InputStream is = styleURL.openStream();
068:                    properties.load(is);
069:                    is.close();
070:                    context.path = new Path(style).removeLastSegments(1);
071:                    String t = (String) properties.get("theme"); //$NON-NLS-1$
072:                    if (t != null && t.trim().equalsIgnoreCase("true")) //$NON-NLS-1$
073:                        context.inTheme = true;
074:                } catch (Exception e) {
075:                    Log.error("Could not load SWT style: " + style, e); //$NON-NLS-1$
076:                }
077:            }
078:
079:            /**
080:             * Get the property from the shared properties.
081:             * 
082:             * @param key
083:             * @return
084:             */
085:            public String getProperty(String key) {
086:                return doGetProperty(properties, key);
087:            }
088:
089:            /*
090:             * Utility method to trim properties retrieval.
091:             */
092:            protected String doGetProperty(Properties aProperties, String key) {
093:                String value = aProperties.getProperty(key);
094:                if (value != null)
095:                    // trim the properties as trailing balnnks cause problems.
096:                    value = value.trim();
097:                return value;
098:            }
099:
100:            protected RGB getRGB(String key) {
101:                String value = getProperty(key);
102:                if (value == null)
103:                    return null;
104:                return parseRGB(value);
105:            }
106:
107:            /**
108:             * A utility method that creates RGB object from a value encoded in the
109:             * following format: #rrggbb, where r, g and b are hex color values in the
110:             * range from 00 to ff.
111:             * 
112:             * @param value
113:             * @return
114:             */
115:
116:            public static RGB parseRGB(String value) {
117:                if (value.charAt(0) == '#') {
118:                    // HEX
119:                    try {
120:                        int r = Integer.parseInt(value.substring(1, 3), 16);
121:                        int g = Integer.parseInt(value.substring(3, 5), 16);
122:                        int b = Integer.parseInt(value.substring(5, 7), 16);
123:                        return new RGB(r, g, b);
124:                    } catch (NumberFormatException e) {
125:                        Log
126:                                .error(
127:                                        "Failed to parser: " + value + " as an integer", e); //$NON-NLS-1$ //$NON-NLS-2$
128:                    }
129:                }
130:                return null;
131:            }
132:
133:            /**
134:             * Finds the bundle from which this key was loaded. This is the bundle from
135:             * which shared styles where loaded.
136:             * 
137:             * @param key
138:             * @return
139:             */
140:            protected Bundle getAssociatedBundle(String key) {
141:                return context.bundle;
142:            }
143:
144:            protected StyleContext getAssociatedContext(String key) {
145:                return context;
146:            }
147:
148:            /**
149:             * @return Returns the properties.
150:             */
151:            public Properties getProperties() {
152:                return properties;
153:            }
154:
155:            /**
156:             * 
157:             * 
158:             * @param toolkit
159:             * @param key
160:             * @return color. May return null.
161:             */
162:            public Color getColor(FormToolkit toolkit, String key) {
163:                FormColors colors = toolkit.getColors();
164:                Color color = colors.getColor(key);
165:                if (color == null) {
166:                    RGB rgb = getRGB(key);
167:                    if (rgb != null)
168:                        color = colors.createColor(key, rgb);
169:                }
170:                return color;
171:            }
172:
173:            /**
174:             * Retrieve an image from this page's properties, given a key.
175:             * 
176:             * @param key
177:             * @param defaultPageKey
178:             * @param defaultKey
179:             * @return
180:             */
181:            public Image getImage(String key, String defaultPageKey,
182:                    String defaultKey) {
183:                String currentKey = key;
184:                String value = getProperty(currentKey);
185:                if (value == null && defaultPageKey != null) {
186:                    currentKey = defaultPageKey;
187:                    value = getProperty(defaultPageKey);
188:                }
189:                if (value != null) {
190:                    if (ImageUtil.hasImage(currentKey))
191:                        return ImageUtil.getImage(currentKey);
192:                    // try to register the image.
193:                    StyleContext ccontext = getAssociatedContext(currentKey);
194:                    if (ccontext.inTheme) {
195:                        // if 'theme' key is set, load image
196:                        // relative to the file, not relative to the bundle
197:                        ImageUtil.registerImage(currentKey, ccontext.path,
198:                                value);
199:                    } else {
200:                        Bundle bundle = ccontext.bundle;
201:                        if (bundle == null)
202:                            // it means that we are getting a key defined in this page's
203:                            // styles. (ie: not an inherited style).
204:                            bundle = this .context.bundle;
205:                        ImageUtil.registerImage(currentKey, bundle, value);
206:                    }
207:                    Image image = ImageUtil.getImage(currentKey);
208:                    if (image != null)
209:                        return image;
210:                }
211:                // try default. We know default is already registered,
212:                if (defaultKey != null)
213:                    return ImageUtil.getImage(defaultKey);
214:                return null;
215:            }
216:
217:            public boolean useCustomHomePagelayout() {
218:                String key = "home-page-custom-layout"; //$NON-NLS-1$
219:                String value = getProperty(key);
220:                if (value == null)
221:                    value = "true"; //$NON-NLS-1$
222:                return value.equalsIgnoreCase("true"); //$NON-NLS-1$
223:            }
224:
225:        }
w___w__w__.j___a___v_a___2__s._c__om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.