Revision 1930 branches/gvSIG_03_raster/applications/appgvSIG/src/com/iver/cit/gvsig/gui/toc/FPopupMenu.java

View differences:

FPopupMenu.java
58 58
import javax.swing.JTabbedPane;
59 59
import javax.swing.tree.DefaultMutableTreeNode;
60 60

  
61
import org.cresques.io.GeoRasterFile;
62
import org.cresques.io.raster.RasterFilterStackManager;
63
import org.cresques.ui.raster.BandSetupPanel;
64
import org.cresques.ui.raster.FilterRasterDialogPanel;
65

  
61 66
import com.iver.andami.PluginServices;
62 67
import com.iver.cit.gvsig.fmap.DriverException;
63 68
import com.iver.cit.gvsig.fmap.FMap;
69
import com.iver.cit.gvsig.fmap.MapControl;
70
import com.iver.cit.gvsig.fmap.ViewPort;
64 71
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
65 72
import com.iver.cit.gvsig.fmap.layers.CancelationException;
66 73
import com.iver.cit.gvsig.fmap.layers.FLayer;
67 74
import com.iver.cit.gvsig.fmap.layers.FLyrDefault;
68 75
import com.iver.cit.gvsig.fmap.layers.FLyrRaster;
76
import com.iver.cit.gvsig.fmap.layers.RasterAdapter;
69 77
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
70 78
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
71 79
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
72 80
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
81
import com.iver.cit.gvsig.gui.View;
73 82
import com.iver.cit.gvsig.gui.Panels.AdjustTransparencyPanel;
83
import com.iver.cit.gvsig.gui.Panels.PropertiesRasterDialog;
74 84
import com.iver.cit.gvsig.gui.legendmanager.FLegendManagerWindow;
75 85
import com.iver.cit.gvsig.gui.thememanager.FThemeManagerWindow;
76 86

  
......
187 197
}
188 198

  
189 199
/**
200
 * 
201
 * @author Nacho Brodin <brodin_ign@gva.es>
202
 *
203
 * Entrada de men? para la activaci?n de la funcionalidad de zoom a un
204
 * pixel.
205
 */
206
class ZoomPixelTocMenuEntry extends TocMenuEntry{
207
	private JMenuItem properties;
208
	FLayer lyr = null;
209
	
210
	public void initialize(FPopupMenu m) {
211
		super.initialize(m);
212
		
213
		if (isTocItemBranch()) {
214
			lyr = getNodeLayer();
215
    		// Opcciones para capas raster
216
    		if ((lyr instanceof FLyrRaster)) {
217
    			properties = new JMenuItem(PluginServices.getText(this, "Zoom_pixel"));
218
    			getMenu().add( properties );
219
    			properties.setFont(FPopupMenu.theFont);
220
    			getMenu().setEnabled(true);
221
    			getMenu().addSeparator();
222
    			properties.addActionListener(this);
223
     		}
224
		}
225
	}
226
	
227
	public void actionPerformed(ActionEvent e) {
228
		System.out.println("Zoom a un pixel");
229

  
230
		FLayer[] actives = getMapContext().getLayers().getActives();
231
		if (actives.length==1) {
232
	        try {
233
	        	Rectangle2D r = actives[0].getFullExtent();
234
	      
235
	        	ArrayList attr = ((FLyrRaster)actives[0]).getSource().getAttributes();
236
	        	int width = 0, height = 0;
237
	       		for (int i=0; i<attr.size(); i++) {
238
	    			Object[] a = (Object []) attr.get(i);
239
	    			if(a[0].toString().equals("Width"))
240
	    				width = ((Integer)a[1]).intValue();
241
	    			if(a[0].toString().equals("Height"))
242
	    				height = ((Integer)a[1]).intValue();	    			    			
243
	    		}
244
	        	ViewPort v = getMapContext().getViewPort();
245
	        	
246
	        	//A centro de imagen
247
	        	
248
	        	/*double centroX = width/2;
249
				double centroY = height/2;
250
				int minX = (int)Math.round(centroX - (v.getImageWidth()/2));
251
				int minY = (int)Math.round(centroY - (v.getImageHeight()/2));
252
				int maxX = (int)Math.round(minX + v.getImageWidth());
253
				int maxY = (int)Math.round(minY + v.getImageHeight());
254
				double wcOriginWidth = r.getMaxX() - r.getMinX();
255
				double wcOriginHeight = r.getMaxY() - r.getMinY();
256
				
257
				double wcDstMinX = r.getMinX()+((minX*wcOriginWidth)/width);
258
				double wcDstMinY = r.getMinY()+((minY*wcOriginHeight)/height);
259
				double wcDstMaxX = r.getMinX()+((maxX*wcOriginWidth)/width);
260
				double wcDstMaxY = r.getMinY()+((maxY*wcOriginHeight)/height);
261
				
262
				double wcDstWidth = wcDstMaxX - wcDstMinX;
263
				double wcDstHeight = wcDstMaxY - wcDstMinY;*/
264
				
265
	        	//A centro de vista
266
	        	double wcOriginCenterX = v.getExtent().getMinX()+((v.getExtent().getMaxX()-v.getExtent().getMinX())/2);
267
	        	double wcOriginCenterY = v.getExtent().getMinY()+((v.getExtent().getMaxY()-v.getExtent().getMinY())/2);
268
	        					
269
	        	//Hallamos la relaci?n entre el pixel y las WC a partir de la imagen de la capa
270
				double relacionPixelWcWidth =  (r.getMaxX() - r.getMinX())/width;
271
				double relacionPixelWcHeight = (r.getMaxY() - r.getMinY())/height;
272
				double desplazamientoX = r.getMinX(); 
273
				double desplazamientoY = r.getMinY();
274
				
275
				double wcOriginX = wcOriginCenterX - ((v.getImageWidth()*relacionPixelWcWidth)/2);
276
				double wcOriginY = wcOriginCenterY - ((v.getImageHeight()*relacionPixelWcHeight)/2);
277
				
278
				double wcDstMinX = wcOriginX; 
279
				double wcDstMinY = wcOriginY; 
280
				double wcDstMaxX = wcDstMinX + (v.getImageWidth()*relacionPixelWcWidth);
281
				double wcDstMaxY = wcDstMinY + (v.getImageHeight()*relacionPixelWcHeight);
282
				
283
				double wcDstWidth = wcDstMaxX - wcDstMinX;
284
				double wcDstHeight = wcDstMaxY - wcDstMinY;
285
								
286
	        	r = new Rectangle2D.Double(wcDstMinX, wcDstMinY, wcDstWidth, wcDstHeight);
287
	        	getMapContext().getViewPort().setExtent(r);
288
	        		        	
289
			} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
290
				e1.printStackTrace();
291
			}
292
		} 
293
		//View vista = (View) PluginServices.getMDIManager().getActiveView();
294
		//MapControl mapCtrl = vista.getMapControl();
295
	
296
	}
