Revision 11930

View differences:

org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.105/org.gvsig.raster.multifile.app.multifileclient/buildNumber.properties
1
#Mon Jul 13 13:31:53 CEST 2020
2
buildNumber=157
0 3

  
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.105/org.gvsig.raster.multifile.app.multifileclient/src/main/resources-plugin/org/gvsig/raster/multifile/app/i18n/text.properties
1
store_tiled=La capa actual est? tileada.\n Para a?adir ficheros a ella se convertir? a no tileada.
2
combinacion_no_asignable=No es posible guardar esa combinaci?n de bandas por defecto.\n Una banda solo puede tener una interpretaci?n de color.
3
color_interpretation_continue=Se va a cambiar la interpretaci?n de color por defecto para su raster. ?Desea continuar?
4
error_carga_capa=Error en la carga de la capa.
5
error_salvando_rmf=Error escribiendo el fichero rmf
6
table_not_initialize=Tabla no inicializada
7
fichero_existe=El fichero existe en el dataset
8
extents_no_coincidentes=La extensi?n de las capas no coinciden
9
addband_error=No se pudo a?adir las bandas del fichero seleccionado al dataset
10
anadir=A?adir
11
eliminar=Eliminar
12
bands_panel=Bandas
13
bands=Bandas
14
save=Salvar
15
save_color_interpretation=Salvar la interpretaci?n de color
16
layer_name=Nombre de capa
17
character_not_valid=Caracter no valido
18
create_multifile=Crear capa multifichero
19
load_layer=Cargar capa
20
generate_file=Generar fichero
21
select_output_file=Capa de salida
22
add_files=A?adir ficheros
0 23

  
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.105/org.gvsig.raster.multifile.app.multifileclient/src/main/resources-plugin/org/gvsig/raster/multifile/app/i18n/text_en.properties
1
store_tiled=The current layer is tiled.\n To add files will be turned into not tiled.
2
combinacion_no_asignable=It's not possible to save this selection of bands as default.\n A band only can to have one color interpretation
3
color_interpretation_continue=It's going to change default color interpretationlor for this raster. Would you like to go on?
4
error_carga_capa=Error loading layer
5
error_salvando_rmf=Error writing in rmf file
6
table_not_initialize=Table not initialize
7
fichero_existe=Selected file already exists as layer band
8
extents_no_coincidentes=Extent of the selected image does not match with the origin image.
9
addband_error=Bands haven't been added to selected dataset.
10
anadir=Add
11
eliminar=Remove
12
bands_panel=Bands
13
bands=Bands
14
save=Save
15
save_color_interpretation=Save color interpretation
16
layer_name=Layer name
17
character_not_valid=Character not valid
18
create_multifile=Create layer multifile
19
load_layer=Load layer
20
generate_file=Builds a file
21
select_output_file=Output layer
22
add_files=Add files
0 23

  
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.105/org.gvsig.raster.multifile.app.multifileclient/src/main/resources-plugin/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
  <depends plugin-name="org.gvsig.raster.mainplugin" />
4
  <depends plugin-name="org.gvsig.raster.tilecache.app" optional="true" />
5
  <resourceBundle name="text" />
6
  <libraries library-dir="lib" />
7
  <extensions>
8
    <extension class-name="org.gvsig.raster.multifile.app.MultifileClientExtension"
9
      description="Support for raster multiband and multifile" active="true"
10
      priority="1">
11

  
12
      <!-- <menu text="Layer/dataset_raster/create_multifile" name="raster-tools-multifile"/>
13
        <action name="raster-tools-multifile" label="create_multifile" action-command="MultifileCreator"
14
        icon="multifile-icon" position="000601500" accelerator="" /> -->
15
    </extension>
16
  </extensions>
17
</plugin-config>
0 18

  
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.105/org.gvsig.raster.multifile.app.multifileclient/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
  </files>
17

  
18
  <fileSets>
19
    <fileSet>
20
      <directory>src/main/resources-plugin</directory>
21
      <outputDirectory>.</outputDirectory>
22
    </fileSet>
23
  </fileSets>
24

  
25

  
26
  <dependencySets>
27
    <dependencySet>
28
      <useProjectArtifact>false</useProjectArtifact>
29
	  <useTransitiveDependencies>false</useTransitiveDependencies>
30
      <outputDirectory>lib</outputDirectory>
31
      <includes> 
32
			<include>org.gvsig:org.gvsig.raster.multifile.app.multifileclient:jar</include>
33
			<include>org.gvsig:org.gvsig.raster.multifile.io:jar</include>
34
	  </includes>
35
	</dependencySet>
36
  </dependencySets>
37
</assembly>
0 38

  
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.105/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/MainDialogActions.java
1
package org.gvsig.raster.multifile.app;
2

  
3
import java.io.File;
4
import java.io.IOException;
5
import java.util.ArrayList;
6
import java.util.List;
7

  
8
import org.gvsig.andami.PluginServices;
9
import org.gvsig.andami.ui.mdiManager.IWindow;
10
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
11
import org.gvsig.fmap.dal.coverage.RasterLocator;
12
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
13
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException;
14
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
15
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
16
import org.gvsig.fmap.mapcontext.MapContextLocator;
17
import org.gvsig.fmap.mapcontext.MapContextManager;
18
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
19
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
20
import org.gvsig.i18n.Messages;
21
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary;
22
import org.gvsig.raster.algorithm.process.DataProcess;
23
import org.gvsig.raster.algorithm.process.IProcessActions;
24
import org.gvsig.raster.algorithm.process.ProcessException;
25
import org.gvsig.raster.fmap.layers.FLyrRaster;
26
import org.gvsig.raster.impl.provider.RasterProvider;
27
import org.gvsig.raster.multifile.app.panel.BandSelectorPanel;
28
import org.gvsig.raster.multifile.io.MultiFileDataParameters;
29
import org.gvsig.raster.multifile.io.MultiFileFormat;
30
import org.gvsig.raster.swing.RasterSwingLibrary;
31

  
32
/**
33
 * @author gvSIG team
34
 *
35
 */
