Revision 12167

View differences:

org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.108/org.gvsig.raster.multifile.app.multifileclient/buildNumber.properties
1
#Mon Aug 24 05:31:20 CEST 2020
2
buildNumber=160
0 3

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

  
23
import java.awt.BorderLayout;
24
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionListener;
26

  
27
import javax.swing.JComponent;
28

  
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.andami.ui.mdiManager.IWindow;
31
import org.gvsig.andami.ui.mdiManager.WindowInfo;
32
import org.gvsig.i18n.Messages;
33
import org.gvsig.raster.swing.basepanel.AbstractButtonsPanel;
34
import org.gvsig.raster.swing.basepanel.IButtonsPanel;
35

  
36

  
37
/**
38
 * Basic frame for a gvSIG <code>IWindow</code> object. This frame adds buttons
39
 * of Cancel, Accept and others.
40
 *
41
 * @author Nacho Brodin (nachobrodin@gmail.com)
42
 */
43
public class MainWindow extends AbstractButtonsPanel implements IWindow, ActionListener {
44

  
45
    private static final long  serialVersionUID = -4401123724140025094L;
46
    private ActionListener     listener         = null;
47
    private WindowInfo         info             = null;
48

  
49
    private Object profile = WindowInfo.EDITOR_PROFILE;
50

  
51
    /**
52
     * @param panel
53
     * @param title
54
     * @param w
55
     * @param h
56
     * @param actionListener
57
     */
58
    public MainWindow(JComponent panel, String title, int w, int h, ActionListener actionListener) {
59
    	this.listener = actionListener;
60

  
61
    	setLayout(new BorderLayout());
62
		add(panel, BorderLayout.CENTER);
63

  
64
		getButtonsPanel().getButton(IButtonsPanel.BUTTON_APPLY).setVisible(false);
65
        getButtonsPanel().getButton(IButtonsPanel.BUTTON_ACCEPT).addActionListener(this);
66
        getButtonsPanel().getButton(IButtonsPanel.BUTTON_CANCEL).addActionListener(this);
67

  
68
        info = new WindowInfo(WindowInfo.PALETTE | WindowInfo.RESIZABLE);
69
        info.setTitle(title);
70
        info.setWidth(w);
71
        info.setHeight(h);
72
    }
73

  
74
    /**
75
     * @param panel
76
     * @param title
77
     * @param w
78
     * @param h
79
     * @param actionListener
80
     * @param mainPanel
81
     */
82
    public MainWindow(JComponent panel, String title, int w, int h, ActionListener actionListener, boolean mainPanel) {
83
    	this.listener = actionListener;
84

  
85
    	setLayout(new BorderLayout());
86
		add(panel, BorderLayout.CENTER);
87

  
88
		getButtonsPanel().getButton(IButtonsPanel.BUTTON_APPLY).setVisible(false);
89

  
90
		if(mainPanel) {
91
			getButtonsPanel().addButton(Messages.getText("load_layer"), IButtonsPanel.BUTTON_USR1);
92
			getButtonsPanel().addButton(Messages.getText("generate_file"), IButtonsPanel.BUTTON_USR2);
93
			getButtonsPanel().getButton(IButtonsPanel.BUTTON_APPLY).setVisible(false);
94
			getButtonsPanel().getButton(IButtonsPanel.BUTTON_ACCEPT).setVisible(false);
95
			getButtonsPanel().getButton(IButtonsPanel.BUTTON_CANCEL).setVisible(false);
96
			getButtonsPanel().addClose();
97
			getButtonsPanel().getButton(IButtonsPanel.BUTTON_CLOSE).addActionListener(this);
98
	        getButtonsPanel().getButton(IButtonsPanel.BUTTON_USR1).addActionListener(this);
99
	        getButtonsPanel().getButton(IButtonsPanel.BUTTON_USR2).addActionListener(this);
100
		} else {
101
			getButtonsPanel().getButton(IButtonsPanel.BUTTON_ACCEPT).addActionListener(this);
102
			getButtonsPanel().getButton(IButtonsPanel.BUTTON_CANCEL).addActionListener(this);
103
		}
104

  
105
        info = new WindowInfo(WindowInfo.PALETTE | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE);
106
        info.setTitle(title);
107
        info.setWidth(w);
108
        info.setHeight(h);
109
    }
110

  
111
    public WindowInfo getWindowInfo() {
112
        return info;
113
    }
114

  
115
    public Object getWindowProfile() {
116
        return profile;
117
    }
118

  
119
    public void actionPerformed(ActionEvent e) {
120
    	if(e.getSource() == getButtonsPanel().getButton(IButtonsPanel.BUTTON_USR1)) {
121
    		listener.actionPerformed(new ActionEvent(e.getSource(), IButtonsPanel.BUTTON_USR1, e.getActionCommand()));
122
    		PluginServices.getMDIManager().closeWindow(this);
123
    	}
124

  
125
    	if(e.getSource() == getButtonsPanel().getButton(IButtonsPanel.BUTTON_USR2)) {
126
    		listener.actionPerformed(new ActionEvent(e.getSource(), IButtonsPanel.BUTTON_USR2, e.getActionCommand()));
127
    		PluginServices.getMDIManager().closeWindow(this);
128
    	}
129

  
130
    	if(e.getSource() == getButtonsPanel().getButton(IButtonsPanel.BUTTON_ACCEPT)) {
131
    		listener.actionPerformed(new ActionEvent(e.getSource(), IButtonsPanel.BUTTON_ACCEPT, e.getActionCommand()));
132
    		PluginServices.getMDIManager().closeWindow(this);
133
    	}
134

  
135
    	if(e.getSource() == getButtonsPanel().getButton(IButtonsPanel.BUTTON_APPLY)) {
136
    		listener.actionPerformed(new ActionEvent(e.getSource(), IButtonsPanel.BUTTON_APPLY, e.getActionCommand()));
137
    	}
138

  
139
    	if(e.getSource() == getButtonsPanel().getButton(IButtonsPanel.BUTTON_CANCEL)) {
140
    		PluginServices.getMDIManager().closeWindow(this);
141
    	}
142

  
143
    	if(e.getSource() == getButtonsPanel().getButton(IButtonsPanel.BUTTON_CLOSE)) {
144
    		PluginServices.getMDIManager().closeWindow(this);
145
    	}
146
    }
147
}
0 148

  
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.108/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/panel/LayerNameDialog.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.raster.multifile.app.panel;
20

  
21
import java.awt.BorderLayout;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24
import java.awt.Insets;
25
import java.awt.geom.Point2D;
26

  
27
import javax.swing.JOptionPane;
28
import javax.swing.JPanel;
29
import javax.swing.JTextField;
30

  
31
import org.gvsig.andami.PluginServices;
32
import org.gvsig.andami.ui.mdiManager.IWindow;
33
import org.gvsig.andami.ui.mdiManager.WindowInfo;
34
import org.gvsig.i18n.Messages;
35
import org.gvsig.raster.swing.basepanel.AbstractButtonsPanel;
36
import org.gvsig.raster.swing.basepanel.ButtonsPanelEvent;
37
import org.gvsig.raster.swing.basepanel.ButtonsPanelListener;
38
import org.gvsig.raster.swing.basepanel.IButtonsPanel;
39

  
40
/**
41
 * <code>LayerNameDialog</code>.
42
 * Window to introduce the name of the new layer
43
 * @author Nacho Brodin (nachobrodin@gmail.com)
44
 */
