Source Code Cross Referenced for XHtmlStyle.java in  » XML-UI » xui32 » com » xoetrope » builder » w3c » html » 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 » XML UI » xui32 » com.xoetrope.builder.w3c.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.builder.w3c.html;
002:
003:        import java.awt.Color;
004:        import java.awt.Font;
005:        import java.util.Hashtable;
006:        import java.util.StringTokenizer;
007:
008:        /**
009:         * XHtmlStyle holds the attributes and properties defined as part of a CSS style
010:         * sheet style.
011:         * <p> Copyright (c) Xoetrope Ltd., 2002-2006</p>
012:         * <p> $Revision: 1.2 $</p>
013:         * <p> License: see License.txt</p>
014:         */
015:        public class XHtmlStyle {
016:            protected String className;
017:            protected Hashtable<String, String> attributes;
018:            protected Hashtable<String, Object> objects;
019:
020:            /** 
021:             * Creates a new instance of XHtmlStyle 
022:             * @param styleName the name of teh style as defined in the style sheet
023:             */
024:            public XHtmlStyle(String styleName) {
025:                className = styleName;
026:                attributes = new Hashtable<String, String>();
027:                objects = new Hashtable<String, Object>();
028:            }
029:
030:            /**
031:             * Get a style attribute
032:             * @param attribName the attribute name
033:             * @return the attribute value
034:             */
035:            public String getAttribute(String attribName) {
036:                return attributes.get(attribName);
037:            }
038:
039:            /**
040:             * Get the Font setup by this style
041:             * @return the font
042:             */
043:            public Font getFont() {
044:                Font f = (Font) objects.get("font");
045:                if (f == null) {
046:                    int fontAttribs = 0;
047:                    String s = attributes.get("font-style");
048:                    if ((s != null) && s.equals("italic"))
049:                        fontAttribs |= Font.ITALIC;
050:
051:                    s = attributes.get("font-weight");
052:                    if ((s != null) && s.equals("bold"))
053:                        fontAttribs |= Font.BOLD;
054:
055:                    int size = 12;
056:                    s = attributes.get("font-size");
057:                    if (s != null) {
058:                        if (s.endsWith("pt"))
059:                            s = s.substring(0, s.length() - 2);
060:                        size = Integer.parseInt(s);
061:                    }
062:
063:                    String face = attributes.get("font-family");
064:                    if (face == null)
065:                        face = "Helvetica";
066:
067:                    f = new Font(face, fontAttribs, size);
068:                }
069:                return f;
070:            }
071:
072:            /**
073:             * Get the foreground color defined by this style, if any. Otherwise black is 
074:             * returned.
075:             * @param returnDefault return the default value if no attribute is specified
076:             * @return the foreground color or null if no default is specified and returnDefault is false
077:             */
078:            public Color getForeground(boolean returnDefault) {
079:                String s = attributes.get("color");
080:                if (s != null)
081:                    return XHtmlBuilder.getColor(s);
082:                return returnDefault ? Color.black : null;
083:            }
084:
085:            /**
086:             * Get the background color defined by this style, if any. Otherwise whiye is 
087:             * returned.
088:             * @param returnDefault return the default value if no attribute is specified
089:             * @return the background color or null if no default is specified and returnDefault is false
090:             */
091:            public Color getBackground(boolean returnDefault) {
092:                String s = attributes.get("background-color");
093:                if (s == null)
094:                    s = attributes.get("background");
095:
096:                if (s != null)
097:                    return XHtmlBuilder.getColor(s);
098:                return returnDefault ? Color.white : null;
099:            }
100:
101:            /**
102:             * Parse a CSS string
103:             * @param the css string containing a single style style
104:             */
105:            public void parse(String css) {
106:                // Now get the attributes of this style
107:                StringTokenizer tokenizer = new StringTokenizer(css, ";");
108:                while (tokenizer.hasMoreTokens()) {
109:                    String attrib = tokenizer.nextToken().trim();
110:                    int pos = attrib.indexOf(':');
111:                    String attrName = attrib.substring(0, pos);
112:                    attributes.put(attrName, attrib.substring(pos + 1).trim());
113:                }
114:            }
115:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.