1 19 package org.openide.explorer.view; 20 21 import org.openide.nodes.Node; 22 23 import java.awt.Point ; 24 import java.awt.dnd.*; 25 26 import javax.swing.JList ; 27 28 29 33 class ListViewDragSupport extends ExplorerDragSupport { 34 36 38 39 41 42 44 45 protected ListView view; 46 47 48 protected JList list; 49 50 52 53 public ListViewDragSupport(ListView view, JList list) { 54 this.comp = list; 55 this.view = view; 56 this.list = list; 57 } 58 59 int getAllowedDropActions() { 60 return view.getAllowedDropActions(); 61 } 62 63 protected int getAllowedDragActions() { 64 return view.getAllowedDragActions(); 65 } 66 67 68 public void dragGestureRecognized(DragGestureEvent dge) { 69 super.dragGestureRecognized(dge); 70 } 71 72 78 Node[] obtainNodes(DragGestureEvent dge) { 79 Point dragOrigin = dge.getDragOrigin(); 80 int index = list.locationToIndex(dge.getDragOrigin()); 81 Object obj = list.getModel().getElementAt(index); 82 83 if (obj instanceof VisualizerNode) { 84 obj = ((VisualizerNode) obj).node; 85 } 86 87 if ((index < 0)) { 89 return null; 90 } 91 92 if (!(obj instanceof Node)) { 93 return null; 94 } 95 96 Node[] result = null; 97 98 if (list.isSelectedIndex(index)) { 99 Object [] selected = list.getSelectedValues(); 101 result = new Node[selected.length]; 102 103 for (int i = 0; i < selected.length; i++) { 104 if (selected[i] instanceof VisualizerNode) { 105 result[i] = ((VisualizerNode) selected[i]).node; 106 } else { 107 if (!(selected[i] instanceof Node)) { 108 return null; 109 } 110 111 result[i] = (Node) selected[i]; 112 } 113 } 114 } else { 115 result = new Node[] { (Node) obj }; 117 } 118 119 return result; 120 } 121 } 122 | Popular Tags |