Source Code Cross Referenced for EventCatcher.java in  » 6.0-JDK-Modules » java-3d » javax » media » j3d » 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 » 6.0 JDK Modules » java 3d » javax.media.j3d 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: EventCatcher.java,v $
003:         *
004:         * Copyright 1998-2008 Sun Microsystems, Inc.  All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006:         *
007:         * This code is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU General Public License version 2 only, as
009:         * published by the Free Software Foundation.  Sun designates this
010:         * particular file as subject to the "Classpath" exception as provided
011:         * by Sun in the LICENSE file that accompanied this code.
012:         *
013:         * This code is distributed in the hope that it will be useful, but WITHOUT
014:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
016:         * version 2 for more details (a copy is included in the LICENSE file that
017:         * accompanied this code).
018:         *
019:         * You should have received a copy of the GNU General Public License version
020:         * 2 along with this work; if not, write to the Free Software Foundation,
021:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022:         *
023:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024:         * CA 95054 USA or visit www.sun.com if you need additional information or
025:         * have any questions.
026:         *
027:         * $Revision: 1.8 $
028:         * $Date: 2008/02/28 20:17:21 $
029:         * $State: Exp $
030:         */
031:
032:        package javax.media.j3d;
033:
034:        import javax.vecmath.*;
035:        import java.awt.*;
036:        import java.awt.event.*;
037:
038:        /**
039:         * The EventCatcher class is used to track events on a Canvas3D using the
040:         * 1.1 event model.  Most events are sent to the canvas for processing.
041:         */
042:        class EventCatcher extends Object implements  ComponentListener,
043:                FocusListener, KeyListener, MouseListener, MouseMotionListener,
044:                MouseWheelListener, WindowListener {
045:
046:            // The canvas associated with this event catcher
047:            private Canvas3D canvas;
048:            private static final boolean DEBUG = false;
049:            private boolean stopped = false;
050:
051:            /**
052:             * flags for event listeners
053:             */
054:            private boolean focusEvents = false;
055:            private boolean keyEvents = false;
056:            private boolean mouseEvents = false;
057:            private boolean mouseMotionEvents = false;
058:            private boolean mouseWheelEvents = false;
059:            private boolean mouseListenerAdded = false;
060:
061:            EventCatcher(Canvas3D c) {
062:                canvas = c;
063:
064:                if (VirtualUniverse.mc.isD3D()) {
065:                    enableKeyEvents();
066:                }
067:            }
068:
069:            void enableFocusEvents() {
070:                if (!focusEvents) {
071:                    canvas.addFocusListener(this );
072:                    focusEvents = true;
073:                }
074:            }
075:
076:            void disableFocusEvents() {
077:                if (focusEvents) {
078:                    canvas.removeFocusListener(this );
079:                    focusEvents = false;
080:                }
081:            }
082:
083:            void enableKeyEvents() {
084:                if (!keyEvents) {
085:                    canvas.addKeyListener(this );
086:                    keyEvents = true;
087:                    // listen for mouseEntered events for keyboard focusing
088:                    if (!mouseListenerAdded) {
089:                        canvas.addMouseListener(this );
090:                        mouseListenerAdded = true;
091:                    }
092:                }
093:            }
094:
095:            void disableKeyEvents() {
096:                if (keyEvents) {
097:                    canvas.removeKeyListener(this );
098:                    keyEvents = false;
099:                    // listen for mouseEntered events for keyboard focusing
100:                    if (!mouseEvents) {
101:                        if (mouseListenerAdded) {
102:                            canvas.removeMouseListener(this );
103:                            mouseListenerAdded = false;
104:                        }
105:                    }
106:                }
107:            }
108:
109:            void enableMouseEvents() {
110:                if (!mouseEvents) {
111:                    mouseEvents = true;
112:                    if (!mouseListenerAdded) {
113:                        canvas.addMouseListener(this );
114:                        mouseListenerAdded = true;
115:                    }
116:                }
117:            }
118:
119:            void disableMouseEvents() {
120:                if (mouseEvents) {
121:                    mouseEvents = false;
122:                    if (!keyEvents) {
123:                        if (mouseListenerAdded) {
124:                            canvas.removeMouseListener(this );
125:                            mouseListenerAdded = false;
126:                        }
127:                    }
128:                }
129:            }
130:
131:            void enableMouseMotionEvents() {
132:                if (!mouseMotionEvents) {
133:                    canvas.addMouseMotionListener(this );
134:                    mouseMotionEvents = true;
135:                }
136:            }
137:
138:            void disableMouseMotionEvents() {
139:                if (mouseMotionEvents) {
140:                    canvas.removeMouseMotionListener(this );
141:                    mouseMotionEvents = false;
142:                }
143:            }
144:
145:            void enableMouseWheelEvents() {
146:                if (!mouseWheelEvents) {
147:                    canvas.addMouseWheelListener(this );
148:                    mouseWheelEvents = true;
149:                }
150:            }
151:
152:            void disableMouseWheelEvents() {
153:                if (mouseWheelEvents) {
154:                    canvas.removeMouseWheelListener(this );
155:                    mouseWheelEvents = false;
156:                }
157:            }
158:
159:            public void componentResized(ComponentEvent e) {
160:                if (e.getSource() == canvas) {
161:                    if (DEBUG) {
162:                        System.err.println(e);
163:                    }
164:                    canvas.sendEventToBehaviorScheduler(e);
165:                    if (VirtualUniverse.mc.isD3D()) {
166:                        canvas.notifyD3DPeer(Canvas3D.RESIZE);
167:                    }
168:                    canvas.evaluateVisiblilty();
169:                    canvas.redraw();
170:                }
171:            }
172:
173:            public void componentMoved(ComponentEvent e) {
174:                if (e.getSource() == canvas) {
175:                    if (DEBUG) {
176:                        System.err.println(e);
177:                    }
178:                    canvas.sendEventToBehaviorScheduler(e);
179:
180:                    // Issue 458 - the following is not needed for a move
181:                    //            if (VirtualUniverse.mc.isD3D()) {
182:                    //                canvas.notifyD3DPeer(Canvas3D.RESIZE);
183:                    //            }
184:                    //            canvas.evaluateVisiblilty(true);
185:                }
186:            }
187:
188:            public void componentHidden(ComponentEvent e) {
189:                if (DEBUG) {
190:                    System.err.println(e);
191:                }
192:                if (e.getSource() == canvas) {
193:                    canvas.sendEventToBehaviorScheduler(e);
194:                }
195:                canvas.evaluateVisiblilty();
196:            }
197:
198:            public void componentShown(ComponentEvent e) {
199:                if (DEBUG) {
200:                    System.err.println(e);
201:                }
202:                if (e.getSource() == canvas) {
203:                    canvas.sendEventToBehaviorScheduler(e);
204:                }
205:                canvas.evaluateVisiblilty();
206:            }
207:
208:            public void focusGained(FocusEvent e) {
209:                canvas.sendEventToBehaviorScheduler(e);
210:                if (DEBUG) {
211:                    System.err.println(e);
212:                }
213:            }
214:
215:            public void focusLost(FocusEvent e) {
216:                canvas.sendEventToBehaviorScheduler(e);
217:                if (DEBUG) {
218:                    System.err.println(e);
219:                }
220:            }
221:
222:            public void keyTyped(KeyEvent e) {
223:                canvas.sendEventToBehaviorScheduler(e);
224:                if (DEBUG) {
225:                    System.err.println(e);
226:                }
227:            }
228:
229:            public void keyPressed(KeyEvent e) {
230:                canvas.sendEventToBehaviorScheduler(e);
231:
232:                if (VirtualUniverse.mc.isD3D() && e.isAltDown()
233:                        && (e.getKeyCode() == KeyEvent.VK_ENTER)) {
234:                    canvas.notifyD3DPeer(Canvas3D.TOGGLEFULLSCREEN);
235:                }
236:
237:                if (DEBUG) {
238:                    System.err.println(e);
239:                }
240:            }
241:
242:            public void keyReleased(KeyEvent e) {
243:                canvas.sendEventToBehaviorScheduler(e);
244:                if (stopped) {
245:                    stopped = false;
246:                } else {
247:                    stopped = true;
248:                }
249:                if (DEBUG) {
250:                    System.err.println(e);
251:                }
252:            }
253:
254:            public void mouseClicked(MouseEvent e) {
255:                //	if (keyEvents &&
256:                //            (VirtualUniverse.mc.getRenderingAPI() !=
257:                //	     MasterControl.RENDER_OPENGL_SOLARIS)) {
258:                //	     // bug 4362074
259:                //           canvas.requestFocus();
260:                //	}
261:
262:                if (mouseEvents) {
263:                    canvas.sendEventToBehaviorScheduler(e);
264:                }
265:                if (DEBUG) {
266:                    System.err.println(e);
267:                }
268:            }
269:
270:            public void mouseEntered(MouseEvent e) {
271:                //	if (keyEvents &&
272:                //           (VirtualUniverse.mc.getRenderingAPI() ==
273:                //	     MasterControl.RENDER_OPENGL_SOLARIS)) {
274:                //	     // bug 4362074
275:                //           canvas.requestFocus();
276:                //	}
277:                if (mouseEvents) {
278:                    canvas.sendEventToBehaviorScheduler(e);
279:                }
280:                if (DEBUG) {
281:                    System.err.println(e);
282:                }
283:            }
284:
285:            public void mouseExited(MouseEvent e) {
286:                if (mouseEvents)
287:                    canvas.sendEventToBehaviorScheduler(e);
288:                if (DEBUG) {
289:                    System.err.println(e);
290:                }
291:            }
292:
293:            public void mousePressed(MouseEvent e) {
294:                if (mouseEvents)
295:                    canvas.sendEventToBehaviorScheduler(e);
296:                if (DEBUG) {
297:                    System.err.println(e);
298:                }
299:            }
300:
301:            public void mouseReleased(MouseEvent e) {
302:                if (mouseEvents)
303:                    canvas.sendEventToBehaviorScheduler(e);
304:                if (DEBUG) {
305:                    System.err.println(e);
306:                }
307:            }
308:
309:            public void mouseDragged(MouseEvent e) {
310:                // Note : We don't have to test for mouseMotionEvent here because 
311:                // this routine will never be called unless mouseMotionEvent is enabled.
312:                canvas.sendEventToBehaviorScheduler(e);
313:                if (DEBUG) {
314:                    System.err.println(e);
315:                }
316:            }
317:
318:            public void mouseMoved(MouseEvent e) {
319:                // Note : We don't have to test for mouseMotionEvent here because 
320:                // this routine will never be called unless mouseMotionEvent is enabled.
321:                canvas.sendEventToBehaviorScheduler(e);
322:                if (DEBUG) {
323:                    System.err.println(e);
324:                }
325:            }
326:
327:            public void mouseWheelMoved(MouseWheelEvent e) {
328:                // Note : We don't have to test for mouseWheelEvent here because 
329:                // this routine will never be called unless mouseWheelEvent is enabled.
330:                canvas.sendEventToBehaviorScheduler(e);
331:                if (DEBUG) {
332:                    System.err.println(e);
333:                }
334:            }
335:
336:            /*
337:             * WindowListener methods
338:             */
339:            public void windowClosed(WindowEvent e) {
340:                if (DEBUG) {
341:                    System.err.println(e);
342:                }
343:                canvas.sendEventToBehaviorScheduler(e);
344:                // Issue 458 - Don't set canvas visible to false
345:            }
346:
347:            public void windowClosing(WindowEvent e) {
348:                if (DEBUG) {
349:                    System.err.println(e);
350:                }
351:                canvas.sendEventToBehaviorScheduler(e);
352:                // Issue 458 - Don't set canvas.visible to false
353:            }
354:
355:            public void windowActivated(WindowEvent e) {
356:                if (DEBUG) {
357:                    System.err.println(e);
358:                }
359:                canvas.sendEventToBehaviorScheduler(e);
360:            }
361:
362:            public void windowDeactivated(WindowEvent e) {
363:                if (DEBUG) {
364:                    System.err.println(e);
365:                }
366:                canvas.sendEventToBehaviorScheduler(e);
367:            }
368:
369:            public void windowDeiconified(WindowEvent e) {
370:                if (DEBUG) {
371:                    System.err.println(e);
372:                }
373:                canvas.sendEventToBehaviorScheduler(e);
374:                if (canvas.view != null) {
375:                    canvas.view.sendEventToSoundScheduler(e);
376:                }
377:                canvas.evaluateVisiblilty();
378:            }
379:
380:            public void windowIconified(WindowEvent e) {
381:                if (DEBUG) {
382:                    System.err.println(e);
383:                }
384:                canvas.sendEventToBehaviorScheduler(e);
385:                if (canvas.view != null) {
386:                    canvas.view.sendEventToSoundScheduler(e);
387:                }
388:                canvas.evaluateVisiblilty();
389:            }
390:
391:            public void windowOpened(WindowEvent e) {
392:                if (DEBUG) {
393:                    System.err.println(e);
394:                }
395:                canvas.sendEventToBehaviorScheduler(e);
396:                canvas.evaluateVisiblilty();
397:            }
398:
399:            void reset() {
400:                focusEvents = false;
401:                keyEvents = false;
402:                mouseEvents = false;
403:                mouseMotionEvents = false;
404:                mouseWheelEvents = false;
405:                mouseListenerAdded = false;
406:                stopped = false;
407:            }
408:
409:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.