Revision 38043
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/DnDJTree.java | ||
---|---|---|
59 | 59 |
*/ |
60 | 60 |
|
61 | 61 |
|
62 |
import java.awt.Color; |
|
63 |
import java.awt.Graphics; |
|
62 | 64 |
import java.awt.Point; |
65 |
import java.awt.Rectangle; |
|
63 | 66 |
import java.awt.datatransfer.Transferable; |
64 | 67 |
import java.awt.datatransfer.UnsupportedFlavorException; |
65 | 68 |
import java.awt.dnd.DnDConstants; |
... | ... | |
118 | 121 |
//private ArrayList treeListeners=new ArrayList(); |
119 | 122 |
//private ArrayList dropListeners=new ArrayList(); |
120 | 123 |
// private TreeModel model1; |
124 |
|
|
125 |
protected Rectangle separatorRectangle = new Rectangle(); |
|
126 |
private int MARGIN = 0; |
|
127 |
|
|
128 |
private int separatorPos; |
|
129 |
|
|
130 |
private boolean bUpSelected; |
|
131 |
|
|
132 |
|
|
121 | 133 |
/** Constructor |
122 | 134 |
@param root The root node of the tree |
123 | 135 |
@param parent Parent JFrame of the JTree */ |
... | ... | |
394 | 406 |
|
395 | 407 |
|
396 | 408 |
if (destParent.equals(oldParent)){ // Es un cambio de orden entre capas en el mismo nivel. |
409 |
// Para no cambiar el api, podemos guardar la posici?n del nodo tocado |
|
410 |
// como una propiedad de la capa (que luego borraremos) |
|
411 |
lpd.setProperty("GO_UP", new Boolean(bUpSelected)); |
|
397 | 412 |
callListeners(oldPos,newPos,lpd); |
398 | 413 |
}else{ // Es un cambio entre capas agrupadas. |
399 | 414 |
// Para no cambiar el api, podemos guardar la posici?n del nodo tocado |
... | ... | |
475 | 490 |
|
476 | 491 |
|
477 | 492 |
// if destination path is okay accept drop... |
493 |
if (destinationPath == null){ |
|
494 |
return; |
|
495 |
} |
|
478 | 496 |
|
497 |
DefaultMutableTreeNode dragedTreeNode = (DefaultMutableTreeNode) destinationPath.getLastPathComponent(); |
|
498 |
if (dragedTreeNode.getUserObject() instanceof TocItemBranch){ |
|
499 |
FLayer draggedLayer = ((TocItemBranch)dragedTreeNode.getUserObject()).getLayer(); |
|
500 |
if (draggedLayer != null){ |
|
501 |
Graphics graphics = this.getGraphics(); |
|
502 |
int increment = (int)separatorRectangle.getHeight(); |
|
503 |
|
|
504 |
graphics.clearRect(0, separatorPos, getWidth(), 1); |
|
505 |
|
|
506 |
bUpSelected = false; |
|
507 |
separatorRectangle = getPathBounds(destinationPath); |
|
508 |
separatorPos = separatorRectangle.y + increment - 1; |
|
509 |
if (cursorLocationBis.y < separatorPos - increment/2) { |
|
510 |
increment = 0; |
|
511 |
bUpSelected = true; |
|
512 |
} |
|
513 |
else |
|
514 |
increment = separatorRectangle.height; |
|
515 |
separatorPos = separatorRectangle.y + increment - 1; |
|
516 |
|
|
517 |
System.out.println("bUpSelected=" + bUpSelected + " separatorPos =" + separatorPos |
|
518 |
+ " cursor=" + cursorLocationBis.y); |
|
519 |
graphics.setColor(Color.red); |
|
520 |
graphics.drawLine(MARGIN, separatorPos , getWidth() - MARGIN, separatorPos); |
|
521 |
} |
|
522 |
} |
|
523 |
|
|
479 | 524 |
if (testSameComponent(e)) |
480 | 525 |
{ |
481 | 526 |
String msg = testDropTarget(destinationPath, SelectedTreePath); |
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/impl/DefaultToc.java | ||
---|---|---|
497 | 497 |
|
498 | 498 |
int newto = lpd.getLayersCount() - newPos - 1; |
499 | 499 |
String layerName = lpd.getLayer(newto).getName(); |
500 |
// obtenemos la capa sobre la que hemos dejado caer la otra. |
|
500 | 501 |
System.out.println("NewPos = " + layerName); |
501 |
final JPopupMenu pop = new JPopupMenu(PluginServices.getText(this, |
|
502 |
"Move")); |
|
503 |
JMenuItem itUp = new JMenuItem(PluginServices.getText(this, |
|
504 |
"Move_above_layer") + " " + layerName); |
|
505 |
JMenuItem itDown = new JMenuItem(PluginServices.getText(this, |
|
506 |
"Move_below_layer") + " " + layerName); |
|
507 |
JMenuItem itGroup = new JMenuItem(PluginServices.getText(this, |
|
508 |
"Group_with_layer") + " " + layerName); |
|
502 |
boolean bUp = (Boolean) lpd.getProperty("GO_UP"); |
|
503 |
lpd.getExtendedProperties().remove("GO_UP"); |
|
504 |
mapContext.beginAtomicEvent(); |
|
505 |
try { |
|
509 | 506 |
|
510 |
itUp.setActionCommand("UP"); |
|
511 |
itDown.setActionCommand("DOWN"); |
|
512 |
itGroup.setActionCommand("GROUP"); |
|
507 |
FLayers all = mapContext.getLayers(); |
|
513 | 508 |
|
514 |
JDialog dlgPop = new JDialog((Frame) null); |
|
515 |
dlgPop.setUndecorated(true); |
|
516 |
dlgPop.getContentPane().add(pop); |
|
517 |
dlgPop.setModal(true); |
|
518 | 509 |
|
519 |
MyMoveListener lis = new MyMoveListener(lpd, newto, oldPos, |
|
520 |
getMapContext(), dlgPop); |
|
510 |
int pos = -1; |
|
511 |
for (int j = 0; j < lpd.getLayersCount(); j++) { |
|
512 |
if (lpd.getLayer(j).getName().equalsIgnoreCase(layerName)) { |
|
513 |
pos = lpd.getLayersCount() - j - 1; |
|
514 |
break; |
|
515 |
} |
|
516 |
} |
|
517 |
if (bUp) { |
|
518 |
if (oldPos > pos) |
|
519 |
pos = pos; |
|
520 |
else |
|
521 |
pos = pos - 1; |
|
522 |
} |
|
523 |
else { |
|
524 |
if (oldPos > pos) |
|
525 |
pos = pos + 1; |
|
526 |
else |
|
527 |
pos = pos; |
|
528 |
} |
|
521 | 529 |
|
522 |
itUp.addActionListener(lis); |
|
523 |
itDown.addActionListener(lis); |
|
524 |
itGroup.addActionListener(lis); |
|
530 |
// System.out.println("oldPos=" + oldPos + " newto=" + newto + " pos=" |
|
531 |
// + pos); |
|
532 |
// if (e.getActionCommand().equalsIgnoreCase("GROUP")) { |
|
533 |
// FLayer origin = lpd.getLayer(lpd.getLayersCount() - oldPos - 1); |
|
534 |
// FLayer dest = lpd.getLayer(layerName); |
|
535 |
// // Creamos una nueva agrupaci?n |
|
536 |
// FLayer[] selected = new FLayer[2]; |
|
537 |
// selected[0] = origin; |
|
538 |
// selected[1] = dest; |
|
539 |
// createLayerGroup(selected); |
|
540 |
// |
|
541 |
// } else |
|
542 |
lpd.moveTo(oldPos, pos); |
|
525 | 543 |
|
526 |
pop.add(itUp);
|
|
527 |
pop.add(itDown);
|
|
528 |
pop.add(itGroup);
|
|
544 |
} catch (Exception ex) {
|
|
545 |
ex.printStackTrace();
|
|
546 |
}
|
|
529 | 547 |
|
530 |
PointerInfo pi = MouseInfo.getPointerInfo(); |
|
531 |
final Point p = pi.getLocation(); |
|
532 |
//SwingUtilities.convertPointToScreen(p, this); |
|
533 |
// pop.show(this, p.x, p.y); |
|
534 |
pop.setInvoker(dlgPop); |
|
535 |
pop.setLocation(p.x, p.y); |
|
536 |
pop.setVisible(true); |
|
537 |
dlgPop.pack(); |
|
548 |
mapContext.endAtomicEvent(); |
|
538 | 549 |
|
539 |
dlgPop.setVisible(true); |
|
550 |
// final JPopupMenu pop = new JPopupMenu(PluginServices.getText(this, |
|
551 |
// "Move")); |
|
552 |
// JMenuItem itUp = new JMenuItem(PluginServices.getText(this, |
|
553 |
// "Move_above_layer") + " " + layerName); |
|
554 |
// JMenuItem itDown = new JMenuItem(PluginServices.getText(this, |
|
555 |
// "Move_below_layer") + " " + layerName); |
|
556 |
// JMenuItem itGroup = new JMenuItem(PluginServices.getText(this, |
|
557 |
// "Group_with_layer") + " " + layerName); |
|
558 |
// |
|
559 |
// itUp.setActionCommand("UP"); |
|
560 |
// itDown.setActionCommand("DOWN"); |
|
561 |
// itGroup.setActionCommand("GROUP"); |
|
562 |
// |
|
563 |
// JDialog dlgPop = new JDialog((Frame) null); |
|
564 |
// dlgPop.setUndecorated(true); |
|
565 |
// dlgPop.getContentPane().add(pop); |
|
566 |
// dlgPop.setModal(true); |
|
567 |
|
|
568 |
// MyMoveListener lis = new MyMoveListener(lpd, newto, oldPos, |
|
569 |
// getMapContext(), dlgPop); |
|
570 |
|
|
571 |
// itUp.addActionListener(lis); |
|
572 |
// itDown.addActionListener(lis); |
|
573 |
// itGroup.addActionListener(lis); |
|
574 |
// |
|
575 |
// pop.add(itUp); |
|
576 |
// pop.add(itDown); |
|
577 |
// pop.add(itGroup); |
|
578 |
// |
|
579 |
// PointerInfo pi = MouseInfo.getPointerInfo(); |
|
580 |
// final Point p = pi.getLocation(); |
|
581 |
// //SwingUtilities.convertPointToScreen(p, this); |
|
582 |
//// pop.show(this, p.x, p.y); |
|
583 |
// pop.setInvoker(dlgPop); |
|
584 |
// pop.setLocation(p.x, p.y); |
|
585 |
// pop.setVisible(true); |
|
586 |
// dlgPop.pack(); |
|
587 |
// |
|
588 |
// dlgPop.setVisible(true); |
|
540 | 589 |
|
541 | 590 |
} catch (CancelationException e) { |
542 | 591 |
// TODO Auto-generated catch block |
Also available in: Unified diff