Revision 11384

View differences:

trunk/extensions/extRasterTools-SE/.classpath
14 14
	<classpathentry kind="var" path="JUNIT_HOME/junit.jar" sourcepath="ECLIPSE_HOME/plugins/org.eclipse.jdt.source_3.1.1/src/org.junit_3.8.1/junitsrc.zip"/>
15 15
	<classpathentry kind="lib" path="/libFMap/lib/gvsig-exceptions.jar" sourcepath="/libExceptions"/>
16 16
	<classpathentry kind="lib" path="/libFMap/lib/gdbms-0.8-SNAPSHOT.jar" sourcepath="/libGDBMS"/>
17
	<classpathentry kind="lib" path="/libRaster/lib/jgdal-0.6.0.jar" sourcepath="/libjni-gdal/src"/>
17 18
	<classpathentry kind="output" path="bin"/>
18 19
</classpath>
trunk/extensions/extRasterTools-SE/config/text.properties
86 86
select_tool=Seleccionar desde la vista
87 87
contraer=Contraer
88 88
expandir=Expandir
89
resolucion_espacial=Resoluci?n espacial
89
resolucion_espacial=Resoluci?n
90 90
tamanyo_celda=Tama?o de celda
91 91
ancho_x_alto=Ancho x Alto
92 92
celda=Celda
......
95 95
distancia_inversa=Distancia Inversa
96 96
bicubico=Bic?bico
97 97
b_splines=B-Spline
98
seleccion_bandas=Selecci?n de Bandas
99
crear_1_capa_por_banda=Crear una capa por banda
98
seleccion_bandas=Bandas
99
crear_1_capa_por_banda=Crear una capa por banda
100
otras_opciones=Opciones
101
nombre_capas=Nombre de las capas
102
cargar_en_toc=Cargar las capas en el TOC
103
seleccionar_directorio=Seleccionar un directorio
104
coordenadas_recorte=Coordenadas
105
guardar_en_disco=Guardar en disco
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/cutting/CuttingTocMenuEntry.java
114 114
		if (!(fLayer instanceof FLyrRasterSE))
115 115
			return;
116 116

  
117
		CuttingDialog cuttingDialog = new CuttingDialog(434, 494);
117
		CuttingDialog cuttingDialog = new CuttingDialog(455, 263);
118 118
		
119 119
		cuttingDialog.setLayer(fLayer);
120 120

  
121 121
		PluginServices.getMDIManager().addWindow(cuttingDialog);
122

  
123
		cuttingDialog.showExtras(false);
124 122
	}
125 123
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/cutting/CuttingProcess.java
23 23
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent;
24 24
import org.gvsig.gui.beans.incrementabletask.IncrementableListener;
25 25
import org.gvsig.gui.beans.incrementabletask.IncrementableTask;
26
import org.gvsig.raster.buffer.BufferFactory;
26 27
import org.gvsig.raster.dataset.GeoRasterWriter;
27 28
import org.gvsig.raster.dataset.IBuffer;
28 29
import org.gvsig.raster.dataset.NotSupportedExtensionException;
29 30
import org.gvsig.raster.dataset.RasterDriverException;
31
import org.gvsig.raster.dataset.RasterMultiDataset;
30 32
import org.gvsig.raster.dataset.WriterParams;
31 33
import org.gvsig.raster.shared.Extent;
34
import org.gvsig.rastertools.cutting.ui.listener.CuttingPanelListener;
32 35

  
33 36
/**
34 37
 * 
......
37 40
 * @author Borja S?nchez Zamorano (borja.sanchez@iver.es)
38 41
 */
