Revision 2178 org.gvsig.raster.multifile/trunk/org.gvsig.raster.multifile/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/MultifileClientExtension.java
MultifileClientExtension.java | ||
---|---|---|
23 | 23 |
|
24 | 24 |
import java.awt.event.ActionEvent; |
25 | 25 |
import java.awt.event.ActionListener; |
26 |
import java.io.File; |
|
27 |
import java.io.IOException; |
|
28 |
import java.util.ArrayList; |
|
29 |
import java.util.List; |
|
30 | 26 |
import java.util.Locale; |
31 | 27 |
|
32 | 28 |
import javax.swing.JComponent; |
... | ... | |
34 | 30 |
import org.gvsig.andami.IconThemeHelper; |
35 | 31 |
import org.gvsig.andami.PluginServices; |
36 | 32 |
import org.gvsig.andami.plugins.Extension; |
37 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
38 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
|
39 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
40 |
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException; |
|
41 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
42 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
|
43 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
44 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
45 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
|
46 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
|
47 | 33 |
import org.gvsig.i18n.Messages; |
48 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
49 |
import org.gvsig.raster.impl.provider.RasterProvider; |
|
50 | 34 |
import org.gvsig.raster.multifile.app.panel.BandSelectorPanel; |
51 | 35 |
import org.gvsig.raster.multifile.app.panel.MainWindow; |
52 |
import org.gvsig.raster.multifile.io.MultiFileDataParameters; |
|
53 |
import org.gvsig.raster.multifile.io.MultiFileFormat; |
|
54 |
import org.gvsig.raster.swing.RasterSwingLibrary; |
|
55 | 36 |
import org.gvsig.raster.swing.RasterSwingLocator; |
56 | 37 |
import org.gvsig.raster.swing.basepanel.IButtonsPanel; |
57 | 38 |
import org.gvsig.raster.swing.newlayer.CreateNewLayerPanel; |
... | ... | |
67 | 48 |
private CreateNewLayerPanel newLayerPanel = null; |
68 | 49 |
private MainWindow layerNamewindow = null; |
69 | 50 |
private MainWindow bandSelectorwindow = null; |
70 |
private BandSelectorPanel panel = null; |
|
71 |
private AbstractViewPanel selectedView = null; |
|
72 |
private String file = null; |
|
73 |
private String folder = null; |
|
51 |
private MainDialogActions actions = null; |
|
74 | 52 |
|
75 | 53 |
public void initialize() { |
76 | 54 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
... | ... | |
97 | 75 |
public void execute(String actionCommand) { |
98 | 76 |
if (actionCommand.compareTo("MultifileCreator") == 0) { |
99 | 77 |
layerNamewindow = new MainWindow((JComponent)getNewLayerPanel(), |
100 |
Messages.getText("bands"), 300, 150, this);
|
|
78 |
Messages.getText("select_output_file"), 300, 150, this);
|
|
101 | 79 |
PluginServices.getMDIManager().addCentredWindow(layerNamewindow); |
102 | 80 |
} |
103 | 81 |
} |
... | ... | |
124 | 102 |
public void actionPerformed(ActionEvent e) { |
125 | 103 |
//Accept the window with the layer name |
126 | 104 |
if(e.getSource() == layerNamewindow.getButtonsPanel().getButton(IButtonsPanel.BUTTON_ACCEPT)) { |
127 |
file = getNewLayerPanel().getFileSelected(); |
|
128 |
folder = getNewLayerPanel().getDirectorySelected(); |
|
129 |
panel = new BandSelectorPanel(BandSelectorPanel.TYPE_DIALOG); |
|
105 |
String file = getNewLayerPanel().getFileSelected();
|
|
106 |
String folder = getNewLayerPanel().getDirectorySelected();
|
|
107 |
BandSelectorPanel panel = new BandSelectorPanel(BandSelectorPanel.TYPE_DIALOG);
|
|
130 | 108 |
panel.getListener().setDestination(file, folder); |
131 |
bandSelectorwindow = new MainWindow(panel, Messages.getText("bands"), 500, 400, this, true); |
|
109 |
actions = new MainDialogActions(panel, file, folder); |
|
110 |
bandSelectorwindow = new MainWindow(panel, Messages.getText("add_files"), 500, 400, this, true); |
|
132 | 111 |
PluginServices.getMDIManager().addCentredWindow(bandSelectorwindow); |
133 | 112 |
} |
134 | 113 |
|
114 |
//Button of load layer in the main dialog |
|
135 | 115 |
if(e.getSource() == bandSelectorwindow.getButtonsPanel().getButton(IButtonsPanel.BUTTON_USR1)) { |
136 |
loadLayer(); |
|
116 |
actions.loadLayer();
|
|
137 | 117 |
} |
138 | 118 |
|
119 |
//Button of create one file with al files |
|
139 | 120 |
if(e.getSource() == bandSelectorwindow.getButtonsPanel().getButton(IButtonsPanel.BUTTON_USR2)) { |
140 |
|
|
121 |
actions.buildOneLayer(); |
|
141 | 122 |
} |
142 | 123 |
|
143 | 124 |
} |
144 |
|
|
145 |
|
|
146 |
private void saveMff(RasterDataStore mainRasterStore) { |
|
147 |
MultiFileDataParameters params = (MultiFileDataParameters)mainRasterStore.getParameters(); |
|
148 |
ArrayList<File> uriList = new ArrayList<File>(); |
|
149 |
List<RasterProvider> providers = params.getProviders(); |
|
150 |
for (int i = 0; i < providers.size(); i++) { |
|
151 |
uriList.add(new File(providers.get(i).getURI())); |
|
152 |
} |
|
153 |
try { |
|
154 |
MultiFileFormat.saveMultiFileFormat(file, folder, uriList); |
|
155 |
} catch (IOException e) { |
|
156 |
RasterSwingLibrary.messageBoxError(Messages.getText("error_salvando_mff"), panel, e); |
|
157 |
} |
|
158 |
} |
|
159 |
|
|
160 |
private void saveMetadata() { |
|
161 |
int rBand = panel.getAssignedBand(RasterDataStore.RED_BAND); |
|
162 |
int gBand = panel.getAssignedBand(RasterDataStore.GREEN_BAND); |
|
163 |
int bBand = panel.getAssignedBand(RasterDataStore.BLUE_BAND); |
|
164 |
int aBand = panel.getAssignedBand(RasterDataStore.ALPHA_BAND); |
|
165 |
|
|
166 |
if (!isCorrectAssignedBand(rBand, gBand, bBand, aBand)) { |
|
167 |
RasterSwingLibrary.messageBoxError(Messages.getText("combinacion_no_asignable"), panel); |
|
168 |
return; |
|
169 |
} |
|
170 |
|
|
171 |
ColorInterpretation ci = RasterLocator.getManager().getDataStructFactory().createColorInterpretation( |
|
172 |
new String[]{ColorInterpretation.ALPHA_BAND, ColorInterpretation.RED_BAND, ColorInterpretation.GREEN_BAND, ColorInterpretation.BLUE_BAND}); |
|
173 |
try { |
|
174 |
// Combinaci?n GRAY |
|
175 |
if ((rBand == gBand) && (rBand == bBand) && (rBand >= 0)) { |
|
176 |
for (int iBand = 0; iBand < panel.getARGBTable().getRowCount(); iBand++) { |
|
177 |
ci.setColorInterpValue(iBand, ColorInterpretation.UNDEF_BAND); |
|
178 |
} |
|
179 |
ci.setColorInterpValue(rBand, ColorInterpretation.GRAY_BAND); |
|
180 |
ci.setColorInterpValue(aBand, ColorInterpretation.ALPHA_BAND); |
|
181 |
} else { |
|
182 |
// Combinaci?n RGB |
|
183 |
for (int iBand = 0; iBand < panel.getARGBTable().getRowCount(); iBand++) |
|
184 |
ci.setColorInterpValue(iBand, panel.getColorInterpretationByBand(iBand)); |
|
185 |
} |
|
186 |
RasterLocator.getManager().getProviderServices().saveObjectToRmfFile(file, ci); |
|
187 |
} catch (RmfSerializerException exc) { |
|
188 |
RasterSwingLibrary.messageBoxError(Messages.getText("error_salvando_rmf"), panel, exc); |
|
189 |
} catch (NotInitializeException exc) { |
|
190 |
RasterSwingLibrary.messageBoxError(Messages.getText("table_not_initialize"), panel, exc); |
|
191 |
} |
|
192 |
} |
|
193 |
|
|
194 |
public void loadLayerInView(RasterDataStore mainRasterStore) throws LoadLayerException { |
|
195 |
MapContextManager mcm = MapContextLocator.getMapContextManager(); |
|
196 |
FLyrRaster lyr = (FLyrRaster) mcm.createLayer(file, mainRasterStore); |
|
197 |
|
|
198 |
getView().getMapControl().getMapContext().beginAtomicEvent(); |
|
199 |
getView().getMapControl().getMapContext().getLayers().addLayer(lyr); |
|
200 |
getView().getMapControl().getMapContext().invalidate(); |
|
201 |
getView().getMapControl().getMapContext().endAtomicEvent(); |
|
202 |
} |
|
203 |
|
|
204 |
private AbstractViewPanel getView() { |
|
205 |
if(selectedView == null) { |
|
206 |
IWindow[] wList = PluginServices.getMDIManager().getAllWindows(); |
|
207 |
for (int i = 0; i < wList.length; i++) { |
|
208 |
if(wList[i] instanceof AbstractViewPanel) |
|
209 |
selectedView = (AbstractViewPanel)wList[i]; |
|
210 |
} |
|
211 |
} |
|
212 |
return selectedView; |
|
213 |
} |
|
214 |
|
|
215 |
public void loadLayer() { |
|
216 |
RasterDataStore mainRasterStore = panel.getResult(); |
|
217 |
if(mainRasterStore == null) { |
|
218 |
return; |
|
219 |
} |
|
220 |
|
|
221 |
saveMff(mainRasterStore); |
|
222 |
saveMetadata(); |
|
223 |
try { |
|
224 |
loadLayerInView(mainRasterStore); |
|
225 |
} catch (LoadLayerException e) { |
|
226 |
RasterSwingLibrary.messageBoxError(Messages.getText("error_loading_layer"), panel, e); |
|
227 |
} |
|
228 |
} |
|
229 |
|
|
230 |
private boolean isCorrectAssignedBand(int r, int g, int b, int a) { |
|
231 |
// Si es gris es correcta la asignacion |
|
232 |
if ((r == g) && (r == b) && (r >= 0)) { |
|
233 |
// Si el alpha esta asignado a la misma banda es incorrecto |
|
234 |
if (r == a) |
|
235 |
return false; |
|
236 |
// En caso contrario es correcto |
|
237 |
return true; |
|
238 |
} |
|
239 |
|
|
240 |
// Si dos bandas coinciden, se dice que no es correcta la asignacion |
|
241 |
int list[] = { r, g, b, a }; |
|
242 |
for (int i = 0; i <= 3; i++) |
|
243 |
for (int j = 0; j <= 3; j++) |
|
244 |
if ((i != j) && (list[i] == list[j]) && (list[i] > -1)) |
|
245 |
return false; |
|
246 |
|
|
247 |
return true; |
|
248 |
} |
|
249 | 125 |
} |
Also available in: Unified diff