Source Code Cross Referenced for FocusManager.java in  » Mail-Clients » columba-1.4 » org » columba » addressbook » gui » focus » 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 » Mail Clients » columba 1.4 » org.columba.addressbook.gui.focus 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //The contents of this file are subject to the Mozilla Public License Version 1.1
002:        //(the "License"); you may not use this file except in compliance with the 
003:        //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004:        //
005:        //Software distributed under the License is distributed on an "AS IS" basis,
006:        //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
007:        //for the specific language governing rights and
008:        //limitations under the License.
009:        //
010:        //The Original Code is "The Columba Project"
011:        //
012:        //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013:        //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003. 
014:        //
015:        //All Rights Reserved.
016:        package org.columba.addressbook.gui.focus;
017:
018:        import java.awt.event.FocusEvent;
019:        import java.awt.event.FocusListener;
020:        import java.util.HashMap;
021:        import java.util.List;
022:        import java.util.Map;
023:        import java.util.Vector;
024:
025:        import org.columba.core.gui.action.AbstractColumbaAction;
026:
027:        /**
028:         * 
029:         * Every {@link FocusOwner}should register at the <code>FocusManager</code>.
030:         * <p>
031:         * FocusManager enables and disables the following Actions:
032:         * <ul>
033:         * <li>CutAction</li>
034:         * <li>CopyAction</li>
035:         * <li>PasteAction</li>
036:         * <li>DeleteAction</li>
037:         * <li>SelectAllAction</li>
038:         * </ul>
039:         * 
040:         * 
041:         * @author fdietz
042:         *  
043:         */
044:        public class FocusManager implements  FocusListener {
045:            /**
046:             * list of focus owners
047:             */
048:            List list;
049:
050:            /**
051:             * map associating focus listener ui with focus owner
052:             */
053:            Map map;
054:
055:            /**
056:             * all actions
057:             */
058:            AbstractColumbaAction cutAction;
059:
060:            AbstractColumbaAction copyAction;
061:
062:            AbstractColumbaAction pasteAction;
063:
064:            AbstractColumbaAction deleteAction;
065:
066:            AbstractColumbaAction selectAllAction;
067:
068:            AbstractColumbaAction undoAction;
069:
070:            AbstractColumbaAction redoAction;
071:
072:            /**
073:             * current focus owner
074:             */
075:            FocusOwner current = null;
076:
077:            /**
078:             * last available focus owner
079:             */
080:            FocusOwner last = null;
081:
082:            private static FocusManager instance = new FocusManager();
083:
084:            public FocusManager() {
085:                list = new Vector();
086:                map = new HashMap();
087:            }
088:
089:            public static FocusManager getInstance() {
090:                return instance;
091:            }
092:
093:            /**
094:             * register FocusOwner and add FocusListener
095:             * 
096:             * @param c
097:             *            focus owner
098:             */
099:            public void registerComponent(FocusOwner c) {
100:                list.add(c);
101:
102:                // associate ui component with FocusOwner
103:                map.put(c.getComponent(), c);
104:
105:                c.getComponent().addFocusListener(this );
106:            }
107:
108:            /**
109:             * Get current focus owner
110:             * 
111:             * Try first current owner. If this fails, try the last available one.
112:             * 
113:             * @return current focus owner
114:             */
115:            public FocusOwner getCurrentOwner() {
116:                if (current != null) {
117:                    return current;
118:                }
119:
120:                if (last != null) {
121:                    return last;
122:                }
123:
124:                return null;
125:            }
126:
127:            /**
128:             * 
129:             * FocusOwner objects should call this method on selection changes in their
130:             * view component to enable/disable the actions
131:             *  
132:             */
133:            public void updateActions() {
134:                // TODO: fix updateActions
135:                //enableActions(getCurrentOwner());
136:            }
137:
138:            /**
139:             * enable/disable actions
140:             * 
141:             * @param o
142:             *            current focus owner
143:             */
144:            protected void enableActions(FocusOwner o) {
145:                if (o == null) {
146:                    //  no component has the focus
147:                    // -> disable all actions
148:                    cutAction.setEnabled(false);
149:                    copyAction.setEnabled(false);
150:                    pasteAction.setEnabled(false);
151:                    deleteAction.setEnabled(false);
152:                    undoAction.setEnabled(false);
153:                    redoAction.setEnabled(false);
154:                    selectAllAction.setEnabled(false);
155:
156:                    return;
157:                }
158:
159:                cutAction.setEnabled(o.isCutActionEnabled());
160:                copyAction.setEnabled(o.isCopyActionEnabled());
161:                pasteAction.setEnabled(o.isPasteActionEnabled());
162:                deleteAction.setEnabled(o.isDeleteActionEnabled());
163:                undoAction.setEnabled(o.isUndoActionEnabled());
164:                redoAction.setEnabled(o.isRedoActionEnabled());
165:                selectAllAction.setEnabled(o.isSelectAllActionEnabled());
166:            }
167:
168:            /**
169:             * Component gained focus
170:             *  
171:             */
172:            public void focusGained(FocusEvent event) {
173:                current = (FocusOwner) map.get(event.getSource());
174:
175:                updateActions();
176:            }
177:
178:            /**
179:             * Component lost focus
180:             */
181:            public void focusLost(FocusEvent event) {
182:                //FocusOwner lost = (FocusOwner) map.get(event.getSource());
183:
184:                last = current;
185:
186:                current = null;
187:
188:                //current = lost;
189:                updateActions();
190:            }
191:
192:            /**
193:             * execute cut action of currently available focus owner
194:             *  
195:             */
196:            public void cut() {
197:                getCurrentOwner().cut();
198:
199:                enableActions(getCurrentOwner());
200:            }
201:
202:            /**
203:             * execute copy action of currently available focus owner
204:             *  
205:             */
206:            public void copy() {
207:                getCurrentOwner().copy();
208:
209:                enableActions(getCurrentOwner());
210:            }
211:
212:            /**
213:             * execute paste action of currently available focus owner
214:             *  
215:             */
216:            public void paste() {
217:                getCurrentOwner().paste();
218:
219:                enableActions(getCurrentOwner());
220:            }
221:
222:            /**
223:             * execute delete action of currently available focus owner
224:             *  
225:             */
226:            public void delete() {
227:                getCurrentOwner().delete();
228:
229:                enableActions(getCurrentOwner());
230:            }
231:
232:            /**
233:             * execute redo action of currentyl available focus owner
234:             *  
235:             */
236:            public void redo() {
237:                getCurrentOwner().redo();
238:                enableActions(getCurrentOwner());
239:            }
240:
241:            /**
242:             * execute undo action of currentyl available focus owner
243:             *  
244:             */
245:            public void undo() {
246:                getCurrentOwner().undo();
247:                enableActions(getCurrentOwner());
248:            }
249:
250:            /**
251:             * execute selectAll action of currentyl available focus owner
252:             *  
253:             */
254:            public void selectAll() {
255:                getCurrentOwner().selectAll();
256:                enableActions(getCurrentOwner());
257:            }
258:
259:            /** *********************** setter of actions ********************* */
260:            /**
261:             * @param action
262:             */
263:            public void setCopyAction(AbstractColumbaAction action) {
264:                copyAction = action;
265:            }
266:
267:            /**
268:             * @param action
269:             */
270:            public void setCutAction(AbstractColumbaAction action) {
271:                cutAction = action;
272:            }
273:
274:            /**
275:             * @param action
276:             */
277:            public void setDeleteAction(AbstractColumbaAction action) {
278:                deleteAction = action;
279:            }
280:
281:            /**
282:             * @param action
283:             */
284:            public void setPasteAction(AbstractColumbaAction action) {
285:                pasteAction = action;
286:            }
287:
288:            /**
289:             * @param action
290:             */
291:            public void setRedoAction(AbstractColumbaAction action) {
292:                redoAction = action;
293:            }
294:
295:            /**
296:             * @param action
297:             */
298:            public void setSelectAllAction(AbstractColumbaAction action) {
299:                selectAllAction = action;
300:            }
301:
302:            /**
303:             * @param action
304:             */
305:            public void setUndoAction(AbstractColumbaAction action) {
306:                undoAction = action;
307:            }
308:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.