Revision 2311 org.gvsig.raster.multifile/branches/org.gvsig.raster.multifile_dataaccess_refactoring/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/panel/BandSelectorPanel.java
BandSelectorPanel.java | ||
---|---|---|
29 | 29 |
import java.awt.image.DataBuffer; |
30 | 30 |
import java.io.File; |
31 | 31 |
import java.util.ArrayList; |
32 |
import java.util.List; |
|
32 | 33 |
|
33 | 34 |
import javax.swing.JButton; |
34 | 35 |
import javax.swing.JComboBox; |
... | ... | |
38 | 39 |
import javax.swing.event.TableModelListener; |
39 | 40 |
import javax.swing.table.DefaultTableModel; |
40 | 41 |
|
42 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
41 | 43 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
42 | 44 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
43 | 45 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
... | ... | |
274 | 276 |
break; |
275 | 277 |
} |
276 | 278 |
|
277 |
addBand((nbands + 1) + " [" + bandType + "] " + bandName);
|
|
279 |
addBand((i + 1) + " [" + bandType + "] " + bandName);
|
|
278 | 280 |
} |
279 | 281 |
|
280 | 282 |
if(fLayer != null) { |
... | ... | |
476 | 478 |
*/ |
477 | 479 |
public String getColorInterpretationByBand(int nBand) { |
478 | 480 |
DefaultTableModel model = ((DefaultTableModel) getARGBTable().getModel()); |
481 |
for (int col = 0; col < 4; col++) { |
|
482 |
if(((Boolean) model.getValueAt(nBand, col)).booleanValue()) { |
|
483 |
switch (col) { |
|
484 |
case 0: return ColorInterpretation.ALPHA_BAND; |
|
485 |
case 1: return ColorInterpretation.RED_BAND; |
|
486 |
case 2: return ColorInterpretation.GREEN_BAND; |
|
487 |
case 3: return ColorInterpretation.BLUE_BAND; |
|
488 |
} |
|
489 |
} |
|
490 |
} |
|
491 |
return ColorInterpretation.UNDEF_BAND; |
|
492 |
} |
|
493 |
|
|
494 |
public ColorInterpretation getSelectedColorInterpretation() { |
|
479 | 495 |
try { |
496 |
String[] colorInter = new String[getARGBTable().getRowCount()]; |
|
480 | 497 |
for (int iBand = 0; iBand < getARGBTable().getRowCount(); iBand++) { |
481 |
for (int col = 0; col < 4; col++) { |
|
482 |
if(((Boolean) model.getValueAt(nBand, col)).booleanValue()) { |
|
483 |
switch (col) { |
|
484 |
case 0: return ColorInterpretation.ALPHA_BAND; |
|
485 |
case 1: return ColorInterpretation.RED_BAND; |
|
486 |
case 2: return ColorInterpretation.GREEN_BAND; |
|
487 |
case 3: return ColorInterpretation.BLUE_BAND; |
|
488 |
} |
|
489 |
} |
|
490 |
} |
|
498 |
if(isSelected(iBand, 1) && isSelected(iBand, 2) && isSelected(iBand, 3)) { |
|
499 |
colorInter[iBand] = ColorInterpretation.GRAY_BAND; |
|
500 |
} else if(isSelected(iBand, 1) && isSelected(iBand, 2)) { |
|
501 |
colorInter[iBand] = ColorInterpretation.RED_GREEN_BAND; |
|
502 |
} else if(isSelected(iBand, 1) && isSelected(iBand, 3)) { |
|
503 |
colorInter[iBand] = ColorInterpretation.RED_BLUE_BAND; |
|
504 |
} else if(isSelected(iBand, 2) && isSelected(iBand, 3)) { |
|
505 |
colorInter[iBand] = ColorInterpretation.GREEN_BLUE_BAND; |
|
506 |
} else if(isSelected(iBand, 1)) { |
|
507 |
colorInter[iBand] = ColorInterpretation.RED_BAND; |
|
508 |
} else if(isSelected(iBand, 2)) { |
|
509 |
colorInter[iBand] = ColorInterpretation.GREEN_BAND; |
|
510 |
} else if(isSelected(iBand, 3)) { |
|
511 |
colorInter[iBand] = ColorInterpretation.BLUE_BAND; |
|
512 |
} else if(isSelected(iBand, 0)) { |
|
513 |
colorInter[iBand] = ColorInterpretation.ALPHA_BAND; |
|
514 |
} else |
|
515 |
colorInter[iBand] = ColorInterpretation.UNDEF_BAND; |
|
491 | 516 |
} |
517 |
return RasterLocator.getManager().getDataStructFactory().createColorInterpretation(colorInter); |
|
492 | 518 |
} catch (NotInitializeException e) { |
493 | 519 |
RasterSwingLibrary.messageBoxError(Messages.getText("table_not_initialize"), this, e); |
494 | 520 |
} |
495 |
return ColorInterpretation.UNDEF_BAND;
|
|
521 |
return null;
|
|
496 | 522 |
} |
497 | 523 |
|
498 |
|
|
524 |
private boolean isSelected(int iBand, int col) { |
|
525 |
DefaultTableModel model = ((DefaultTableModel) getARGBTable().getModel()); |
|
526 |
return ((Boolean) model.getValueAt(iBand, col)).booleanValue(); |
|
527 |
} |
|
528 |
|
|
499 | 529 |
public void tableChanged(TableModelEvent e) { |
500 | 530 |
getARGBTable().revalidate(); |
501 | 531 |
revalidate(); |
... | ... | |
541 | 571 |
*/ |
542 | 572 |
public void readDrawedBands() { |
543 | 573 |
if (fLayer.getRender() != null) { |
544 |
int[] renderBands = fLayer.getRender().getRenderBands(); |
|
574 |
int[] renderBands = fLayer.getRender().getRenderColorInterpretation().buildRenderBands();
|
|
545 | 575 |
Transparency transp = fLayer.getRender().getRenderingTransparency(); |
546 | 576 |
if(transp != null && transp.getAlphaBandNumber() != -1) |
547 | 577 |
this.assignBand(transp.getAlphaBandNumber(), RasterDataStore.ALPHA_BAND); |
... | ... | |
594 | 624 |
*/ |
595 | 625 |
@SuppressWarnings("unchecked") |
596 | 626 |
private void saveStatus() { |
597 |
ArrayList<Integer> aux = new ArrayList<Integer>();
|
|
598 |
int[] renderBands = fLayer.getRender().getRenderBands();
|
|
599 |
for (int i = 0; i < renderBands.length; i++) {
|
|
600 |
aux.add(new Integer(renderBands[i]));
|
|
627 |
List<String> aux = new ArrayList<String>();
|
|
628 |
String[] valuesCI = fLayer.getRender().getRenderColorInterpretation().getValues();
|
|
629 |
for (int i = 0; i < valuesCI.length; i++) {
|
|
630 |
aux.add(valuesCI[i]);
|
|
601 | 631 |
} |
602 |
int alphaBand = fLayer.getRender().getLastAlphaBandNumber(); |
|
603 |
getPanelGroup().getProperties().put("alphaBand", new Integer(alphaBand)); |
|
604 | 632 |
getPanelGroup().getProperties().put("renderBands", aux); |
605 | 633 |
} |
606 | 634 |
|
... | ... | |
608 | 636 |
/** |
609 | 637 |
* Deja la capa en el ?ltimo estado guardado y la refresca |
610 | 638 |
*/ |
611 |
@SuppressWarnings("rawtypes")
|
|
639 |
@SuppressWarnings("unchecked")
|
|
612 | 640 |
public void restoreStatus() { |
613 | 641 |
if (fLayer != null) |
614 | 642 |
return; |
615 | 643 |
|
616 |
ArrayList aux = (ArrayList) getPanelGroup().getProperties().get("renderBands"); |
|
617 |
Integer alphaBand = (Integer) getPanelGroup().getProperties().get("alphaBand"); |
|
644 |
List<String> aux = (List<String>) getPanelGroup().getProperties().get("renderBands"); |
|
618 | 645 |
|
619 |
int[] renderBands = new int[aux.size() + 1]; |
|
620 |
for (int i = 0; i < aux.size(); i++) |
|
621 |
renderBands[i] = ((Integer) aux.get(i)).intValue(); |
|
622 |
renderBands[aux.size()] = alphaBand.intValue(); |
|
623 |
|
|
624 | 646 |
if(fLayer.getRender() != null) { |
625 |
fLayer.getRender().setRenderBands(renderBands); |
|
626 |
if(alphaBand != null) { |
|
627 |
// Ultima transparencia aplicada en el renderizador |
|
628 |
Transparency gt = fLayer.getRender().getRenderingTransparency(); |
|
629 |
if(gt != null) |
|
630 |
gt.setTransparencyBand(alphaBand.intValue()); |
|
631 |
} |
|
647 |
ColorInterpretation ci = RasterLocator.getManager().getDataStructFactory().createColorInterpretation((String[])aux.toArray()); |
|
648 |
fLayer.getRender().setRenderColorInterpretation(ci); |
|
632 | 649 |
} |
633 | 650 |
|
634 | 651 |
fLayer.getMapContext().invalidate(); |
Also available in: Unified diff