297
}
298

  
299
/**
300
 * 
301
 * @author Nacho Brodin <brodin_ign@gva.es>
302
 *
303
 * Entrada de men? para la activaci?n de la funcionalidad de salvar
304
 * a raster una parte de la vista.
305
 */
306
class SaveRasterTocMenuEntry extends TocMenuEntry{
307
	private JMenuItem properties;
308
	FLayer lyr = null;
309
	
310
	public void initialize(FPopupMenu m) {
311
		super.initialize(m);
312
		
313
		if (isTocItemBranch()) {
314
			lyr = getNodeLayer();
315
    		// Opcciones para capas raster
316
    		if ((lyr instanceof FLyrRaster)) {
317
    			properties = new JMenuItem(PluginServices.getText(this, "salvar_raster"));
318
    			getMenu().add( properties );
319
    			properties.setFont(FPopupMenu.theFont);
320
    			getMenu().setEnabled(true);
321
    			getMenu().addSeparator();
322
    	        //Cambio color
323
    			properties.addActionListener(this);
324
     		}
325
		}
326
	}
327
	
328
	public void actionPerformed(ActionEvent e) {
329
		lyr = getNodeLayer();
330
		View vista = (View) PluginServices.getMDIManager().getActiveView();
331
		MapControl mapCtrl = vista.getMapControl();
332
		mapCtrl.setTool("saveRaster");
333
	}
334
}
335

  
336
/**
190 337
 * Muestra el men? de propiedades del tema.
191 338
 * 
192 339
 * @author jmorell
......
272 419
	}
273 420
}
274 421

  
275
class FLyrRasterAdjustTransparencyTocMenuEntry extends TocMenuEntry {
276
	private JMenuItem transparency;
277
	FLayer lyr = null;
422
/**
423
 * 
424
 * @author Nacho Brodin <brodin_ign@gva.es>
425
 *
426
 * Entrada de men? para el dialogo de propiedades del raster
427
 */
428
class FLyrRasterAdjustPropertiesTocMenuEntry extends TocMenuEntry {
429
	private JMenuItem 				properties;
430
	FLayer 							lyr = null;
431
	private PropertiesRasterDialog	propsDialog = null;
432
	private BandSetupPanel 			bandSetup = null;
433

  
434
	
278 435
	public void initialize(FPopupMenu m) {
279 436
		super.initialize(m);
280 437
		
......
282 439
			lyr = getNodeLayer();
283 440
    		// Opcciones para capas raster
284 441
    		if ((lyr instanceof FLyrRaster)) {
285
    		    transparency = new JMenuItem(PluginServices.getText(this, "adjust_transparency"));
286
    			getMenu().add( transparency );
287
    			transparency.setFont(FPopupMenu.theFont);
442
    			properties = new JMenuItem(PluginServices.getText(this, "propiedades_raster"));
443
    			getMenu().add( properties );
444
    			properties.setFont(FPopupMenu.theFont);
288 445
    			getMenu().setEnabled(true);
289 446
    			getMenu().addSeparator();
290 447
    	        //Cambio color
291
    	        transparency.addActionListener(this);
448
    			properties.addActionListener(this);
292 449
     		}
293 450
		}
294 451
	}