39 42
public class CuttingProcess implements Runnable, IncrementableListener {
40
		
41
//	private GeoRasterWriter			writer = null;
42
	private String 					fileName = "";
43
	private IncrementableTask 			incrementableTask = null;
44
	private volatile Thread 			blinker = null;
45
	private WriterBufferServer writerBufferServer = null;
46
	private IBuffer buffer = null;
47
	private Extent extent = null;
48

  
43
//	private GeoRasterWriter				writer = null;
44
	private String 								fileName = "";
45
	private IncrementableTask			incrementableTask = null;
46
	private volatile Thread				blinker = null;
47
	private WriterBufferServer		writerBufferServer = null;
48
	private RasterMultiDataset		rasterMultiDataset = null;
49
	private Extent								extent = null;
50
	private boolean								oneLayerPerBand = false;
51
	private int[]									drawableBands = null;
52
	private CuttingPanelListener	cuttingPanelListener = null; 
53
	
49 54
	/**
50 55
	 * Constructor
51 56
	 * @param vp ViewPortData
......
54 59
	 * @param fName Nombre del fichero de salida
55 60
	 * @param params Par?metros del escritor
56 61
	 */	
57
	public CuttingProcess(String fileName, WriterBufferServer writerBufferServer, IBuffer buffer, Extent extent) {
62
	public CuttingProcess(CuttingPanelListener cuttingPanelListener, String fileName, WriterBufferServer writerBufferServer, RasterMultiDataset rasterMultiDataset, Extent extent, int[] drawableBands, boolean oneLayerPerBand) {
58 63
		this.fileName = fileName;
59 64
		this.writerBufferServer = writerBufferServer;
60
		this.buffer = buffer;
65
		this.rasterMultiDataset = rasterMultiDataset;
61 66
		this.extent = extent;
67
		this.oneLayerPerBand = oneLayerPerBand;
68
		this.drawableBands = drawableBands;
69
		this.cuttingPanelListener = cuttingPanelListener;
62 70
	}
63
		
71
	
64 72
	/**
65 73
	 * Arranca el proceso de salvado a raster
66 74
	 */
......
77 85
		notify();
78 86
	}
79 87
	
88
	private void WriteFile(String file, int[] bands)
89
			throws NotSupportedExtensionException, RasterDriverException, IOException {
90

  
91
		BufferFactory bufferFactory = new BufferFactory(rasterMultiDataset);
92
		bufferFactory.addDrawableBands(bands);
93
		bufferFactory.setAreaOfInterest(extent.minX(), extent.maxY(), extent.width(), extent.height(), true);
94
		IBuffer buffer = bufferFactory.getRasterBuf();
95

  
96
		writerBufferServer.setBuffer(buffer);
97

  
98
		WriterParams params = GeoRasterWriter.getWriter(file).getParams();
99
		GeoRasterWriter grw = GeoRasterWriter.getWriter(writerBufferServer, file,
100
				buffer.getBandCount(), extent, buffer.getWidth(), buffer.getHeight(),
101
				buffer.getDataType(), params);
102
		grw.dataWrite();
103
		grw.writeClose();
104
	}
105

  
80 106
	/**
81 107
	 * 
82 108
	 */
83 109
	public void run() {
84
		System.out.println("Guardando en:" + fileName);
85 110
		try {
86
			WriterParams params = GeoRasterWriter.getWriter(fileName).getParams();
87
			GeoRasterWriter grw = GeoRasterWriter.getWriter(writerBufferServer, 
88
					fileName,
89
					buffer.getBandCount(),
90
					extent,
91
					buffer.getWidth(), 
92
					buffer.getHeight(), 
93
					buffer.getDataType(),
94
					params);
95
			grw.dataWrite();
96
			grw.writeClose();
111
			if (oneLayerPerBand) {
112
				int[] drawableBandsAux = new int[1];
113
				for (int i = 0; i < drawableBands.length; i++) {
114
					drawableBandsAux[0] = drawableBands[i];
115
					WriteFile(fileName + "_B" + drawableBandsAux[0] + ".tif", drawableBandsAux);
116
					cuttingPanelListener.cutFinalize(fileName + "_B" + drawableBandsAux[0] + ".tif");
117
				}
118
			} else {
119
				WriteFile(fileName + ".tif", drawableBands);
120
				cuttingPanelListener.cutFinalize(fileName + ".tif");
121
			}
97 122
		} catch (NotSupportedExtensionException e) {
98 123
			e.printStackTrace();
99 124
		} catch (RasterDriverException e) {
......
116 141
	}
117 142

  
118 143
	public void actionCanceled(IncrementableEvent e) {
119
		// TODO Auto-generated method stub
120
		
121 144
	}
122 145

  
123 146
	public void actionResumed(IncrementableEvent e) {
124
		// TODO Auto-generated method stub
125
		
126 147
	}
127 148

  
128 149
	public void actionSuspended(IncrementableEvent e) {
129
		// TODO Auto-generated method stub
130
		
131 150
	}
132 151
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/cutting/WriterBufferServer.java
33 33
	private int 			row = 0;
34 34
	private int				block = 0;
35 35

  
36
	public WriterBufferServer(IBuffer buffer){
36
	public WriterBufferServer() {
37
	}
38

  
39
	public WriterBufferServer(IBuffer buffer) {
40
		setBuffer(buffer);
41
	}
42
	
43
	public void setBuffer(IBuffer buffer) {
37 44
		this.buffer = buffer;
38 45
	}
39 46

  
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/cutting/ui/CuttingDialog.java
106 106
			close();
107 107
		}
108 108
	}
109
	
110
	public void showExtras(boolean show) {
111
		getCuttingPanel().showExtrasForPanel(show);
112
	}
113 109
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/cutting/ui/CuttingPanel.java
22 22
import java.awt.Dimension;
23 23
import java.awt.GridBagConstraints;
24 24
import java.awt.GridBagLayout;
25
import java.awt.Insets;
25 26
import java.io.File;
26 27
import java.util.ArrayList;
27 28

  
28
import javax.swing.ImageIcon;
29 29
import javax.swing.JCheckBox;
30 30
import javax.swing.JLabel;
31 31
import javax.swing.JPanel;
32
import javax.swing.JTabbedPane;
33
import javax.swing.JTextField;
32 34

  
33 35
import org.gvsig.fmap.layers.FLyrRasterSE;
34 36
import org.gvsig.gui.beans.buttonbar.ButtonBarContainer;
......
70 72
	private ButtonBarContainer			buttonBarContainer = null;
71 73
	private JPanel									pSelection = null;
72 74
	private TableContainer					tSelection = null;
73
	private JPanel									pCheck = null;
74 75
	private JCheckBox								jCheckBox = null;
76
	private JCheckBox								jCheckLoadLayerInToc = null;
77
	private JCheckBox								jCheckSaveFile = null;
75 78
	private ResolutionPanel					pResolution = null;
76 79
	private CuttingDialog						cuttingDialog = null;
80
	private JPanel									jOptions = null;
81
	private JPanel									jPNameFile = null;
82
	private JTextField							filenameTextField = null;
77 83

  
84
	private JTabbedPane							jTabbedPane1 = null;
85

  
78 86
	FLayer fLayer = null;
79 87

  
80 88
	/**
......
111 119
	 * 
112 120
	 */
113 121
	public CuttingPanel(CuttingDialog cuttingDialog) {
114
		super(ButtonsPanel.BUTTONS_NONE);
115
		this.getButtonsPanel().addSave();
116
		this.getButtonsPanel().addApply();
117
		this.getButtonsPanel().addCancel();
122
		super(ButtonsPanel.BUTTONS_ACCEPTCANCELAPPLY);
118 123

  
119 124
		this.cuttingDialog = cuttingDialog;
120 125
		initialize();
......
147 152
	
148 153
		getButtonBarContainer().getButton(0).addActionListener(cuttingPanelListener);
149 154
		getButtonBarContainer().getButton(1).addActionListener(cuttingPanelListener);
150
		getButtonBarContainer().getButton(2).addActionListener(cuttingPanelListener);
151 155

  
152 156
		this.addButtonPressedListener(cuttingPanelListener);
153 157
	}
......
261 265
		m_MapControl.setTool("cutRaster");
262 266
	}
