Source Code Cross Referenced for SubstanceFontUtilities.java in  » Swing-Library » substance-look-feel » org » jvnet » substance » fonts » 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 » Swing Library » substance look feel » org.jvnet.substance.fonts 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.fonts;
031:
032:        import java.awt.Font;
033:        import java.security.AccessController;
034:        import java.security.PrivilegedAction;
035:
036:        import javax.swing.UIDefaults;
037:        import javax.swing.plaf.FontUIResource;
038:
039:        import org.jvnet.lafwidget.utils.LookUtils;
040:        import org.jvnet.substance.utils.SubstanceSizeUtils;
041:
042:        /**
043:         * Font-related utilities.
044:         * 
045:         * @author Kirill Grouchnikov
046:         */
047:        public class SubstanceFontUtilities {
048:            /**
049:             * Font set implementation for Substance. This is used to make the window
050:             * title font bold.
051:             * 
052:             * @author Kirill Grouchnikov
053:             */
054:            private static class SubstanceFontSet implements  FontSet {
055:                /**
056:                 * The default system font set.
057:                 */
058:                private FontSet systemFontSet;
059:
060:                /**
061:                 * Creates a new font set for Substance.
062:                 * 
063:                 * @param systemFontSet
064:                 *            The default system font set.
065:                 */
066:                public SubstanceFontSet(FontSet systemFontSet) {
067:                    this .systemFontSet = systemFontSet;
068:                }
069:
070:                /**
071:                 * Returns Substance-specific font resource.
072:                 * 
073:                 * @param systemFont
074:                 *            The default system font.
075:                 * @return Substance-specific font resource.
076:                 */
077:                private FontUIResource getSubstanceFont(
078:                        FontUIResource systemFont) {
079:                    return this .getSubstanceFont(systemFont, false, 0);
080:                }
081:
082:                /**
083:                 * Returns Substance-specific font resource.
084:                 * 
085:                 * @param systemFont
086:                 *            The default system font.
087:                 * @param toBoldify
088:                 *            If <code>true</code>, the original font (the first
089:                 *            parameter) is boldified.
090:                 * @param extraFontSize
091:                 *            Extra font size in pixels.
092:                 * @return Substance-specific font resource.
093:                 */
094:                private FontUIResource getSubstanceFont(
095:                        FontUIResource systemFont, boolean toBoldify,
096:                        int extraFontSize) {
097:                    boolean isOrigItalic = systemFont.isItalic();
098:                    int newStyle = systemFont.getStyle();
099:                    if (toBoldify) {
100:                        if (isOrigItalic)
101:                            newStyle = Font.ITALIC + Font.BOLD;
102:                        else
103:                            newStyle = Font.BOLD;
104:                    }
105:                    return new FontUIResource(systemFont.getFontName(),
106:                            newStyle, systemFont.getSize() + extraFontSize);
107:                }
108:
109:                /*
110:                 * (non-Javadoc)
111:                 * 
112:                 * @see contrib.com.jgoodies.looks.common.FontSet#getControlFont()
113:                 */
114:                public FontUIResource getControlFont() {
115:                    return this .getSubstanceFont(this .systemFontSet
116:                            .getControlFont());
117:                }
118:
119:                /*
120:                 * (non-Javadoc)
121:                 * 
122:                 * @see contrib.com.jgoodies.looks.common.FontSet#getMenuFont()
123:                 */
124:                public FontUIResource getMenuFont() {
125:                    return this .getSubstanceFont(this .systemFontSet
126:                            .getMenuFont());
127:                }
128:
129:                /*
130:                 * (non-Javadoc)
131:                 * 
132:                 * @see contrib.com.jgoodies.looks.common.FontSet#getMessageFont()
133:                 */
134:                public FontUIResource getMessageFont() {
135:                    return this .getSubstanceFont(this .systemFontSet
136:                            .getMessageFont());
137:                }
138:
139:                /*
140:                 * (non-Javadoc)
141:                 * 
142:                 * @see contrib.com.jgoodies.looks.common.FontSet#getSmallFont()
143:                 */
144:                public FontUIResource getSmallFont() {
145:                    return this .getSubstanceFont(this .systemFontSet
146:                            .getSmallFont(), false, 1);
147:                }
148:
149:                /*
150:                 * (non-Javadoc)
151:                 * 
152:                 * @see contrib.com.jgoodies.looks.common.FontSet#getTitleFont()
153:                 */
154:                public FontUIResource getTitleFont() {
155:                    return this .getSubstanceFont(this .systemFontSet
156:                            .getTitleFont());
157:                }
158:
159:                /*
160:                 * (non-Javadoc)
161:                 * 
162:                 * @see contrib.com.jgoodies.looks.common.FontSet#getWindowTitleFont()
163:                 */
164:                public FontUIResource getWindowTitleFont() {
165:                    return this .getSubstanceFont(this .systemFontSet
166:                            .getWindowTitleFont(), true, 1);
167:                }
168:            }
169:
170:            /**
171:             * Returns the default platform-specific font policy.
172:             * 
173:             * @return Default platform-specific font policy.
174:             */
175:            public static FontPolicy getDefaultFontPolicy() {
176:                // boolean toWrapPolicy = !LookUtils.IS_OS_MAC;
177:                FontPolicy defaultPolicy = FontPolicies
178:                        .getDefaultPlasticPolicy();
179:                boolean isKDE = false;
180:                try {
181:                    isKDE = DefaultKDEFontPolicy.isKDERunning();
182:                } catch (Throwable t) {
183:                    // security access - too bad for KDE desktops.
184:                }
185:                if (LookUtils.IS_OS_WINDOWS) {
186:                    defaultPolicy = FontPolicies.getDefaultWindowsPolicy();
187:                } else {
188:                    if (LookUtils.IS_OS_MAC) {
189:                        defaultPolicy = new DefaultMacFontPolicy();
190:                    } else {
191:                        if (isKDE) {
192:                            // new in version 4.2
193:                            defaultPolicy = new DefaultKDEFontPolicy();
194:                        } else {
195:                            try {
196:                                String desktop = AccessController
197:                                        .doPrivileged(new PrivilegedAction<String>() {
198:                                            public String run() {
199:                                                return System
200:                                                        .getProperty("sun.desktop");
201:                                            }
202:                                        });
203:                                if ("gnome".equals(desktop)) {
204:                                    // new in version 4.1
205:                                    defaultPolicy = new DefaultGnomeFontPolicy();
206:                                }
207:                            } catch (Throwable t) {
208:                                // security access - too bad for Gnome desktops.
209:                            }
210:                        }
211:                    }
212:                }
213:
214:                // System.out.println("System " + System.getProperty("os.name")
215:                // + ", policy " + defaultPolicy.getClass().getName());
216:                //
217:                SubstanceSizeUtils.resetPointsToPixelsRatio(defaultPolicy);
218:                final FontPolicy fontPolicy = FontPolicies
219:                        .customSettingsPolicy(defaultPolicy);
220:                if (LookUtils.IS_OS_MAC || isKDE)
221:                    return fontPolicy;
222:                return new FontPolicy() {
223:                    public FontSet getFontSet(String lafName, UIDefaults table) {
224:                        FontSet baseResult = fontPolicy.getFontSet(lafName,
225:                                table);
226:                        FontSet substanceFontSet = new SubstanceFontSet(
227:                                baseResult);
228:                        return substanceFontSet;
229:                    }
230:                };
231:            }
232:
233:            /**
234:             * Returns scaled platform-specific font policy.
235:             * 
236:             * @param scaleFactor
237:             *            Scale factor. Should be positive.
238:             * @return Scaled platform-specific font policy.
239:             */
240:            public static FontPolicy getScaledFontPolicy(final float scaleFactor) {
241:                final FontSet substanceCoreFontSet = SubstanceFontUtilities
242:                        .getDefaultFontPolicy().getFontSet("Substance", null);
243:                // Create the scaled font set
244:                FontPolicy newFontPolicy = new FontPolicy() {
245:                    public FontSet getFontSet(String lafName, UIDefaults table) {
246:                        return new ScaledFontSet(substanceCoreFontSet,
247:                                scaleFactor);
248:                    }
249:                };
250:                return newFontPolicy;
251:            }
252:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.