Statistics
| Revision:

gvsig-3d / 2.1 / branches / extrusion / org.gvsig.view3d.swing / org.gvsig.view3d.swing.impl / src / main / java / org / gvsig / view3d / swing / impl / data / DefaultDataRasterReader.java @ 657

History | View | Annotate | Download (4.35 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 gov.nasa.worldwind.avlist.AVKey;
28
import gov.nasa.worldwind.avlist.AVList;
29
import gov.nasa.worldwind.avlist.AVListImpl;
30
import gov.nasa.worldwind.data.AbstractDataRasterReader;
31
import gov.nasa.worldwind.data.DataRaster;
32
import gov.nasa.worldwind.geom.Sector;
33

    
34
import java.io.IOException;
35

    
36
import org.gvsig.fmap.mapcontext.layers.FLayer;
37
import org.gvsig.view3d.swing.api.MapControl3D;
38
import org.gvsig.view3d.swing.impl.DefaultMapControl3D;
39

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

    
48
    /**
49
     * Default constructor of {@link DefaultDataRasterReader}.
50
     * 
51
     * @param description Description of this reader.
52
     */
53
    protected DefaultDataRasterReader(String description) {
54
        super(description);
55
    }
56
    
57
    @Override
58
    public boolean canRead(Object source, AVList params) {
59

    
60
        if (source == null) {
61
            throw new IllegalArgumentException();
62
        }
63

    
64
        return this.doCanRead(source, params);
65
    }
66

    
67
    @Override
68
    protected boolean doCanRead(Object source, AVList params) {
69

    
70
        if (params == null) {
71
            return false;
72
        }
73

    
74
        Sector sector = (Sector) params.getValue(AVKey.SECTOR);
75
        if (sector == null) {
76
            return false;
77
        }
78

    
79
        if (source instanceof FLayer) {
80

    
81
            boolean canRead = false;
82
            GvSIGLayerDataRaster dataRaster = null;
83

    
84
            try {
85
                FLayer layer = (FLayer) source;
86
                MapControl3D mapControl3D =
87
                    (MapControl3D) params.getValue(DefaultMapControl3D.GVSIG_MAPCONTROL3D);
88
                dataRaster =
89
                    new GvSIGLayerDataRaster(mapControl3D, layer, params);
90
                canRead = true;
91
            } catch (Throwable e) {
92
                canRead = false;
93
            } finally {
94
                if (dataRaster != null) {
95
                    dataRaster.dispose();
96
                }
97
            }
98

    
99
            return canRead;
100
        }
101

    
102
        return false;
103
    }
104

    
105
    @Override
106
    protected DataRaster[] doRead(Object source, AVList params)
107
        throws IOException {
108

    
109
        if (source == null) {
110
            throw new IllegalArgumentException();
111
        }
112

    
113
        if (source instanceof FLayer) {
114

    
115
            FLayer layer = (FLayer) source;
116
            MapControl3D mapControl3D =
117
                (MapControl3D) params.getValue(DefaultMapControl3D.GVSIG_MAPCONTROL3D);
118
            GvSIGLayerDataRaster dataRaster =
119
                new GvSIGLayerDataRaster(mapControl3D, layer, params);
120
            return new DataRaster[] { dataRaster };
121

    
122
        }
123

    
124
        return null;
125
    }
126

    
127
    @Override
128
    protected void doReadMetadata(Object source, AVList params)
129
        throws IOException {
130
        
131
        //TODO: fill weigth height and sector
132

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

    
143
        if (params == null)
144
            params = new AVListImpl();
145

    
146
        this.doReadMetadata(source, params);
147

    
148
        String message = this.validateMetadata(source, params);
149
        if (message != null)
150
            throw new java.io.IOException(message);
151

    
152
        return params;
153
    }
154

    
155
}