gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / raster / bean / previewbase / RasterDataSourcePreview.java @ 2582
History | View | Annotate | Download (4.01 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 |
*/
|
22 |
package org.gvsig.raster.tools.app.basic.raster.bean.previewbase; |
23 |
|
24 |
import java.awt.Dimension; |
25 |
import java.awt.Graphics2D; |
26 |
import java.awt.geom.Rectangle2D; |
27 |
import java.awt.image.BufferedImage; |
28 |
|
29 |
import org.cresques.cts.IProjection; |
30 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
31 |
import org.gvsig.fmap.dal.exception.ReadException; |
32 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
33 |
import org.gvsig.fmap.geom.GeometryLocator; |
34 |
import org.gvsig.fmap.geom.GeometryManager; |
35 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
36 |
import org.gvsig.fmap.geom.primitive.Envelope; |
37 |
import org.gvsig.fmap.mapcontext.ViewPort; |
38 |
import org.gvsig.gui.beans.imagenavigator.ImageUnavailableException; |
39 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
40 |
import org.gvsig.raster.swing.preview.DataSourcePreview; |
41 |
import org.gvsig.tools.task.Cancellable; |
42 |
import org.slf4j.Logger; |
43 |
import org.slf4j.LoggerFactory; |
44 |
|
45 |
/**
|
46 |
* Source for a preview using a raster layer
|
47 |
* @author Nacho Brodin nachobrodin@gmail.com
|
48 |
*/
|
49 |
@SuppressWarnings("deprecation") |
50 |
public class RasterDataSourcePreview implements DataSourcePreview { |
51 |
private FLyrRaster lyr = null; |
52 |
private IProjection viewProjection = null; |
53 |
private static GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
54 |
private static final Logger logger = LoggerFactory.getLogger(RasterDataSourcePreview.class); |
55 |
|
56 |
public RasterDataSourcePreview(FLyrRaster lyr, IProjection proj) {
|
57 |
this.lyr = lyr;
|
58 |
this.viewProjection = proj;
|
59 |
} |
60 |
|
61 |
public void closePreviewLayer() { |
62 |
if (lyr != null) { |
63 |
lyr.setRemoveRasterFlag(true);
|
64 |
lyr.removeLayerListener(null);
|
65 |
} |
66 |
} |
67 |
|
68 |
public Rectangle2D getBBoxRectangle() { |
69 |
Extent e = lyr.getFullRasterExtent(); |
70 |
return e.toRectangle2D();
|
71 |
} |
72 |
|
73 |
public double getCellSize() { |
74 |
return lyr.getDataStore().getCellSize();
|
75 |
} |
76 |
|
77 |
public DataSourcePreview cloneDataSourcePreview() {
|
78 |
if(lyr != null) { |
79 |
try {
|
80 |
IProjection viewProj = null;
|
81 |
if(lyr.getMapContext() != null) |
82 |
viewProj = lyr.getMapContext().getProjection(); |
83 |
return new RasterDataSourcePreview((FLyrRaster)lyr.cloneLayer(), viewProj); |
84 |
} catch (Exception e) { |
85 |
} |
86 |
} |
87 |
return null; |
88 |
} |
89 |
|
90 |
public void popStatus() { |
91 |
if (lyr != null) |
92 |
lyr.getRender().getFilterList().popStatus(); |
93 |
} |
94 |
|
95 |
public void pushStatus() { |
96 |
if (lyr != null) |
97 |
lyr.getRender().getFilterList().pushStatus(); |
98 |
} |
99 |
|
100 |
public void draw(BufferedImage image, |
101 |
Graphics2D g,
|
102 |
double[] coords, |
103 |
int w,
|
104 |
int h,
|
105 |
Cancellable cancel, |
106 |
double scale) throws ImageUnavailableException { |
107 |
try {
|
108 |
// Inicializo el ViewPort
|
109 |
ViewPort vp = new ViewPort(viewProjection);
|
110 |
Envelope env; |
111 |
try {
|
112 |
env = geomManager.createEnvelope(coords[0], coords[3], coords[2], coords[1], SUBTYPES.GEOM2D); |
113 |
vp.setEnvelope(env); |
114 |
} catch (CreateEnvelopeException e3) {
|
115 |
logger.error("Error drawing the image", e3);
|
116 |
} |
117 |
vp.setImageSize(new Dimension(w, h)); |
118 |
|
119 |
if (lyr != null) { |
120 |
lyr.setLayerInitialized(true);
|
121 |
lyr.draw(image, g, vp, cancel, scale); |
122 |
} |
123 |
} catch (ReadException e) {
|
124 |
throw new ImageUnavailableException("Error drawing raster"); |
125 |
} |
126 |
} |
127 |
|
128 |
public Object getSource() { |
129 |
return lyr;
|
130 |
} |
131 |
|
132 |
} |