Source Code Cross Referenced for DropTargetHelper.java in  » Database-ORM » db-ojb » org » apache » ojb » tools » mapping » reversedb2 » dnd2 » 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 » Database ORM » db ojb » org.apache.ojb.tools.mapping.reversedb2.dnd2 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.ojb.tools.mapping.reversedb2.dnd2;
002:
003:        /* Copyright 2002-2005 The Apache Software Foundation
004:         *
005:         * Licensed under the Apache License, Version 2.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        import java.awt.dnd.DropTarget;
019:
020:        /**
021:         * Starting from JDK 1.2 drag and drop was possible for Java applications. Unfortunately
022:         * the framework to be used is rather complex. As of JDK 1.4 a new, more simple Dnd framework
023:         * was added, but unfortunately if you want to be backwards compatible, you still have to
024:         * stick with the old framework.
025:         *
026:         * This helper class should make it easier to implement DnD for JDK 1.2 and 1.3. To add drop
027:         * support for a Component, you only have to write your Implementation of DropPasteWorkerInterface.
028:         * This interface is responsible to read data from a Transferable and add it to the model of the
029:         * target component.
030:         * <CODE>
031:         *       DropTargetHelper helper = new DropTargetHelper();
032:         *       helper.registerDropPasteWorker (new ReverseDbNodesDropWorker());
033:         *       aComponent.setDropTarget(helper.getDropTarget ());
034:         * </CODE>
035:         * If you want to supply your own implementation of a DropTargetListener or an extension
036:         * of the implementation in this class, you have to use the following code:
037:         * <CODE>
038:         * helper.setDefaultDropTargetListener(aDTListener);
039:         * helper.removeDefaultDropTargetListener();
040:         * helper.registerDefaultDropTargetListener();
041:         * </CODE>
042:         * Because the DropTarget is a unicast source, you first have to remove the
043:         * old listener and the register the new. If you do not remove the listener
044:         * before adding a new one, a TooManyListenersException is thrown.
045:         * @author <a href="mailto:bfl@florianbruckner.com">Florian Bruckner</a> 
046:         * @version $Id: DropTargetHelper.java,v 1.1.2.1 2005/12/21 22:32:42 tomdz Exp $
047:         */
048:        public class DropTargetHelper {
049:            private java.awt.dnd.DropTargetListener defaultDTListener = new org.apache.ojb.tools.mapping.reversedb2.dnd2.DropTargetHelper.DTListener();
050:
051:            private DropTarget defaultDropTarget = new DropTarget();
052:
053:            private java.util.Set dropPasteWorkerSet = new java.util.HashSet();
054:
055:            /** Creates a new instance of DropTarget */
056:            public DropTargetHelper() {
057:                super ();
058:                try {
059:                    defaultDropTarget.addDropTargetListener(defaultDTListener);
060:                    defaultDropTarget.setActive(true);
061:                } catch (java.util.TooManyListenersException tmle) {
062:                    throw new RuntimeException(
063:                            "Internal Error: Drop Target already has a listener registered but this mustn't be at this stage");
064:                }
065:            }
066:
067:            /**
068:             * Remove current DropTargetListener from the DropTarget.
069:             */
070:            public void removeDefaultDropTargetListener() {
071:                defaultDropTarget.removeDropTargetListener(defaultDTListener);
072:            }
073:
074:            /** Set the current DropTargetListener as listener of the current DropTarget.
075:             * @throws TooManyListenersException
076:             */
077:            public void registerDefaultDropTargetListener()
078:                    throws java.util.TooManyListenersException {
079:                defaultDropTarget.addDropTargetListener(defaultDTListener);
080:            }
081:
082:            /** Set a new DropTargetListner this helper is going to use.
083:             * @param dtl The new DropTargetListener
084:             */
085:            public void setDefaultDropTargetListener(
086:                    java.awt.dnd.DropTargetListener dtl) {
087:                this .defaultDTListener = dtl;
088:            }
089:
090:            /** Register a new DropPasteWorkerInterface.
091:             * @param worker The new worker
092:             */
093:            public void registerDropPasteWorker(DropPasteWorkerInterface worker) {
094:                this .dropPasteWorkerSet.add(worker);
095:                defaultDropTarget.setDefaultActions(defaultDropTarget
096:                        .getDefaultActions()
097:                        | worker.getAcceptableActions(defaultDropTarget
098:                                .getComponent()));
099:            }
100:
101:            /** Remove a DropPasteWorker from the helper.
102:             * @param worker the worker that should be removed
103:             */
104:            public void removeDropPasteWorker(DropPasteWorkerInterface worker) {
105:                this .dropPasteWorkerSet.remove(worker);
106:                java.util.Iterator it = this .dropPasteWorkerSet.iterator();
107:                int newDefaultActions = 0;
108:                while (it.hasNext())
109:                    newDefaultActions |= ((DropPasteWorkerInterface) it.next())
110:                            .getAcceptableActions(defaultDropTarget
111:                                    .getComponent());
112:                defaultDropTarget.setDefaultActions(newDefaultActions);
113:            }
114:
115:            /** Get the DropTarget (to be used in Component.setDropTarget());
116:             * @return a DropTarget
117:             */
118:            public DropTarget getDropTarget() {
119:                return this .defaultDropTarget;
120:            }
121:
122:            /**
123:             * An implementation of a DropTargetListener.
124:             */
125:            public class DTListener implements  java.awt.dnd.DropTargetListener {
126:                /** see java.awt.dnd.DropTargetListener
127:                 * @param dropTargetDragEvent
128:                 */
129:                public void dragEnter(
130:                        java.awt.dnd.DropTargetDragEvent dropTargetDragEvent) {
131:                    // 1. Check which actions are supported with the given DataFlavors 
132:                    // and Components
133:                    System.err.println("DTListener.dragEnter()"
134:                            + dropTargetDragEvent);
135:                    java.util.Iterator it = dropPasteWorkerSet.iterator();
136:                    int dropTargetSupportedActions = DnDWorkerConstants.NONE;
137:                    while (it.hasNext())
138:                        dropTargetSupportedActions |= ((DropPasteWorkerInterface) it
139:                                .next()).getAcceptableActions(
140:                                dropTargetDragEvent.getDropTargetContext()
141:                                        .getComponent(), dropTargetDragEvent
142:                                        .getCurrentDataFlavors());
143:                    //            System.err.println(dropTargetDragEvent.getDropTargetContext().getTransferable().getTransferDataFlavors());
144:                    int dragSourceSupportedActions = dropTargetDragEvent
145:                            .getSourceActions();
146:                    // Check wheter current actions and acceptable actions match.
147:                    if ((dropTargetSupportedActions & dragSourceSupportedActions) != DnDWorkerConstants.NONE) {
148:                        System.err
149:                                .println("   accepting "
150:                                        + (dropTargetSupportedActions & dragSourceSupportedActions));
151:                        dropTargetDragEvent
152:                                .acceptDrag(dropTargetSupportedActions
153:                                        & dragSourceSupportedActions);
154:                    }
155:                    // No match, accept the drag with the supported drop target actions
156:                    else if (dropTargetSupportedActions != DnDWorkerConstants.NONE) {
157:                        System.err.println("   accepting "
158:                                + dropTargetSupportedActions);
159:                        dropTargetDragEvent
160:                                .acceptDrag(dropTargetSupportedActions);
161:                    }
162:                    // No import possible at all, reject the drag
163:                    else {
164:                        System.err.println("   rejecting");
165:                        dropTargetDragEvent.rejectDrag();
166:                    }
167:                }
168:
169:                /** see java.awt.dnd.DropTargetListener
170:                 * @param dropTargetEvent
171:                 */
172:                public void dragExit(
173:                        java.awt.dnd.DropTargetEvent dropTargetEvent) {
174:                    System.err.println("DTListener.dragExit()"
175:                            + dropTargetEvent);
176:                }
177:
178:                /** see java.awt.dnd.DropTargetListener
179:                 * @param dropTargetDragEvent
180:                 */
181:                public void dragOver(
182:                        java.awt.dnd.DropTargetDragEvent dropTargetDragEvent) {
183:
184:                }
185:
186:                /** see java.awt.dnd.DropTargetListener
187:                 * @param dropTargetDropEvent
188:                 */
189:                public void drop(
190:                        java.awt.dnd.DropTargetDropEvent dropTargetDropEvent) {
191:                    System.err.println("DTListener.drop()"
192:                            + dropTargetDropEvent);
193:
194:                    java.util.Iterator it = dropPasteWorkerSet.iterator();
195:                    boolean result = false;
196:
197:                    while (!result & it.hasNext()) {
198:                        DropPasteWorkerInterface worker = (DropPasteWorkerInterface) it
199:                                .next();
200:                        int acceptableActions = worker.getAcceptableActions(
201:                                dropTargetDropEvent.getDropTargetContext()
202:                                        .getComponent(), dropTargetDropEvent
203:                                        .getTransferable()
204:                                        .getTransferDataFlavors());
205:                        if ((acceptableActions & dropTargetDropEvent
206:                                .getDropAction()) != DnDWorkerConstants.NONE) {
207:                            dropTargetDropEvent.acceptDrop(acceptableActions
208:                                    & dropTargetDropEvent.getDropAction());
209:                            result = worker.importData(dropTargetDropEvent
210:                                    .getDropTargetContext().getComponent(),
211:                                    dropTargetDropEvent.getTransferable(),
212:                                    dropTargetDropEvent.getDropAction());
213:                        }
214:                    }
215:                    dropTargetDropEvent.dropComplete(result);
216:                }
217:
218:                /** see java.awt.dnd.DropTargetListener
219:                 * @param dropTargetDragEvent
220:                 * @see java.awt.dnd.DropTargetListener
221:                 */
222:                public void dropActionChanged(
223:                        java.awt.dnd.DropTargetDragEvent dropTargetDragEvent) {
224:                    System.err.println("DTListener.dragEnter()"
225:                            + dropTargetDragEvent);
226:                    dragEnter(dropTargetDragEvent);
227:                }
228:
229:            }
230:
231:        }
w___ww_.__j___a___v___a_2_s_._c___om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.