Statistics
| Revision:

gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / impl / BufferParamImpl.java @ 1939

History | View | Annotate | Download (3.91 KB)

1
package org.gvsig.raster.cache.buffer.impl;
2

    
3
import java.io.IOException;
4

    
5
import org.gvsig.raster.cache.buffer.Buffer;
6
import org.gvsig.raster.cache.buffer.BufferDataSource;
7
import org.gvsig.raster.cache.buffer.BufferParam;
8
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl;
9
import org.gvsig.raster.cache.buffer.impl.io.BufferMultiDataSourceImpl;
10

    
11
/**
12
 * Buffer parameters. This class contains generic parameters. 
13
 * Basic information to fill: x, y, w, h, datatype and bandcount. If
14
 * the buffer is RasterReadOnlyBuffer is necessary a IBufferDataSource too.
15
 * 02/11/2008
16
 * @author Nacho Brodin nachobrodin@gmail.com
17
 */
18
public class BufferParamImpl extends PxTileImpl implements BufferParam {
19
        private static final long serialVersionUID = 1L;
20
        private int               accessType       = Buffer.READ_WRITE;
21
        private int[]             bands            = null;
22

    
23
        /**
24
         * Constructor
25
         * @param  w
26
         *         Width
27
         * @param  h
28
         *         Height
29
         */
30
        public BufferParamImpl(int w, int h) {
31
                super(0, 0, w, h);
32
        }
33
        
34
        /**
35
         * Constructor
36
         * @param  file
37
         *         file name
38
         * @param  x
39
         *         X position
40
         * @param  y
41
         *         Y position
42
         * @param  w
43
         *         Width
44
         * @param  h
45
         *         Height
46
         * @param  bands
47
         *         bands to load in the buffer
48
         * @throws IOException 
49
         */
50
        public BufferParamImpl(String file, int x, int y, int w, int h, int[] bands) throws IOException {
51
                super(x, y, w, h);
52
                PxTileImpl pxTile = new PxTileImpl(x, y, w, h);
53
                BufferDataSourceImpl datasource = new BufferDataSourceImpl(file, pxTile);
54
                setDataSource(datasource);
55
                if(bands == null) {
56
                        int bandCount = getDataSource().getBandCount();
57
                        this.bands = new int[bandCount];
58
                        for (int i = 0; i < bandCount; i++) {
59
                                this.bands[i] = i;
60
                        }
61
                } else
62
                        this.bands = bands;
63
                setBandCount(this.bands.length);
64
                accessType = Buffer.READ_ONLY;
65
        }
66
        
67
        /**
68
         * Constructor for multifiles
69
         * @param  file
70
         *         file name
71
         * @param  x
72
         *         X position
73
         * @param  y
74
         *         Y position
75
         * @param  w
76
         *         Width in pixels
77
         * @param  h
78
         *         Height in pixels
79
         * @param  bands
80
         *         bands to load in the buffer. It can be null. In this case all bands will be used
81
         * @throws IOException 
82
         */
83
        public BufferParamImpl(String[] file, int x, int y, int w, int h, int[] bands) throws IOException {
84
                super(x, y, w, h);
85
                PxTileImpl pxTile = new PxTileImpl(x, y, w, h);
86
                BufferDataSource datasource = new BufferMultiDataSourceImpl(file, pxTile);
87
                setDataSource(datasource);
88
                
89
                if(bands == null) {
90
                        int bandCount = getDataSource().getBandCount();
91
                        this.bands = new int[bandCount];
92
                        for (int i = 0; i < bandCount; i++) {
93
                                this.bands[i] = i;
94
                        }
95
                } else
96
                        this.bands = bands;
97
                setBandCount(this.bands.length);
98
                accessType = Buffer.READ_ONLY;
99
        }
100
        
101
        /**
102
         * Creates a parameter object for building a buffer. The buffer type is read-write.
103
         * This type could be changed after the creation of a {@link BufferParam} object.
104
         * @param  w
105
         *         Width
106
         * @param  h
107
         *         Height
108
         * @param  bandCount
109
         *                    Number of bands
110
         * @param  dataType
111
         *         Type of data        
112
         */
113
        public BufferParamImpl(int w, int h, int bandCount, int dataType) {
114
                super(0, 0, w, h);
115
                this.setBandCount(bandCount);
116
                this.setDataType(dataType);
117
                this.setAccessType(Buffer.READ_WRITE);
118
        }
119
        
120
        /*
121
         * 
122
         * (non-Javadoc)
123
         * @see org.gvsig.raster.cache.buffer.BufferParam#setAccessType(int)
124
         */
125
        public void setAccessType(int accessType) {
126
                this.accessType = accessType;
127
        }
128
        
129
        /*
130
         * (non-Javadoc)
131
         * @see org.gvsig.raster.cache.buffer.BufferParam#getAccessType()
132
         */
133
        public int getAccessType() {
134
                return accessType;
135
        }
136

    
137
        /*
138
         * (non-Javadoc)
139
         * @see org.gvsig.raster.cache.buffer.BufferParam#setFile(java.lang.String)
140
         */
141
        public void setBandList(int[] bands) {
142
                this.bands = bands;
143
        }
144

    
145
        /*
146
         * (non-Javadoc)
147
         * @see org.gvsig.raster.cache.buffer.BufferParam#getFile()
148
         */
149
        public int[] getBandList() {
150
                return bands;
151
        }
152
}