svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / toc / DnDJTree.java @ 40558
History | View | Annotate | Download (20.4 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/*
|
25 |
* Created on 02-jun-2004
|
26 |
*
|
27 |
*/
|
28 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
29 |
*
|
30 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
31 |
*
|
32 |
* This program is free software; you can redistribute it and/or
|
33 |
* modify it under the terms of the GNU General Public License
|
34 |
* as published by the Free Software Foundation; either version 2
|
35 |
* of the License, or (at your option) any later version.
|
36 |
*
|
37 |
* This program is distributed in the hope that it will be useful,
|
38 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
39 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
40 |
* GNU General Public License for more details.
|
41 |
*
|
42 |
* You should have received a copy of the GNU General Public License
|
43 |
* along with this program; if not, write to the Free Software
|
44 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
45 |
*
|
46 |
* For more information, contact:
|
47 |
*
|
48 |
* Generalitat Valenciana
|
49 |
* Conselleria d'Infraestructures i Transport
|
50 |
* Av. Blasco Ib??ez, 50
|
51 |
* 46010 VALENCIA
|
52 |
* SPAIN
|
53 |
*
|
54 |
* +34 963862235
|
55 |
* gvsig@gva.es
|
56 |
* www.gvsig.gva.es
|
57 |
*
|
58 |
* or
|
59 |
*
|
60 |
* IVER T.I. S.A
|
61 |
* Salamanca 50
|
62 |
* 46005 Valencia
|
63 |
* Spain
|
64 |
*
|
65 |
* +34 963163400
|
66 |
* dac@iver.es
|
67 |
*/
|
68 |
package org.gvsig.app.project.documents.view.toc; |
69 |
/*
|
70 |
** This is version II of DnDJTree. The first version allowed for what I
|
71 |
** thought was a JDK oversight. However, we can set the cursor appropriately,
|
72 |
** relative to whether the current cursor location is a valid drop target.
|
73 |
**
|
74 |
** If this is your first time reading the source code. Just ignore the above
|
75 |
** comment and ignore the "CHANGED" comments below. Otherwise, the
|
76 |
** "CHANGED" comments will show where the code has changed.
|
77 |
**
|
78 |
** Credit for finding this shortcoming in my code goes Laurent Hubert.
|
79 |
** Thanks Laurent.
|
80 |
**
|
81 |
** Rob. [ rkenworthy@hotmail.com ]
|
82 |
*/
|
83 |
|
84 |
|
85 |
import java.awt.Point; |
86 |
import java.awt.datatransfer.Transferable; |
87 |
import java.awt.datatransfer.UnsupportedFlavorException; |
88 |
import java.awt.dnd.DnDConstants; |
89 |
import java.awt.dnd.DragGestureEvent; |
90 |
import java.awt.dnd.DragGestureListener; |
91 |
import java.awt.dnd.DragGestureRecognizer; |
92 |
import java.awt.dnd.DragSource; |
93 |
import java.awt.dnd.DragSourceDragEvent; |
94 |
import java.awt.dnd.DragSourceDropEvent; |
95 |
import java.awt.dnd.DragSourceEvent; |
96 |
import java.awt.dnd.DragSourceListener; |
97 |
import java.awt.dnd.DropTarget; |
98 |
import java.awt.dnd.DropTargetDragEvent; |
99 |
import java.awt.dnd.DropTargetDropEvent; |
100 |
import java.awt.dnd.DropTargetEvent; |
101 |
import java.awt.dnd.DropTargetListener; |
102 |
import java.awt.dnd.MouseDragGestureRecognizer; |
103 |
import java.awt.event.InputEvent; |
104 |
import java.awt.event.MouseEvent; |
105 |
import java.io.IOException; |
106 |
import java.util.ArrayList; |
107 |
|
108 |
import javax.swing.JTree; |
109 |
import javax.swing.SwingUtilities; |
110 |
import javax.swing.event.TreeSelectionEvent; |
111 |
import javax.swing.event.TreeSelectionListener; |
112 |
import javax.swing.tree.DefaultMutableTreeNode; |
113 |
import javax.swing.tree.DefaultTreeModel; |
114 |
import javax.swing.tree.MutableTreeNode; |
115 |
import javax.swing.tree.TreeModel; |
116 |
import javax.swing.tree.TreeNode; |
117 |
import javax.swing.tree.TreePath; |
118 |
|
119 |
import org.gvsig.andami.PluginServices; |
120 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
121 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
122 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
123 |
|
124 |
|
125 |
public class DnDJTree extends JTree |
126 |
implements TreeSelectionListener, |
127 |
DragGestureListener, DropTargetListener, |
128 |
DragSourceListener {
|
129 |
|
130 |
protected ArrayList m_Listeners = new ArrayList(); |
131 |
|
132 |
private static DnDJTree oDnDtocOrigin = null; |
133 |
private static DnDJTree oDnDtocDestination = null; |
134 |
/** Stores the parent Frame of the component */
|
135 |
// private Frame Parent = null;
|
136 |
|
137 |
/** Stores the selected node info */
|
138 |
protected TreePath SelectedTreePath = null; |
139 |
protected DefaultMutableTreeNode SelectedNode = null; |
140 |
|
141 |
/** Variables needed for DnD */
|
142 |
private DragSource dragSource = null; |
143 |
//private DragSourceContext dragSourceContext = null;
|
144 |
private DropTarget dropTarget; |
145 |
//private ArrayList treeListeners=new ArrayList();
|
146 |
//private ArrayList dropListeners=new ArrayList();
|
147 |
// private TreeModel model1;
|
148 |
/** Constructor
|
149 |
@param root The root node of the tree
|
150 |
@param parent Parent JFrame of the JTree */
|
151 |
public DnDJTree(TreeModel treeModel) { |
152 |
super(treeModel);
|
153 |
// Parent = parent;
|
154 |
|
155 |
//addTreeSelectionListener(this);
|
156 |
|
157 |
/* ********************** CHANGED ********************** */
|
158 |
dragSource = DragSource.getDefaultDragSource() ;
|
159 |
/* ****************** END OF CHANGE ******************** */
|
160 |
|
161 |
DragGestureRecognizer dgr =
|
162 |
dragSource.createDefaultDragGestureRecognizer( |
163 |
this, //DragSource |
164 |
DnDConstants.ACTION_COPY_OR_MOVE, //specifies valid actions |
165 |
this //DragGestureListener |
166 |
); |
167 |
|
168 |
|
169 |
/* Eliminates right mouse clicks as valid actions - useful especially
|
170 |
* if you implement a JPopupMenu for the JTree
|
171 |
*/
|
172 |
dgr.setSourceActions(dgr.getSourceActions() & ~InputEvent.BUTTON3_MASK);
|
173 |
|
174 |
/* First argument: Component to associate the target with
|
175 |
* Second argument: DropTargetListener
|
176 |
*/
|
177 |
//DropTarget dropTarget = new DropTarget(this, this);
|
178 |
setDropTarget(); |
179 |
} |
180 |
public void invalidateListeners(){ |
181 |
removeDropListener(); |
182 |
removeTreeListener(); |
183 |
} |
184 |
private void addDropListener(){ |
185 |
dropTarget= new DropTarget(this, this); |
186 |
} |
187 |
private void removeDropListener(){ |
188 |
dropTarget=null;
|
189 |
} |
190 |
private void addTreeListener(){ |
191 |
addTreeSelectionListener(this);
|
192 |
} |
193 |
private void removeTreeListener(){ |
194 |
removeTreeSelectionListener(this);
|
195 |
} |
196 |
public void setDropTarget(){ |
197 |
// TODO: COMENTADO POR FJP
|
198 |
/* com.iver.andami.ui.mdiManager.View[] views=PluginServices.getMDIManager().getAllViews();
|
199 |
for(int i=0;i<views.length;i++){
|
200 |
if (views[i] instanceof View){
|
201 |
// model1=((View)views[i]).getTOC().getTree().getModel();
|
202 |
((View)views[i]).getTOC().getTree().removeTreeListener();
|
203 |
((View)views[i]).getTOC().getTree().addTreeListener();
|
204 |
((View)views[i]).getTOC().getTree().removeDropListener();
|
205 |
((View)views[i]).getTOC().getTree().addDropListener();
|
206 |
} */
|
207 |
addTreeListener(); |
208 |
addDropListener(); |
209 |
// }
|
210 |
////////// new DropTarget(this, this);
|
211 |
} |
212 |
/** Returns The selected node */
|
213 |
public DefaultMutableTreeNode getSelectedNode() { |
214 |
return SelectedNode;
|
215 |
} |
216 |
|
217 |
///////////////////////// Interface stuff ////////////////////
|
218 |
|
219 |
|
220 |
/** DragGestureListener interface method */
|
221 |
public void dragGestureRecognized(DragGestureEvent e) { |
222 |
if (((MouseEvent)((MouseDragGestureRecognizer)e.getSource()).getTriggerEvent()).getButton()==MouseEvent.BUTTON3){ |
223 |
return;
|
224 |
} |
225 |
//Get the selected node
|
226 |
DefaultMutableTreeNode dragNode = getSelectedNode();
|
227 |
if (dragNode != null) { |
228 |
|
229 |
|
230 |
if (!(dragNode.getUserObject() instanceof Transferable)) { |
231 |
return;
|
232 |
} |
233 |
|
234 |
// Get the Transferable Object
|
235 |
Transferable transferable = (Transferable) dragNode.getUserObject(); |
236 |
|
237 |
/* ********************** CHANGED ********************** */
|
238 |
|
239 |
//Select the appropriate cursor;
|
240 |
// Cursor cursor = DragSource.DefaultCopyNoDrop;
|
241 |
int action = e.getDragAction();
|
242 |
/* if (action == DnDConstants.ACTION_MOVE)
|
243 |
cursor = DragSource.DefaultMoveDrop; */
|
244 |
|
245 |
|
246 |
//In fact the cursor is set to NoDrop because once an action is rejected
|
247 |
// by a dropTarget, the dragSourceListener are no more invoked.
|
248 |
// Setting the cursor to no drop by default is so more logical, because
|
249 |
// when the drop is accepted by a component, then the cursor is changed by the
|
250 |
// dropActionChanged of the default DragSource.
|
251 |
/* ****************** END OF CHANGE ******************** */
|
252 |
|
253 |
//begin the drag
|
254 |
oDnDtocOrigin = this;
|
255 |
dragSource.startDrag(e, null, transferable, this); |
256 |
} |
257 |
} |
258 |
|
259 |
/** DragSourceListener interface method */
|
260 |
public void dragDropEnd(DragSourceDropEvent dsde) { |
261 |
} |
262 |
|
263 |
/** DragSourceListener interface method */
|
264 |
public void dragEnter(DragSourceDragEvent dsde) { |
265 |
/* ********************** CHANGED ********************** */
|
266 |
// System.err.println("dragOver" + dsde.getDragSourceContext().getComponent());
|
267 |
|
268 |
/* ****************** END OF CHANGE ******************** */
|
269 |
} |
270 |
|
271 |
/** DragSourceListener interface method */
|
272 |
public void dragOver(DragSourceDragEvent dsde) { |
273 |
/* ********************** CHANGED ********************** */
|
274 |
// System.err.println("dragOver" + dsde.getDragSourceContext().getComponent());
|
275 |
/* ****************** END OF CHANGE ******************** */
|
276 |
} |
277 |
|
278 |
/** DragSourceListener interface method */
|
279 |
public void dropActionChanged(DragSourceDragEvent dsde) { |
280 |
} |
281 |
|
282 |
/** DragSourceListener interface method */
|
283 |
public void dragExit(DragSourceEvent dsde) { |
284 |
} |
285 |
|
286 |
/** DropTargetListener interface method - What we do when drag is released */
|
287 |
public void drop(DropTargetDropEvent e) { |
288 |
try {
|
289 |
Transferable tr = e.getTransferable();
|
290 |
//flavor not supported, reject drop
|
291 |
if (!tr.isDataFlavorSupported( TocItemBranch.INFO_FLAVOR)) {
|
292 |
e.rejectDrop(); |
293 |
} |
294 |
//cast into appropriate data type
|
295 |
TocItemBranch childInfo = |
296 |
(TocItemBranch) tr.getTransferData( TocItemBranch.INFO_FLAVOR ); |
297 |
//get new parent node
|
298 |
Point loc = e.getLocation();
|
299 |
TreePath destinationPath = getPathForLocation(loc.x, loc.y);
|
300 |
|
301 |
final String msg = testDropTarget(destinationPath, SelectedTreePath); |
302 |
if (msg != null) { |
303 |
/* if (testSameComponent())
|
304 |
{ */
|
305 |
e.rejectDrop(); |
306 |
SwingUtilities.invokeLater(new Runnable() { |
307 |
public void run() { |
308 |
System.err.println(msg);
|
309 |
} |
310 |
}); |
311 |
return;
|
312 |
/* }
|
313 |
else
|
314 |
{
|
315 |
// TODO: Por ahora solo dejamos mover, no copiar
|
316 |
// TODO: ?Y qu? pasa si la vista a la que vamos
|
317 |
// no tiene la misma proyecci?n? MEJOR DESHABILITO ESTO POR AHORA
|
318 |
if (e.getDropAction() == DnDConstants.ACTION_MOVE)
|
319 |
dropRoot(SelectedNode);
|
320 |
else
|
321 |
e.rejectDrop();
|
322 |
return;
|
323 |
} */
|
324 |
} |
325 |
if (!testSameComponent(e))
|
326 |
{ |
327 |
e.rejectDrop(); |
328 |
return;
|
329 |
} |
330 |
int oldPos,newPos;
|
331 |
//boolean isContainer=false;
|
332 |
|
333 |
DefaultMutableTreeNode nodoTocado =
|
334 |
(DefaultMutableTreeNode) destinationPath.getLastPathComponent();
|
335 |
// get old parent node
|
336 |
DefaultMutableTreeNode oldParent = (DefaultMutableTreeNode) getSelectedNode().getParent(); |
337 |
if (nodoTocado.getParent().equals(getSelectedNode())){
|
338 |
return;
|
339 |
} |
340 |
//oldParent.setUserObject(new TocItemBranch(((TocItemBranch)getSelectedNode().getUserObject()).getLayer().getParentLayer()));
|
341 |
if (oldParent==null) { |
342 |
return;
|
343 |
} |
344 |
oldPos = oldParent.getIndex(getSelectedNode()); |
345 |
// Para no tener en cuenta los nodos de s?mbolos:
|
346 |
if (!(nodoTocado.getUserObject() instanceof TocItemBranch)){ |
347 |
nodoTocado = (DefaultMutableTreeNode) nodoTocado.getParent();
|
348 |
} |
349 |
|
350 |
///posActual = oldParent.getIndex(getSelectedNode());
|
351 |
//Destino
|
352 |
DefaultMutableTreeNode destParent=null; |
353 |
|
354 |
if (((TocItemBranch)nodoTocado.getUserObject()).getLayer() instanceof FLayers){ |
355 |
//isContainer=true;
|
356 |
newPos=0;
|
357 |
destParent=nodoTocado; |
358 |
}else{//Si donde se deja la capa seleccionada no es un contenedor de capas. |
359 |
destParent= (DefaultMutableTreeNode)nodoTocado.getParent();
|
360 |
newPos=destParent.getIndex(nodoTocado); |
361 |
} |
362 |
|
363 |
|
364 |
|
365 |
|
366 |
int action = e.getDropAction();
|
367 |
boolean copyAction = (action == DnDConstants.ACTION_COPY); |
368 |
|
369 |
//make new child node
|
370 |
DefaultMutableTreeNode newChild = new DefaultMutableTreeNode(childInfo); |
371 |
if (getSelectedNode().getAllowsChildren()){
|
372 |
int childs=getSelectedNode().getChildCount();
|
373 |
|
374 |
for (int i=0;i<childs;i++){ |
375 |
newChild.add((MutableTreeNode)getSelectedNode().getChildAt(0)); |
376 |
} |
377 |
} |
378 |
|
379 |
try {
|
380 |
if (!copyAction){
|
381 |
oldParent.remove(getSelectedNode()); |
382 |
destParent.insert(newChild,newPos); |
383 |
// newParent.add(newChild);
|
384 |
} |
385 |
if (copyAction) {
|
386 |
e.acceptDrop (DnDConstants.ACTION_COPY);
|
387 |
} else {
|
388 |
e.acceptDrop (DnDConstants.ACTION_MOVE);
|
389 |
} |
390 |
} |
391 |
catch (java.lang.IllegalStateException ils) {
|
392 |
e.rejectDrop(); |
393 |
} |
394 |
|
395 |
e.getDropTargetContext().dropComplete(true);
|
396 |
|
397 |
//expand nodes appropriately - this probably isnt the best way...
|
398 |
|
399 |
// TODO: COMENTADO POR FJP
|
400 |
/* com.iver.andami.ui.mdiManager.View[] views=PluginServices.getMDIManager().getAllViews();
|
401 |
for(int i=0;i<views.length;i++){
|
402 |
if (views[i] instanceof View){
|
403 |
((DefaultTreeModel)((View)views[i]).getTOC().getTree().getModel()).reload(oldParent);
|
404 |
}
|
405 |
} */
|
406 |
|
407 |
|
408 |
|
409 |
// ((DefaultTreeModel)model1).reload(oldParent);
|
410 |
DefaultTreeModel model = (DefaultTreeModel) getModel(); |
411 |
|
412 |
model.reload(getSelectedNode().getRoot()); |
413 |
FLayers lpo=null;
|
414 |
FLayers lpd=null;
|
415 |
|
416 |
if (oldParent.getUserObject() instanceof TocItemBranch){ |
417 |
lpo=(FLayers)((TocItemBranch)oldParent.getUserObject()).getLayer(); |
418 |
//lpd=(FLayers)((TocItemBranch)destParent.getUserObject()).getLayer();
|
419 |
}/*else if (((TocItemBranch)nodoTocado.getUserObject()).getLayer().getParentLayer()!=null){
|
420 |
lpo=((TocItemBranch)nodoTocado.getUserObject()).getLayer().getParentLayer();
|
421 |
}*/else{ |
422 |
lpo=((TocItemBranch)getSelectedNode().getUserObject()).getLayer().getParentLayer(); |
423 |
} |
424 |
if (destParent.getUserObject() instanceof TocItemBranch){ |
425 |
lpd=(FLayers)((TocItemBranch)destParent.getUserObject()).getLayer(); |
426 |
}else{
|
427 |
lpd=((TocItemBranch)nodoTocado.getUserObject()).getLayer().getParentLayer(); |
428 |
} |
429 |
|
430 |
|
431 |
if (destParent.equals(oldParent)){
|
432 |
callListeners(oldPos,newPos,lpd); |
433 |
}else{
|
434 |
callListeners(lpo,lpd,((TocItemBranch)newChild.getUserObject()).getLayer()); |
435 |
} |
436 |
} |
437 |
|
438 |
catch (IOException io) { e.rejectDrop(); } |
439 |
catch (UnsupportedFlavorException ufe) {e.rejectDrop();} |
440 |
} //end of method
|
441 |
public void dropRoot(TreeNode tn){ |
442 |
int oldPos,newPos;
|
443 |
DefaultMutableTreeNode nodoTocado =
|
444 |
(DefaultMutableTreeNode) tn;
|
445 |
// get old parent node
|
446 |
if (getSelectedNode()==null) { |
447 |
return;
|
448 |
} |
449 |
DefaultMutableTreeNode oldParent = (DefaultMutableTreeNode) getSelectedNode().getParent(); |
450 |
if (oldParent!=null){ |
451 |
oldPos = oldParent.getIndex(getSelectedNode()); |
452 |
//Destino
|
453 |
DefaultMutableTreeNode destParent=null; |
454 |
newPos=0;
|
455 |
destParent=nodoTocado; |
456 |
|
457 |
//make new child node
|
458 |
DefaultMutableTreeNode newChild = (DefaultMutableTreeNode)getSelectedNode().clone(); |
459 |
oldParent.remove(getSelectedNode()); |
460 |
destParent.insert(newChild,newPos); |
461 |
|
462 |
org.gvsig.andami.ui.mdiManager.IWindow[] views=PluginServices.getMDIManager().getAllWindows();
|
463 |
for(int i=0;i<views.length;i++){ |
464 |
if (views[i] instanceof DefaultViewPanel){ |
465 |
((DefaultTreeModel)((DefaultViewPanel)views[i]).getTOC().getTree().getModel()).reload(oldParent);
|
466 |
} |
467 |
} |
468 |
// ((DefaultTreeModel)model1).reload(oldParent);
|
469 |
DefaultTreeModel model = (DefaultTreeModel) getModel(); |
470 |
model.reload(destParent); |
471 |
FLayers lpo=null;
|
472 |
FLayers lpd=null;
|
473 |
|
474 |
lpo=((TocItemBranch)getSelectedNode().getUserObject()).getLayer().getParentLayer(); |
475 |
for(int i=0;i<views.length;i++){ |
476 |
if (views[i] instanceof DefaultViewPanel){ |
477 |
if (((DefaultViewPanel)views[i]).getTOC().getTree().equals(this)){ |
478 |
lpd= ((DefaultViewPanel)views[i]).getMapControl().getMapContext().getLayers(); |
479 |
} |
480 |
} |
481 |
} |
482 |
if (destParent.equals(oldParent)){
|
483 |
callListeners(oldPos,newPos,lpd); |
484 |
}else{
|
485 |
callListeners(lpo,lpd,((TocItemBranch)newChild.getUserObject()).getLayer()); |
486 |
} |
487 |
} |
488 |
} |
489 |
|
490 |
/** DropTaregetListener interface method */
|
491 |
public void dragEnter(DropTargetDragEvent e) { |
492 |
} |
493 |
|
494 |
/** DropTaregetListener interface method */
|
495 |
public void dragExit(DropTargetEvent e) { |
496 |
} |
497 |
|
498 |
/** DropTaregetListener interface method */
|
499 |
public void dragOver(DropTargetDragEvent e) { |
500 |
/* ********************** CHANGED ********************** */
|
501 |
//set cursor location. Needed in setCursor method
|
502 |
Point cursorLocationBis = e.getLocation();
|
503 |
TreePath destinationPath =
|
504 |
getPathForLocation(cursorLocationBis.x, cursorLocationBis.y); |
505 |
|
506 |
|
507 |
// if destination path is okay accept drop...
|
508 |
|
509 |
if (testSameComponent(e))
|
510 |
{ |
511 |
String msg = testDropTarget(destinationPath, SelectedTreePath);
|
512 |
if ( msg == null) { |
513 |
e.acceptDrag(DnDConstants.ACTION_MOVE) ;
|
514 |
return;
|
515 |
} |
516 |
|
517 |
} |
518 |
// ...otherwise reject drop
|
519 |
// else {
|
520 |
// System.err.println(e.getDropTargetContext().getComponent());
|
521 |
|
522 |
// if (testSameComponent(e))
|
523 |
e.rejectDrag() ; |
524 |
/* else
|
525 |
e.acceptDrag(DnDConstants.ACTION_MOVE); */
|
526 |
// }
|
527 |
/* ****************** END OF CHANGE ******************** */
|
528 |
} |
529 |
|
530 |
/** DropTaregetListener interface method */
|
531 |
public void dropActionChanged(DropTargetDragEvent e) { |
532 |
} |
533 |
private void setSelectedNode(DefaultMutableTreeNode smtn){ |
534 |
if (smtn!=null) { |
535 |
SelectedNode=smtn; |
536 |
} |
537 |
} |
538 |
|
539 |
/** TreeSelectionListener - sets selected node */
|
540 |
public void valueChanged(TreeSelectionEvent evt) { |
541 |
SelectedTreePath = evt.getNewLeadSelectionPath(); |
542 |
/* com.iver.andami.ui.mdiManager.View[] views=PluginServices.getMDIManager().getAllViews();
|
543 |
for(int i=0;i<views.length;i++){
|
544 |
if (views[i] instanceof View){
|
545 |
if (SelectedTreePath == null) {
|
546 |
((View)views[i]).getTOC().getTree().setSelectedNode(null);
|
547 |
}else{
|
548 |
((View)views[i]).getTOC().getTree().setSelectedNode((DefaultMutableTreeNode)SelectedTreePath.getLastPathComponent());
|
549 |
}
|
550 |
}
|
551 |
} */
|
552 |
if (SelectedTreePath == null){ |
553 |
setSelectedNode(null);
|
554 |
}else{
|
555 |
setSelectedNode((DefaultMutableTreeNode)SelectedTreePath.getLastPathComponent());
|
556 |
} |
557 |
} |
558 |
|
559 |
/** Convenience method to test whether drop location is valid
|
560 |
@param destination The destination path
|
561 |
@param dropper The path for the node to be dropped
|
562 |
@return null if no problems, otherwise an explanation
|
563 |
*/
|
564 |
private String testDropTarget(TreePath destination, TreePath dropper) { |
565 |
//Typical Tests for dropping
|
566 |
|
567 |
//Test 1.
|
568 |
boolean destinationPathIsNull = destination == null; |
569 |
if (destinationPathIsNull) {
|
570 |
return "Invalid drop location."; |
571 |
} |
572 |
|
573 |
//Test 2.
|
574 |
DefaultMutableTreeNode node = (DefaultMutableTreeNode) destination.getLastPathComponent(); |
575 |
if ( !node.getAllowsChildren() ) {
|
576 |
return "This node does not allow children"; |
577 |
} |
578 |
|
579 |
if (destination.equals(dropper)) {
|
580 |
return "Destination cannot be same as source"; |
581 |
} |
582 |
|
583 |
//Test 3.
|
584 |
/* if ( dropper.isDescendant(destination))
|
585 |
return "Destination node cannot be a descendant.";
|
586 |
|
587 |
//Test 4.
|
588 |
if ( dropper.getParentPath().equals(destination))
|
589 |
return "Destination node cannot be a parent."; */
|
590 |
|
591 |
return null; |
592 |
} |
593 |
|
594 |
private boolean testSameComponent(DropTargetEvent e) |
595 |
{ |
596 |
oDnDtocDestination = this;
|
597 |
return (oDnDtocOrigin == oDnDtocDestination);
|
598 |
} |
599 |
/**
|
600 |
* @param arg0
|
601 |
* @return
|
602 |
*/
|
603 |
public boolean addOrderListener(ITocOrderListener arg0) { |
604 |
return m_Listeners.add(arg0);
|
605 |
} |
606 |
/**
|
607 |
* @param arg0
|
608 |
* @return
|
609 |
*/
|
610 |
public boolean removeOrderListener(ITocOrderListener arg0) { |
611 |
return m_Listeners.remove(arg0);
|
612 |
} |
613 |
private void callListeners(int oldPos, int newPos,FLayers lpd) |
614 |
{ |
615 |
for (int i=0; i < m_Listeners.size(); i++) |
616 |
{ |
617 |
ITocOrderListener listener = (ITocOrderListener) m_Listeners.get(i); |
618 |
listener.orderChanged(oldPos, newPos,lpd); |
619 |
} |
620 |
} |
621 |
|
622 |
private void callListeners(FLayers lpo,FLayers lpd,FLayer ls){ |
623 |
for (int i=0; i < m_Listeners.size(); i++) |
624 |
{ |
625 |
ITocOrderListener listener = (ITocOrderListener) m_Listeners.get(i); |
626 |
listener.parentChanged(lpo,lpd,ls); |
627 |
} |
628 |
} |
629 |
|
630 |
} //end of DnDJTree
|