Source Code Cross Referenced for MenuState.java in  » Testing » jacareto » jacareto » cleverphl » gui » 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 » jacareto » jacareto.cleverphl.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Jacareto Copyright (c) 2002-2005
003:         * Applied Computer Science Research Group, Darmstadt University of
004:         * Technology, Institute of Mathematics & Computer Science,
005:         * Ludwigsburg University of Education, and Computer Based
006:         * Learning Research Group, Aachen University. All rights reserved.
007:         *
008:         * Jacareto is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public
010:         * License as published by the Free Software Foundation; either
011:         * version 2 of the License, or (at your option) any later version.
012:         *
013:         * Jacareto is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:         * General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public
019:         * License along with Jacareto; if not, write to the Free
020:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021:         *
022:         */
023:
024:        package jacareto.cleverphl.gui;
025:
026:        import jacareto.cleverphl.CleverPHL;
027:        import jacareto.cleverphl.menu.CleverPHLAction;
028:        import jacareto.cleverphl.session.Session;
029:        import jacareto.cleverphl.session.SessionEvent;
030:        import jacareto.cleverphl.session.SessionList;
031:        import jacareto.cleverphl.session.SessionListEvent;
032:        import jacareto.cleverphl.session.SessionListListener;
033:        import jacareto.cleverphl.session.SessionListener;
034:        import jacareto.system.EnvironmentMember;
035:
036:        import java.util.Collection;
037:        import java.util.Iterator;
038:
039:        import javax.swing.Action;
040:
041:        /**
042:         * Stores the actual state of the menu. Some menu items should be enabled in some states an
043:         * disabled in other states. Whenever the menu state changes this instance enables or disables the
044:         * menu items dependent on the value of the <code>STATES_ENABLED</code> property of their actions.
045:         *
046:         * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
047:         * @version 1.0
048:         */
049:        public class MenuState extends EnvironmentMember implements 
050:                SessionListener, SessionListListener {
051:            /** The state when no session is open. */
052:            public static final long NO_SESSION = 0x1L;
053:
054:            /** The standard state (no capturing and replaying). */
055:            public static final long STANDARD = 0x2L;
056:
057:            /** The state when the program captures events. */
058:            public static final long CAPTURING = 0x4L;
059:
060:            /** The state when the program replays the record. */
061:            public static final long REPLAYING = 0x8L;
062:
063:            /** The pause during a replay. */
064:            public static final long REPLAY_PAUSE = 0x10L;
065:
066:            /** Disables all menu items. */
067:            public static final long ALL_DISABLED = 0x0L;
068:
069:            /** All states. */
070:            public static final long ALL_STATES = -1L;
071:
072:            /** The actual state. */
073:            private long state;
074:
075:            /** The CleverPHL instance. */
076:            private CleverPHL cleverPHL;
077:
078:            /** The menu bar of the CleverPHL main frame. */
079:            private CleverPHLMenuBar menuBar;
080:
081:            /**
082:             * Creates a new menu state instance with the given initial state and menu bar.
083:             *
084:             * @param cleverPHL the cleverPHL instance.
085:             * @param menuBar the menu bar of the CleverPHL main frame
086:             * @param initialState the initial state
087:             */
088:            public MenuState(CleverPHL cleverPHL, CleverPHLMenuBar menuBar,
089:                    long initialState) {
090:                super (cleverPHL.getEnvironment());
091:                this .cleverPHL = cleverPHL;
092:                this .menuBar = menuBar;
093:                setState(initialState);
094:                cleverPHL.getSessionList().addSessionListListener(this );
095:            }
096:
097:            /**
098:             * Sets a menu state to the given value. All menu items in the menu tree of the actual menu bar
099:             * will be disabled if the new state is not contained in the <code>STATES_ENABLED</code>
100:             * property of their actions. (or enabled if it is contained).
101:             *
102:             * @param state the new state
103:             */
104:            public void setState(long state) {
105:                if (this .state != state) {
106:                    this .state = state;
107:                    getLogger().debug(
108:                            getLanguage().getString(
109:                                    "CleverPHL.Menu.MenuState.Msg.StateSetTo")
110:                                    + " " + state);
111:                    enableDisable();
112:                }
113:            }
114:
115:            /**
116:             * Returns the actual menu state.
117:             *
118:             * @return DOCUMENT ME!
119:             */
120:            public long getState() {
121:                return state;
122:            }
123:
124:            /**
125:             * Invoked when the session list has changed.
126:             *
127:             * @param event the session list event
128:             */
129:            public void sessionListChanged(SessionListEvent event) {
130:                SessionList sessionList = cleverPHL.getSessionList();
131:                Session session = event.getSession();
132:                int ID = event.getID();
133:
134:                if (ID == SessionListEvent.SESSION_ADDED) {
135:                    session.addSessionListener(this );
136:
137:                    if (sessionList.size() == 1) {
138:                        setState(STANDARD);
139:                    }
140:                } else if (ID == SessionListEvent.SESSION_REMOVED) {
141:                    session.removeSessionListener(this );
142:
143:                    if (sessionList.isEmpty()) {
144:                        setState(NO_SESSION);
145:                    }
146:
147:                    if (sessionList.size() == 0) {
148:                        menuBar.adaptToNoSession();
149:                    }
150:                } else if (ID == SessionListEvent.NEW_ACTUAL_SESSION) {
151:                    menuBar.rebuild(session.getType());
152:                    session.addAccelerators();
153:
154:                    if (session.isCapturing()) {
155:                        setState(CAPTURING);
156:                    } else if (session.isReplaying()) {
157:                        if (session.isReplayPause()) {
158:                            setState(REPLAY_PAUSE);
159:                        } else {
160:                            setState(REPLAYING);
161:                        }
162:                    } else {
163:                        setState(STANDARD);
164:                    }
165:                }
166:            }
167:
168:            /**
169:             * Invoked when the session state changed.
170:             *
171:             * @param event the session event
172:             */
173:            public void sessionStateChanged(SessionEvent event) {
174:                SessionList sessionList = cleverPHL.getSessionList();
175:                Session session = event.getSession();
176:                int ID = event.getID();
177:
178:                if (session == sessionList.getActual()) {
179:                    if (ID == SessionEvent.CAPTURE_START) {
180:                        setState(CAPTURING);
181:                    } else if (ID == SessionEvent.CAPTURE_STOP) {
182:                        setState(STANDARD);
183:                    } else if ((ID == SessionEvent.REPLAY_START)
184:                            || (ID == SessionEvent.REPLAY_CONTINUE)) {
185:                        setState(REPLAYING);
186:                    } else if (ID == SessionEvent.REPLAY_PAUSE) {
187:                        setState(REPLAY_PAUSE);
188:                    } else if (ID == SessionEvent.REPLAY_STOP) {
189:                        setState(STANDARD);
190:                    } else if (ID == SessionEvent.REPLAY_RESET) {
191:                        setState(STANDARD);
192:                    }
193:                }
194:            }
195:
196:            /**
197:             * Enables or disables the specified menu element and all its sub elements belonging to the
198:             * <code>STATES_ENABLED</code> property of their actions.
199:             */
200:            private void enableDisable() {
201:                Collection actions = menuBar.getActions();
202:                Iterator it = actions.iterator();
203:
204:                while (it.hasNext()) {
205:                    Action action = (Action) it.next();
206:
207:                    if ((action != null) && action instanceof  CleverPHLAction) {
208:                        String sStatesEnabled = (String) action
209:                                .getValue(CleverPHLAction.STATES_ENABLED);
210:                        long statesEnabled = (new Long(sStatesEnabled))
211:                                .longValue();
212:                        boolean enabledState = (statesEnabled & getState()) != 0;
213:                        action.setEnabled(enabledState);
214:                    }
215:                }
216:            }
217:
218:            /**
219:             * Updates the enabled / disabled states of all menu items of the current menu bar.
220:             */
221:            public void update() {
222:                setState(getState());
223:            }
224:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.