36
public class MainDialogActions implements IProcessActions {
37
	private String                          file                 = null;
38
	private String                          folder               = null;
39
	private BandSelectorPanel               panel                = null;
40
	private AbstractViewPanel               selectedView         = null;
41

  
42
	/**
43
	 * @param panel
44
	 * @param file
45
	 * @param folder
46
	 */
47
	public MainDialogActions(BandSelectorPanel panel, String file, String folder) {
48
		this.file = file;
49
		this.folder = folder;
50
		this.panel = panel;
51
	}
52

  
53
	/**
54
	 *
55
	 */
56
	public void buildOneLayer() {
57
		RasterDataStore mainRasterStore = panel.getResult();
58
		saveMetadata();
59

  
60
		DataProcess clippingProcess = null;
61
		try {
62
			clippingProcess = RasterBaseAlgorithmLibrary.getManager().createRasterTask("ClippingProcess");
63
		} catch (ProcessException e) {
64
			RasterSwingLibrary.messageBoxError(Messages.getText("error_processing_layer"), panel, e);
65
		}
66
		clippingProcess.setActions(this);
67
		String tit = PluginServices.getMDIManager().getWindowInfo(getView()).getTitle();
68
		clippingProcess.addParam("viewname", tit);
69
		clippingProcess.addParam("pixelcoordinates", new int[] { 0, (int) mainRasterStore.getHeight(), (int) mainRasterStore.getWidth(), 0 });
70
		clippingProcess.addParam("resolution", new int[]{(int) mainRasterStore.getWidth(),
71
					 										 (int) mainRasterStore.getHeight()});
72
		clippingProcess.addParam("suffix", ".tif");
73

  
74
		clippingProcess.addParam("filename", folder + File.separator + file);
75
		clippingProcess.addParam("layer", mainRasterStore);
76
		int[] drawableBands = new int[mainRasterStore.getBandCount()];
77
		for (int i = 0; i < drawableBands.length; i++) {
78
			drawableBands[i] = i;
79
		}
80
		clippingProcess.addParam("drawablebands", drawableBands);
81
		clippingProcess.addParam("onelayerperband", new Boolean(false));
82
		clippingProcess.addParam("interpolationmethod", new Integer(Buffer.INTERPOLATION_NearestNeighbour));
83
		clippingProcess.addParam("affinetransform", mainRasterStore.getAffineTransform());
84

  
85

  
86
		/*if (params != null)
87
			RasterToolsUtil.loadWriterParamsFromPropertiesPanel(panelProperty, params);
88
		clippingProcess.addParam("driverparams", params);*/
89
		clippingProcess.start();
90
	}
91

  
92
	/**
93
	 *
94
	 */
95
	public void loadLayer() {
96
		RasterDataStore mainRasterStore = panel.getResult();
97
		if(mainRasterStore == null) {
98
			return;
99
		}
100

  
101
		saveMff(mainRasterStore);
102
		saveMetadata();
103
		try {
104
			loadLayerInView(mainRasterStore);
105
		} catch (LoadLayerException e) {
106
			RasterSwingLibrary.messageBoxError(Messages.getText("error_loading_layer"), panel, e);
107
		}
108
	}
109

  
110
	private void saveMff(RasterDataStore mainRasterStore) {
111
		MultiFileDataParameters params = (MultiFileDataParameters)mainRasterStore.getParameters();
112
		ArrayList<File> uriList = new ArrayList<File>();
113
		List<RasterProvider> providers = params.getProviders();
114
		for (int i = 0; i < providers.size(); i++) {
115
			uriList.add(new File(providers.get(i).getURI()));
116
		}
117
		try {
118
			MultiFileFormat.saveMultiFileFormat(file, folder, uriList);
119
		} catch (IOException e) {
120
			RasterSwingLibrary.messageBoxError(Messages.getText("error_salvando_mff"), panel, e);
121
		}
122
	}
123

  
124
	private void saveMetadata() {
125
		RasterDataStore mainRasterStore = panel.getResult();
126
		int rBand = panel.getColorInterpretationByColorBandBand(RasterDataStore.RED_BAND);
127
		int gBand = panel.getColorInterpretationByColorBandBand(RasterDataStore.GREEN_BAND);
128
		int bBand = panel.getColorInterpretationByColorBandBand(RasterDataStore.BLUE_BAND);
129
		int aBand = panel.getColorInterpretationByColorBandBand(RasterDataStore.ALPHA_BAND);
130

  
131
		if (!isCorrectAssignedBand(rBand, gBand, bBand, aBand)) {
132
			RasterSwingLibrary.messageBoxError(Messages.getText("combinacion_no_asignable"), panel);
133
			return;
134
		}
135

  
136
		try {
137
			ColorInterpretation ci = RasterLocator.getManager().getDataStructFactory().createColorInterpretation(
138
					new String[mainRasterStore.getBandCount()]);
139
			// Combinaci?n GRAY
140
			if ((rBand == gBand) && (rBand == bBand) && (rBand >= 0)) {
141
				for (int iBand = 0; iBand < panel.getARGBTable().getRowCount(); iBand++) {
142
					ci.setColorInterpValue(iBand, ColorInterpretation.UNDEF_BAND);
143
				}
144
				ci.setColorInterpValue(rBand, ColorInterpretation.GRAY_BAND);
145
				ci.setColorInterpValue(aBand, ColorInterpretation.ALPHA_BAND);
146
			} else {
147
				// Combinaci?n RGB
148
				ci.setColorInterpValue(aBand, ColorInterpretation.ALPHA_BAND);
149
				ci.setColorInterpValue(rBand, ColorInterpretation.RED_BAND);
150
				ci.setColorInterpValue(gBand, ColorInterpretation.GREEN_BAND);
151
				ci.setColorInterpValue(bBand, ColorInterpretation.BLUE_BAND);
152
			}
153
			RasterLocator.getManager().getProviderServices().saveObjectToRmfFile(folder + File.separator + file, ci);
154
		} catch (RmfSerializerException exc) {
155
			RasterSwingLibrary.messageBoxError(Messages.getText("error_salvando_rmf"), panel, exc);
156
		} catch (NotInitializeException exc) {
157
			RasterSwingLibrary.messageBoxError(Messages.getText("table_not_initialize"), panel, exc);
158
		}
159
	}
160

  
161
	private void loadLayerInView(RasterDataStore mainRasterStore) throws LoadLayerException {
162
		MapContextManager mcm = MapContextLocator.getMapContextManager();
163
		FLyrRaster lyr = (FLyrRaster) mcm.createLayer(file, mainRasterStore);
164
		lyr.reload();
165

  
166
		getView().getMapControl().getMapContext().beginAtomicEvent();
167
		getView().getMapControl().getMapContext().getLayers().addLayer(lyr);
168
		getView().getMapControl().getMapContext().invalidate();
169
		getView().getMapControl().getMapContext().endAtomicEvent();
170
	}
171

  
172
	private AbstractViewPanel getView() {
173
		if(selectedView == null) {
174
			IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
175
			for (int i = 0; i < wList.length; i++) {
176
				if(wList[i] instanceof AbstractViewPanel)
177
					selectedView = (AbstractViewPanel)wList[i];
178
			}
179
		}
180
		return selectedView;
181
	}
182

  
183
	private boolean isCorrectAssignedBand(int r, int g, int b, int a) {
184
		// Si es gris es correcta la asignacion
185
		if ((r == g) && (r == b) && (r >= 0)) {
186
			// Si el alpha esta asignado a la misma banda es incorrecto
187
			if (r == a)
188
				return false;
189
			// En caso contrario es correcto
190
			return true;
191
		}
192

  
193
		// Si dos bandas coinciden, se dice que no es correcta la asignacion
194
		int list[] = { r, g, b, a };
195
		for (int i = 0; i <= 3; i++)
196
			for (int j = 0; j <= 3; j++)
197
				if ((i != j) && (list[i] == list[j]) && (list[i] > -1))
198
					return false;
199

  
200
		return true;
201
	}
202

  
203
	public void interrupted() {
204
		// TODO Auto-generated method stub
205

  
206
	}
207

  
208
	public void end(Object param) {
209

  
210
	}
211

  
212
	public void updateProgress(int current, int total) {
213
		// TODO Auto-generated method stub
214

  
215
	}
216
}
0 217

  
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.105/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/MultifileClientExtension.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22
package org.gvsig.raster.multifile.app;
23

  
24
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionListener;
26
import java.util.Locale;
27

  
28
import javax.swing.JComponent;
29

  
30
import org.gvsig.andami.IconThemeHelper;
31
import org.gvsig.andami.PluginServices;
32
import org.gvsig.andami.plugins.Extension;
33
import org.gvsig.i18n.Messages;
34
import org.gvsig.raster.multifile.app.panel.BandSelectorPanel;
35
import org.gvsig.raster.multifile.app.panel.MainWindow;
36
import org.gvsig.raster.swing.RasterSwingLocator;
37
import org.gvsig.raster.swing.basepanel.IButtonsPanel;
38
import org.gvsig.raster.swing.newlayer.CreateNewLayerPanel;
39
import org.gvsig.tools.ToolsLocator;
40
import org.gvsig.tools.extensionpoint.ExtensionPoint;
41
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
42

  
43
/**
44
 * Extension for adding grid netcdf support to gvSIG.
45
 * @author Nacho Brodin (nachobrodin@gmail.com)
46
 */