263 267
	
264
	
265 268
	/**
266 269
	 * This method initializes this
267
	 * 
268 270
	 */
269 271
	private void initialize() {
272
		jTabbedPane1 = new JTabbedPane();
273
		
270 274
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
271 275
		gridBagConstraints.gridx = 0;
272 276
		gridBagConstraints.gridy = 0;
......
276 280
		GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
277 281
		gridBagConstraints2.gridx = 0;
278 282
		gridBagConstraints2.gridy = 2;
279
		GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
280
		gridBagConstraints3.gridx = 0;
281
		gridBagConstraints3.gridy = 3;
282
		GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
283
		gridBagConstraints4.gridx = 0;
284
		gridBagConstraints4.gridy = 4;
285
		GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
286
		gridBagConstraints5.gridx = 0;
287
		gridBagConstraints5.gridy = 5;
288
		this.setLayout(new GridBagLayout());
289
		this.add(getCoor_pixel(), gridBagConstraints);
290
		this.add(getCoor_reales(), gridBagConstraints1);
291
		this.add(getButtonBarContainer(), gridBagConstraints2);
292
		this.add(getPResolution(), gridBagConstraints3);
293
		this.add(getPSelection(), gridBagConstraints4);
294
		this.add(getPCheck(), gridBagConstraints5);
295
		getButtonsPanel().getButton(ButtonsPanel.BUTTON_SAVE).setEnabled(false);
283
		gridBagConstraints2.insets = new java.awt.Insets(5, 0, 0, 0);
284

  
285
		JPanel jpanel1 = new JPanel();
286
		jpanel1.setLayout(new GridBagLayout());
287
		jpanel1.add(getCoor_pixel(), gridBagConstraints);
288
		jpanel1.add(getCoor_reales(), gridBagConstraints1);
289
		jpanel1.add(getButtonBarContainer(), gridBagConstraints2);
290

  
291
		jTabbedPane1.addTab(PluginServices.getText(this, "coordenadas_recorte"), jpanel1);
292
		jTabbedPane1.addTab(PluginServices.getText(this, "resolucion_espacial"), getPResolution());
293
		jTabbedPane1.addTab(PluginServices.getText(this, "seleccion_bandas"), getPSelection());
294
		jTabbedPane1.addTab(PluginServices.getText(this, "otras_opciones"), getJOptions());
295

  
296
		this.setLayout(new BorderLayout());
297
		this.add(jTabbedPane1, BorderLayout.CENTER);
296 298
	}
