gvsig-3d / org.gvsig.netcdf3d / trunk / org.gvsig.netcdf3d / org.gvsig.netcdf3d.lib / org.gvsig.netcdf3d.lib.impl / src / main / java / org / gvsig / netcdf3d / lib / impl / DefaultNetCDFTimerTask.java @ 727
History | View | Annotate | Download (3.76 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2016 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
|
24 |
package org.gvsig.netcdf3d.lib.impl; |
25 |
|
26 |
import java.awt.event.ActionEvent; |
27 |
import java.awt.event.ActionListener; |
28 |
import java.util.Calendar; |
29 |
import java.util.List; |
30 |
import java.util.TimerTask; |
31 |
|
32 |
import org.gvsig.fmap.dal.raster.api.BandAttributeDescriptor; |
33 |
import org.gvsig.fmap.dal.raster.api.BandDescriptor; |
34 |
import org.gvsig.fmap.dal.raster.api.BandQuery; |
35 |
import org.gvsig.fmap.dal.raster.api.RasterQuery; |
36 |
import org.gvsig.fmap.dal.raster.api.RasterStore; |
37 |
import org.gvsig.fmap.mapcontext.raster.api.RasterLayer; |
38 |
import org.gvsig.netcdf3d.lib.api.NetCDFLoaderParameters; |
39 |
|
40 |
/**
|
41 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
42 |
*
|
43 |
*/
|
44 |
public class DefaultNetCDFTimerTask implements ActionListener { |
45 |
|
46 |
private NetCDFLoaderParameters parameters;
|
47 |
private DefaultNetCDFTiledImageLayer netCDFTiledImageLayer;
|
48 |
private Calendar time; |
49 |
|
50 |
/**
|
51 |
*
|
52 |
* @param netCDFTiledImageLayer
|
53 |
* @param defaultNetCDFTiledImageLayer
|
54 |
* @param parameters
|
55 |
*/
|
56 |
public DefaultNetCDFTimerTask(DefaultNetCDFTiledImageLayer netCDFTiledImageLayer,
|
57 |
NetCDFLoaderParameters parameters) { |
58 |
|
59 |
this.parameters = parameters;
|
60 |
this.netCDFTiledImageLayer = netCDFTiledImageLayer;
|
61 |
|
62 |
if (parameters.getStartDate() == null || parameters.getFinalDate() == null) { |
63 |
throw new IllegalArgumentException("Start date or final date can not be null"); |
64 |
} |
65 |
} |
66 |
|
67 |
@Override
|
68 |
public void actionPerformed(ActionEvent e) { |
69 |
|
70 |
RasterLayer layer = (RasterLayer) parameters.getLayer(); |
71 |
RasterStore rasterStore = layer.getRasterStore(); |
72 |
|
73 |
if (this.time == null) { |
74 |
this.time = parameters.getStartDate();
|
75 |
} else {
|
76 |
BandDescriptor bandDescriptor = |
77 |
layer.getRasterStore().getBandDescriptor(parameters.getBand()); |
78 |
BandAttributeDescriptor bandAttributeDescriptor = bandDescriptor.get("time");
|
79 |
|
80 |
if (bandAttributeDescriptor == null) { |
81 |
throw new IllegalArgumentException(String.format( |
82 |
"Band descriptor of %1s band does not have \"time\" band attribute descriptor",
|
83 |
parameters.getVariable())); |
84 |
} |
85 |
|
86 |
List<Object> values = bandAttributeDescriptor.getValues(); |
87 |
int index = values.indexOf(this.time); |
88 |
if (index == values.size() - 1) { |
89 |
this.time = parameters.getStartDate();
|
90 |
} else {
|
91 |
this.time = (Calendar) values.get(index + 1); |
92 |
} |
93 |
} |
94 |
|
95 |
int band = parameters.getBand();
|
96 |
BandQuery bandQuery = rasterStore.createBandQuery(band); |
97 |
bandQuery.setValue("level", parameters.getLevel());
|
98 |
bandQuery.setValue("time", time);
|
99 |
|
100 |
RasterQuery rasterQuery = rasterStore.createRasterQuery(); |
101 |
rasterQuery.addBand(bandQuery); |
102 |
netCDFTiledImageLayer.setBaseQuery(rasterQuery); |
103 |
} |
104 |
|
105 |
} |