47
public class MultifileClientExtension extends Extension implements ActionListener {
48
	private CreateNewLayerPanel             newLayerPanel        = null;
49
	private MainWindow                      layerNamewindow      = null;
50
	private MainWindow                      bandSelectorwindow   = null;
51
	private MainDialogActions               actions              = null;
52

  
53
	public void initialize() {
54
		ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
55

  
56
		ExtensionPoint point = extensionPoints.get("AplicationPreferences");
57
		point = extensionPoints.get("RasterSEPropertiesDialog");
58
		point.append("Bandas", "", BandSelectorPanel.class);
59

  
60
		point = extensionPoints.add("GenericToolBarMenu");
61
		point.append("Multifile", "", MultiFileCreatorTocMenuEntry.getSingleton());
62
		MultiFileCreatorTocMenuEntry.setExtension(this);
63

  
64
		if (!Messages.hasLocales()) {
65
			Messages.addLocale(Locale.getDefault());
66
		}
67

  
68
		Messages.addResourceFamily("org.gvsig.raster.multifile.app.i18n.text",
69
				MultifileClientExtension.class.getClassLoader(),
70
				MultifileClientExtension.class.getClass().getName());
71

  
72
		initilizeIcons();
73
	}
74

  
75
	public void execute(String actionCommand) {
76
		if (actionCommand.compareTo("MultifileCreator") == 0) {
77
			layerNamewindow = new MainWindow((JComponent)getNewLayerPanel(),
78
					Messages.getText("select_output_file"), 300, 150, this);
79
			PluginServices.getMDIManager().addCentredWindow(layerNamewindow);
80
    	}
81
	}
82

  
83
	private void initilizeIcons() {
84
		IconThemeHelper.registerIcon(null, "multifile-icon", this);
85
    }
86

  
87
	public boolean isEnabled() {
88
		return true;
89
	}
90

  
91
	public boolean isVisible() {
92
		return true;
93
	}
94

  
95
	/**
96
	 * @return CreateNewLayerPanel
97
	 */
98
	public CreateNewLayerPanel getNewLayerPanel() {
99
		if(newLayerPanel == null) {
100
			newLayerPanel = RasterSwingLocator.getSwingManager().createNewLayerPanel();
101
		}
102
		return newLayerPanel;
103
	}
104

  
105
	public void actionPerformed(ActionEvent e) {
106
		//Accept the window with the layer name
107
		if(e.getSource() == layerNamewindow.getButtonsPanel().getButton(IButtonsPanel.BUTTON_ACCEPT)) {
108
			String file = getNewLayerPanel().getFileSelected();
109
			String folder = getNewLayerPanel().getDirectorySelected();
110
			BandSelectorPanel panel = new BandSelectorPanel(BandSelectorPanel.TYPE_DIALOG);
111
			panel.getListener().setDestination(file, folder);
112
			actions = new MainDialogActions(panel, file, folder);
113
			bandSelectorwindow = new MainWindow(panel, Messages.getText("add_files"), 500, 400, this, true);
114
			PluginServices.getMDIManager().addCentredWindow(bandSelectorwindow);
115
		}
116

  
117
		//Button of load layer in the main dialog
118
		if(e.getSource() == bandSelectorwindow.getButtonsPanel().getButton(IButtonsPanel.BUTTON_USR1)) {
119
			actions.loadLayer();
120
		}
121

  
122
		//Button of create one file with al files
123
		if(e.getSource() == bandSelectorwindow.getButtonsPanel().getButton(IButtonsPanel.BUTTON_USR2)) {
124
			actions.buildOneLayer();
125
		}
126

  
127
	}
128
}
0 129

  
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.105/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/MultiFileCreatorTocMenuEntry.java
1
package org.gvsig.raster.multifile.app;
2

  
3
import javax.swing.Icon;
4

  
5
import org.gvsig.andami.IconThemeHelper;
6
import org.gvsig.andami.plugins.Extension;
7
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
8
import org.gvsig.app.project.documents.view.toc.ITocItem;
9
import org.gvsig.fmap.mapcontext.layers.FLayer;
10
import org.gvsig.i18n.Messages;
11
import org.gvsig.raster.mainplugin.toolbar.IGenericToolBarMenuItem;
12

  
13
/**
14
 * @author gvSIG team
15
 *
16
 */
