Source Code Cross Referenced for CollapsableWidget.java in  » Wiki-Engine » fitnesse » fitnesse » wikitext » widgets » 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 » Wiki Engine » fitnesse » fitnesse.wikitext.widgets 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
002:        // Released under the terms of the GNU General Public License version 2 or later.
003:        package fitnesse.wikitext.widgets;
004:
005:        import fitnesse.html.HtmlElement;
006:        import fitnesse.html.HtmlTag;
007:        import fitnesse.html.HtmlUtil;
008:        import fitnesse.html.RawHtml;
009:
010:        import java.util.Random;
011:        import java.util.regex.Matcher;
012:        import java.util.regex.Pattern;
013:
014:        public class CollapsableWidget extends ParentWidget {
015:            private static final String ENDL = LineBreakWidget.REGEXP;
016:            public static final String REGEXP = "!\\*+>? .*?" + ENDL + ".*?"
017:                    + ENDL + "\\*+!" + ENDL + "?";
018:            private static final Pattern pattern = Pattern.compile(
019:                    "!\\*+(>)? (.*?)" + ENDL + "(.*?)" + ENDL + "\\*+!",
020:                    Pattern.MULTILINE + Pattern.DOTALL);
021:
022:            private static Random random = new Random();
023:
024:            private String cssClass = "collapse_rim";
025:            private ParentWidget titleWidget;
026:            public boolean expanded = true;
027:
028:            private static final String collapsableOpenCss = "collapsable";
029:            private static final String collapsableClosedCss = "hidden";
030:            private static final String collapsableOpenImg = "/files/images/collapsableOpen.gif";
031:            private static final String collapsableClosedImg = "/files/images/collapsableClosed.gif";
032:            private static final String collapseAllLink = "<a href=\"javascript:collapseAll();\">Collapse All</a>";
033:            private static final String expandAllLink = "<a href=\"javascript:expandAll();\">Expand All</a>";
034:
035:            public CollapsableWidget(ParentWidget parent) {
036:                super (parent);
037:            }
038:
039:            public CollapsableWidget(ParentWidget parent, String text)
040:                    throws Exception {
041:                this (parent);
042:                Matcher match = pattern.matcher(text);
043:                match.find();
044:                expanded = match.group(1) == null;
045:                String title = match.group(2);
046:                String body = match.group(3);
047:                init(title, body);
048:            }
049:
050:            public CollapsableWidget(ParentWidget parent, String title,
051:                    String body, String cssClass, boolean collapsed)
052:                    throws Exception {
053:                this (parent);
054:                init(title, body);
055:                this .cssClass = cssClass;
056:                this .expanded = !collapsed;
057:            }
058:
059:            private void init(String title, String body) throws Exception {
060:                titleWidget = new BlankParentWidget(this , "!meta " + title);
061:                addChildWidgets(body);
062:            }
063:
064:            public String render() throws Exception {
065:                HtmlElement titleElement = new RawHtml("&nbsp;"
066:                        + titleWidget.childHtml());
067:                HtmlElement bodyElement = new RawHtml(childHtml());
068:                HtmlElement html = makeCollapsableSection(titleElement,
069:                        bodyElement);
070:                return html.html();
071:            }
072:
073:            public HtmlTag makeCollapsableSection(HtmlElement title,
074:                    HtmlElement content) {
075:                String id = random.nextLong() + "";
076:                HtmlTag outerDiv = HtmlUtil.makeDivTag(cssClass);
077:
078:                HtmlTag image = new HtmlTag("img");
079:                image.addAttribute("src", imageSrc());
080:                image.addAttribute("class", "left");
081:                image.addAttribute("id", "img" + id);
082:
083:                HtmlTag anchor = new HtmlTag("a", image);
084:                anchor.addAttribute("href", "javascript:toggleCollapsable('"
085:                        + id + "');");
086:
087:                HtmlTag links = new HtmlTag("div");
088:                links.addAttribute("style", "float: right;");
089:                links.addAttribute("class", "meta");
090:                links.add(expandAllLink + " | " + collapseAllLink);
091:
092:                outerDiv.add(links);
093:                outerDiv.add(anchor);
094:                outerDiv.add(title);
095:
096:                HtmlTag collapsablediv = makeCollapsableDiv();
097:                collapsablediv.addAttribute("id", id);
098:                collapsablediv.add(content);
099:                outerDiv.add(collapsablediv);
100:
101:                return outerDiv;
102:            }
103:
104:            private HtmlTag makeCollapsableDiv() {
105:                if (!expanded)
106:                    return HtmlUtil.makeDivTag(collapsableClosedCss);
107:                else
108:                    return HtmlUtil.makeDivTag(collapsableOpenCss);
109:            }
110:
111:            private String imageSrc() {
112:                if (expanded)
113:                    return collapsableOpenImg;
114:                else
115:                    return collapsableClosedImg;
116:            }
117:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.