Revision 4181 org.gvsig.raster.multifile/trunk/org.gvsig.raster.multifile/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/panel/AbstractBandSelectorListener.java
AbstractBandSelectorListener.java | ||
---|---|---|
45 | 45 |
protected boolean enabled = true; |
46 | 46 |
protected String file = null; |
47 | 47 |
protected String folder = null; |
48 |
|
|
48 |
|
|
49 | 49 |
/** |
50 | 50 |
* Constructor |
51 | 51 |
* @param bs Panel del selector de bandas |
... | ... | |
57 | 57 |
bs.getFileList().getJButtonRemove().addActionListener(this); |
58 | 58 |
bs.getNumBandSelectorCombo().addActionListener(this); |
59 | 59 |
} |
60 |
|
|
60 |
|
|
61 | 61 |
public void setDestination(String file, String folder) { |
62 | 62 |
this.file = file; |
63 | 63 |
this.folder = folder; |
64 | 64 |
} |
65 |
|
|
65 |
|
|
66 | 66 |
/** |
67 | 67 |
* Enables or disables the panel action |
68 | 68 |
*/ |
69 | 69 |
public void setEnabledPanelAction(boolean enabled) { |
70 | 70 |
this.enabled = enabled; |
71 | 71 |
} |
72 |
|
|
72 |
|
|
73 | 73 |
/** |
74 | 74 |
* Sets the band position when these are rendered. The position is read from |
75 | 75 |
* the band table |
76 | 76 |
*/ |
77 | 77 |
public abstract void setNewBandsPositionInRendering(); |
78 |
|
|
78 |
|
|
79 | 79 |
public abstract RasterDataStore getResult(); |
80 |
|
|
80 |
|
|
81 | 81 |
/** |
82 | 82 |
* Actions when is applied |
83 | 83 |
*/ |
84 | 84 |
public abstract void apply(); |
85 |
|
|
85 |
|
|
86 | 86 |
public abstract void addFileBand(); |
87 |
|
|
87 |
|
|
88 | 88 |
public abstract void delFileBand(); |
89 |
|
|
89 |
|
|
90 | 90 |
/** |
91 | 91 |
* Listener para la gesti?n de los botones de a?adir, eliminar fichero y |
92 | 92 |
* el combo de selecci?n de bandas. |
... | ... | |
99 | 99 |
if (e.getSource().equals(bandSetupPanel.getFileList().getJButtonRemove())) |
100 | 100 |
delFileBand(); |
101 | 101 |
} |
102 |
|
|
102 |
|
|
103 | 103 |
protected JFileChooser createJFileChooser() { |
104 | 104 |
JFileChooser fileChooser = new JFileChooser( |
105 | 105 |
FilesystemExplorerWizardPanel.OPEN_LAYER_FILE_CHOOSER_ID, |
... | ... | |
110 | 110 |
fileChooser.addChoosableFileFilter(new DriverFileFilter()); |
111 | 111 |
return fileChooser; |
112 | 112 |
} |
113 |
|
|
113 |
|
|
114 | 114 |
protected boolean checkStoresCompatibility(RasterDataStore mainRasterStore, List<File> fileList) { |
115 | 115 |
for (int i = fileList.size() - 1; i >= 0; i--) { |
116 | 116 |
//Checks extents |
... | ... | |
129 | 129 |
return false; |
130 | 130 |
} |
131 | 131 |
} |
132 |
|
|
132 |
|
|
133 | 133 |
return true; |
134 | 134 |
} |
135 |
|
|
135 |
|
|
136 | 136 |
/** |
137 | 137 |
* Creates a multifile data provider |
138 | 138 |
* @param layerName |
... | ... | |
141 | 141 |
*/ |
142 | 142 |
protected MultiFileProvider createMultiFileProvider(String layerName, String path) { |
143 | 143 |
DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager(); |
144 |
|
|
144 |
|
|
145 | 145 |
try { |
146 | 146 |
//It creates the new Multifile provider |
147 | 147 |
DataServerExplorerParameters explParams = dataManager.createServerExplorerParameters(MultiFileProvider.NAME); |
148 | 148 |
DataServerExplorer explorer = dataManager.openServerExplorer(MultiFileProvider.NAME, explParams); |
149 | 149 |
MultiFileDataParameters newParamsMultifile = (MultiFileDataParameters)dataManager.createStoreParameters(explorer.getProviderName()); |
150 |
|
|
150 |
|
|
151 | 151 |
if(!path.endsWith(File.separator)) |
152 | 152 |
path = path + File.separator; |
153 |
String fileURI = path + layerName + ".mff";
|
|
154 |
String rmfURI = path + layerName + ".rmf";
|
|
153 |
File fileURI = new File(path + layerName + ".mff");
|
|
154 |
File rmfURI = new File(path + layerName + ".rmf");
|
|
155 | 155 |
int counter = 0; |
156 |
while(new File(fileURI).exists() || new File(rmfURI).exists()) {
|
|
157 |
fileURI = path + layerName + "_" + counter + ".mff";
|
|
158 |
rmfURI = path + layerName + "_" + counter + ".rmf";
|
|
156 |
while(fileURI.exists() || rmfURI.exists()) {
|
|
157 |
fileURI = new File(path + layerName + "_" + counter + ".mff");
|
|
158 |
rmfURI = new File(path + layerName + "_" + counter + ".rmf");
|
|
159 | 159 |
counter ++; |
160 | 160 |
} |
161 | 161 |
if(counter > 0) |
162 | 162 |
layerName += "_" + counter; |
163 |
|
|
164 |
newParamsMultifile.setURI(fileURI); |
|
165 |
|
|
163 |
|
|
164 |
newParamsMultifile.setURI(fileURI.toURI());
|
|
165 |
|
|
166 | 166 |
return (MultiFileProvider)dataManager.createProvider(null, newParamsMultifile); |
167 | 167 |
} catch (Exception exc) { |
168 | 168 |
RasterSwingLibrary.messageBoxError(Messages.getText("addband_error"), bandSetupPanel, exc); |
169 | 169 |
} |
170 | 170 |
return null; |
171 | 171 |
} |
172 |
|
|
172 |
|
|
173 | 173 |
/** |
174 | 174 |
* Comprobar si la asignacion de color es correcta para las 4 bandas. No puede |
175 | 175 |
* existir una banda con distintas interpretaciones de color. Se comprueban dos |
... | ... | |
199 | 199 |
|
200 | 200 |
return true; |
201 | 201 |
} |
202 |
|
|
202 |
|
|
203 | 203 |
/** |
204 | 204 |
* Checks if the new file is compatible with the old one |
205 | 205 |
* @param file |
... | ... | |
211 | 211 |
*/ |
212 | 212 |
protected boolean checkNewFile(RasterDataStore oldStore, String file) throws LocatorException, NotSupportedExtensionException, RasterDriverException, CloseException { |
213 | 213 |
Rectangle2D extentOrigin = oldStore.getExtent().toRectangle2D(); |
214 |
|
|
214 |
|
|
215 | 215 |
ProviderServices provServ = RasterLocator.getManager().getProviderServices(); |
216 | 216 |
RasterDataParameters storeParameters = provServ.createParameters(file); |
217 | 217 |
storeParameters.setSRS(oldStore.getProjection()); |
218 | 218 |
RasterDataStore dataStore = RasterLocator.getManager().getProviderServices().open(storeParameters); |
219 |
|
|
219 |
|
|
220 | 220 |
Extent extentNewFile = dataStore.getExtent(); |
221 | 221 |
|
222 | 222 |
// Comprobamos que el extent y tama?o del fichero a?adido sea igual al |
... | ... | |
238 | 238 |
dataStore.close(); |
239 | 239 |
return true; |
240 | 240 |
} |
241 |
|
|
241 |
|
|
242 | 242 |
/** |
243 | 243 |
* Saves the new layer in disk |
244 | 244 |
* @param layerName |
... | ... | |
249 | 249 |
protected String saveMultiFileLayer(String layerName, String file, ArrayList<File> uriList) throws IOException { |
250 | 250 |
String path = file.substring(0, file.lastIndexOf(File.separator) + 1); |
251 | 251 |
path = path + layerName + ".mff"; |
252 |
|
|
252 |
|
|
253 | 253 |
/*File filePath = new File(path); |
254 | 254 |
if(filePath.exists()) { |
255 | 255 |
RasterToolsUtil.messageBoxInfo("file_exists_rename", bandSetupPanel); |
256 | 256 |
filePath.renameTo(new File(path + "~")); |
257 | 257 |
}*/ |
258 |
|
|
258 |
|
|
259 | 259 |
MultiFileFormat format = new MultiFileFormat(); |
260 | 260 |
for (int i = 0; i < uriList.size(); i++) { |
261 | 261 |
format.addFile(uriList.get(i)); |
262 | 262 |
} |
263 | 263 |
format.setName(layerName); |
264 |
|
|
264 |
|
|
265 | 265 |
format.write(path); |
266 | 266 |
return path; |
267 | 267 |
} |
Also available in: Unified diff