Source Code Cross Referenced for FontLib.java in  » Database-Client » prefuse » prefuse » util » 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 » Database Client » prefuse » prefuse.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package prefuse.util;
002:
003:        import java.awt.Font;
004:
005:        import prefuse.util.collections.IntObjectHashMap;
006:
007:        /**
008:         * Library maintaining a cache of fonts and other useful font computation
009:         * routines.
010:         *
011:         * @author <a href="http://jheer.org">jeffrey heer</a>
012:         */
013:        public class FontLib {
014:
015:            private static final IntObjectHashMap fontMap = new IntObjectHashMap();
016:            private static int misses = 0;
017:            private static int lookups = 0;
018:
019:            /**
020:             * Get a Font instance with the given font family name and size. A
021:             * plain font style is assumed.
022:             * @param name the font name. Any font installed on your system should
023:             * be valid. Common examples include "Arial", "Verdana", "Tahoma",
024:             * "Times New Roman", "Georgia", and "Courier New".
025:             * @param size the size, in points, of the font
026:             * @return the requested Font instance
027:             */
028:            public static Font getFont(String name, double size) {
029:                int isize = (int) Math.floor(size);
030:                return getFont(name, Font.PLAIN, isize);
031:            }
032:
033:            /**
034:             * Get a Font instance with the given font family name, style, and size
035:             * @param name the font name. Any font installed on your system should
036:             * be valid. Common examples include "Arial", "Verdana", "Tahoma",
037:             * "Times New Roman", "Georgia", and "Courier New".
038:             * @param style the font style, such as bold or italics. This field
039:             * uses the same style values as the Java {@link java.awt.Font} class.
040:             * @param size the size, in points, of the font
041:             * @return the requested Font instance
042:             */
043:            public static Font getFont(String name, int style, double size) {
044:                int isize = (int) Math.floor(size);
045:                return getFont(name, style, isize);
046:            }
047:
048:            /**
049:             * Get a Font instance with the given font family name, style, and size
050:             * @param name the font name. Any font installed on your system should
051:             * be valid. Common examples include "Arial", "Verdana", "Tahoma",
052:             * "Times New Roman", "Georgia", and "Courier New".
053:             * @param style the font style, such as bold or italics. This field
054:             * uses the same style values as the Java {@link java.awt.Font} class.
055:             * @param size the size, in points, of the font
056:             * @return the requested Font instance
057:             */
058:            public static Font getFont(String name, int style, int size) {
059:                int key = (name.hashCode() << 8) + (size << 2) + style;
060:                Font f = null;
061:                if ((f = (Font) fontMap.get(key)) == null) {
062:                    f = new Font(name, style, size);
063:                    fontMap.put(key, f);
064:                    misses++;
065:                }
066:                lookups++;
067:                return f;
068:            }
069:
070:            /**
071:             * Get the number of cache misses to the Font object cache.
072:             * @return the number of cache misses
073:             */
074:            public static int getCacheMissCount() {
075:                return misses;
076:            }
077:
078:            /**
079:             * Get the number of cache lookups to the Font object cache.
080:             * @return the number of cache lookups
081:             */
082:            public static int getCacheLookupCount() {
083:                return lookups;
084:            }
085:
086:            /**
087:             * Clear the Font object cache.
088:             */
089:            public static void clearCache() {
090:                fontMap.clear();
091:            }
092:
093:            /**
094:             * Interpolate between two font instances. Font sizes are interpolated
095:             * linearly. If the interpolation fraction is under 0.5, the face and
096:             * style of the starting font are used, otherwise the face and style of
097:             * the second font are applied.
098:             * @param f1 the starting font
099:             * @param f2 the target font
100:             * @param frac a fraction between 0 and 1.0 controlling the interpolation
101:             * amount.
102:             * @return an interpolated Font instance
103:             */
104:            public static Font getIntermediateFont(Font f1, Font f2, double frac) {
105:                String name;
106:                int size, style;
107:                if (frac < 0.5) {
108:                    name = f1.getName();
109:                    style = f1.getStyle();
110:                } else {
111:                    name = f2.getName();
112:                    style = f2.getStyle();
113:                }
114:                size = (int) Math.round(frac * f2.getSize() + (1 - frac)
115:                        * f1.getSize());
116:                return getFont(name, style, size);
117:            }
118:
119:        } // end of class FontLib
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.