295
	/* (non-Javadoc)
296
	 * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
452
	
453
	/**
454
	 * Gestiona la apertura del dialogo de propiedades de raster cuando se pulsa
455
	 * la opci?n asignando a este las propiedades iniciales. 
297 456
	 */
298 457
	public void actionPerformed(ActionEvent e) {
299 458
       	lyr = getNodeLayer();
300
        AdjustTransparencyPanel transPanel = new AdjustTransparencyPanel((FLyrDefault) lyr);
301
		transPanel.openJDialog();
302
        //getMapContext().invalidate();                    
459
                   
460
       	if(lyr instanceof FLyrRaster){
461
       		RasterFilterStackManager 	stackManager = null;
462
       
463
       		stackManager = new RasterFilterStackManager(((FLyrRaster)lyr).getSource().getFilterStack());
464
       		int[][] rangeR = stackManager.getTransparecyR();
465
       		int[][] rangeG = stackManager.getTransparecyG();
466
       		int[][] rangeB = stackManager.getTransparecyB();
467
       		
468
       		propsDialog = new PropertiesRasterDialog(((FLyrRaster)lyr), rangeR, rangeG, rangeB);
469
       	       			
470
			int alpha = 255-((FLyrRaster)lyr).getSource().getTransparency();
471
			
472
			bandSetup = ((FilterRasterDialogPanel)propsDialog.getContentPane()).getBandSetup();
473
			GeoRasterFile[] files = ((FLyrRaster)lyr).getSource().getFiles();
474
			bandSetup.addFiles(files);
475
			RasterAdapter rad = ((FLyrRaster)lyr).getSource();
476
			int posR = 0, posG = 0, posB = 0;
477
			
478
			for(int i=0;i<rad.getPosFile(GeoRasterFile.RED_BAND);i++)
479
				posR += files[i].getBandCount();
480
			posR += rad.getBand(GeoRasterFile.RED_BAND);
481
			
482
			for(int i=0;i<rad.getPosFile(GeoRasterFile.GREEN_BAND);i++)
483
				posG += files[i].getBandCount();
484
			posG += rad.getBand(GeoRasterFile.GREEN_BAND);
485
			
486
			for(int i=0;i<rad.getPosFile(GeoRasterFile.BLUE_BAND);i++)
487
				posB += files[i].getBandCount();
488
			posB += rad.getBand(GeoRasterFile.BLUE_BAND);
489
			
490
			bandSetup.assignBand(posR, GeoRasterFile.RED_BAND);
491
			bandSetup.assignBand(posG, GeoRasterFile.GREEN_BAND);
492
			bandSetup.assignBand(posB, GeoRasterFile.BLUE_BAND);	
493
									
494
			//Asignaci?n del alpha actual de la imagen al dialogo
495
			RasterTransparencyPanel rasterTrans = ((FilterRasterDialogPanel)propsDialog.getContentPane()).getTransparencyPanel();
496
			rasterTrans.setOpacity(alpha);
497
				
498
			//Asignaci?n del porcentaje de recorte actual de la imagen al dialogo
499
			EnhancedPanel pEnhan =  ((FilterRasterDialogPanel)propsDialog.getContentPane()).getEnhancedPanel();
500
			
501
			propsDialog.setRasterFilterStackManager(stackManager);
502
			int tail = 0;
503
			if(	pEnhan != null &&
504
				stackManager.getStackStats() != null){
505
				tail = (int)(stackManager.getStackStats().tailPercent*200);
506
				pEnhan.setPercentTail(tail);
507
			}
508
			if(stackManager.isActive(stackManager.getTypeFilter("enhanced")))
509
				pEnhan.setSelectedFilter(1);
510
			else
511
				pEnhan.setSelectedFilter(0);
512
							
513
			propsDialog.readStat();
514
			
515
       		PluginServices.getMDIManager().addView(propsDialog);
516
        }
303 517
	}
304 518
}
305 519

  
......
430 644
    	menuEntrys = new ArrayList();
431 645
    	menuEntrys.add(new FSymbolChangeColorTocMenuEntry());
432 646
    	menuEntrys.add(new FLyrVectChangeStyleTocMenuEntry());
433
    	menuEntrys.add(new FLyrRasterAdjustTransparencyTocMenuEntry());
647
    	menuEntrys.add(new FLyrRasterAdjustPropertiesTocMenuEntry());
648
    	menuEntrys.add(new ZoomPixelTocMenuEntry());
434 649
    	menuEntrys.add(new ZoomAlTemaTocMenuEntry());
435 650
    	menuEntrys.add(new EliminarCapaTocMenuEntry());
436 651
    	//050201 jmorell: Acceso al men? propiedades.

Also available in: Unified diff