17
public class MultiFileCreatorTocMenuEntry extends AbstractTocContextMenuAction implements IGenericToolBarMenuItem {
18
	static private MultiFileCreatorTocMenuEntry     singleton  = null;
19
	private static Extension                     extension  = null;
20

  
21

  
22
	/**
23
	 * @param ext
24
	 */
25
	public static void setExtension(Extension ext) {
26
		extension = ext;
27
	}
28

  
29
	private MultiFileCreatorTocMenuEntry() {}
30

  
31
	/**
32
	 * @return MultiFileCreatorTocMenuEntry
33
	 */
34
	static public MultiFileCreatorTocMenuEntry getSingleton() {
35
		if (singleton == null)
36
			singleton = new MultiFileCreatorTocMenuEntry();
37
		return singleton;
38
	}
39

  
40
	public String getGroup() {
41
		return "Dataset";
42
	}
43

  
44
	public int getGroupOrder() {
45
		return 55;
46
	}
47

  
48
	public int getOrder() {
49
		return 0;
50
	}
51

  
52
	public String getText() {
53
		return Messages.getText("create_multifile");
54
	}
55

  
56
	public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
57
		return true;
58
	}
59

  
60
	public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
61
		return true;
62
	}
63

  
64
	public void execute(ITocItem item, FLayer[] selectedItems) {
65
		extension.execute("MultifileCreator");
66
	}
67

  
68
	public Icon getIcon() {
69
		return IconThemeHelper.getImageIcon("multifile-icon");
70
	}
71

  
72
}
0 73

  
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.105/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/panel/AbstractBandSelectorListener.java
1
package org.gvsig.raster.multifile.app.panel;
2

  
3
import java.awt.event.ActionEvent;
4
import java.awt.event.ActionListener;
5
import java.awt.geom.Rectangle2D;
6
import java.io.File;
7
import java.io.IOException;
8
import java.util.ArrayList;
9
import java.util.List;
10

  
11
import javax.swing.JOptionPane;
12

  
13
import org.gvsig.gui.beans.swing.JFileChooser;
14
import org.gvsig.fmap.dal.DALLocator;
15
import org.gvsig.fmap.dal.DataServerExplorer;
16
import org.gvsig.fmap.dal.DataServerExplorerParameters;
17
import org.gvsig.fmap.dal.coverage.RasterLocator;
18
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
19
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
20
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
21
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
22
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
23
import org.gvsig.fmap.dal.coverage.util.ProviderServices;
24
import org.gvsig.fmap.dal.exception.CloseException;
25
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerWizardPanel;
26
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
27
import org.gvsig.i18n.Messages;
28
import org.gvsig.raster.multifile.io.MultiFileDataParameters;
29
import org.gvsig.raster.multifile.io.MultiFileFormat;
30
import org.gvsig.raster.multifile.io.MultiFileProvider;
31
import org.gvsig.raster.swing.RasterSwingLibrary;
32
import org.gvsig.raster.swing.basepanel.ButtonsPanelListener;
33
import org.gvsig.tools.locator.LocatorException;
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36

  
37
/**
38
 * Listener for <code>BandSelectorPanel</code>. This interface is implemented by two listeners
39
 * , the new layer listener and the properties panel listener.
40
 * @author Nacho Brodin (nachobrodin@gmail.com)
41
 */
