svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.library / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.buffer.impl / src / main / java / org / gvsig / raster / lib / buffer / impl / AbstractConvertedTypeBand.java @ 43803
History | View | Annotate | Download (3.72 KB)
1 |
package org.gvsig.raster.lib.buffer.impl; |
---|---|
2 |
|
3 |
import org.gvsig.raster.lib.buffer.api.Band; |
4 |
import org.gvsig.raster.lib.buffer.api.BandInfo; |
5 |
import org.gvsig.raster.lib.buffer.api.Buffer; |
6 |
import org.gvsig.raster.lib.buffer.api.BufferLocator; |
7 |
import org.gvsig.raster.lib.buffer.api.BufferManager; |
8 |
import org.gvsig.raster.lib.buffer.impl.exceptions.CopyFromBandException; |
9 |
import org.gvsig.tools.ToolsLocator; |
10 |
import org.gvsig.tools.dispose.DisposableManager; |
11 |
import org.gvsig.tools.dispose.DisposeUtils; |
12 |
import org.gvsig.tools.exception.BaseException; |
13 |
|
14 |
|
15 |
/**
|
16 |
* @author fdiaz
|
17 |
*
|
18 |
*/
|
19 |
public abstract class AbstractConvertedTypeBand extends AbstractBand implements Band { |
20 |
protected Band band;
|
21 |
|
22 |
/**
|
23 |
* @param buffer
|
24 |
* @param band
|
25 |
*/
|
26 |
public AbstractConvertedTypeBand(Buffer buffer, Band band) { |
27 |
if (buffer instanceof ConvertedTypeBuffer) { |
28 |
ConvertedTypeBuffer convertedTypeBuffer = (ConvertedTypeBuffer) buffer; |
29 |
|
30 |
DisposableManager disposableManager = ToolsLocator.getDisposableManager(); |
31 |
disposableManager.bind(band); |
32 |
this.band = band;
|
33 |
this.noData = this.getNoData(); |
34 |
} else {
|
35 |
throw new IllegalArgumentException("buffer isn't a ConvertedTypeBuffer"); |
36 |
} |
37 |
} |
38 |
|
39 |
@Override
|
40 |
protected void doSet(int row, int column, Object value) { |
41 |
switch (band.getDataType()) {
|
42 |
case BufferManager.TYPE_BYTE:
|
43 |
((BandByte) band).setValue(row, column, ((Number)value).byteValue());
|
44 |
break;
|
45 |
case BufferManager.TYPE_SHORT:
|
46 |
case BufferManager.TYPE_USHORT:
|
47 |
((BandShort) band).setValue(row, column, ((Number)value).shortValue());
|
48 |
break;
|
49 |
case BufferManager.TYPE_INT:
|
50 |
((BandInt) band).setValue(row, column, ((Number)value).intValue());
|
51 |
break;
|
52 |
case BufferManager.TYPE_FLOAT:
|
53 |
((BandFloat) band).setValue(row, column, ((Number)value).floatValue());
|
54 |
break;
|
55 |
case BufferManager.TYPE_DOUBLE:
|
56 |
((BandDouble) band).setValue(row, column, ((Number)value).doubleValue());
|
57 |
break;
|
58 |
default:
|
59 |
throw new IllegalArgumentException("Unknow dataType " + band.getDataType() + "."); |
60 |
} |
61 |
// throw new UnsupportedOperationException("Can't write in a converted type band.");
|
62 |
} |
63 |
|
64 |
@Override
|
65 |
protected void doFill(Object value) { |
66 |
throw new UnsupportedOperationException("Can't write in a converted type band."); |
67 |
} |
68 |
|
69 |
@Override
|
70 |
protected void doCopyFrom(Band source) throws CopyFromBandException { |
71 |
throw new UnsupportedOperationException("Can't write in a converted type band."); |
72 |
} |
73 |
|
74 |
@Override
|
75 |
protected void doCopyFrom(Band source, int row, int column) throws CopyFromBandException { |
76 |
throw new UnsupportedOperationException("Can't write in a converted type band."); |
77 |
} |
78 |
|
79 |
@Override
|
80 |
protected void doPutRow(int row, Object rowBuffer) { |
81 |
throw new UnsupportedOperationException("Can't write in a converted type band."); |
82 |
} |
83 |
|
84 |
@Override
|
85 |
public boolean isReadOnly() { |
86 |
return true; |
87 |
} |
88 |
|
89 |
// ?es necesario? ?es conveniente?
|
90 |
@Override
|
91 |
public void doDispose() throws BaseException { |
92 |
super.doDispose();
|
93 |
DisposeUtils.dispose(band); |
94 |
band = null;
|
95 |
} |
96 |
|
97 |
@Override
|
98 |
public int getRows() { |
99 |
return this.band.getRows(); |
100 |
} |
101 |
|
102 |
@Override
|
103 |
public int getColumns() { |
104 |
return this.band.getColumns(); |
105 |
} |
106 |
|
107 |
@Override
|
108 |
public BandInfo getBandInfo() {
|
109 |
BandInfo bandInfo = band.getBandInfo(); |
110 |
//FIXME: ?values?
|
111 |
return BufferLocator.getBufferManager().createBandInfo(bandInfo.getBand(), bandInfo.getName(), bandInfo.getDescription(), getDataType(), bandInfo.getValues());
|
112 |
} |
113 |
|
114 |
} |