297 299

  
298 300
	/*
......
349 351
			buttonBarContainer.setPreferredSize(new java.awt.Dimension(wPanel - 4, 32));
350 352
			buttonBarContainer.addButton("fullExtent.png", PluginServices.getText(this, "fullExtent"), 0);
351 353
			buttonBarContainer.addButton("selectTool.png", PluginServices.getText(this, "select_tool"), 1);
352
			buttonBarContainer.addButton("down.png", PluginServices.getText(this, "expandir"), 2);
353 354
			buttonBarContainer.setButtonAlignment("right");
354
			buttonBarContainer.setComponentBorder(true);
355
			buttonBarContainer.setComponentBorder(false);
355 356
		}
356 357
		return buttonBarContainer;
357 358
	}
......
380 381
			pSelection = new JPanel();
381 382
			pSelection.setLayout(new BorderLayout());
382 383
			pSelection.setPreferredSize(new java.awt.Dimension(wPanel, 120));
383
			pSelection.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this, "seleccion_bandas"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10), null));
384 384
			pSelection.add(getTSelection(), BorderLayout.CENTER);
385 385
			
386 386
		}
......
409 409
	 * 	
410 410
	 * @return javax.swing.JPanel	
411 411
	 */
412
	private JPanel getPCheck() {
413
		if (pCheck == null) {
414
			JLabel jLabel = new JLabel();
415
			jLabel.setText(PluginServices.getText(this, "crear_1_capa_por_banda"));
416
			pCheck = new JPanel();
417
			pCheck.setLayout(new BorderLayout());
418
			pCheck.setPreferredSize(new Dimension(410 - 10, 30));
419
			pCheck.add(getCbOneLyrPerBand(), java.awt.BorderLayout.WEST);
420
			pCheck.add(jLabel, java.awt.BorderLayout.CENTER);
412
	private JPanel getJOptions() {
413
		if (jOptions == null) {
414
			jOptions = new JPanel();
415
			jOptions.setLayout(new GridBagLayout());
416
			jOptions.add(getJPNameFile(), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
417
	        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
418
	        new Insets(0, 0, 5, 5), 0, 0));
419
			jOptions.add(getCbOneLyrPerBand(), new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
420
	        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
421
	        new Insets(0, 0, 5, 5), 0, 0));
422
			jOptions.add(getCbSaveFile(), new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
423
	        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
424
	        new Insets(0, 0, 5, 5), 0, 0));
425
			jOptions.add(getCbLoadLayerInToc(), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
426
	        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
427
	        new Insets(0, 0, 5, 5), 0, 0));
428
			jOptions.setPreferredSize(new java.awt.Dimension(wPanel, 135));
421 429
		}
422
		return pCheck;
430
		return jOptions;
