14,19d13
< import CH.ifa.draw.standard.AbstractTool;
< import java.util.List;
< import java.awt.event.MouseEvent;
< import java.awt.*;
< import java.util.Iterator;
< 
22c16,20
< import CH.ifa.draw.util.CollectionsFactory;
---
> import java.awt.Cursor;
> import java.awt.dnd.DragGestureListener;
> import javax.swing.JComponent;
> 
> //import CH.ifa.draw.util.CollectionsFactory;
49c47,48
<  * express this.
---
>  * express this.  It won't work until setVisible(true) is called.  then you can 
>  * initialize DND.
57c56
< public class DragNDropTool extends AbstractTool {
---
> public class DragNDropTool extends CH.ifa.draw.standard.AbstractTool {
59c58,61
< 	private List            comps;
---
> //	private java.util.List       comps;
> 	private DragGestureListener dragGestureListener;
> 	private boolean dragOn;
> 	
63c65,67
< 		comps = CollectionsFactory.current().createList();
---
> //		comps = CollectionsFactory.current().createList();
> 		setDragGestureListener(createDragGestureListener());
> 		dragOn = false;
71c75
< 		if (DNDInterface.class.isInstance(view)) {
---
> 		if (view instanceof DNDInterface) {
73,75c77,78
< 			dndi.setDropTargetActive(true);
< 			dndi.setDragSourceActive(false);
< 			comps.add(dndi);
---
> 			dndi.DNDInitialize( getDragGestureListener() );
> //			comps.add(dndi);
83c86
< 		if (DNDInterface.class.isInstance(view)) {
---
> 		if (view instanceof DNDInterface) {
85,87c88,89
< 			dndi.setDropTargetActive(false);
< 			dndi.setDragSourceActive(false);
< 			comps.remove(dndi);
---
> 			dndi.DNDDeinitialize();
> //			comps.remove(dndi);
98,100c100,102
< 		System.out.println("DNDTool Activation");
< 
< 		setDragSourceActive(true);
---
> //		setDragSourceActive(true);
> 		//System.out.println("DNDTool Activation");
> 		setDragOn(true);
104,105c106,108
< 		System.out.println("DNDTool deactivation.");
< 		setDragSourceActive(false);
---
> 		//System.out.println("DNDTool deactivation.");
> 		setDragOn(false);
> //		setDragSourceActive(false);//if its not turned off other tools will have problems since drag will start
109,115c112,118
< 	private void setDragSourceActive(boolean newState) {
< 		Iterator it = comps.iterator();
< 		while (it.hasNext()) {
< 			DNDInterface dndi = (DNDInterface)it.next();
< 			dndi.setDragSourceActive(newState);
< 		}
< 	}
---
> //	private void setDragSourceActive(boolean newState) {
> //		Iterator it = comps.iterator();
> //		while (it.hasNext()) {
> //			DNDInterface dndi = (DNDInterface)it.next();
> //			dndi.setDragSourceState(newState);
> //		}
> //	}
131c134
< 				Locator loc = lh.getLocator();
---
> 				CH.ifa.draw.framework.Locator loc = lh.getLocator();
175,177c178,180
< 	public void mouseMove(MouseEvent evt, int x, int y) {
< 		if (evt.getSource() == getActiveView()) {
< 			setCursor(evt.getX(), evt.getY(), getActiveView());
---
> 	public void mouseMove(java.awt.event.MouseEvent e, int x, int y) {
> 		if (e.getSource() == getActiveView()) {
> 			setCursor(x, y, getActiveView());
186c189
< 	public void mouseUp(MouseEvent e, int x, int y) {
---
> 	public void mouseUp(java.awt.event.MouseEvent e, int x, int y) {
189d191
< 		}
190a193,194
> 		}
> 		setDragOn(true);
191a196
> 		//get undo actions and push into undo stack?
198c203
< 	public void mouseDown(MouseEvent e, int x, int y) {
---
> 	public void mouseDown(java.awt.event.MouseEvent e, int x, int y) {
209c214
< 		Handle handle = view().findHandle(e.getX(), e.getY());
---
> 		Handle handle = view().findHandle(getAnchorX(), getAnchorY());
210a216,217
> 			//Turn off DND
> 			setDragOn(false);
214c221
< 			Figure figure = drawing().findFigure(e.getX(), e.getY());
---
> 			Figure figure = drawing().findFigure(getAnchorX(), getAnchorY());
227a235,236
> 				//Turn off DND
> 				setDragOn(false);
244c253
< 	public void mouseDrag(MouseEvent e, int x, int y) {
---
> 	public void mouseDrag(java.awt.event.MouseEvent e, int x, int y) {
255c264
< 		return new SelectAreaTracker(editor());
---
> 		return new CH.ifa.draw.standard.SelectAreaTracker(editor());
262c271
< 		return new DragTracker(editor, f);
---
> 		return new CH.ifa.draw.standard.DragTracker(editor, f);
269c278,299
< 		return new HandleTracker(editor(), handle);
---
> 		return new CH.ifa.draw.standard.HandleTracker(editor(), handle);
> 	}
> 	
> 	
> 	
> 	
> 	
> 	
> 	
> 	
> 	
> 	
> 	
> 	
> 	
> 	
> 	
> 	
> 
> 
> 	private DragGestureListener getDragGestureListener(){
> 		return dragGestureListener;
270a301,400
> 	private void setDragGestureListener(DragGestureListener dragGestureListener){
> 		this.dragGestureListener = dragGestureListener;
> 	}
> 	protected boolean isDragOn(){
> 		return dragOn;
> 	}
> 	protected void setDragOn(boolean dragOn){
> 		this.dragOn = dragOn;
> 	}
> 	private DragGestureListener createDragGestureListener() {
> 		
> 		return new DragGestureListener() {
> 			
> 			public void dragGestureRecognized(final java.awt.dnd.DragGestureEvent dge) {
> 				java.awt.Component c = dge.getComponent();
> 				//System.out.println("Drag Gesture Recognized for " + c);
> 				if(isDragOn() == false) {
> 					return;
> 				}
> 
> 				if (c instanceof DrawingView) {
> 					boolean found = false;
> 					DrawingView dv = (DrawingView)c;
> 					/* Send the drawing view which inspired the action a mouseUp to clean
> 					up its current tool.  This is because mouse up will otherwise never
> 					be sent and the tool will be stuck with only mouse down which means
> 					it will likely stay activated.  solve later for now just make
> 					but report. */
> 					/* this is a list of cloned figures */
> 					CH.ifa.draw.framework.FigureEnumeration selectedElements = dv.selection();
> 
> 					if (selectedElements.hasNextFigure() == false) {
> 						return;
> 					}
> 
> 					java.awt.Point p = dge.getDragOrigin();
> 		//				System.out.println("origin at " + p);
> 					while (selectedElements.hasNextFigure()) {
> 						Figure f = selectedElements.nextFigure();
> 						if (f.containsPoint(p.x, p.y)) {
> 		/*              Rectangle r = figgy.displayBox();
> 							sx = r.width;
> 							sy = r.height;*/
> 							//System.out.println("figure is " + figgy);
> 							found = true;
> 							break;
> 						}
> 					}
> 					if (found == true) {
> 						DNDFigures dndff = new DNDFigures(dv.selection(), p);
> 						DNDFiguresTransferable trans = new DNDFiguresTransferable(dndff);
> 
> 						/* SAVE FOR FUTURE DRAG IMAGE SUPPORT */
> 						/* drag image support that I need to test on some supporting platform.
> 						windows is not supporting this on NT so far. Ill test 98 and 2K next
> 
> 						boolean support = dragSource.isDragImageSupported();
> 						java.awt.image.BufferedImage  bi = new BufferedImage(sx,sy,BufferedImage.TYPE_INT_RGB);
> 						Graphics2D g = bi.createGraphics();
> 						Iterator itr2 = selectedElements.iterator();
> 						while ( itr2.hasNext() ) {
> 							Figure fig = (Figure) itr2.next();
> 							fig = (Figure)fig.clone();
> 							Rectangle rold = fig.displayBox();
> 							fig.moveBy(-rold.x,-rold.y);
> 							fig.draw(g);
> 						}
> 						g.setBackground(Color.red);
> 						dge.getDragSource().startDrag(
> 										dge,
> 										DragSource.DefaultMoveDrop,
> 										bi,
> 										new Point(0,0),
> 										trans,
> 										this);
> 						*/
> 						if (c instanceof JComponent) {
> 							((JComponent)c).setAutoscrolls(false);
> 						}
> 						dge.getDragSource().startDrag(
> 										dge,
> 										null,
> 										trans,
> 										((DNDInterface)dv).getDragSourceListener());
> 					}
> 				}
> 			}
> 		};
> 	}
> 	
> 	
> 	
> 	
> 	
> 	
> 	
> 	
> 	
> 	
> 	
