svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / beans / previewbase / PreviewRequestManager.java @ 20080
History | View | Annotate | Download (3.77 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.raster.beans.previewbase; |
20 |
|
21 |
import java.awt.Dimension; |
22 |
import java.awt.Graphics2D; |
23 |
|
24 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
25 |
import org.gvsig.gui.beans.imagenavigator.IClientImageNavigator; |
26 |
import org.gvsig.raster.datastruct.Extent; |
27 |
import org.gvsig.raster.grid.filter.FilterTypeException; |
28 |
import org.gvsig.raster.hierarchy.IRasterRendering; |
29 |
import org.gvsig.raster.util.RasterToolsUtil; |
30 |
|
31 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
32 |
import com.iver.andami.PluginServices; |
33 |
import com.iver.cit.gvsig.fmap.ViewPort; |
34 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
35 |
|
36 |
/**
|
37 |
* Gestor de visualizaci?n de preview. Se encarga del repintado de la imagen
|
38 |
* de la previsualizaci?n
|
39 |
*
|
40 |
* 19/02/2008
|
41 |
* @author Nacho Brodin nachobrodin@gmail.com
|
42 |
*/
|
43 |
public class PreviewRequestManager implements IClientImageNavigator { |
44 |
private PreviewBasePanel previewBasePanel = null; |
45 |
private FLyrRasterSE previewLayer = null; |
46 |
private IPreviewRenderProcess renderProcess = null; |
47 |
|
48 |
/**
|
49 |
* Construye un ColorTableListener
|
50 |
* @param
|
51 |
*/
|
52 |
public PreviewRequestManager( PreviewBasePanel panel,
|
53 |
IPreviewRenderProcess renderProcess, |
54 |
FLyrRasterSE layer) { |
55 |
this.previewBasePanel = panel;
|
56 |
this.renderProcess = renderProcess;
|
57 |
setLayer(layer); |
58 |
} |
59 |
|
60 |
/**
|
61 |
* Asigna la capa raster de la vista
|
62 |
* @param fLayer
|
63 |
*/
|
64 |
private void setLayer(FLayer fLayer) { |
65 |
if (fLayer instanceof FLyrRasterSE) { |
66 |
try {
|
67 |
previewLayer = (FLyrRasterSE) fLayer.cloneLayer(); |
68 |
} catch (Exception e) { |
69 |
RasterToolsUtil.messageBoxError("preview_not_available", previewBasePanel, e);
|
70 |
} |
71 |
} |
72 |
} |
73 |
|
74 |
/**
|
75 |
* Cierra la capa abierta para previsualizaci?n
|
76 |
*/
|
77 |
public void closePreviewLayer() { |
78 |
if (previewLayer != null) { |
79 |
previewLayer.getDataSource().close(); |
80 |
previewLayer.setRemoveRasterFlag(true);
|
81 |
} |
82 |
} |
83 |
|
84 |
/*
|
85 |
* (non-Javadoc)
|
86 |
* @see org.gvsig.gui.beans.imagenavigator.IClientImageNavigator#drawImage(java.awt.Graphics2D,
|
87 |
* double, double, double, double, double, int, int)
|
88 |
*/
|
89 |
public void drawImage(Graphics2D g, double x1, double y1, double x2, double y2, double zoom, int width, int height) { |
90 |
if (previewLayer == null || !(previewLayer instanceof IRasterRendering)) |
91 |
return;
|
92 |
|
93 |
IRasterRendering rendering = ((IRasterRendering) previewLayer); |
94 |
|
95 |
// Inicializo el ViewPort
|
96 |
ViewPort vp = new ViewPort(null); |
97 |
Extent extent = new Extent(x1, y1, x2, y2);
|
98 |
vp.setExtent(extent.toRectangle2D()); |
99 |
vp.setImageSize(new Dimension(width, height)); |
100 |
|
101 |
rendering.getRenderFilterList().pushStatus(); |
102 |
try {
|
103 |
renderProcess.process(rendering); |
104 |
} catch (FilterTypeException e1) {
|
105 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_adding_filters"), this, e1); |
106 |
} |
107 |
|
108 |
try {
|
109 |
previewLayer.draw(null, g, vp, null, 1.0); |
110 |
} catch (ReadDriverException e) {
|
111 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_preview_render"), this, e); |
112 |
} |
113 |
rendering.getRenderFilterList().popStatus(); |
114 |
} |
115 |
} |