Source Code Cross Referenced for Menu.java in  » Report » openi » org » openi » menu » 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 » Report » openi » org.openi.menu 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*********************************************************************************
002:         * The contents of this file are subject to the OpenI Public License Version 1.0
003:         * ("License"); You may not use this file except in compliance with the
004:         * License. You may obtain a copy of the License at
005:         * http://www.openi.org/docs/LICENSE.txt
006:         *
007:         * Software distributed under the License is distributed on an "AS IS" basis,
008:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
009:         * the specific language governing rights and limitations under the License.
010:         *
011:         * The Original Code is: OpenI Open Source
012:         *
013:         * The Initial Developer of the Original Code is Loyalty Matrix, Inc.
014:         * Portions created by Loyalty Matrix, Inc. are
015:         * Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
016:         *
017:         * Contributor(s): ______________________________________.
018:         *
019:         ********************************************************************************/package org.openi.menu;
020:
021:        import java.io.Serializable;
022:        import java.util.*;
023:
024:        /**
025:         * @author Uddhab Pant
026:         *
027:         * This class represents menu. Menu is a place holder for
028:         * sub menu and menu item.
029:         *
030:         */
031:        public class Menu implements  Serializable {
032:            private String displayName;
033:
034:            /**
035:             * Sub menu or menu item
036:             * 
037:             */
038:            private List childNodes;
039:
040:            /**
041:             * Default contructor
042:             *
043:             */
044:            public Menu() {
045:                childNodes = new ArrayList();
046:            }
047:
048:            /**
049:             * Creates menu from existing menu instance. Does not copy childnodes
050:             *
051:             */
052:            public Menu(Menu menu) {
053:                this .displayName = menu.displayName;
054:            }
055:
056:            /**
057:             *
058:             * @param displayName String
059:             */
060:            public Menu(String displayName) {
061:                this .displayName = displayName;
062:                childNodes = new ArrayList();
063:            }
064:
065:            /**
066:             * @return Returns the displayName.
067:             */
068:            public String getDisplayName() {
069:                return displayName;
070:            }
071:
072:            /**
073:             * @param displayName The displayName to set.
074:             */
075:            public void setDisplayName(String displayName) {
076:                this .displayName = displayName;
077:            }
078:
079:            /**
080:             * Adds menu item.
081:             * @param menuItem MenuItem
082:             */
083:            public void addMenuItem(MenuItem menuItem) {
084:                this .childNodes.add(menuItem);
085:            }
086:
087:            /**
088:             * Adds sub menu
089:             * @param subMenu Menu
090:             */
091:            public void addSubMenu(Menu subMenu) {
092:                this .childNodes.add(subMenu);
093:            }
094:
095:            /**
096:             * Returns sub menu and menu items
097:             * @return List
098:             */
099:            public List getChildNodes() {
100:                return this .childNodes;
101:            }
102:
103:            /**
104:             * sets child nodes
105:             * @return Collection
106:             */
107:            public void setChildNodes(List childNodes) {
108:                this .childNodes = childNodes;
109:            }
110:
111:            /**
112:             * Returns display name
113:             * @return String
114:             */
115:            public String toString() {
116:                return String.valueOf(displayName);
117:            }
118:
119:            public void accept(MenuVisitor visitor) {
120:                this .recurse(this .getChildNodes(), visitor);
121:            }
122:
123:            public Object clone() {
124:                Menu menu = new Menu("");
125:                menu.setDisplayName(this .displayName);
126:
127:                if (menu.getChildNodes() != null) {
128:                    List nodes = new ArrayList();
129:                    for (Iterator iter = this .childNodes.iterator(); iter
130:                            .hasNext();) {
131:                        Object item = iter.next();
132:                        if (item instanceof  Menu) {
133:                            nodes.add(((Menu) item).clone());
134:                        } else if (item instanceof  MenuItem) {
135:                            nodes.add(((MenuItem) item).clone());
136:                        }
137:                    }
138:                    menu.setChildNodes(nodes);
139:                }
140:                return menu;
141:            }
142:
143:            private void recurse(Collection nodes, MenuVisitor visitor) {
144:                Iterator children = nodes.iterator();
145:                while (children.hasNext()) {
146:                    Object child = children.next();
147:
148:                    if (child instanceof  Menu) {
149:                        Menu childMenu = (Menu) child;
150:                        visitor.visit(childMenu);
151:                        recurse(childMenu.getChildNodes(), visitor);
152:                    } else if (child instanceof  MenuItem) {
153:                        visitor.visit((MenuItem) child);
154:                    }
155:                }
156:            }
157:
158:            public Menu getSubMenu(String displayName) {
159:                SubmenuVisitor visitor = new SubmenuVisitor(displayName);
160:                this .recurse(this .getChildNodes(), visitor);
161:                return visitor.getSubmenu();
162:            }
163:
164:            public List getMenuDisplayNames() {
165:                NameCollectionVisitor visitor = new NameCollectionVisitor();
166:                this .recurse(this .getChildNodes(), visitor);
167:                return visitor.getMenuNames();
168:            }
169:        }
170:
171:        class SubmenuVisitor implements  MenuVisitor {
172:            private Menu submenu;
173:            private String displayName;
174:
175:            public SubmenuVisitor(String displayName) {
176:                this .displayName = displayName;
177:            }
178:
179:            public void visit(Menu menu) {
180:                if (displayName.equals(menu.getDisplayName())) {
181:                    submenu = menu;
182:                }
183:            }
184:
185:            public void visit(MenuItem menuItem) {
186:                // nothing
187:            }
188:
189:            public Menu getSubmenu() {
190:                return this .submenu;
191:            }
192:        }
193:
194:        class NameCollectionVisitor implements  MenuVisitor {
195:            private List menuNames;
196:
197:            public NameCollectionVisitor() {
198:                menuNames = new LinkedList();
199:            }
200:
201:            public void visit(Menu menu) {
202:                if (menu != null && menu.getDisplayName() != null) {
203:                    menuNames.add(menu.getDisplayName());
204:                }
205:            }
206:
207:            public List getMenuNames() {
208:                return this .menuNames;
209:            }
210:
211:            public void visit(MenuItem menuItem) {
212:                //nothing
213:            }
214:
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.