Revision 35646

View differences:

branches/gvSIG_1.11.0_Mejoras_gvSIG-EIEL/applications/appgvSIG/src/com/iver/cit/gvsig/LayerOrderExtension.java
6 6

  
7 7
import com.iver.andami.PluginServices;
8 8
import com.iver.andami.plugins.Extension;
9
import com.iver.andami.plugins.IExtension;
9 10
import com.iver.andami.preferences.IPreference;
10 11
import com.iver.andami.preferences.IPreferenceExtension;
11 12
import com.iver.cit.gvsig.fmap.MapContext;
12 13
import com.iver.cit.gvsig.fmap.layers.order.DefaultOrderManager;
13 14
import com.iver.cit.gvsig.fmap.layers.order.OrderManager;
15
import com.iver.cit.gvsig.fmap.layers.order.RasterPolLinePointOrderManager;
14 16
import com.iver.cit.gvsig.gui.preferencespage.LayerOrderPage;
15 17
import com.iver.utiles.XMLEntity;
16 18
import com.iver.utiles.extensionPoints.ExtensionPoint;
......
28 30
		registerDefaultManager();
29 31
		initDefaultOrderManager();
30 32
		
33
		// register second order manager (raster-point)
34
		registerRasterPointManager();
31 35
	}
36
	
37
	private void registerRasterPointManager() {
38
		
39
		ExtensionPoint ep = 
40
			(ExtensionPoint) ExtensionPointsSingleton.getInstance().
41
			get(DefaultOrderManager.getExtensionPointName());
32 42

  
43
		OrderManager manager = new RasterPolLinePointOrderManager();
44
		ep.put(manager.getCode(), manager);
45
		
46
		// if there is no default Order Manager, set our manager as default
47
		IExtension ext = PluginServices.getExtension(com.iver.cit.gvsig.LayerOrderExtension.class);
48
		com.iver.cit.gvsig.LayerOrderExtension orderExt = (com.iver.cit.gvsig.LayerOrderExtension) ext;
49
		if (!orderExt.existsDefaultOrderManager()) {
50
			orderExt.setDefaultOrderManager(manager);
51
		}
52

  
53
	}
54

  
33 55
	public boolean isEnabled() {
34 56
		return false;
35 57
	}
branches/gvSIG_1.11.0_Mejoras_gvSIG-EIEL/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/util/DropTargetInfo.java
1
package com.iver.cit.gvsig.project.documents.view.toc.util;
2

  
3
import java.awt.Point;
4
import java.awt.geom.Point2D;
5

  
6
import javax.swing.tree.TreePath;
7

  
8
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
9

  
10

  
11
public class DropTargetInfo {
12
	
13
	private ITocItem tocItem = null;
14
	
15
	/**
16
	 * mouse screen coords
17
	 */
18
	private Point mousePosition = null;
19
		
20
	public DropTargetInfo(
21
			ITocItem ti,
22
			Point mouse_screen_coords) {
23
		
24
		mousePosition = mouse_screen_coords;
25
		tocItem = ti;
26
	}
27
	
28
	public Point getMousePos() {
29
		return mousePosition;
30
	}
31
	
32
	public ITocItem getTocItem() {
33
		return tocItem; 
34
	}
35

  
36
}
0 37

  
branches/gvSIG_1.11.0_Mejoras_gvSIG-EIEL/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/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;
branches/gvSIG_1.11.0_Mejoras_gvSIG-EIEL/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/gui/TOCRenderer.java
54 54
import java.awt.GridBagConstraints;
55 55
import java.awt.GridBagLayout;
56 56
import java.awt.Rectangle;
57
import java.util.Random;
57 58

  
58 59
import javax.swing.BorderFactory;
59 60
import javax.swing.Icon;
......
70 71
import com.iver.cit.gvsig.fmap.layers.FLyrDefault;
71 72
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
72 73
import com.iver.cit.gvsig.project.documents.view.toc.TocItemBranch;
74
import com.iver.cit.gvsig.project.documents.view.toc.util.DropTargetInfo;
73 75

  
74 76

  
75 77

  
......
95 97

  
96 98
	GridBagLayout gridbag = new GridBagLayout();
97 99
	GridBagConstraints c = new GridBagConstraints();
100
	
101
	private DropTargetInfo graphicIndicatorInfo = null;
98 102
    /**
99 103
     * Creates a new TOCRenderer object.
100 104
     */
......
174 178
        
175 179
        
176 180
    }
181
    
182
    public void setGraphicIndicatorInfo(DropTargetInfo dti) {
183
    	graphicIndicatorInfo = dti;
184
    }
177 185

  
178 186
    /**
179 187
     * M?todo llamado una vez por cada nodo, y todas las veces que se redibuja
......
190 198
     * @return
191 199
     */
192 200
    public Component getTreeCellRendererComponent(JTree tree, Object value,
193
        boolean isSelected, boolean expanded, boolean leaf, int row,
201
        boolean isSelected, boolean expanded, boolean leaf, int _row,
194 202
        boolean hasFocus) {
195 203
                
196 204
        DefaultMutableTreeNode n = (DefaultMutableTreeNode) value;
......
202 210
		if (n.getUserObject() instanceof ITocItem)
203 211
		{
204 212
			
205
	       	ITocItem item = (ITocItem) n.getUserObject();	       	
213
	       	ITocItem item = (ITocItem) n.getUserObject();	  
214
	       	
215
	       	if (graphicIndicatorInfo != null) {
216
       			if (item == graphicIndicatorInfo.getTocItem()) {
217
    	    		this.setBackground( getRndColor() );
218
    	       	}
219
	       	}
220
	       	
206 221
			stringValue = item.getLabel();
207 222
			
208
	        Dimension sizeNode = item.getSize(); // Se fija en el resize del TOC
223
	        Dimension sizeNode = item.getSize();
224
	        // Se fija en el resize del TOC
209 225
	        
210 226
			this.setPreferredSize(sizeNode);
211 227
			
......
271 287
	public Rectangle getCheckBoxBounds() {
272 288
		return check.getBounds();
273 289
	}
290
	
291
	private static Random rnd = new Random(System.currentTimeMillis());
292
	
293
	private Color getRndColor() {
294
		int r = 128 + rnd.nextInt(128);
295
		int g = 128 + rnd.nextInt(128);
296
		int b = 128 + rnd.nextInt(128);
297
		return new Color(r,g,b);
298
	}
274 299

  
275 300
}

Also available in: Unified diff