45
public class LayerNameDialog extends AbstractButtonsPanel implements IWindow, ButtonsPanelListener {
46
	private static final long     serialVersionUID = 7362459094802955247L;
47
	private JPanel                panel            = null;
48
	private String                layerName        = null;
49
	private JTextField            name             = null;
50
	private ButtonsPanelListener  listener         = null;
51
	private Point2D               position         = null;
52

  
53
	/**
54
	 * Builds a new window.
55
	 * @param position
56
	 * @param width
57
	 * @param height
58
	 * @param listener
59
	 */
60
	public LayerNameDialog(Point2D position, int width, int height, ButtonsPanelListener listener) {
61
		super(IButtonsPanel.BUTTONS_ACCEPTCANCEL);
62
		this.position = position;
63
		layerName = null;
64
		this.listener = listener;
65
		this.setSize(width, height);
66
		this.setLayout(new BorderLayout(5, 5));
67
		this.add(getMainPanel(), java.awt.BorderLayout.CENTER);
68
		this.addButtonPressedListener(this);
69
	}
70

  
71
	/**
72
	 * Builds a new window.
73
	 * @param width
74
	 * @param height
75
	 * @param listener
76
	 */
77
	public LayerNameDialog(int width, int height, ButtonsPanelListener listener) {
78
		this(new Point2D.Double(), width, height, listener);
79
	}
80

  
81
	/**
82
	 * Gets the main panel
83
	 * @return JPanel
84
	 */
85
	public JPanel getMainPanel() {
86
		if (panel == null) {
87
			panel = new JPanel();
88
			panel.setLayout(new GridBagLayout());
89
			GridBagConstraints gbc = new GridBagConstraints();
90
			gbc.insets = new Insets(0, 0, 0, 0);
91
			gbc.fill = GridBagConstraints.HORIZONTAL;
92
			gbc.anchor = GridBagConstraints.CENTER;
93
			gbc.weightx = 1.0;
94
			panel.add(getNameField(), gbc);
95
		}
96
		return panel;
97
	}
98

  
99
	private JTextField getNameField() {
100
		if(name == null) {
101
			name = new JTextField();
102
		}
103
		return name;
104
	}
105

  
106
	public WindowInfo getWindowInfo() {
107
		WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
108
		m_viewinfo.setTitle(Messages.getText("layer_name"));
109
		m_viewinfo.setHeight(this.getHeight());
110
		m_viewinfo.setWidth(this.getWidth());
111
		m_viewinfo.setX((int)position.getX());
112
		m_viewinfo.setY((int)position.getY());
113
		return m_viewinfo;
114
	}
115

  
116
	/**
117
	 * Cancel actions
118
	 */
119
	private void close() {
120
		try {
121
			PluginServices.getMDIManager().closeWindow(this);
122
		} catch (ArrayIndexOutOfBoundsException e) {
123
			//Si la ventana no se puede eliminar no hacemos nada
124
		}
125
	}
126

  
127
	/**
128
	 * Accept actions
129
	 */
130
	private void accept() {
131
		String txt = getNameField().getText();
132
		if(txt == null || txt.compareTo("") == 0) {
133
			JOptionPane.showMessageDialog(null, Messages.getText("character_not_valid"), "", JOptionPane.ERROR_MESSAGE);
134
			return;
135
		}
136

  
137
		byte[] byteList = txt.getBytes();
138
		for (int i = 0; i < byteList.length; i++) {
139
			if(byteList[i] < 45 ||
140
			   (byteList[i] > 45 && byteList[i] < 48) ||
141
			   (byteList[i] > 57 && byteList[i] < 65) ||
142
			   (byteList[i] > 90 && byteList[i] < 95) ||
143
			   (byteList[i] > 95 && byteList[i] < 97) ||
144
			   (byteList[i] > 122 && byteList[i] < 126) ||
145
			   (byteList[i] > 126)) {
146
				JOptionPane.showMessageDialog(null, Messages.getText("character_not_valid"), "", JOptionPane.ERROR_MESSAGE);
147
				return;
148
			}
149
		}
150

  
151
		layerName = txt;
152
		close();
153
		listener.actionButtonPressed(new ButtonsPanelEvent(layerName, IButtonsPanel.BUTTON_ACCEPT));
154
	}
155

  
156
	public void actionButtonPressed(ButtonsPanelEvent e) {
157
		if (e.getButton() == IButtonsPanel.BUTTON_CANCEL) {
158
			close();
159
		}
160

  
161
		if (e.getButton() == IButtonsPanel.BUTTON_ACCEPT) {
162
			accept();
163
		}
164
	}
165

  
166
	public Object getWindowProfile() {
167
		return WindowInfo.PROPERTIES_PROFILE;
168
	}
169
}
0 170

  
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.108/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.108/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.108/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.108/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
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff