Source Code Cross Referenced for AlignmentRender.java in  » Ajax » NextApp-Echo2 » nextapp » echo2 » webcontainer » propertyrender » 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 » Ajax » NextApp Echo2 » nextapp.echo2.webcontainer.propertyrender 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003:         * Copyright (C) 2002-2005 NextApp, Inc.
004:         *
005:         * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006:         *
007:         * The contents of this file are subject to the Mozilla Public License Version
008:         * 1.1 (the "License"); you may not use this file except in compliance with
009:         * the License. You may obtain a copy of the License at
010:         * http://www.mozilla.org/MPL/
011:         *
012:         * Software distributed under the License is distributed on an "AS IS" basis,
013:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014:         * for the specific language governing rights and limitations under the
015:         * License.
016:         *
017:         * Alternatively, the contents of this file may be used under the terms of
018:         * either the GNU General Public License Version 2 or later (the "GPL"), or
019:         * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020:         * in which case the provisions of the GPL or the LGPL are applicable instead
021:         * of those above. If you wish to allow use of your version of this file only
022:         * under the terms of either the GPL or the LGPL, and not to allow others to
023:         * use your version of this file under the terms of the MPL, indicate your
024:         * decision by deleting the provisions above and replace them with the notice
025:         * and other provisions required by the GPL or the LGPL. If you do not delete
026:         * the provisions above, a recipient may use your version of this file under
027:         * the terms of any one of the MPL, the GPL or the LGPL.
028:         */
029:
030:        package nextapp.echo2.webcontainer.propertyrender;
031:
032:        import org.w3c.dom.Element;
033:
034:        import nextapp.echo2.app.Alignment;
035:        import nextapp.echo2.app.Component;
036:        import nextapp.echo2.app.LayoutDirection;
037:        import nextapp.echo2.webrender.output.CssStyle;
038:
039:        /**
040:         * Utility class for rendering <code>nextapp.echo2.app.Alignment</code>
041:         * properties to CSS.
042:         */
043:        public class AlignmentRender {
044:
045:            /**
046:             * Returns the horizontal property of an <code>Alignment</code> object,
047:             * with <code>Alignment.LEADING</code> and <code>Alignment.TRAILING</code>
048:             * automatically translated based on the layout direction of the provided
049:             * <code>Component</code>.  If the provided component is null, a 
050:             * left-to-right layout direction will be assumed.
051:             * 
052:             * @param alignment the <code>Alignment</code> to analyze
053:             * @param component the <code>Component</code> to analyze
054:             * @return the horizontal alignment constant
055:             */
056:            public static int getRenderedHorizontal(Alignment alignment,
057:                    Component component) {
058:                LayoutDirection layoutDirection;
059:                if (component == null) {
060:                    layoutDirection = LayoutDirection.LTR;
061:                } else {
062:                    layoutDirection = component.getRenderLayoutDirection();
063:                }
064:                switch (alignment.getHorizontal()) {
065:                case Alignment.LEADING:
066:                    return layoutDirection.isLeftToRight() ? Alignment.LEFT
067:                            : Alignment.RIGHT;
068:                case Alignment.TRAILING:
069:                    return layoutDirection.isLeftToRight() ? Alignment.RIGHT
070:                            : Alignment.LEFT;
071:                default:
072:                    return alignment.getHorizontal();
073:                }
074:            }
075:
076:            /**
077:             * Renders an <code>Alignment</code> property to the given element.
078:             * The 'align' and 'valign' attributes will be set if they
079:             * can be derived from the provided <code>Alignment</code>.
080:             * Null property values are ignored.
081:             * 
082:             * @param element the target <code>Element</code>
083:             * @param alignment the property value
084:             */
085:            public static void renderToElement(Element element,
086:                    Alignment alignment) {
087:                renderToElement(element, alignment, null);
088:            }
089:
090:            /**
091:             * Renders an <code>Alignment</code> property to the given element.
092:             * The 'align' and 'valign' attributes will be set if they
093:             * can be derived from the provided <code>Alignment</code>.
094:             * Null property values are ignored.
095:             * 
096:             * @param element the target <code>Element</code>
097:             * @param alignment the property value
098:             * @param component The <code>Component</code> for which the style is being
099:             *        rendered (necessary for property translation of leading/trailing
100:             *        alignment settings).
101:             */
102:            public static void renderToElement(Element element,
103:                    Alignment alignment, Component component) {
104:                if (alignment == null) {
105:                    return;
106:                }
107:
108:                String horizontal = getHorizontalCssAttributeValue(alignment,
109:                        component);
110:                if (horizontal != null) {
111:                    element.setAttribute("align", horizontal);
112:                }
113:                String vertical = getVerticalCssAttributeValue(alignment);
114:                if (vertical != null) {
115:                    element.setAttribute("valign", vertical);
116:                }
117:            }
118:
119:            /**
120:             * Renders an <code>Alignment</code> property to the given CSS style.
121:             * The 'text-align' and 'vertical-align' properties will be set if they
122:             * can be derived from the provided <code>Alignment</code>.
123:             * Null property values are ignored.
124:             * 
125:             * @param cssStyle the target <code>CssStyle</code>
126:             * @param alignment the property value
127:             */
128:            public static void renderToStyle(CssStyle cssStyle,
129:                    Alignment alignment) {
130:                renderToStyle(cssStyle, alignment, null);
131:            }
132:
133:            /**
134:             * Renders an <code>Alignment</code> property to the given CSS style.
135:             * The 'text-align' and 'vertical-align' properties will be set if they
136:             * can be derived from the provided <code>Alignment</code>.
137:             * Null property values are ignored.
138:             * 
139:             * @param cssStyle the target <code>CssStyle</code>
140:             * @param component The <code>Component</code> for which the style is being
141:             *        rendered (necessary for property translation of leading/trailing
142:             *        alignment settings).
143:             * @param alignment the property value
144:             */
145:            public static void renderToStyle(CssStyle cssStyle,
146:                    Alignment alignment, Component component) {
147:                if (alignment == null) {
148:                    return;
149:                }
150:
151:                String horizontal = getHorizontalCssAttributeValue(alignment,
152:                        component);
153:                if (horizontal != null) {
154:                    cssStyle.setAttribute("text-align", horizontal);
155:                }
156:                String vertical = getVerticalCssAttributeValue(alignment);
157:                if (vertical != null) {
158:                    cssStyle.setAttribute("vertical-align", vertical);
159:                }
160:            }
161:
162:            /**
163:             * Determines the CSS attribute value of the horizontal property of the 
164:             * specified <code>Alignment</code>.  The provided <code>Component</code>
165:             * is used to determine the rendered alignment setting for 
166:             * <code>Alignment.LEADING</code> and <code>alignment.TRAILING</code> 
167:             * values.
168:             * 
169:             * @param alignment the <code>Alignment</code> property value
170:             * @param component the <code>Component</code> to use in order to determine
171:             *        appropriate rendered values for <code>Alignment.LEADING</code> /
172:             *        <code>Alignment.TRAILING</code> (this value may be null, in
173:             *        which case an LTR layout direction will be assumed)
174:             * @return the horizontal CSS attribute value, or null if it is not 
175:             *         specified by the <code>Alignment</code>
176:             */
177:            private static String getHorizontalCssAttributeValue(
178:                    Alignment alignment, Component component) {
179:                switch (getRenderedHorizontal(alignment, component)) {
180:                case Alignment.LEFT:
181:                    return "left";
182:                case Alignment.CENTER:
183:                    return "center";
184:                case Alignment.RIGHT:
185:                    return "right";
186:                default:
187:                    return null;
188:                }
189:            }
190:
191:            /**
192:             * Determines the CSS attribute value of the vertical property of the 
193:             * specified <code>Alignment</code>. 
194:             * 
195:             * @param alignment the <code>Alignment</code> property value
196:             * @return the CSS attribute value, or null if it is not specified by the
197:             *         <code>Alignment</code>
198:             */
199:            private static String getVerticalCssAttributeValue(
200:                    Alignment alignment) {
201:                switch (alignment.getVertical()) {
202:                case Alignment.TOP:
203:                    return "top";
204:                case Alignment.CENTER:
205:                    return "middle";
206:                case Alignment.BOTTOM:
207:                    return "bottom";
208:                default:
209:                    return null;
210:                }
211:            }
212:
213:            /** Non-instantiable class. */
214:            private AlignmentRender() {
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.