Source Code Cross Referenced for FontSets.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) 2001-2006 JGoodies Karsten Lentzsch. 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 JGoodies Karsten Lentzsch 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:
031:        package org.jvnet.substance.fonts;
032:
033:        import java.awt.Font;
034:
035:        import javax.swing.plaf.FontUIResource;
036:
037:        import org.jvnet.substance.fonts.*;
038:
039:        /**
040:         * Provides predefined FontSet implementations.
041:         *
042:         * @author  Karsten Lentzsch
043:         * @version $Revision: 1.1 $
044:         * 
045:         * @see     FontSet
046:         * @see     FontPolicy
047:         * @see     FontPolicies
048:         * 
049:         * @since 2.0
050:         */
051:        public final class FontSets {
052:
053:            private static FontSet logicalFontSet;
054:
055:            private FontSets() {
056:                // Override default constructor; prevents instantation.
057:            }
058:
059:            // Default FontSets *******************************************************
060:
061:            /**
062:             * Creates and returns a FontSet that is based only 
063:             * on the given control font. The small font will be
064:             * derived from the control font; all other fonts 
065:             * returned are the control font.
066:             * 
067:             * @param controlFont   the font used for all controls
068:             * 
069:             * @return a FontSet based on the given fonts
070:             * 
071:             * @throws NullPointerException  if the control font is <code>null</code>
072:             */
073:            public static FontSet createDefaultFontSet(Font controlFont) {
074:                return createDefaultFontSet(controlFont, null);
075:            }
076:
077:            /**
078:             * Creates and returns a FontSet that is based on the given control font
079:             * and menu font. The small font will be derived from the control font; 
080:             * all other fonts return, except the menu font, are the control font.
081:             * 
082:             * @param controlFont   the font used for all controls
083:             * @param menuFont      the font used for the menu bar and menu items
084:             * 
085:             * @return a FontSet based on the given fonts
086:             * 
087:             * @throws NullPointerException  if the control font is <code>null</code>
088:             */
089:            public static FontSet createDefaultFontSet(Font controlFont,
090:                    Font menuFont) {
091:                return createDefaultFontSet(controlFont, menuFont, null, null,
092:                        null, null);
093:            }
094:
095:            /**
096:             * Creates and returns a FontSet that is based on the given control font
097:             * and menu font. The small font will be derived from the control font; 
098:             * all other fonts return, except the menu font, are the control font.
099:             * 
100:             * @param controlFont   the font used for all controls
101:             * @param menuFont      the font used for the menu bar and menu items
102:             * @param titleFont     used for TitledBorder, titles and titled separators
103:             * 
104:             * @return a FontSet based on the given fonts
105:             * 
106:             * @throws NullPointerException  if the control font is <code>null</code>
107:             */
108:            public static FontSet createDefaultFontSet(Font controlFont,
109:                    Font menuFont, Font titleFont) {
110:                return createDefaultFontSet(controlFont, menuFont, titleFont,
111:                        null, null, null);
112:            }
113:
114:            /**
115:             * Creates and returns a FontSet for the given fonts.
116:             * If a font is <code>null</code>, it uses the control font as
117:             * fallback. If the small font is <code>null</code> it will 
118:             * be derived from the control font.
119:             * 
120:             * @param controlFont      used for all controls
121:             * @param menuFont         used for the menu bar and menu items
122:             * @param titleFont        used for TitledBorder, titles and titled separators
123:             * @param messageFont      used for OptionPanes
124:             * @param smallFont        used for tool tips and similar components 
125:             * @param windowTitleFont  used for internal frame window titles
126:             * 
127:             * @return a FontSet based on the given fonts
128:             * 
129:             * @throws NullPointerException  if the control font is <code>null</code>
130:             */
131:            public static FontSet createDefaultFontSet(Font controlFont,
132:                    Font menuFont, Font titleFont, Font messageFont,
133:                    Font smallFont, Font windowTitleFont) {
134:                return new DefaultFontSet(controlFont, menuFont, titleFont,
135:                        messageFont, smallFont, windowTitleFont);
136:            }
137:
138:            // Logical FontSet ********************************************************
139:
140:            /**
141:             * Lazily creates and returns the FontSet that returns 
142:             * the logical fonts specified by the Java runtime environment.
143:             * 
144:             * @return a FontSets that uses the logical fonts specified
145:             *     by the Java environment
146:             */
147:            public static FontSet getLogicalFontSet() {
148:                if (logicalFontSet == null) {
149:                    logicalFontSet = new LogicalFontSet();
150:                }
151:                return logicalFontSet;
152:            }
153:
154:            // Helper Code ************************************************************
155:
156:            private static final class DefaultFontSet implements  FontSet {
157:
158:                private final FontUIResource controlFont;
159:                private final FontUIResource menuFont;
160:                private final FontUIResource titleFont;
161:                private final FontUIResource messageFont;
162:                private final FontUIResource smallFont;
163:                private final FontUIResource windowTitleFont;
164:
165:                // Instance Creation --------------------------------------------------
166:
167:                /**
168:                 * Constructs a DefaultFontSet for the given fonts.
169:                 * If a font is <code>null</code>, it uses the control font as
170:                 * fallback. If the small font is <code>null</code> it will 
171:                 * be derived from the control font.
172:                 * 
173:                 * @param controlFont      used for all controls
174:                 * @param menuFont         used for the menu bar and menu items
175:                 * @param titleFont        used for TitledBorder, titles and titled separators
176:                 * @param messageFont      used for OptionPanes
177:                 * @param smallFont        used for tool tips and similar components 
178:                 * @param windowTitleFont  used for internal frame window titles
179:                 * 
180:                 * @throws NullPointerException  if the control font is <code>null</code>
181:                 */
182:                public DefaultFontSet(Font controlFont, Font menuFont,
183:                        Font titleFont, Font messageFont, Font smallFont,
184:                        Font windowTitleFont) {
185:                    this .controlFont = new FontUIResource(controlFont);
186:                    this .menuFont = menuFont != null ? new FontUIResource(
187:                            menuFont) : this .controlFont;
188:                    this .titleFont = titleFont != null ? new FontUIResource(
189:                            titleFont) : this .controlFont; //new FontUIResource(controlFont.deriveFont(Font.BOLD))
190:                    this .messageFont = messageFont != null ? new FontUIResource(
191:                            messageFont)
192:                            : this .controlFont;
193:                    this .smallFont = new FontUIResource(
194:                            smallFont != null ? smallFont : controlFont
195:                                    .deriveFont(controlFont.getSize2D() - 2f));
196:                    this .windowTitleFont = windowTitleFont != null ? new FontUIResource(
197:                            windowTitleFont)
198:                            : this .titleFont;
199:                }
200:
201:                // FontSet API --------------------------------------------------------
202:
203:                public FontUIResource getControlFont() {
204:                    return controlFont;
205:                }
206:
207:                public FontUIResource getMenuFont() {
208:                    return menuFont;
209:                }
210:
211:                public FontUIResource getTitleFont() {
212:                    return titleFont;
213:                }
214:
215:                public FontUIResource getWindowTitleFont() {
216:                    return windowTitleFont;
217:                }
218:
219:                public FontUIResource getSmallFont() {
220:                    return smallFont;
221:                }
222:
223:                public FontUIResource getMessageFont() {
224:                    return messageFont;
225:                }
226:
227:            }
228:
229:            /**
230:             * Looks up and returns the logical fonts as specified
231:             * by the Java runtime environment.
232:             */
233:            private static final class LogicalFontSet implements  FontSet {
234:
235:                private FontUIResource controlFont;
236:                private FontUIResource titleFont;
237:                private FontUIResource systemFont;
238:                private FontUIResource smallFont;
239:
240:                public FontUIResource getControlFont() {
241:                    if (controlFont == null) {
242:                        controlFont = new FontUIResource(Font.getFont(
243:                                "swing.plaf.metal.controlFont", new Font(
244:                                        "Dialog", Font.PLAIN, 12)));
245:
246:                    }
247:                    return controlFont;
248:                }
249:
250:                public FontUIResource getMenuFont() {
251:                    return getControlFont();
252:                }
253:
254:                public FontUIResource getTitleFont() {
255:                    if (titleFont == null) {
256:                        titleFont = new FontUIResource(getControlFont()
257:                                .deriveFont(Font.BOLD));
258:                    }
259:                    return titleFont;
260:                }
261:
262:                public FontUIResource getSmallFont() {
263:                    if (smallFont == null) {
264:                        smallFont = new FontUIResource(Font.getFont(
265:                                "swing.plaf.metal.smallFont", new Font(
266:                                        "Dialog", Font.PLAIN, 10)));
267:                    }
268:                    return smallFont;
269:                }
270:
271:                public FontUIResource getMessageFont() {
272:                    if (systemFont == null) {
273:                        systemFont = new FontUIResource(Font.getFont(
274:                                "swing.plaf.metal.systemFont", new Font(
275:                                        "Dialog", Font.PLAIN, 12)));
276:                    }
277:                    return systemFont;
278:                }
279:
280:                public FontUIResource getWindowTitleFont() {
281:                    return getTitleFont();
282:                }
283:
284:            }
285:
286:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.