423 431
	}
424 432
	
433
	private JPanel getJPNameFile() {
434
		if (jPNameFile == null) {
435
			jPNameFile = new JPanel();
436
			jPNameFile.add(new JLabel(PluginServices.getText(this, "nombre_capas") + ":"));
437
			jPNameFile.add(getFilenameTextField());
438
		}
439
		return jPNameFile;
440
	}
425 441

  
442
	public JTextField getFilenameTextField() {
443
		if (filenameTextField == null) {
444
			filenameTextField = new JTextField();
445
			filenameTextField.setText("cutlayer");
446
			filenameTextField.setPreferredSize(new Dimension(150, filenameTextField.getPreferredSize().height));
447
		}
448
		return filenameTextField;
449
	}
450
	
451
	public JCheckBox getCbSaveFile() {
452
		if (jCheckSaveFile == null) {
453
			jCheckSaveFile = new JCheckBox();
454
			jCheckSaveFile.setText(PluginServices.getText(this, "guardar_en_disco"));
455
		}
456
		return jCheckSaveFile;
457
	}
426 458
	/**
427 459
	 * This method initializes jCheckBox1	
428 460
	 * 	
......
431 463
	public JCheckBox getCbOneLyrPerBand() {
432 464
		if (jCheckBox == null) {
433 465
			jCheckBox = new JCheckBox();
466
			jCheckBox.setText(PluginServices.getText(this, "crear_1_capa_por_banda"));
434 467
		}
435 468
		return jCheckBox;
436 469
	}
437 470
	
471
	public JCheckBox getCbLoadLayerInToc() {
472
		if (jCheckLoadLayerInToc == null) {
473
			jCheckLoadLayerInToc = new JCheckBox();
474
			jCheckLoadLayerInToc.setText(PluginServices.getText(this, "cargar_en_toc"));
475
		}
476
		return jCheckLoadLayerInToc;
477
	}
478
	
438 479
	/**
439 480
	 * Expande o contrae el panel inferior seg?n el estado en el que se encuentre.
440
	 *
441 481
	 */
482
/*
442 483
	public void showExtrasForPanel(boolean contract) {
443 484
		this.getPResolution().setVisible(contract);
444 485
		this.getPSelection().setVisible(contract);
445
		this.getPCheck().setVisible(contract);
486
		this.getJOptions().setVisible(contract);
446 487

  
447 488
		wPanel = PluginServices.getMDIManager().getWindowInfo(getCuttingDialog()).getWidth();
448

  
449
		int minHeight = getCoor_pixel().getHeight() + getCoor_reales().getHeight() + getButtonBarContainer().getHeight() + getButtonsPanel().getHeight() + 40;
450
		int maxHeight = minHeight + getPResolution().getHeight() + getPSelection().getHeight() + getPCheck().getHeight();
489
		
490
		int minHeight = getCoor_pixel().getHeight() + getCoor_reales().getHeight() + getButtonBarContainer().getHeight() + getButtonsPanel().getHeight() + 49;
491
		int maxHeight = minHeight + getPResolution().getHeight() + getPSelection().getHeight() + getJOptions().getHeight();
451 492
		if (contract) {
452 493
			PluginServices.getMDIManager().getWindowInfo(getCuttingDialog()).setWidth(wPanel);
453 494
			PluginServices.getMDIManager().getWindowInfo(getCuttingDialog()).setHeight(maxHeight);
......
462 503
		}
463 504
		this.validate();
464 505
	}
465
	
506
*/
466 507
	/**
467 508
	 * Asigna el valor del campo "Ancho" a partir del double que lo representa
468 509
	 * y con el n?mero de decimales que se especifica en el par?metro dec
......
677 718
	public String getLastTool() {
678 719
		return lastTool;
679 720
	}
721
	
722
	public String getViewName() {
723
		return viewName;
724
	}
680 725
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/cutting/ui/ResolutionPanel.java
100 100
			gridBagConstraints.gridy = 0;
101 101
			pResolution = new JPanel();
102 102
			pResolution.setLayout(new GridBagLayout());
103
			pResolution.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this, "resolucion_espacial"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10), null));
104 103
			pResolution.add(getPOption(), gridBagConstraints);
105 104
			pResolution.add(getPDataInput(), gridBagConstraints1);
106 105
		}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/cutting/ui/listener/CuttingPanelListener.java
28 28
import java.awt.event.KeyListener;
29 29
import java.awt.geom.Rectangle2D;
30 30
import java.io.File;
31
import java.io.FileNotFoundException;
32
import java.io.IOException;
33 31

  
34 32
import javax.swing.JFileChooser;
35 33
import javax.swing.JOptionPane;
......
41 39
import org.gvsig.gui.beans.coorddatainput.CoordDataInputContainer;
42 40
import org.gvsig.gui.beans.incrementabletask.IncrementableTask;
43 41
import org.gvsig.gui.beans.table.models.CheckBoxModel;
44
import org.gvsig.raster.buffer.BufferFactory;
45
import org.gvsig.raster.dataset.IBuffer;
46 42
import org.gvsig.raster.dataset.RasterMultiDataset;
47 43
import org.gvsig.raster.shared.Extent;
48 44
import org.gvsig.raster.util.RasterUtilities;
......
50 46
import org.gvsig.rastertools.cutting.WriterBufferServer;
51 47
import org.gvsig.rastertools.cutting.ui.CuttingPanel;
52 48

  
49
import com.hardcode.driverManager.Driver;
50
import com.hardcode.driverManager.DriverLoadException;
53 51
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
54 52
import com.iver.andami.PluginServices;
55 53
import com.iver.andami.Utilities;
54
import com.iver.andami.ui.mdiManager.IWindow;
56 55
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
56
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
57
import com.iver.cit.gvsig.fmap.drivers.RasterDriver;
58
import com.iver.cit.gvsig.fmap.layers.FLayer;
59
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
57 60
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
58 61
import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent;
59 62
import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener;
63
import com.iver.cit.gvsig.project.documents.view.gui.View;
60 64
/**
61 65
 * <code>CuttingPanelListener</code>. Clase donde se recogeran y trataran
62 66
 * todos los eventos del panel de recorte
......
69 73
	CuttingPanel panel = null;
70 74
	private int widthPx = 0;
71 75
	private int heightPx = 0;
72
	private boolean showExtras = false;
73 76

  
74 77
	/**
75 78
	 *  Valores iniciales de ancho y alto en pixeles de la ventana.
......
81 84
	 */
