Source Code Cross Referenced for SideColumnsView.java in  » J2EE » wicket » org » apache » wicket » extensions » markup » html » tree » table » 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 » J2EE » wicket » org.apache.wicket.extensions.markup.html.tree.table 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.wicket.extensions.markup.html.tree.table;
018:
019:        import java.util.ArrayList;
020:        import java.util.List;
021:
022:        import javax.swing.tree.TreeNode;
023:
024:        import org.apache.wicket.Component;
025:        import org.apache.wicket.RequestCycle;
026:        import org.apache.wicket.Response;
027:        import org.apache.wicket.extensions.markup.html.tree.table.ColumnLocation.Alignment;
028:        import org.apache.wicket.extensions.markup.html.tree.table.ColumnLocation.Unit;
029:        import org.apache.wicket.markup.MarkupStream;
030:        import org.apache.wicket.markup.html.WebMarkupContainer;
031:
032:        /**
033:         * Class that renders cell of columns aligned to the left or to the right.
034:         * 
035:         * @author Matej Knopp
036:         */
037:        final class SideColumnsView extends WebMarkupContainer {
038:            private static final long serialVersionUID = 1L;
039:
040:            private final List columns = new ArrayList();
041:
042:            private final List components = new ArrayList();
043:
044:            private TreeNode node;
045:
046:            private final List renderables = new ArrayList();
047:
048:            /**
049:             * Constructor.
050:             * 
051:             * @param id
052:             *            The component id
053:             * @param node
054:             *            The tree node
055:             */
056:            public SideColumnsView(String id, TreeNode node) {
057:                super (id);
058:                setRenderBodyOnly(true);
059:                this .node = node;
060:            }
061:
062:            /**
063:             * Adds a column to be rendered.
064:             * 
065:             * @param column
066:             *            The column to add
067:             * @param component
068:             *            The component
069:             * @param renderable
070:             *            The renderer
071:             */
072:            public void addColumn(IColumn column, Component component,
073:                    IRenderable renderable) {
074:                if (column.isVisible()) {
075:                    // if the column is aligned to the left, just append it.
076:                    // Otherwise we prepend it, because we want columns aligned to right
077:                    // to be rendered reverse order (because they will have set
078:                    // float:right
079:                    // in css, so they will be displayed in reverse order too).
080:                    if (column.getLocation().getAlignment() == Alignment.LEFT) {
081:                        columns.add(column);
082:                        components.add(component);
083:                        renderables.add(renderable);
084:                    } else {
085:                        columns.add(0, column);
086:                        components.add(0, component);
087:                        renderables.add(0, renderable);
088:                    }
089:                }
090:            }
091:
092:            /**
093:             * Renders the columns.
094:             * 
095:             * @param markupStream
096:             *            The markup stream of this component
097:             */
098:            protected void onRender(final MarkupStream markupStream) {
099:                final int markupStart = markupStream.getCurrentIndex();
100:                Response response = RequestCycle.get().getResponse();
101:
102:                boolean firstLeft = true; // whether there was no left column rendered
103:                // yet
104:                boolean rendered = false;
105:
106:                for (int i = 0; i < columns.size(); ++i) {
107:                    IColumn column = (IColumn) columns.get(i);
108:                    Component component = (Component) components.get(i);
109:                    IRenderable renderable = (IRenderable) renderables.get(i);
110:
111:                    // write wrapping markup
112:                    response.write("<span class=\"b_\" style=\""
113:                            + renderColumnStyle(column) + "\">");
114:                    if (column.getLocation().getAlignment() == Alignment.LEFT
115:                            && firstLeft == true) {
116:                        // for the first left column we have different style class
117:                        // (without the left border)
118:                        response.write("<span class=\"d_\">");
119:                        firstLeft = false;
120:                    } else {
121:                        response.write("<span class=\"c_\">");
122:                    }
123:
124:                    if (component != null) {
125:                        markupStream.setCurrentIndex(markupStart);
126:                        component.render(markupStream);
127:                        rendered = true;
128:                    } else if (renderable != null) {
129:                        renderable.render(node, response);
130:                    } else {
131:                        throw new IllegalStateException(
132:                                "Either renderable or cell component must be created for this noode");
133:                    }
134:
135:                    response.write("</span></span>\n");
136:                }
137:
138:                // if no component was rendered just advance in the markup stream
139:                if (rendered == false) {
140:                    markupStream.skipComponent();
141:                }
142:            }
143:
144:            /**
145:             * Renders the float css atribute of the given column.
146:             * 
147:             * @param column
148:             *            The
149:             * @return The column as a string
150:             */
151:            private String renderColumnFloat(IColumn column) {
152:                ColumnLocation location = column.getLocation();
153:                if (location.getAlignment() == Alignment.LEFT) {
154:                    return "left";
155:                } else if (location.getAlignment() == Alignment.RIGHT) {
156:                    return "right";
157:                } else {
158:                    throw new IllegalStateException("Wrong column allignment.");
159:                }
160:            }
161:
162:            /**
163:             * Renders content of the style attribute for the given column.
164:             * 
165:             * @param column
166:             *            The column to render the style attribute from
167:             * @return The style as a string
168:             */
169:            private String renderColumnStyle(IColumn column) {
170:                return "width:" + renderColumnWidth(column) + ";float:"
171:                        + renderColumnFloat(column);
172:            }
173:
174:            /**
175:             * Renders width of given column as string.
176:             * 
177:             * @param column
178:             *            The column to render as a string
179:             * @return The column as a string
180:             */
181:            private String renderColumnWidth(IColumn column) {
182:                ColumnLocation location = column.getLocation();
183:                return "" + location.getSize() + renderUnit(location.getUnit());
184:            }
185:
186:            /**
187:             * Renders given unit as string.
188:             * 
189:             * @param unit
190:             *            The unit to render to a string
191:             * @return The unit as a string
192:             */
193:            private String renderUnit(Unit unit) {
194:                if (unit == Unit.EM) {
195:                    return "em";
196:                } else if (unit == Unit.PX) {
197:                    return "px";
198:                } else if (unit == Unit.PERCENT) {
199:                    return "%";
200:                } else {
201:                    throw new IllegalStateException(
202:                            "Wrong column unit for column aligned left or right.");
203:                }
204:            }
205:
206:        }
ww_w_.__j__a__v__a2___s__.__c___o__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.