42
public abstract class AbstractBandSelectorListener implements ActionListener, ButtonsPanelListener {
43
	protected Logger                log              = LoggerFactory.getLogger(AbstractBandSelectorListener.class);
44
	protected BandSelectorPanel     bandSetupPanel   = null;
45
	protected boolean               enabled          = true;
46
	protected String                file             = null;
47
	protected String                folder           = null;
48

  
49
	/**
50
	 * Constructor
51
	 * @param bs Panel del selector de bandas
52
	 * @param lyr Capa raster
53
	 */
54
	public AbstractBandSelectorListener(BandSelectorPanel bs) {
55
		this.bandSetupPanel = bs;
56
		bs.getFileList().getJButtonAdd().addActionListener(this);
57
		bs.getFileList().getJButtonRemove().addActionListener(this);
58
		bs.getNumBandSelectorCombo().addActionListener(this);
59
	}
60

  
61
	/**
62
	 * @param file
63
	 * @param folder
64
	 */
65
	public void setDestination(String file, String folder) {
66
		this.file = file;
67
		this.folder = folder;
68
	}
69

  
70
	/**
71
	 * Enables or disables the panel action
72
	 * @param enabled
73
	 */
74
	public void setEnabledPanelAction(boolean enabled) {
75
		this.enabled = enabled;
76
	}
77

  
78
	/**
79
	 * Sets the band position when these are rendered. The position is read from
80
	 * the band table
81
	 */
82
	public abstract void setNewBandsPositionInRendering();
83

  
84
	/**
85
	 * @return RasterDataStore
86
	 */
87
	public abstract RasterDataStore getResult();
88

  
89
	/**
90
	 * Actions when is applied
91
	 */
92
	public abstract void apply();
93

  
94
	/**
95
	 *
96
	 */
97
	public abstract void addFileBand();
98

  
99
	/**
100
	 *
101
	 */
102
	public abstract void delFileBand();
103

  
104
	/**
105
	 * Listener para la gesti?n de los botones de a?adir, eliminar fichero y
106
	 * el combo de selecci?n de bandas.
107
	 */
108
	public void actionPerformed(ActionEvent e) {
109

  
110
		if (e.getSource().equals(bandSetupPanel.getFileList().getJButtonAdd()))
111
			addFileBand();
112

  
113
		if (e.getSource().equals(bandSetupPanel.getFileList().getJButtonRemove()))
114
			delFileBand();
115
	}
116

  
117
	protected JFileChooser createJFileChooser() {
118
		JFileChooser fileChooser = new JFileChooser(
119
				FilesystemExplorerWizardPanel.OPEN_LAYER_FILE_CHOOSER_ID,
120
				JFileChooser.getLastPath(FilesystemExplorerWizardPanel.OPEN_LAYER_FILE_CHOOSER_ID, null));
121
		fileChooser.setMultiSelectionEnabled(true);
122
		fileChooser.setAcceptAllFileFilterUsed(false);
123

  
124
		fileChooser.addChoosableFileFilter(new DriverFileFilter());
125
		return fileChooser;
126
	}
127

  
128
	protected boolean checkStoresCompatibility(RasterDataStore mainRasterStore, List<File> fileList) {
129
		for (int i = fileList.size() - 1; i >= 0; i--) {
130
			//Checks extents
131
			try {
132
				if(!checkNewFile(mainRasterStore, fileList.get(i).getAbsolutePath())) {
133
					JOptionPane.showMessageDialog(null, Messages.getText("extents_no_coincidentes") +  " " + fileList.get(i).getAbsolutePath(), "", JOptionPane.ERROR_MESSAGE);
134
					fileList.remove(i);
135
				}
136
			} catch (Exception e) {
137
				log.debug("Problems check the bounding boxes", e);
138
			}
139
		}
140

  
141
		if(mainRasterStore.isTiled()) {
142
			if(!RasterSwingLibrary.messageBoxYesOrNot(Messages.getText("store_tiled"), this)) {
143
				return false;
144
			}
145
		}
146

  
147
		return true;
148
	}
149

  
150
	/**
151
	 * Creates a multifile data provider
152
	 * @param layerName
153
	 * @param path
154
	 * @return
155
	 */
156
	protected MultiFileProvider createMultiFileProvider(String layerName, String path) {
157
		DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager();
158

  
159
		try {
160
			//It creates the new Multifile provider
161
			MultiFileDataParameters newParamsMultifile = (MultiFileDataParameters)dataManager.createStoreParameters(MultiFileProvider.NAME);
162

  
163
			if(!path.endsWith(File.separator))
164
				path = path + File.separator;
165
			File fileURI = new File(path + layerName + ".mff");
166
			File rmfURI = new File(path + layerName + ".rmf");
167
			int counter = 0;
168
			while(fileURI.exists() || rmfURI.exists()) {
169
				fileURI = new File(path + layerName + "_" + counter + ".mff");
170
				rmfURI = new File(path + layerName + "_" + counter + ".rmf");
171
				counter ++;
172
			}
173
			if(counter > 0)
174
				layerName += "_" + counter;
175

  
176
			newParamsMultifile.setURI(fileURI.toURI());
177

  
178
			return (MultiFileProvider)dataManager.createProvider(null, newParamsMultifile);
179
		} catch (Exception exc) {
180
			RasterSwingLibrary.messageBoxError(Messages.getText("addband_error"), bandSetupPanel, exc);
181
		}
182
		return null;
183
	}
184

  
185
	/**
186
	 * Comprobar si la asignacion de color es correcta para las 4 bandas. No puede
187
	 * existir una banda con distintas interpretaciones de color. Se comprueban dos
188
	 * casos, asignaciones en escala de grises o en RGB.
189
	 * @param r
190
	 * @param g
191
	 * @param b
192
	 * @param a
193
	 * @return
194
	 */
195
	protected boolean isCorrectAssignedBand(int r, int g, int b, int a) {
196
		// Si es gris es correcta la asignacion
197
		if ((r == g) && (r == b) && (r >= 0)) {
198
			// Si el alpha esta asignado a la misma banda es incorrecto
199
			if (r == a)
200
				return false;
201
			// En caso contrario es correcto
202
			return true;
203
		}
204

  
205
		// Si dos bandas coinciden, se dice que no es correcta la asignacion
206
		int list[] = { r, g, b, a };
207
		for (int i = 0; i <= 3; i++)
208
			for (int j = 0; j <= 3; j++)
209
				if ((i != j) && (list[i] == list[j]) && (list[i] > -1))
210
					return false;
211

  
212
		return true;
213
	}
214

  
215
	/**
216
	 * Checks if the new file is compatible with the old one
217
	 * @param file
218
	 * @return
219
	 * @throws LocatorException
220
	 * @throws NotSupportedExtensionException
221
	 * @throws RasterDriverException
222
	 * @throws CloseException
223
	 */
224
	protected boolean checkNewFile(RasterDataStore oldStore, String file) throws LocatorException, NotSupportedExtensionException, RasterDriverException, CloseException {
225
		Rectangle2D extentOrigin = oldStore.getExtent().toRectangle2D();
226

  
227
		ProviderServices provServ = RasterLocator.getManager().getProviderServices();
228
		RasterDataParameters storeParameters = provServ.createParameters(file);
229
		storeParameters.setSRS(oldStore.getProjection());
230
		RasterDataStore dataStore = RasterLocator.getManager().getProviderServices().open(storeParameters);
231

  
232
		Extent extentNewFile = dataStore.getExtent();
233

  
234
		// Comprobamos que el extent y tama?o del fichero a?adido sea igual al
235
		// fichero original. Si no es as? no abrimos la capa y mostramos un aviso
236

  
237
		double widthNewFile = (extentNewFile.getMax().getX() - extentNewFile.getMin().getX());
238
		double heightNewFile = (extentNewFile.getMax().getY() - extentNewFile.getMin().getY());
239

  
240
		if ((widthNewFile - extentOrigin.getWidth()) > 1.0 || (widthNewFile - extentOrigin.getWidth()) < -1.0 || (heightNewFile - extentOrigin.getHeight()) > 1.0
241
				|| (heightNewFile - extentOrigin.getHeight()) < -1.0) {
242
			return false;
243
		}
244

  
245
		if ((extentNewFile.getMax().getX() - extentNewFile.getMin().getX()) != extentOrigin.getWidth()
246
				|| (extentNewFile.getMax().getY() - extentNewFile.getMin().getY()) != extentOrigin.getHeight()) {
247
			return false;
248
		}
249

  
250
		dataStore.close();
251
		return true;
252
	}
253

  
254
	/**
255
	 * Saves the new layer in disk
256
	 * @param layerName
257
	 * @param file
258
	 * @param uriList
259
	 * @return String
260
	 * @throws IOException
261
	 */
262
	protected String saveMultiFileLayer(String layerName, String file, ArrayList<File> uriList) throws IOException {
263
		String path = file.substring(0, file.lastIndexOf(File.separator) + 1);
264
		path = path + layerName + ".mff";
265

  
266
		/*File filePath = new File(path);
267
		if(filePath.exists()) {
268
			RasterToolsUtil.messageBoxInfo("file_exists_rename", bandSetupPanel);
269
			filePath.renameTo(new File(path + "~"));
270
		}*/
271

  
272
		MultiFileFormat format = new MultiFileFormat();
273
		for (int i = 0; i < uriList.size(); i++) {
274
			format.addFile(uriList.get(i));
275
		}
276
		format.setName(layerName);
277

  
278
		format.write(path);
279
		return path;
280
	}
281

  
282
}
0 283

  
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.105/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/panel/BandSelectorFileList.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22
package org.gvsig.raster.multifile.app.panel;
23

  
24
import java.awt.BorderLayout;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.Insets;
28

  
29
import javax.swing.DefaultListModel;
30
import javax.swing.JButton;
31
import javax.swing.JList;
32
import javax.swing.JPanel;
33
import javax.swing.JScrollPane;
34
import javax.swing.ListSelectionModel;
35

  
36
import org.gvsig.gui.beans.Messages;
37

  
38

  
39
/**
40
 * Panel que contiene la lista de ficheros cargados desde donde se leen las
41
 * bandas visualizadas. Contiene controles para a?adir y eliminar los ficheros,
42
 * as? como un control para seleccionar el n?mero de bandas a visualizar.
43
 *
44
 * @author Nacho Brodin (nachobrodin@gmail.com)
45
 */
