Source Code Cross Referenced for FontNodeContract.java in  » Scripting » oscript-2.10.4 » ti » chimera » pref » 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 » Scripting » oscript 2.10.4 » ti.chimera.pref 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*=============================================================================
002:         *     Copyright Texas Instruments 2002. All Rights Reserved.
003:         * 
004:         *  This program is free software; you can redistribute it and/or modify
005:         *  it under the terms of the GNU General Public License as published by
006:         *  the Free Software Foundation; either version 2 of the License, or
007:         *  (at your option) any later version.
008:         * 
009:         *  This program is distributed in the hope that it will be useful,
010:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         *  GNU General Public License for more details.
013:         * 
014:         *  You should have received a copy of the GNU General Public License
015:         *  along with this program; if not, write to the Free Software
016:         *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:
019:        package ti.chimera.pref;
020:
021:        import java.awt.*;
022:
023:        /**
024:         * A {@link NodeContract} which constrains the value to be a font matching the
025:         * specified style.  Note that some of the styles are mutually exclusive, so
026:         * if you specify, for example a style <code>BOLD | NOT_BOLD</code>, then no
027:         * possible font will match.
028:         * 
029:         * @author ;Rob Clark;a0873619;San Diego;;
030:         * @version 0.1
031:         */
032:        public class FontNodeContract extends
033:                ti.chimera.registry.TypeNodeContract {
034:            /**
035:             * The bit mask of parameters to futher limit the font choice.
036:             */
037:            private int style;
038:
039:            /**
040:             * A style flag indicating that only monospace fonts are acceptible.
041:             */
042:            public static final int MONOSPACE = 0x00000001;
043:
044:            /**
045:             * A style flag indicating that only non-monospace fonts are acceptible.
046:             */
047:            public static final int NOT_MONOSPACE = 0x00000002;
048:
049:            /**
050:             * A style flag indicating that only bold fonts are acceptible.
051:             */
052:            public static final int BOLD = 0x00000004;
053:
054:            /**
055:             * A style flag indicating that only non-bold fonts are acceptible.
056:             */
057:            public static final int NOT_BOLD = 0x00000008;
058:
059:            /**
060:             * A style flag indicating that only italic fonts are acceptible.
061:             */
062:            public static final int ITALIC = 0x00000010;
063:
064:            /**
065:             * A style flag indicating that only non-italic fonts are acceptible.
066:             */
067:            public static final int NOT_ITALIC = 0x00000020;
068:
069:            // XXX part of a hack to get at a FontMetrics for a given Font
070:            private static Component c;
071:
072:            /**
073:             * Class Constructor.
074:             */
075:            public FontNodeContract() {
076:                this (0);
077:            }
078:
079:            /**
080:             * Class Constructor.
081:             * 
082:             * @param style        a bitmask of constraints on the acceptible font
083:             */
084:            public FontNodeContract(int style) {
085:                super (Font.class);
086:                this .style = style;
087:            }
088:
089:            private final static String ALPHANUMERIC = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
090:
091:            /**
092:             * Determine if the specified <code>value</code> meets this contract.
093:             * 
094:             * @param value        the value to check
095:             * @return <code>true</code> if meets contract
096:             */
097:            public boolean accepts(Object value) {
098:                if (!super .accepts(value))
099:                    return false;
100:
101:                Font font = (Font) value;
102:
103:                // check that the font can display regular alphanumeric characters:
104:                int idx = font.canDisplayUpTo(ALPHANUMERIC);
105:                if ((idx != -1) && (idx < ALPHANUMERIC.length()))
106:                    return false;
107:
108:                if (((style & MONOSPACE) != 0)
109:                        || ((style & NOT_MONOSPACE) != 0)) {
110:                    // XXX is there a cleaner way to get a FontMetrics for this font??
111:                    if (c == null)
112:                        c = new javax.swing.JPanel();
113:
114:                    FontMetrics fm = c.getFontMetrics(font);
115:
116:                    boolean isMonospace = fm.charWidth('l') == fm
117:                            .charWidth('m');
118:
119:                    if (((style & MONOSPACE) != 0) && !isMonospace)
120:                        return false;
121:
122:                    if (((style & NOT_MONOSPACE) != 0) && isMonospace)
123:                        return false;
124:                }
125:
126:                if (((style & BOLD) != 0) && !font.isBold())
127:                    return false;
128:
129:                if (((style & NOT_BOLD) != 0) && font.isBold())
130:                    return false;
131:
132:                if (((style & ITALIC) != 0) && !font.isItalic())
133:                    return false;
134:
135:                if (((style & NOT_ITALIC) != 0) && font.isItalic())
136:                    return false;
137:
138:                return true;
139:            }
140:
141:            /**
142:             * Get the style
143:             */
144:            public int getStyle() {
145:                return style;
146:            }
147:
148:            /**
149:             * The contract implementation should overload <code>toString</code> so
150:             * the contract can be displayed to the user in a sane format, for use
151:             * in error messages, etc.
152:             */
153:            public String toString() {
154:                return "(" + super .toString() + " && (style is " + style + "))";
155:            }
156:        }
157:
158:        /*
159:         *   Local Variables:
160:         *   tab-width: 2
161:         *   indent-tabs-mode: nil
162:         *   mode: java
163:         *   c-indentation-style: java
164:         *   c-basic-offset: 2
165:         *   eval: (c-set-offset 'substatement-open '0)
166:         *   eval: (c-set-offset 'case-label '+)
167:         *   eval: (c-set-offset 'inclass '+)
168:         *   eval: (c-set-offset 'inline-open '0)
169:         *   End:
170:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.