82 85
	private static String				lastPath = "./";
83 86

  
84
	/**
85
	 * Lista de ficheros creados. Si se ha creado una imagen por banda solo 
86
	 * tendr? un elemento, sino tendr? uno por banda.
87
	 */
88
	private String[]					fileNames = null;
89
	
90 87
	public CuttingPanelListener(CuttingPanel panel) {
91 88
		this.panel = panel;
92 89
	}
......
209 206
			panel.selectToolButton();
210 207
			return;
211 208
		}
212

  
213
		// Bot?n de contraer y expandir el panel
214
		if (e.getSource() == panel.getButtonBarContainer().getButton(2)) {
215
			showExtras = !showExtras;
216
			panel.showExtrasForPanel(showExtras);
217
			return;
218
		}
219 209
	}
220 210

  
221 211
	/**
......
361 351
	}
362 352

  
363 353
	public void actionButtonPressed(ButtonsPanelEvent e) {
364
		//Bot?n de Aceptar o Aplicar
365
		if (e.getButton() == ButtonsPanel.BUTTON_APPLY)
354
		// Bot?n de Aceptar
355
		if (e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
366 356
			accept();
357
			close();
358
		}
359

  
360
		// Bot?n de Aplicar
361
		if (e.getButton() == ButtonsPanel.BUTTON_APPLY) {
362
			accept();
363
			// TODO: Cambiar el nombre del fichero
364
		}
367 365
		
368
		//Bot?n de Cerrar
366
		// Bot?n de Cerrar
369 367
		if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) {
370
			try {
371
				if (getCuttingPanel().getLastTool() != null)
372
					getCuttingPanel().getMapControl().setTool(getCuttingPanel().getLastTool());
373
				PluginServices.getMDIManager().closeWindow(getCuttingPanel().getCuttingDialog());
374
			} catch (ArrayIndexOutOfBoundsException ex) {
375
				// Si la ventana no se puede eliminar no hacemos nada
376
			}
368
			close();
377 369
		}
378 370

  
379
		// Bot?n de Salvar
380
		if (e.getButton() == ButtonsPanel.BUTTON_SAVE)
381
			saveRaster();
382

  
383 371
		getCuttingPanel().getFLayer().getMapContext().invalidate();		
384 372
	}
385 373
	
374
	private void close() {
375
		try {
376
			if (getCuttingPanel().getLastTool() != null)
377
				getCuttingPanel().getMapControl().setTool(getCuttingPanel().getLastTool());
378
			PluginServices.getMDIManager().closeWindow(getCuttingPanel().getCuttingDialog());
379
		} catch (ArrayIndexOutOfBoundsException ex) {
380
			// Si la ventana no se puede eliminar no hacemos nada
381
		}
382
	}
383
	
386 384
	public CuttingPanel getCuttingPanel() {
387 385
		return panel;
388 386
	}
......
393 391
	 * gestiona el recortado, ajustamos el tama?o del grid de salida y procesamos.
394 392
	 */