46
public class BandSelectorFileList extends JPanel {
47
	private static final long serialVersionUID = 3329020254004687818L;
48
	private JScrollPane       jScrollPane      = null;
49
	private JButton           addButton        = null;
50
	private JButton           delButton        = null;
51
	private JList             jList            = null;
52
	private DefaultListModel  listModel        = null;
53
	private JPanel            jPanel1          = null;
54

  
55
	/**
56
	* This is the default constructor
57
	*/
58
	public BandSelectorFileList() {
59
		super();
60
		listModel = new DefaultListModel();
61
		initialize();
62
	}
63

  
64
	/**
65
	 * Inicializaci?n de componentes gr?ficos
66
	 *
67
	 */
68
	private void initialize() {
69
		setLayout(new BorderLayout());
70
		add(getJScrollPane(), BorderLayout.CENTER);
71
		add(getButtonsPanel(), BorderLayout.EAST);
72
	}
73

  
74
	/**
75
	 * This method initializes jScrollPane
76
	 *
77
	 * @return javax.swing.JScrollPane
78
	 */
79
	private JScrollPane getJScrollPane() {
80
		if (jScrollPane == null) {
81
			jScrollPane = new JScrollPane();
82
			jScrollPane.setViewportView(getJList());
83
		}
84
		return jScrollPane;
85
	}
86

  
87
	/**
88
	 * Obtiene el bot?n de a?adir fichero
89
	 * @return JButton
90
	 */
91
	public JButton getJButtonAdd() {
92
		if (addButton == null) {
93
			addButton = new JButton(Messages.getText("anadir"));
94
			addButton.setPreferredSize(new java.awt.Dimension(80, 25));
95
		}
96
		return addButton;
97
	}
98

  
99
	/**
100
	 * Obtiene el bot?n de eliminar fichero
101
	 * @return JButton
102
	 */
103
	public JButton getJButtonRemove() {
104
		if (delButton == null) {
105
			delButton = new JButton(Messages.getText("eliminar"));
106
			delButton.setPreferredSize(new java.awt.Dimension(80, 25));
107
		}
108
		return delButton;
109
	}
110

  
111
	/**
112
	 * This method initializes jList
113
	 *
114
	 * @return javax.swing.JList
115
	 */
116
	public JList getJList() {
117
		if (jList == null) {
118
			jList = new JList(listModel);
119
			jList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
120
			jList.setLayoutOrientation(JList.VERTICAL);
121
		}
122
		return jList;
123
	}
124

  
125
	/**
126
	 * This method initializes jPanel1
127
	 *
128
	 * @return javax.swing.JPanel
129
	 */
130
	private JPanel getButtonsPanel() {
131
		if (jPanel1 == null) {
132
			jPanel1 = new JPanel();
133
			GridBagConstraints gbc = new GridBagConstraints();
134
			gbc.insets = new Insets(0, 0, 3, 0);
135
			gbc.weightx = 1.0;
136
			jPanel1.setLayout(new GridBagLayout());
137
			jPanel1.add(getJButtonAdd(), gbc);
138
			gbc.gridy = 1;
139
			jPanel1.add(getJButtonRemove(), gbc);
140
		}
141
		return jPanel1;
142
	}
143

  
144
	/**
145
	 * A?ade el nombre de un fichero a la lista
146
	 * @param fName
147
	 */
148
	public void addFName(String fName) {
149
		listModel.addElement(fName);
150
	}
151

  
152
	/**
153
	 * Elimina un fichero de la lista
154
	 * @param fName
155
	 */
156
	public void removeFName(String fName) {
157
		for (int i = 0; i < listModel.size(); i++) {
158
			if(((String)listModel.get(i)).endsWith(fName))
159
				listModel.remove(i);
160
		}
161
	}
162

  
163
	/**
164
	 * Elimina todos los ficheros de la lista
165
	 */
166
	public void clear() {
167
		listModel.clear();
168
	}
169

  
170
	/**
171
	 * Obtiene el n?mero de ficheros en la lista
172
	 * @return number of files
173
	 */
174
	public int getNFiles() {
175
		return listModel.size();
176
	}
177

  
178
	/**
179
	 * Obtiene el modelo de la lista
180
	 * @return DefaultListModel
181
	 */
182
	public DefaultListModel getModel() {
183
		return listModel;
184
	}
185

  
186
	/**
187
	 * Activa y desactiva el control
188
	 * @param enabled true para activar y false para desactivar
189
	 */
190
	public void setEnabled(boolean enabled) {
191
		getJButtonAdd().setEnabled(enabled);
192
		getJButtonRemove().setEnabled(enabled);
193
		getJList().setEnabled(enabled);
194
		getJScrollPane().setEnabled(enabled);
195
	}
196
}
0 197

  
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.105/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/panel/DriverFileFilter.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.multifile.app.panel;
23

  
24
import java.io.File;
25
import java.io.FileInputStream;
26

  
27
import javax.swing.filechooser.FileFilter;
28

  
29
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster;
30
/**
31
 * Clase para indicar los ficheros que se ver?n en el JFileChooser.
32
 * 
33
 * @version 04/09/2007
34
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
35
 */
