Statistics
| Revision:

gvsig-3d / 2.1 / trunk / org.gvsig.view3d / org.gvsig.view3d.swing / org.gvsig.view3d.swing.impl / src / main / java / org / gvsig / view3d / swing / impl / data / DefaultDataRasterReader.java @ 451

History | View | Annotate | Download (4.14 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

    
25
package org.gvsig.view3d.swing.impl.data;
26

    
27
import java.io.IOException;
28

    
29
import org.gvsig.fmap.mapcontext.MapContext;
30
import org.gvsig.fmap.mapcontext.layers.FLayer;
31
import org.gvsig.view3d.swing.api.MapControl3D;
32

    
33
import gov.nasa.worldwind.avlist.AVKey;
34
import gov.nasa.worldwind.avlist.AVList;
35
import gov.nasa.worldwind.avlist.AVListImpl;
36
import gov.nasa.worldwind.data.AbstractDataRasterReader;
37
import gov.nasa.worldwind.data.DataRaster;
38
import gov.nasa.worldwind.geom.Sector;
39

    
40
/**
41
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
42
 *
43
 */
44
public class DefaultDataRasterReader extends AbstractDataRasterReader {
45

    
46
    /**
47
     * @param description
48
     */
49
    protected DefaultDataRasterReader(String description) {
50
        super(description);
51
    }
52

    
53
    @Override
54
    public boolean canRead(Object source, AVList params) {
55

    
56
        if (source == null) {
57
            throw new IllegalArgumentException();
58
        }
59

    
60
        return this.doCanRead(source, params);
61
    }
62

    
63
    @Override
64
    protected boolean doCanRead(Object source, AVList params) {
65

    
66
        if (params == null) {
67
            return false;
68
        }
69

    
70
        Sector sector = (Sector) params.getValue(AVKey.SECTOR);
71
        if (sector == null) {
72
            return false;
73
        }
74

    
75
        if (source instanceof FLayer) {
76

    
77
            boolean canRead = false;
78
            GvSIGLayerDataRaster dataRaster = null;
79

    
80
            try {
81
                FLayer layer = (FLayer) source;
82
                MapContext mapContext =
83
                    (MapContext) params.getValue(MapControl3D.GVSIG_MAPCONTEXT);
84
                dataRaster =
85
                    new GvSIGLayerDataRaster(mapContext, layer, params);
86
                canRead = true;
87
            } catch (Throwable e) {
88
                canRead = false;
89
            } finally {
90
                if (dataRaster != null) {
91
                    dataRaster.dispose();
92
                }
93
            }
94

    
95
            return canRead;
96
        }
97

    
98
        return false;
99
    }
100

    
101
    @Override
102
    protected DataRaster[] doRead(Object source, AVList params)
103
        throws IOException {
104

    
105
        if (source == null) {
106
            throw new IllegalArgumentException();
107
        }
108

    
109
        if (source instanceof FLayer) {
110

    
111
            FLayer layer = (FLayer) source;
112
            MapContext mapContext =
113
                (MapContext) params.getValue(MapControl3D.GVSIG_MAPCONTEXT);
114
            GvSIGLayerDataRaster dataRaster =
115
                new GvSIGLayerDataRaster(mapContext, layer, params);
116
            return new DataRaster[] { dataRaster };
117

    
118
        }
119

    
120
        return null;
121
    }
122

    
123
    @Override
124
    protected void doReadMetadata(Object source, AVList params)
125
        throws IOException {
126
        
127
        //TODO: fill weigth height and sector
128

    
129
    }
130
    
131
    @Override
132
    public AVList readMetadata(Object source, AVList params) throws java.io.IOException
133
    {
134
        if (!this.canRead(source, params))
135
        {
136
            throw new IllegalArgumentException();
137
        }
138

    
139
        if (params == null)
140
            params = new AVListImpl();
141

    
142
        this.doReadMetadata(source, params);
143

    
144
        String message = this.validateMetadata(source, params);
145
        if (message != null)
146
            throw new java.io.IOException(message);
147

    
148
        return params;
149
    }
150

    
151
}