Revision 35646 branches/gvSIG_1.11.0_Mejoras_gvSIG-EIEL/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/DnDJTree.java
DnDJTree.java | ||
---|---|---|
59 | 59 |
*/ |
60 | 60 |
|
61 | 61 |
|
62 |
import java.awt.Component; |
|
63 |
import java.awt.Dimension; |
|
62 | 64 |
import java.awt.Point; |
63 | 65 |
import java.awt.datatransfer.Transferable; |
64 | 66 |
import java.awt.datatransfer.UnsupportedFlavorException; |
... | ... | |
89 | 91 |
import javax.swing.tree.DefaultMutableTreeNode; |
90 | 92 |
import javax.swing.tree.DefaultTreeModel; |
91 | 93 |
import javax.swing.tree.MutableTreeNode; |
94 |
import javax.swing.tree.TreeCellRenderer; |
|
92 | 95 |
import javax.swing.tree.TreeModel; |
93 | 96 |
import javax.swing.tree.TreeNode; |
94 | 97 |
import javax.swing.tree.TreePath; |
... | ... | |
97 | 100 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
98 | 101 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
99 | 102 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
103 |
import com.iver.cit.gvsig.project.documents.view.toc.gui.TOCRenderer; |
|
104 |
import com.iver.cit.gvsig.project.documents.view.toc.util.DropTargetInfo; |
|
100 | 105 |
|
101 | 106 |
public class DnDJTree extends JTree |
102 | 107 |
implements TreeSelectionListener, |
... | ... | |
121 | 126 |
//private ArrayList treeListeners=new ArrayList(); |
122 | 127 |
//private ArrayList dropListeners=new ArrayList(); |
123 | 128 |
// private TreeModel model1; |
129 |
|
|
130 |
|
|
124 | 131 |
/** Constructor |
125 | 132 |
@param root The root node of the tree |
126 | 133 |
@param parent Parent JFrame of the JTree */ |
... | ... | |
227 | 234 |
//begin the drag |
228 | 235 |
oDnDtocOrigin = this; |
229 | 236 |
dragSource.startDrag(e, null, transferable, this); |
237 |
|
|
238 |
System.out.println("+++ dragGestureRecognized"); |
|
230 | 239 |
} |
231 | 240 |
} |
232 | 241 |
|
233 | 242 |
/** DragSourceListener interface method */ |
234 | 243 |
public void dragDropEnd(DragSourceDropEvent dsde) { |
244 |
showEvent("DRAG DROP END", dsde); |
|
245 |
clearGraphicTarget(); |
|
235 | 246 |
} |
236 | 247 |
|
237 | 248 |
/** DragSourceListener interface method */ |
238 | 249 |
public void dragEnter(DragSourceDragEvent dsde) { |
250 |
showEvent("DRAG ENTER", dsde); |
|
239 | 251 |
/* ********************** CHANGED ********************** */ |
240 | 252 |
// System.err.println("dragOver" + dsde.getDragSourceContext().getComponent()); |
241 | 253 |
|
... | ... | |
244 | 256 |
|
245 | 257 |
/** DragSourceListener interface method */ |
246 | 258 |
public void dragOver(DragSourceDragEvent dsde) { |
247 |
/* ********************** CHANGED ********************** */ |
|
248 |
// System.err.println("dragOver" + dsde.getDragSourceContext().getComponent()); |
|
249 |
/* ****************** END OF CHANGE ******************** */ |
|
259 |
Point screen_loc = dsde.getLocation(); |
|
260 |
Point loc = (Point) screen_loc.clone(); |
|
261 |
SwingUtilities.convertPointFromScreen(loc, this); |
|
262 |
// TreePath auxDragTarget = getPathForLocation(loc.x, loc.y); |
|
263 |
|
|
264 |
TreePath auxDragTarget = getPathForLocation(loc.x, loc.y); |
|
265 |
if (auxDragTarget == null) { |
|
266 |
return; |
|
267 |
} |
|
268 |
TreeCellRenderer tcr = getCellRenderer(); |
|
269 |
TOCRenderer tocr = null; |
|
270 |
if (tcr instanceof TOCRenderer) { |
|
271 |
tocr = (TOCRenderer) tcr; |
|
272 |
} else { |
|
273 |
return; |
|
274 |
} |
|
275 |
|
|
276 |
|
|
277 |
DefaultMutableTreeNode dmtn = |
|
278 |
(DefaultMutableTreeNode) auxDragTarget.getLastPathComponent(); |
|
279 |
|
|
280 |
Object obj = dmtn.getUserObject(); |
|
281 |
if (obj instanceof ITocItem) { |
|
282 |
ITocItem toc_it = (ITocItem) obj; |
|
283 |
DropTargetInfo dti = new DropTargetInfo(toc_it, screen_loc); |
|
284 |
tocr.setGraphicIndicatorInfo(dti); |
|
285 |
this.repaint(); |
|
286 |
} |
|
250 | 287 |
} |
251 | 288 |
|
289 |
private void clearGraphicTarget() { |
|
290 |
TreeCellRenderer tcr = getCellRenderer(); |
|
291 |
TOCRenderer tocr = null; |
|
292 |
if (tcr instanceof TOCRenderer) { |
|
293 |
tocr = (TOCRenderer) tcr; |
|
294 |
tocr.setGraphicIndicatorInfo(null); |
|
295 |
} else { |
|
296 |
return; |
|
297 |
} |
|
298 |
|
|
299 |
|
|
300 |
} |
|
301 |
|
|
302 |
|
|
252 | 303 |
/** DragSourceListener interface method */ |
253 | 304 |
public void dropActionChanged(DragSourceDragEvent dsde) { |
305 |
showEvent("DROP ACT CHANGED", dsde); |
|
254 | 306 |
} |
255 | 307 |
|
256 | 308 |
/** DragSourceListener interface method */ |
257 | 309 |
public void dragExit(DragSourceEvent dsde) { |
310 |
showEvent("DRAG EXIT", dsde); |
|
258 | 311 |
} |
259 | 312 |
|
313 |
private void showEvent(String msg, DragSourceEvent ev) { |
|
314 |
|
|
315 |
System.out.println("+++ " + msg + ": " + ev.getDragSourceContext().getComponent()); |
|
316 |
Point loc = ev.getLocation(); |
|
317 |
SwingUtilities.convertPointFromScreen(loc, this); |
|
318 |
TreePath destinationPath = getPathForLocation(loc.x, loc.y); |
|
319 |
System.out.println(" dest (" + loc.x + " , " + loc.y + "): " + |
|
320 |
(destinationPath == null ? "NULL" : destinationPath.toString())); |
|
321 |
} |
|
322 |
|
|
260 | 323 |
/** DropTargetListener interface method - What we do when drag is released */ |
261 | 324 |
public void drop(DropTargetDropEvent e) { |
262 | 325 |
try { |
... | ... | |
269 | 332 |
//get new parent node |
270 | 333 |
Point loc = e.getLocation(); |
271 | 334 |
TreePath destinationPath = getPathForLocation(loc.x, loc.y); |
335 |
|
|
336 |
|
|
337 |
System.out.println("+++ " + "DROP"); |
|
338 |
System.out.println(" dest (" + loc.x + " , " + loc.y + "): " + |
|
339 |
(destinationPath == null ? "NULL" : destinationPath.toString())); |
|
272 | 340 |
|
341 |
|
|
342 |
|
|
273 | 343 |
final String msg = testDropTarget(destinationPath, SelectedTreePath); |
274 | 344 |
if (msg != null) { |
275 | 345 |
/* if (testSameComponent()) |
... | ... | |
280 | 350 |
System.err.println(msg); |
281 | 351 |
} |
282 | 352 |
}); |
353 |
clearGraphicTarget(); |
|
283 | 354 |
return; |
284 | 355 |
/* } |
285 | 356 |
else |
... | ... | |
297 | 368 |
if (!testSameComponent(e)) |
298 | 369 |
{ |
299 | 370 |
e.rejectDrop(); |
371 |
clearGraphicTarget(); |
|
300 | 372 |
return; |
301 | 373 |
} |
302 | 374 |
int oldPos,newPos; |
... | ... | |
307 | 379 |
// get old parent node |
308 | 380 |
DefaultMutableTreeNode oldParent = (DefaultMutableTreeNode) getSelectedNode().getParent(); |
309 | 381 |
if (nodoTocado.getParent().equals(getSelectedNode())){ |
382 |
clearGraphicTarget(); |
|
310 | 383 |
return; |
311 | 384 |
} |
312 | 385 |
//oldParent.setUserObject(new TocItemBranch(((TocItemBranch)getSelectedNode().getUserObject()).getLayer().getParentLayer())); |
313 |
if (oldParent==null) |
|
386 |
if (oldParent==null) { |
|
387 |
clearGraphicTarget(); |
|
314 | 388 |
return; |
389 |
} |
|
390 |
|
|
315 | 391 |
oldPos = oldParent.getIndex(getSelectedNode()); |
316 | 392 |
// Para no tener en cuenta los nodos de s?mbolos: |
317 | 393 |
if (!(nodoTocado.getUserObject() instanceof TocItemBranch)){ |
... | ... | |
405 | 481 |
|
406 | 482 |
catch (IOException io) { e.rejectDrop(); } |
407 | 483 |
catch (UnsupportedFlavorException ufe) {e.rejectDrop();} |
484 |
|
|
485 |
clearGraphicTarget(); |
|
486 |
|
|
408 | 487 |
} //end of method |
409 | 488 |
public void dropRoot(TreeNode tn){ |
410 | 489 |
int oldPos,newPos; |
Also available in: Unified diff