KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > grapheditor > DragOverSceneLayer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * DragOverSceneLayer.java
22  *
23  * Created on November 6, 2006, 6:08 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.wsdl.ui.view.grapheditor;
30
31 import java.awt.Image JavaDoc;
32 import java.awt.Point JavaDoc;
33 import java.awt.Rectangle JavaDoc;
34 import java.awt.datatransfer.Transferable JavaDoc;
35 import java.beans.BeanInfo JavaDoc;
36 import org.netbeans.api.visual.action.WidgetAction.WidgetDropTargetDragEvent;
37 import org.netbeans.api.visual.widget.LayerWidget;
38 import org.netbeans.api.visual.widget.Scene;
39 import org.netbeans.api.visual.widget.general.IconNodeWidget;
40 import org.netbeans.spi.palette.PaletteController;
41 import org.openide.nodes.Node;
42 import org.openide.util.Lookup;
43
44 /**
45  * Drag Layer on which icons for drag events are rendered.
46  * Need to provide methods for changing custom icon?
47  *
48  * @author radval
49  */

50 public class DragOverSceneLayer extends LayerWidget {
51
52
53     private IconNodeWidget icon;
54
55
56     /** Creates a new instance of DragOverSceneLayer */
57     public DragOverSceneLayer(Scene scene) {
58         super(scene);
59     }
60
61     public void resetLayer() {
62         removeChildren();
63         icon = null;
64         setPreferredBounds(new Rectangle JavaDoc());
65         setPreferredLocation(new Point JavaDoc());
66     }
67
68
69     public boolean dragOver(Point JavaDoc scenePoint, WidgetDropTargetDragEvent event) {
70         if (icon == null) {
71             try {
72                 Transferable JavaDoc t = event.getTransferable();
73                 if (t != null) {
74                     if (t.isDataFlavorSupported(PaletteController.ITEM_DATA_FLAVOR)) {
75                         Lookup lookup = (Lookup) t.getTransferData(
76                                 PaletteController.ITEM_DATA_FLAVOR);
77                         Node node = (Node) lookup.lookup(Node.class);
78                         icon = new IconNodeWidget(getScene(),
79                                 IconNodeWidget.TextOrientation.BOTTOM_CENTER);
80                         icon.setOpaque(false);
81                         addChild(icon);
82                         icon.setLabel(node.getName());
83                         Image JavaDoc image = node.getIcon(BeanInfo.ICON_COLOR_16x16);
84                         if (image == null) {
85                             image = node.getIcon(BeanInfo.ICON_COLOR_32x32);
86                         }
87                         if (image != null) {
88                             icon.setImage(image);
89                         }
90                         getScene().revalidate();
91                     }
92                 }
93             } catch (Exception JavaDoc e) {
94             }
95         }
96         if (icon != null) {
97             icon.setPreferredLocation(convertSceneToLocal(scenePoint));
98         }
99         return false;
100     }
101 }
102
Popular Tags