36
public class DriverFileFilter extends FileFilter {
37

  
38
	
39
	public boolean accept(File f) {
40
		if (f.isDirectory())
41
			return true;
42

  
43
		if (f.getParentFile().getName().equals("cellhd")) {
44
			if (f.getName().endsWith(".rmf") || f.getName().endsWith(".rmf~"))
45
				return false;
46
			return true;
47
		}
48

  
49
		// Comprobamos que no sea un rmf propio, osea, que contenga xml
50
		if (f.getName().toLowerCase().endsWith(".rmf")) {
51
			FileInputStream reader = null;
52
			try {
53
				reader = new FileInputStream(f);
54
				String xml = "";
55
				for (int i = 0; i < 6; i++)
56
					xml += (char) reader.read();
57
				if (xml.equals("<?xml "))
58
					return false;
59
			} catch (Exception e) {
60
			} finally {
61
				try {
62
					reader.close();
63
				} catch (Exception e) {}
64
			}
65
		}
66

  
67
		return DefaultFLyrRaster.isFileSupported(f);
68
	}
69

  
70
	public String getDescription() {
71
		return "gvSIG Raster Driver";
72
	}
73
}
0 74

  
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.105/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/panel/BandSelectorNewLayerListener.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22
package org.gvsig.raster.multifile.app.panel;
23

  
24
import java.awt.event.ActionEvent;
25
import java.io.File;
26
import java.net.URI;
27
import java.util.ArrayList;
28
import java.util.List;
29

  
30
import javax.swing.JRadioButton;
31

  
32
import org.gvsig.fmap.dal.coverage.RasterLocator;
33
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException;
34
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
35
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
36
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
37
import org.gvsig.fmap.dal.exception.InitializeException;
38
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
39
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerWizardPanel;
40
import org.gvsig.gui.beans.swing.JFileChooser;
41
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
42
import org.gvsig.i18n.Messages;
43
import org.gvsig.raster.multifile.io.MultiFileDataParameters;
44
import org.gvsig.raster.multifile.io.MultiFileProvider;
45
import org.gvsig.raster.swing.RasterSwingLibrary;
46
import org.gvsig.raster.swing.basepanel.ButtonsPanelEvent;
47
import org.gvsig.tools.locator.LocatorException;
48

  
49
/**
50
 * Class to manage events when this functionality is call to create a new multifile layer
51
 *
52
 * @author Nacho Brodin (nachobrodin@gmail.com)
53
 */
