Revision 8682 org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.app/org.gvsig.raster.app.mainplugin/src/main/java/org/gvsig/raster/app/mainplugin/colortable/ColorTablePagePanelController.java
ColorTablePagePanelController.java | ||
---|---|---|
26 | 26 |
import java.awt.event.ItemEvent; |
27 | 27 |
import java.awt.event.ItemListener; |
28 | 28 |
import java.io.File; |
29 |
import java.util.ArrayList; |
|
30 |
import java.util.Iterator; |
|
31 | 29 |
import java.util.List; |
32 | 30 |
import java.util.Locale; |
33 | 31 |
|
... | ... | |
55 | 53 |
import org.gvsig.fmap.mapcontext.raster.api.RasterLayer; |
56 | 54 |
import org.gvsig.fmap.mapcontext.raster.swing.MapContextRasterSwingLocator; |
57 | 55 |
import org.gvsig.fmap.mapcontext.raster.swing.previewer.OneLayerPreviewer; |
58 |
import org.gvsig.raster.lib.buffer.api.BufferLocator; |
|
59 |
import org.gvsig.raster.lib.buffer.api.BufferManager; |
|
60 |
import org.gvsig.raster.lib.buffer.api.operations.Operation; |
|
61 |
import org.gvsig.raster.lib.buffer.api.operations.OperationListEntry; |
|
62 | 56 |
import org.gvsig.raster.lib.buffer.api.statistics.Statistics; |
63 |
import org.gvsig.raster.lib.buffer.impl.operations.linearstretchenhancement.LinearStretchEnhancementOperation; |
|
64 |
import org.gvsig.raster.lib.buffer.impl.operations.linearstretchenhancement.LinearStretchEnhancementOperationFactory; |
|
65 |
import org.gvsig.raster.lib.buffer.spi.OperationListManager; |
|
66 | 57 |
import org.gvsig.raster.lib.legend.api.RasterLegend; |
67 | 58 |
import org.gvsig.raster.lib.legend.api.RasterLegendLocator; |
68 | 59 |
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation; |
69 | 60 |
import org.gvsig.raster.lib.legend.api.colortable.ColorTable; |
70 | 61 |
import org.gvsig.raster.lib.legend.api.colortable.colortableclass.ColorTableClass; |
71 |
import org.gvsig.raster.lib.legend.impl.operations.colortable.ColorTableOperation; |
|
72 |
import org.gvsig.raster.lib.legend.impl.operations.colortable.ColorTableOperationFactory; |
|
62 |
import org.gvsig.raster.lib.legend.api.operations.ColoredOperation; |
|
73 | 63 |
import org.gvsig.raster.swing.legend.RasterSwingLegendLocator; |
74 | 64 |
import org.gvsig.raster.swing.legend.colortable.editor.ColorTableEditorPanel; |
75 | 65 |
import org.gvsig.raster.swing.legend.colortable.selector.ColorTableSelectorPanel; |
... | ... | |
99 | 89 |
private boolean initialized; |
100 | 90 |
private TableModelListener editorTableModelListener; |
101 | 91 |
private RasterLayer clonedLayerForPreview; |
92 |
private boolean isChanged; |
|
102 | 93 |
|
103 | 94 |
/** |
104 | 95 |
* |
... | ... | |
237 | 228 |
|
238 | 229 |
RasterLegend legend = this.clonedLayerForPreview.getLegend(); |
239 | 230 |
|
240 |
removePreviousOperationIfExists(legend, LinearStretchEnhancementOperationFactory.NAME); |
|
241 |
removePreviousOperationIfExists(legend, ColorTableOperationFactory.NAME); |
|
242 |
|
|
243 | 231 |
ColorInterpretation colorInterpretation = legend.getColorInterpretation(); |
244 | 232 |
updateColorInterpretation(colorInterpretation); |
245 | 233 |
|
246 | 234 |
if (colorInterpretation.isPalette()) { |
247 |
addNewColorTableOperation(legend, colorInterpretation);
|
|
235 |
legend.addColorTableOperation(colorInterpretation, 0);
|
|
248 | 236 |
} else { |
249 |
addNewLinearStretchEnhancementOperationIfNeeded(legend, colorInterpretation);
|
|
237 |
legend.addLinearStretchEnhancementOperationIfNeeded(colorInterpretation, (RasterStore)this.clonedLayerForPreview.getDataStore(), 0);
|
|
250 | 238 |
} |
239 |
isChanged = true; |
|
251 | 240 |
} |
252 | 241 |
} |
253 | 242 |
|
254 |
/** |
|
255 |
* @param rasterLegend |
|
256 |
* @param colorInterpretation |
|
257 |
*/ |
|
258 |
private void addNewColorTableOperation(RasterLegend rasterLegend, ColorInterpretation colorInterpretation) { |
|
259 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
|
260 |
Operation colorTableOperation = bufferManager.createOperation(ColorTableOperationFactory.NAME); |
|
261 |
DynObject colorTableOperationParameters = bufferManager.createOperationParameters(ColorTableOperationFactory.NAME); |
|
262 |
colorTableOperationParameters.setDynValue(ColorTableOperation.COLOR_INTERPRETATION_PARAM, colorInterpretation); |
|
263 |
colorTableOperationParameters.setDynValue(ColorTableOperation.COPY_UNPROCESSED_BANDS_PARAM, true); |
|
264 |
OperationListEntry colorTableEntry = ((OperationListManager)bufferManager).createOperationListEntry(colorTableOperation, colorTableOperationParameters); |
|
265 |
rasterLegend.getFilters().add(0, colorTableEntry); |
|
266 |
} |
|
267 |
|
|
268 |
/** |
|
269 |
* @param rasterLegend |
|
270 |
* @param colorInterpretation |
|
271 |
*/ |
|
272 |
private void addNewLinearStretchEnhancementOperationIfNeeded(RasterLegend rasterLegend, |
|
273 |
ColorInterpretation colorInterpretation) { |
|
274 |
|
|
275 |
BufferManager bufferManager = BufferLocator.getBufferManager(); |
|
276 |
if ((!colorInterpretation.isPalette()) && (colorInterpretation.hasAnyColorInterpretationBand() || colorInterpretation.hasAlphaBand() || colorInterpretation |
|
277 |
.hasAnyGrayBand())) { |
|
278 |
|
|
279 |
List<Integer> bandsToProcess = new ArrayList<Integer>(); |
|
280 |
RasterStore store = rasterLayer.getRasterStore(); |
|
281 |
for (int i = 0; i < store.getBands(); i++) { |
|
282 |
if ((colorInterpretation.isColorInterpretation(i) || colorInterpretation.isAlphaInterpretation(i) || colorInterpretation |
|
283 |
.isGrayInterpretation(i)) && (store.getBandDescriptor(i).getDataType() != BufferManager.TYPE_BYTE)) { |
|
284 |
bandsToProcess.add(i); |
|
285 |
} |
|
286 |
} |
|
287 |
if (!bandsToProcess.isEmpty()) { |
|
288 |
Operation linearStretchEnhancementOperation = |
|
289 |
bufferManager.createOperation(LinearStretchEnhancementOperationFactory.NAME); |
|
290 |
DynObject linearStretchEnhancementOperationParameters = |
|
291 |
bufferManager.createOperationParameters(LinearStretchEnhancementOperationFactory.NAME); |
|
292 |
linearStretchEnhancementOperationParameters.setDynValue( |
|
293 |
LinearStretchEnhancementOperation.BANDS_TO_PROCESS_PARAM, bandsToProcess); |
|
294 |
OperationListEntry colorTableEntry = |
|
295 |
((OperationListManager) bufferManager).createOperationListEntry(linearStretchEnhancementOperation, |
|
296 |
linearStretchEnhancementOperationParameters); |
|
297 |
rasterLegend.getFilters().add(0, colorTableEntry); |
|
298 |
|
|
299 |
} |
|
300 |
} |
|
301 |
} |
|
302 |
|
|
303 |
/** |
|
304 |
* @param rasterLegend |
|
305 |
*/ |
|
306 |
private void removePreviousOperationIfExists(RasterLegend rasterLegend, String name) { |
|
307 |
for (Iterator<OperationListEntry> iterator = rasterLegend.getFilters().iterator(); iterator.hasNext();) { |
|
308 |
OperationListEntry entry = (OperationListEntry) iterator.next(); |
|
309 |
Operation operation = entry.getOperation(); |
|
310 |
if (operation.getFactory().getName().equals(name)) { |
|
311 |
iterator.remove(); |
|
312 |
} |
|
313 |
} |
|
314 |
} |
|
315 |
|
|
316 |
|
|
317 | 243 |
protected ColorTable adaptToTheBand(ColorTable colorTable) { |
318 | 244 |
ColorTable cloned = RasterLegendLocator.getRasterLegendManager().createColorTable(); |
319 | 245 |
cloned.copyFrom(colorTable); |
... | ... | |
380 | 306 |
*/ |
381 | 307 |
@Override |
382 | 308 |
public boolean fetch(FLayer layer) { |
309 |
if(isChanged){ |
|
383 | 310 |
RasterLayer rasterLayer = (RasterLayer) layer; |
384 | 311 |
RasterLegend rasterLegend = (RasterLegend) rasterLayer.getLegend(); |
385 | 312 |
ColorInterpretation colorInterpretation = rasterLegend.getColorInterpretation(); |
386 | 313 |
updateColorInterpretation(colorInterpretation); |
314 |
if (colorInterpretation.isPalette()) { |
|
315 |
rasterLegend.addColorTableOperation(colorInterpretation, 0); |
|
316 |
} else { |
|
317 |
rasterLegend.addLinearStretchEnhancementOperationIfNeeded(colorInterpretation, (RasterStore)rasterLayer.getDataStore(), 0); |
|
318 |
} |
|
387 | 319 |
updateCmbBands(rasterLayer); |
320 |
} |
|
388 | 321 |
return true; |
389 | 322 |
} |
390 | 323 |
|
... | ... | |
446 | 379 |
|
447 | 380 |
initializePreviewer(); |
448 | 381 |
this.initialized = true; |
382 |
isChanged = false; |
|
449 | 383 |
} |
450 | 384 |
|
451 | 385 |
/** |
Also available in: Unified diff