Source Code Cross Referenced for DragableLabel.java in  » IDE-Netbeans » soa » org » netbeans » modules » soa » mapper » basicmapper » util » 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 » IDE Netbeans » soa » org.netbeans.modules.soa.mapper.basicmapper.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the terms of the Common Development
003:         * and Distribution License (the License). You may not use this file except in
004:         * compliance with the License.
005:         * 
006:         * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007:         * or http://www.netbeans.org/cddl.txt.
008:         * 
009:         * When distributing Covered Code, include this CDDL Header Notice in each file
010:         * and include the License file at http://www.netbeans.org/cddl.txt.
011:         * If applicable, add the following below the CDDL Header, with the fields
012:         * enclosed by brackets [] replaced by your own identifying information:
013:         * "Portions Copyrighted [year] [name of copyright owner]"
014:         * 
015:         * The Original Software is NetBeans. The Initial Developer of the Original
016:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017:         * Microsystems, Inc. All Rights Reserved.
018:         */
019:
020:        package org.netbeans.modules.soa.mapper.basicmapper.util;
021:
022:        import java.awt.Cursor;
023:        import java.awt.datatransfer.DataFlavor;
024:        import java.awt.datatransfer.Transferable;
025:        import java.awt.dnd.DnDConstants;
026:        import java.awt.dnd.DragGestureEvent;
027:        import java.awt.dnd.DragGestureListener;
028:        import java.awt.dnd.DragGestureRecognizer;
029:        import java.awt.dnd.DragSource;
030:        import java.awt.dnd.DragSourceDragEvent;
031:        import java.awt.dnd.DragSourceDropEvent;
032:        import java.awt.dnd.DragSourceEvent;
033:        import java.awt.dnd.DragSourceListener;
034:        import java.awt.event.MouseEvent;
035:        import java.awt.event.MouseMotionAdapter;
036:        import java.util.Collections;
037:        import java.util.HashMap;
038:        import java.util.Map;
039:
040:        import javax.swing.Icon;
041:        import javax.swing.JButton;
042:
043:        /**
044:         * <p>
045:         *
046:         * Title: </p> DragableLabel <p>
047:         *
048:         * Description: </p> DragableLabel provide a JLabel with a drag guesture
049:         * listener. <p>
050:         *
051:         * @author    Un Seng Leong
052:         * @created   December 4, 2002
053:         */
054:        public class DragableLabel extends JButton implements 
055:                DragGestureListener, Transferable {
056:
057:            /**
058:             * The default data flavor of this class.
059:             */
060:            protected static final DataFlavor DEFAULT_FLAVORS[] = new DataFlavor[1];
061:
062:            /**
063:             * Is this label draggable.
064:             */
065:            protected boolean mIsDraggable = true;
066:
067:            /**
068:             * The cursor of this drag operation. Default to copy drop cursor.
069:             */
070:            protected Cursor mDragCursor = DragSource.DefaultCopyDrop;
071:
072:            /**
073:             * data flavor and transfer object storage
074:             */
075:            protected Map dataFlavorMap;
076:
077:            /**
078:             * The default transfer data. Default reference to this object instance.
079:             */
080:            protected Object mDefaultData;
081:
082:            /**
083:             * the gesture recognizer from default drag source.
084:             */
085:            protected DragGestureRecognizer mRecognizer;
086:
087:            static {
088:                try {
089:                    DEFAULT_FLAVORS[0] = new DataFlavor(
090:                            DataFlavor.javaJVMLocalObjectMimeType);
091:                } catch (ClassNotFoundException ex) {
092:                    // ignore
093:                }
094:            }
095:
096:            /**
097:             * Creates a DragableJLabel instance with no image and with an empty string
098:             * for the title.
099:             */
100:            public DragableLabel() {
101:                super ();
102:                init();
103:            }
104:
105:            /**
106:             * Creates a DragableJLabel instance with the specified image.
107:             *
108:             * @param image  the image of this label
109:             */
110:            public DragableLabel(Icon image) {
111:                super (image);
112:                init();
113:            }
114:
115:            /**
116:             * Creates a DragableJLabel instance with the specified image and horizontal
117:             * alignment.
118:             *
119:             * @param image                the image of this label
120:             * @param horizontalAlignment  the horizontal aligmenet
121:             */
122:            public DragableLabel(Icon image, int horizontalAlignment) {
123:                super (image);
124:                this .setHorizontalAlignment(horizontalAlignment);
125:                init();
126:            }
127:
128:            /**
129:             * Creates a DragableJLabel instance with the specified text.
130:             *
131:             * @param text  the text of this label.
132:             */
133:            public DragableLabel(String text) {
134:                super (text);
135:                init();
136:            }
137:
138:            /**
139:             * Creates a DragableJLabel instance with the specified text, image, and
140:             * horizontal alignment.
141:             *
142:             * @param text                 the text of this label
143:             * @param icon                 the icon of this label.
144:             * @param horizontalAlignment  the horizontal aligment
145:             */
146:            public DragableLabel(String text, Icon icon, int horizontalAlignment) {
147:                super (text, icon);
148:                this .setHorizontalAlignment(horizontalAlignment);
149:                init();
150:            }
151:
152:            /**
153:             * Creates a DragableJLabel instance with the specified text and horizontal
154:             * alignment.
155:             *
156:             * @param text                 the text of this label
157:             * @param horizontalAlignment  the horizontal aligment
158:             */
159:            public DragableLabel(String text, int horizontalAlignment) {
160:                super (text);
161:                this .setHorizontalAlignment(horizontalAlignment);
162:                init();
163:            }
164:
165:            /**
166:             * Return the default data flavor DataFlavor.javaJVMLocalObjectMimeType. Or
167:             * null if the VM does not support DataFlavor.javaJVMLocalObjectMimeType.
168:             *
169:             * @return   the default data flavor of this drag operation.
170:             */
171:            public DataFlavor getDefaultDataFlavor() {
172:                return DEFAULT_FLAVORS[0];
173:            }
174:
175:            /**
176:             * Retrun the drag action of this dragable.
177:             *
178:             * @return   the drag action of this dragable.
179:             */
180:            public int getDragAction() {
181:                return mRecognizer.getSourceActions();
182:            }
183:
184:            /**
185:             * Retrun the cursor for this drag operation.
186:             *
187:             * @return   the cursor to display during this drag operation.
188:             */
189:            public Cursor getDragCursor() {
190:                return mDragCursor;
191:            }
192:
193:            /**
194:             * Default getTransferData implementation for Transferable.
195:             *
196:             * @param flavor  Description of the Parameter
197:             * @return        The transferData value
198:             */
199:            public Object getTransferData(DataFlavor flavor) {
200:                return dataFlavorMap.get(flavor);
201:            }
202:
203:            /**
204:             * Retrieves an array of valid data flavors.
205:             *
206:             * @return   The transferDataFlavors value
207:             */
208:            public DataFlavor[] getTransferDataFlavors() {
209:                return (DataFlavor[]) dataFlavorMap.keySet().toArray(
210:                        new DataFlavor[0]);
211:            }
212:
213:            /**
214:             * Checks whether the data flavor is supported.
215:             *
216:             * @param flavor  Description of the Parameter
217:             * @return        The dataFlavorSupported value
218:             */
219:            public boolean isDataFlavorSupported(DataFlavor flavor) {
220:                DataFlavor dataFlavors[] = this .getTransferDataFlavors();
221:
222:                if ((dataFlavors != null) && (dataFlavors.length > 0)) {
223:                    for (int i = 0; i < dataFlavors.length; i++) {
224:                        if (flavor.equals(dataFlavors[i])) {
225:                            return true;
226:                        }
227:                    }
228:                }
229:
230:                return false;
231:            }
232:
233:            /**
234:             * Determines whether this button isDraggable
235:             *
236:             * @return   The draggable value
237:             */
238:            public boolean isDraggable() {
239:                return mIsDraggable;
240:            }
241:
242:            /**
243:             * Set the default transfer data object. This object is returned when <code>getTransferData</code>
244:             * has been passed the default data flavor as its paramter. If data is null,
245:             * transfer data will be this object instance.
246:             *
247:             * @param data  the defautl transfer data for the drag operation.
248:             */
249:            public void setDefaultTransferData(Object data) {
250:                if (data == null) {
251:                    dataFlavorMap.put(getDefaultDataFlavor(), this );
252:                }
253:
254:                dataFlavorMap.put(getDefaultDataFlavor(), data);
255:            }
256:
257:            /**
258:             * Set the drag action of this label.
259:             *
260:             * @param dragAction  the drag action of this label.
261:             */
262:            public void setDragAction(int dragAction) {
263:                mRecognizer.setSourceActions(dragAction);
264:            }
265:
266:            /**
267:             * Set the cursor for this drag operation. Default to <code>DragSource.DefaultCopyDrop</code>
268:             * if dragCursor is null.
269:             *
270:             * @param dragCursor  the cursor to display during this drag operation.
271:             */
272:            public void setDragCursor(Cursor dragCursor) {
273:                if (dragCursor == null) {
274:                    mDragCursor = DragSource.DefaultCopyDrop;
275:                }
276:
277:                mDragCursor = dragCursor;
278:            }
279:
280:            /**
281:             * Sets the button's draggablity
282:             *
283:             * @param val  The new draggable value
284:             */
285:            public void setDraggable(boolean val) {
286:                mIsDraggable = val;
287:            }
288:
289:            /**
290:             * Add a data flavor for this drag action.
291:             *
292:             * @param flavor        the dataflavor of this drag action.
293:             * @param transferData  the object return by this dataflavor.
294:             */
295:            public void addDataFlavor(DataFlavor flavor, Object transferData) {
296:                dataFlavorMap.put(flavor, transferData);
297:            }
298:
299:            /**
300:             * Add a drag source listener for this drag operation.
301:             *
302:             * @param listener  the listener to be added
303:             */
304:            public void addDragSourceListener(DragSourceListener listener) {
305:                DragSource.getDefaultDragSource().addDragSourceListener(
306:                        listener);
307:            }
308:
309:            /**
310:             * DOCUMENT ME!
311:             *
312:             * @param event  Description of the Parameter
313:             */
314:            public void dragDropEnd(DragSourceDropEvent event) {
315:                setCursor(Cursor.getDefaultCursor());
316:            }
317:
318:            /**
319:             * DOCUMENT ME!
320:             *
321:             * @param event  Description of the Parameter
322:             */
323:            public void dragEnter(DragSourceDragEvent event) {
324:            }
325:
326:            /**
327:             * DOCUMENT ME!
328:             *
329:             * @param event  Description of the Parameter
330:             */
331:            public void dragExit(DragSourceEvent event) {
332:                DragableLabel.this .doClick(0);
333:
334:            }
335:
336:            /**
337:             * Default drag and drop interface implementation
338:             *
339:             * @param event  Description of the Parameter
340:             */
341:            public void dragGestureRecognized(DragGestureEvent event) {
342:                if (this .isEnabled() && this .isVisible() && this .isDraggable()) {
343:                    DragSource.getDefaultDragSource().startDrag(event,
344:                            mDragCursor, this , null);
345:
346:                }
347:            }
348:
349:            /**
350:             * DOCUMENT ME!
351:             *
352:             * @param event  Description of the Parameter
353:             */
354:            public void dragOver(DragSourceDragEvent event) {
355:            }
356:
357:            /**
358:             * DOCUMENT ME!
359:             *
360:             * @param event  Description of the Parameter
361:             */
362:            public void dropActionChanged(DragSourceDragEvent event) {
363:            }
364:
365:            /**
366:             * Remove a data flavor for this drag action.
367:             *
368:             * @param flavor  the data flavor to be removed.
369:             */
370:            public void removeDataFlavor(DataFlavor flavor) {
371:                dataFlavorMap.remove(flavor);
372:            }
373:
374:            /**
375:             * DOCUMENT ME!
376:             *
377:             * @param listener  DOCUMENT ME!
378:             */
379:            public void removeDragSourceListener(DragSourceListener listener) {
380:                DragSource.getDefaultDragSource().removeDragSourceListener(
381:                        listener);
382:            }
383:
384:            /**
385:             * Initialize this Object with the following steps: 1. initialize a
386:             * DragGestureRecognizer to start listener on the gesture. 2. set the
387:             * default transfer data to this object instance.
388:             */
389:            private void init() {
390:                mRecognizer = DragSource.getDefaultDragSource()
391:                        .createDefaultDragGestureRecognizer(this ,
392:                                DnDConstants.ACTION_COPY_OR_MOVE, this );
393:                dataFlavorMap = Collections.synchronizedMap(new HashMap());
394:                dataFlavorMap.put(DEFAULT_FLAVORS[0], this );
395:                this .addMouseMotionListener(new MouseMotionAdapter() {
396:                    public void mouseExit(MouseEvent event) {
397:                        DragableLabel.this .doClick(0);
398:                    }
399:                });
400:            }
401:        }
ww_w._j__a___va__2_s__.c___o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.