54
public class BandSelectorNewLayerListener extends AbstractBandSelectorListener {
55
	protected RasterDataStore       mainRasterStore  = null;
56

  
57
	/**
58
	 * Constructor
59
	 * @param bs Panel del selector de bandas
60
	 */
61
	public BandSelectorNewLayerListener(BandSelectorPanel bs) {
62
		super(bs);
63
	}
64

  
65
	public RasterDataStore getResult() {
66
		return mainRasterStore;
67
	}
68

  
69
	/**
70
	 * Listener para la gesti?n de los botones de a?adir, eliminar fichero y
71
	 * el combo de selecci?n de bandas.
72
	 */
73
	public void actionPerformed(ActionEvent e) {
74
		if (e.getSource().equals(bandSetupPanel.getFileList().getJButtonAdd())) {
75
			addFileBand();
76
			return;
77
		}
78

  
79
		if (e.getSource().equals(bandSetupPanel.getFileList().getJButtonRemove())) {
80
			delFileBand();
81
			return;
82
		}
83
		if(e.getSource() instanceof JRadioButton) {
84
			return;
85
		}
86
		apply();
87
	}
88

  
89
	public void actionButtonPressed(ButtonsPanelEvent e) {
90

  
91
	}
92

  
93
	@Override
94
	public void setNewBandsPositionInRendering() {
95

  
96
	}
97

  
98
	@Override
99
	public void apply() {
100
	}
101

  
102
	@Override
103
	public void addFileBand() {
104
		JFileChooser fileChooser = createJFileChooser();
105
		int result = fileChooser.showOpenDialog(bandSetupPanel);
106

  
107
		if (result == JFileChooser.APPROVE_OPTION) {
108
			File[] files = fileChooser.getSelectedFiles();
109
			if(files == null || files.length <= 0)
110
				return;
111

  
112
			JFileChooser.setLastPath(FilesystemExplorerWizardPanel.OPEN_LAYER_FILE_CHOOSER_ID, files[0]);
113
			int initPosition = 0;
114

  
115
			if(mainRasterStore == null) {
116
				initPosition = 1;
117
				MultiFileProvider provider = createMultiFileProvider(file, folder);
118
				MultiFileDataParameters newParamsMultifile = (MultiFileDataParameters)provider.getDataParameters();
119

  
120
				try {
121
					RasterDataStore firstDataStore = RasterLocator.getManager().getProviderServices().open(files[0].getAbsolutePath());
122
					newParamsMultifile.addProvider(firstDataStore);
123
					mainRasterStore = RasterLocator.getManager().getProviderServices().open(provider, provider.getDataStoreParameters());
124
				} catch (RasterDriverException e) {
125
					log.debug("Error loading the main store", e);
126
				} catch (LocatorException e) {
127
					log.debug("Error loading the main store", e);
128
				} catch (NotSupportedExtensionException e) {
129
					log.debug("Error loading the main store", e);
130
				} catch (InitializeException e) {
131
					log.debug("Error loading the main store", e);
132
				} catch (ProviderNotRegisteredException e) {
133
					log.debug("Error loading the main store", e);
134
				}
135
			}
136

  
137
			List<File> fileList = new ArrayList<File>();
138

  
139
			for (int i = initPosition; i < files.length; i++) {
140
				//Checks that the file does not exist
141
				URI[] uris = mainRasterStore.getURIByProvider();
142
				boolean exists = false;
143
				for (int j = 0; j < uris.length; j++) {
144
					if (new File(uris[j]).getAbsolutePath().endsWith(files[i].getName())) {
145
						RasterSwingLibrary.messageBoxError( Messages.getText("fichero_existe") + ": " + files[i].getAbsolutePath(), bandSetupPanel);
146
						exists = true;
147
						break;
148
					}
149
				}
150
				if(!exists)
151
					fileList.add(files[i]);
152
			}
153

  
154
			if(!checkStoresCompatibility(mainRasterStore, fileList))
155
				return;
156

  
157
			if(mainRasterStore.isMultiFile()) {
158
				for (int i = 0; i < fileList.size(); i++) {
159
					try {
160
						mainRasterStore.addFile(fileList.get(i)); //.getAbsolutePath());
161
					} catch (InvalidSourceException e) {
162
						RasterSwingLibrary.messageBoxError(Messages.getText("addband_error"), bandSetupPanel, e);
163
					}
164
				}
165

  
166
				mainRasterStore.setProvider(mainRasterStore.getProvider());
167

  
168
				//It shows the files and bands in the panel
169
				try {
170
					bandSetupPanel.addFiles(mainRasterStore);
171
				} catch (NotInitializeException e) {
172
					RasterSwingLibrary.messageBoxError("table_not_initialize", this, e);
173
				}
174
			}
175
		}
176
	}
177

  
178
	@Override
179
	public void delFileBand() {
180
		if(mainRasterStore == null)
181
			return;
182

  
183
		Object[] objects = bandSetupPanel.getFileList().getJList().getSelectedValues();
184

  
185
		for (int i = objects.length - 1; i >= 0; i--) {
186
			if (bandSetupPanel.getFileList().getNFiles() > 1) {
187
				String pathName = objects[i].toString();
188
				mainRasterStore.removeFile(new File(pathName));
189

  
190
				String file = pathName.substring(pathName.lastIndexOf(File.separator) + 1);
191
				file = file.substring(file.lastIndexOf("\\") + 1);
192
				bandSetupPanel.removeFile(file);
193
			}
194
		}
195

  
196
		setNewBandsPositionInRendering();
197
	}
198

  
199

  
200
}
0 201

  
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.105/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/panel/BandSelectorPanel.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22
package org.gvsig.raster.multifile.app.panel;
23

  
24
import java.awt.Dimension;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.Insets;
28
import java.awt.event.ComponentEvent;
29
import java.awt.image.DataBuffer;
30
import java.io.File;
31
import java.net.URI;
32
import java.util.ArrayList;
33
import java.util.List;
34

  
35
import javax.swing.JButton;
36
import javax.swing.JComboBox;
37
import javax.swing.JLabel;
38
import javax.swing.JPanel;
39
import javax.swing.event.TableModelEvent;
40
import javax.swing.event.TableModelListener;
41
import javax.swing.table.DefaultTableModel;
42

  
43
import org.gvsig.fmap.dal.coverage.RasterLocator;
44
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
45
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
46
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
47
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
48
import org.gvsig.gui.beans.table.TableContainer;
49
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
50
import org.gvsig.i18n.Messages;
51
import org.gvsig.raster.fmap.layers.FLyrRaster;
52
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
53
import org.gvsig.raster.mainplugin.properties.RasterPropertiesTocMenuEntry;
54
import org.gvsig.raster.swing.RasterSwingLibrary;
55
import org.slf4j.Logger;
56
import org.slf4j.LoggerFactory;
57

  
58
/**
59
 * Selecciona las bandas visibles en un raster. Contiene una tabla con una fila
60
 * por cada banda de la imagen. Por medio de checkbox se selecciona para cada
61
 * RGB que banda de la imagen ser? visualizada.
62
 *
63

  
64
 * @author Nacho Brodin (nachobrodin@gmail.com)
65
 */
66
public class BandSelectorPanel extends AbstractPanel implements TableModelListener {
67
	final private static long       serialVersionUID  = -3370601314380922368L;
68
	public static final int         TYPE_PROPERTIES   = 0;
69
	public static final int         TYPE_DIALOG       = 1;
70

  
71
	private final String[]          columnNames       = { "A", "R", "G", "B", "Band" };
72
	private final int[]             columnWidths      = { 22, 22, 22, 22, 334 };
73

  
74
	private FLyrRaster              fLayer = null;
75

  
76
	private BandSelectorFileList    fileList          = null;
77

  
78
	// Ultima y penultima columnas activadas del jtable para cuando hay 2 bandas seleccionadas en el combo
79
	private int[]                   col               = { 0, 1 };
80
	private AbstractBandSelectorListener
81
	                                panelListener     = null;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff