Source Code Cross Referenced for CollapsableWidget.java in  » Testing » StoryTestIQ » 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 » Testing » StoryTestIQ » 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:
017:            public static final String REGEXP = "!\\*+>? .*?" + ENDL + ".*?"
018:                    + ENDL + "\\*+!" + ENDL + "?";
019:
020:            private static final Pattern pattern = Pattern.compile(
021:                    "!\\*+(>)? (.*?)" + ENDL + "(.*?)" + ENDL + "\\*+!",
022:                    Pattern.MULTILINE + Pattern.DOTALL);
023:
024:            private static Random random = new Random();
025:
026:            private String cssClass = "collapse_rim";
027:
028:            private ParentWidget titleWidget;
029:
030:            public boolean expanded = true;
031:
032:            private static final String collapsableOpenCss = "collapsable";
033:
034:            private static final String collapsableClosedCss = "hidden";
035:
036:            private static final String collapsableOpenImg = "/files/images/collapsableOpen.gif";
037:
038:            private static final String collapsableClosedImg = "/files/images/collapsableClosed.gif";
039:
040:            public CollapsableWidget(ParentWidget parent) {
041:                super (parent);
042:            }
043:
044:            public CollapsableWidget(ParentWidget parent, String text)
045:                    throws Exception {
046:                this (parent);
047:                Matcher match = pattern.matcher(text);
048:                match.find();
049:                expanded = match.group(1) == null;
050:                String title = match.group(2);
051:                String body = match.group(3);
052:                init(title, body);
053:            }
054:
055:            public CollapsableWidget(ParentWidget parent, String title,
056:                    String body, String cssClass) throws Exception {
057:                this (parent);
058:                init(title, body);
059:                this .cssClass = cssClass;
060:            }
061:
062:            private void init(String title, String body) throws Exception {
063:                titleWidget = new BlankParentWidget(this , "!meta " + title);
064:                addChildWidgets(body);
065:            }
066:
067:            public String render() throws Exception {
068:                HtmlElement titleElement = new RawHtml(" "
069:                        + titleWidget.childHtml());
070:                HtmlElement bodyElement = new RawHtml(childHtml());
071:                HtmlElement html = makeCollapsableSection(titleElement,
072:                        bodyElement);
073:                return html.html();
074:            }
075:
076:            public HtmlTag makeCollapsableSection(HtmlElement title,
077:                    HtmlElement content) {
078:                String id = random.nextLong() + "";
079:                HtmlTag outerDiv = HtmlUtil.makeDivTag(cssClass);
080:
081:                HtmlTag image = new HtmlTag("img");
082:                image.addAttribute("src", imageSrc());
083:                image.addAttribute("class", "imageleft");
084:                image.addAttribute("id", "img" + id);
085:                HtmlTag anchor = new HtmlTag("a", image);
086:                anchor.addAttribute("class", "anchoredimage");
087:                anchor.addAttribute("href", "javascript:toggleCollapsable('"
088:                        + id + "');");
089:                outerDiv.add(anchor);
090:                outerDiv.add(title);
091:
092:                HtmlTag collapsablediv = makeCollapsableDiv();
093:                collapsablediv.addAttribute("id", id);
094:                collapsablediv.add(content);
095:                outerDiv.add(collapsablediv);
096:
097:                return outerDiv;
098:            }
099:
100:            private HtmlTag makeCollapsableDiv() {
101:                if (!expanded)
102:                    return HtmlUtil.makeDivTag(collapsableClosedCss);
103:                else
104:                    return HtmlUtil.makeDivTag(collapsableOpenCss);
105:            }
106:
107:            private String imageSrc() {
108:                if (expanded)
109:                    return collapsableOpenImg;
110:                else
111:                    return collapsableClosedImg;
112:            }
113:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.