395 393
	private void accept() {
396
//		getCuttingPanel().getFLayer()
397
		// grid = fLayer.getGrid();
398

  
399 394
		// Controlamos las coordenadas del recorte que no se salgan de la imagen.
400 395
		// De ser as? mostramos un error
401 396
		CoordDataInputContainer values = getCuttingPanel().getCoor_reales();
......
438 433
			// Los valores de las cajas son incorrectos. Terminamos la funci?n
439 434
			return;
440 435
		}
441

  
436
		
442 437
		// Seleccionamos las bandas que se usaran en el recorte a partir de la tabla
443 438
		int countBands = 0;
444 439
		int rowCount = ((CheckBoxModel) getCuttingPanel().getTSelection().getModel())
......
456 451
				drawableBands[i++] = iRow;
457 452
			}
458 453
		}
459
		
460
//		ViewPort vp = new ViewPort(getCuttingPanel().getFLayer().getProjection());
461
		
462
//		WriterParams params = getWriterParams(fName);
454

  
455
		/**
456
		 * Donde se va a guardar el fichero
457
		 */
458
		String path = "";
459
		if (getCuttingPanel().getCbSaveFile().isSelected()) {
460
			JFileChooser chooser = new JFileChooser(CuttingPanelListener.lastPath);
461
			chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
462
			chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_directorio"));
463
	
464
			if (chooser.showOpenDialog(getCuttingPanel()) != JFileChooser.APPROVE_OPTION)
465
				return;
466
			CuttingPanelListener.lastPath = chooser.getSelectedFile().toString();
467
			path = CuttingPanelListener.lastPath;
468
		} else {
469
			path = Utilities.createTempDirectory();
470
		}
471

  
472
		String file = getCuttingPanel().getFilenameTextField().getText();
473
		if (file == "") file = "cutlayer";
474

  
475
		String filename = path + File.separator + file;
476

  
477
		/**
478
		 * Preparacion para la generacion del proceso del recorte
479
		 */
463 480
		RasterMultiDataset rasterMultiDataset = ((FLyrRasterSE) getCuttingPanel().getFLayer()).getGeoRasterMultiDataset();
464
		BufferFactory bufferFactory = new BufferFactory(rasterMultiDataset);
465
		bufferFactory.addDrawableBands(drawableBands);
466
		bufferFactory.setAreaOfInterest(dValues[0], dValues[3], dValues[2] - dValues[0], dValues[1] - dValues[3]);
467
		IBuffer buffer = bufferFactory.getRasterBuf();
468
		
469
		WriterBufferServer dataWriter1 = new WriterBufferServer(buffer);
470
		
471
		String tmpImgs = Utilities.createTempDirectory();
472
		String filename = tmpImgs + File.separator + "cutLayer.tif";
481
		WriterBufferServer dataWriter1 = new WriterBufferServer();
473 482
		Extent extent = new Extent(minX, maxY, maxX, minY);
474
		CuttingProcess cuttingProcess = new CuttingProcess(filename, dataWriter1, buffer, extent);
483

  
484
		CuttingProcess cuttingProcess = new CuttingProcess(this, filename, dataWriter1, rasterMultiDataset, extent, drawableBands, getCuttingPanel().getCbOneLyrPerBand().isSelected());
475 485
		IncrementableTask incrementableTask = new IncrementableTask(dataWriter1);
