gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.swing / org.gvsig.raster.swing.impl / src / main / java / org / gvsig / raster / swing / impl / preview / PreviewRequestManager.java @ 2308
History | View | Annotate | Download (4.53 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.swing.impl.preview; |
23 |
|
24 |
import java.awt.Component; |
25 |
import java.awt.Graphics2D; |
26 |
|
27 |
import javax.swing.JOptionPane; |
28 |
|
29 |
import org.gvsig.gui.beans.imagenavigator.IClientImageNavigator; |
30 |
import org.gvsig.gui.beans.imagenavigator.ImageUnavailableException; |
31 |
import org.gvsig.i18n.Messages; |
32 |
import org.gvsig.raster.swing.preview.DataSourcePreview; |
33 |
import org.gvsig.raster.swing.preview.PreviewRenderProcess; |
34 |
import org.slf4j.Logger; |
35 |
import org.slf4j.LoggerFactory; |
36 |
|
37 |
/**
|
38 |
* Gestor de visualizaci?n de preview. Se encarga del repintado de la imagen
|
39 |
* de la previsualizaci?n
|
40 |
*
|
41 |
* @author Nacho Brodin nachobrodin@gmail.com
|
42 |
*/
|
43 |
public class PreviewRequestManager implements IClientImageNavigator { |
44 |
private static final Logger logger = LoggerFactory.getLogger(PreviewRequestManager.class); |
45 |
private DataSourcePreview previewLayer = null; |
46 |
private PreviewRenderProcess renderProcess = null; |
47 |
|
48 |
/**
|
49 |
* Construye un ColorTableListener
|
50 |
* @param
|
51 |
*/
|
52 |
public PreviewRequestManager( PreviewRenderProcess renderProcess,
|
53 |
DataSourcePreview layer) { |
54 |
this.renderProcess = renderProcess;
|
55 |
setLayer(layer); |
56 |
} |
57 |
|
58 |
/**
|
59 |
* Asigna la capa raster de la vista
|
60 |
* @param fLayer
|
61 |
*/
|
62 |
private void setLayer(DataSourcePreview fLayer) { |
63 |
//if (fLayer instanceof IRasterLayerActions) {
|
64 |
//IRasterLayerActions ly = (IRasterLayerActions) fLayer;
|
65 |
//try {
|
66 |
//Este c?digo no va bien pq la preview siempre tiene el extent global y el ?ltimo fichero
|
67 |
//puede ser de un zoom
|
68 |
/*if(ly.isActionEnabled(IRasterLayerActions.REMOTE_ACTIONS))
|
69 |
previewLayer = (FLyrRaster)fLayer.getFileLayer();
|
70 |
else*/
|
71 |
previewLayer = fLayer.cloneDataSourcePreview(); |
72 |
//} catch (Exception e) {
|
73 |
//messageBoxError("preview_not_available", previewBasePanel, e);
|
74 |
//}
|
75 |
//}
|
76 |
} |
77 |
|
78 |
/**
|
79 |
* Cierra la capa abierta para previsualizaci?n
|
80 |
*/
|
81 |
public void closePreviewLayer() { |
82 |
previewLayer.closePreviewLayer(); |
83 |
} |
84 |
|
85 |
public void drawImage(Graphics2D g, double x1, double y1, double x2, double y2, double zoom, int width, int height) |
86 |
throws ImageUnavailableException {
|
87 |
if (previewLayer == null) |
88 |
throw new ImageUnavailableException(Messages.getText("error_dont_exists_layer")); |
89 |
|
90 |
previewLayer.pushStatus(); |
91 |
try {
|
92 |
if(renderProcess != null) |
93 |
renderProcess.process(previewLayer); |
94 |
} catch (ImageUnavailableException e2) {
|
95 |
throw new ImageUnavailableException(Messages.getText("error_adding_filters")); |
96 |
} catch (Exception e2) { |
97 |
logger.debug("error_adding_filters", this, e2); |
98 |
throw new ImageUnavailableException(Messages.getText("error_adding_filters")); |
99 |
} |
100 |
|
101 |
try {
|
102 |
double[] coords = new double[]{x1, y1, x2, y2}; |
103 |
previewLayer.draw(null, g, coords, width, height, null, 1.0); |
104 |
} catch (ImageUnavailableException e) {
|
105 |
logger.debug("error_preview_render", this, e); |
106 |
throw new ImageUnavailableException(Messages.getText("error_preview_render")); |
107 |
} catch (Exception e2) { |
108 |
logger.debug("error_preview_render", this, e2); |
109 |
throw new ImageUnavailableException(Messages.getText("error_preview_render")); |
110 |
} |
111 |
previewLayer.popStatus(); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* Shows a error dialog with a text and a accept button
|
116 |
* @param msg Message to show in the dialog
|
117 |
* @param parentWindow Parent window
|
118 |
*/
|
119 |
public void messageBoxError(String msg, Object parentWindow, Exception exception) { |
120 |
logger.debug(msg, parentWindow, exception); |
121 |
String string = Messages.getText("accept"); |
122 |
Object[] options = {string}; |
123 |
JOptionPane.showOptionDialog((Component)parentWindow, |
124 |
"<html>" + Messages.getText(msg).replaceAll("\n", "<br>") + "</html>", |
125 |
Messages.getText("confirmacion"),
|
126 |
JOptionPane.OK_OPTION,
|
127 |
JOptionPane.ERROR_MESSAGE,
|
128 |
null,
|
129 |
options, |
130 |
string); |
131 |
} |
132 |
} |