Source Code Cross Referenced for SelectionControl.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3dfly » 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 » org.jdesktop.j3dfly 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/SelectionControl.java,v 1.1 2005/04/20 21:04:21 paulby Exp $
003:         *
004:         *                         Sun Public License Notice
005:         *
006:         *  The contents of this file are subject to the Sun Public License Version
007:         *  1.0 (the "License"). You may not use this file except in compliance with
008:         *  the License. A copy of the License is available at http://www.sun.com/
009:         *  
010:         *  The Original Code is Java 3D(tm) Fly Through.
011:         *  The Initial Developer of the Original Code is Paul Byrne.
012:         *  Portions created by Paul Byrne are Copyright (C) 2002.
013:         *  All Rights Reserved.
014:         *  
015:         *  Contributor(s): Paul Byrne.
016:         *  
017:         **/
018:        package org.jdesktop.j3dfly;
019:
020:        import java.awt.event.MouseListener;
021:        import java.awt.event.MouseMotionListener;
022:        import java.awt.event.MouseEvent;
023:        import java.util.LinkedList;
024:
025:        import javax.media.j3d.Locale;
026:        import javax.media.j3d.Canvas3D;
027:        import com.sun.j3d.utils.picking.PickCanvas;
028:        import com.sun.j3d.utils.picking.PickResult;
029:
030:        /**
031:         *
032:         * @author  paulby
033:         * @version $Revision: 1.1 $
034:         */
035:        public class SelectionControl extends Object implements  MouseListener,
036:                MouseMotionListener {
037:
038:            public static final int MOUSE_CLICKED = 0x01;
039:            public static final int MOUSE_PRESSED = 0x02;
040:            public static final int MOUSE_RELEASED = 0x04;
041:            public static final int MOUSE_MOVED = 0x08;
042:            public static final int MOUSE_DRAGGED = 0x0F;
043:
044:            protected PickCanvas pickCanvas;
045:            private Canvas3D canvas;
046:
047:            private int currentFlags = 0;
048:
049:            private LinkedList listeners = new LinkedList();
050:            private SelectionListener currentListener = null;
051:
052:            /** Creates new PickControl */
053:            public SelectionControl(Locale locale, Canvas3D canvas) {
054:                this .canvas = canvas;
055:
056:                pickCanvas = new PickCanvas(canvas, locale);
057:                pickCanvas.setTolerance(0f);
058:                pickCanvas.setMode(PickCanvas.BOUNDS);
059:            }
060:
061:            /**
062:             * Add a new Listener for pick events. The listener will receive all
063:             * SelectionListener events, the flag determines if a pick is performed
064:             * before calling the listener
065:             *
066:             * @param listener The event listener
067:             * @param listenFlags Flags for which events should be a combination of
068:             * MOUSE_CLICKED, MOUSE_PRESSED, MOUSE_RELEASED, MOUSE_MOVED and MOUSE_DRAGGED
069:             */
070:            public void pushSelectionListener(SelectionListener listener,
071:                    int listenFlags) {
072:                if (currentFlags == 0) {
073:                    canvas.addMouseListener(this );
074:                    canvas.addMouseMotionListener(this );
075:                }
076:
077:                listeners.add(new ListenerObj(listener, listenFlags));
078:                currentFlags = listenFlags;
079:                currentListener = listener;
080:            }
081:
082:            /**
083:             * Remove a listener and update the global listenFlags 
084:             */
085:            public void popSelectionListener(SelectionListener listener) {
086:
087:                if (currentListener != listener)
088:                    throw new RuntimeException(
089:                            "Not poping top SelectionListener");
090:
091:                listeners.removeLast();
092:                if (listeners.size() != 0) {
093:                    ListenerObj obj = (ListenerObj) listeners.getLast();
094:                    currentListener = obj.selectionListener;
095:                    currentFlags = obj.listenerFlags;
096:                } else {
097:                    currentFlags = 0;
098:                    canvas.removeMouseListener(this );
099:                    canvas.removeMouseMotionListener(this );
100:                }
101:            }
102:
103:            protected PickResult doPick(java.awt.event.MouseEvent evt) {
104:                pickCanvas.setShapeLocation(evt);
105:                PickResult result;
106:                try {
107:                    result = pickCanvas.pickClosest();
108:                } catch (javax.media.j3d.CapabilityNotSetException e) {
109:                    result = null;
110:                    System.out.println("No Capability to pick object");
111:                }
112:
113:                return result;
114:            }
115:
116:            public void mouseReleased(java.awt.event.MouseEvent p1) {
117:                PickResult pick = null;
118:                if ((currentFlags & MOUSE_RELEASED) != 0)
119:                    pick = doPick(p1);
120:
121:                currentListener.mouseReleased(p1, pick);
122:            }
123:
124:            public void mouseEntered(java.awt.event.MouseEvent p1) {
125:            }
126:
127:            public void mouseClicked(java.awt.event.MouseEvent p1) {
128:                PickResult pick = null;
129:                if ((currentFlags & MOUSE_CLICKED) != 0)
130:                    pick = doPick(p1);
131:
132:                currentListener.mouseClicked(p1, pick);
133:            }
134:
135:            public void mousePressed(java.awt.event.MouseEvent p1) {
136:                if ((p1.getModifiers() & MouseEvent.BUTTON1_MASK) != MouseEvent.BUTTON1_MASK)
137:                    return;
138:
139:                PickResult pick = null;
140:                if ((currentFlags & MOUSE_PRESSED) != 0)
141:                    pick = doPick(p1);
142:
143:                currentListener.mousePressed(p1, pick);
144:            }
145:
146:            public void mouseExited(java.awt.event.MouseEvent p1) {
147:            }
148:
149:            public void mouseDragged(java.awt.event.MouseEvent p1) {
150:                if ((p1.getModifiers() & MouseEvent.BUTTON1_MASK) != MouseEvent.BUTTON1_MASK)
151:                    return;
152:
153:                PickResult pick = null;
154:                if ((currentFlags & MOUSE_DRAGGED) != 0)
155:                    pick = doPick(p1);
156:
157:                currentListener.mouseDragged(p1, pick);
158:            }
159:
160:            public void mouseMoved(java.awt.event.MouseEvent p1) {
161:                PickResult pick = null;
162:                if ((currentFlags & MOUSE_MOVED) != 0)
163:                    pick = doPick(p1);
164:
165:                currentListener.mouseMoved(p1, pick);
166:            }
167:
168:            class ListenerObj {
169:                public SelectionListener selectionListener;
170:                public int listenerFlags;
171:
172:                public ListenerObj(SelectionListener listener, int flags) {
173:                    this.selectionListener = listener;
174:                    this.listenerFlags = flags;
175:                }
176:            }
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.