476 486
		cuttingProcess.setIncrementableTask(incrementableTask);
477 487
		incrementableTask.showWindow();
478 488
		cuttingProcess.start();
479 489
		incrementableTask.start();		
480

  
481
		getCuttingPanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_SAVE).setEnabled(true);
482 490
	}
483 491
	
484

  
485 492
	/**
486
	 * Acciones realizadas cuando se salva los recortes de raster. Aparecer? un dialogo para introducir
487
	 * la ruta y salvaremos el raster completo con el nombre proporcionado o si se ha salvado por bandas
488
	 * se guardar? un fichero por cada una con el nombre proporcionado m?s _Bn.
493
	 * Acciones que se realizan al finalizar de crear los recortes de imagen.
494
	 * Este m?todo es llamado por el thread TailRasterProcess al finalizar.
489 495
	 */
490
	private void saveRaster() {
491
		JFileChooser chooser = new JFileChooser(lastPath);
492
		chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_directorio"));
496
	public void cutFinalize(String fileNames) {
497
		if (!getCuttingPanel().getCbLoadLayerInToc().isSelected())
498
			return;
499
		// seleccionamos la vista de gvSIG
500
		com.iver.cit.gvsig.project.documents.view.gui.View theView = null;
501
		try {
502
			IWindow[] allViews = PluginServices.getMDIManager().getAllWindows();
503
			for (int i = 0; i < allViews.length; i++) {
504
				if (allViews[i] instanceof com.iver.cit.gvsig.project.documents.view.gui.View
505
						&& PluginServices.getMDIManager().getWindowInfo((View) allViews[i])
506
								.getTitle().equals(getCuttingPanel().getViewName()))
507
					theView = (com.iver.cit.gvsig.project.documents.view.gui.View) allViews[i];
508
			}
509
			if (theView == null)
510
				return;
511
		} catch (ClassCastException ex) {
512
			// logger.error(PluginServices.getText(this,"cant_get_view "), ex);
513
			return;
514
		}
493 515

  
494
		int returnVal = chooser.showOpenDialog(getCuttingPanel());
495
		if (returnVal == JFileChooser.APPROVE_OPTION) {
496
			String fName = chooser.getSelectedFile().toString();
516
		// Cargamos las capas
517
		theView.getMapControl().getMapContext().beginAtomicEvent();
518
		try {
519
			Driver driver = LayerFactory.getDM().getDriver("gvSIG Image Driver");
520
			int endIndex = fileNames.lastIndexOf(".");
521
			if (endIndex < 0)
522
				endIndex = fileNames.length();
523
			FLayer lyr = LayerFactory.createLayer(fileNames.substring(
524
					fileNames.lastIndexOf(File.separator) + 1, endIndex),
525
					(RasterDriver) driver, new File(fileNames), theView
526
							.getMapControl().getProjection());
527
			theView.getMapControl().getMapContext().getLayers().addLayer(lyr);
528
			theView.getMapControl().getMapContext().endAtomicEvent();
497 529

  
498
			if (fileNames == null || fileNames.length == 0)
499
				return;
500

  
501
			try {
502
				if (fileNames.length == 1) {
503
					if (!fName.endsWith(".tif"))
504
						fName += ".tif";
505
//					File oldFile = new File(fileNames[0]);
506
					RasterUtilities.copyFile(fileNames[0], fName);
507
				} else {
508
					if (fName.endsWith(".tif"))
509
						fName = fName.substring(0, fName.indexOf("."));
510
					for (int iFile = 0; iFile < fileNames.length; iFile++) {
511
//						File oldFile = new File(fileNames[iFile]);
512
						RasterUtilities.copyFile(fileNames[iFile], fName + "_B" + iFile + ".tif");
513
					}
514
				}
515
			} catch (FileNotFoundException e) {
516
				e.printStackTrace();
517
			} catch (IOException e) {
518
				e.printStackTrace();
519
			}
520
			lastPath = chooser.getCurrentDirectory().getAbsolutePath();
530
			theView.getMapControl().getMapContext().invalidate();
531
//			grid.free();
532
		} catch (DriverLoadException e) {
533
			e.printStackTrace();
534
		} catch (LoadLayerException e) {
535
			e.printStackTrace();
521 536
		}
522
	}	
537
	}
523 538
}

Also available in: Unified diff