Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / georeferencing / view / ViewDialog.java @ 18321

History | View | Annotate | Download (8.71 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.rastertools.georeferencing.view;
20

    
21
import java.awt.BorderLayout;
22
import java.awt.geom.Point2D;
23
import java.awt.geom.Rectangle2D;
24
import java.awt.image.BufferedImage;
25

    
26
import org.gvsig.rastertools.georeferencing.ui.zoom.IExtensionRequest;
27
import org.gvsig.rastertools.georeferencing.ui.zoom.IGraphicLayer;
28
import org.gvsig.rastertools.georeferencing.ui.zoom.ViewControl;
29
import org.gvsig.rastertools.georeferencing.ui.zoom.layers.ZoomCursorGraphicLayer;
30
import org.gvsig.rastertools.georeferencing.ui.zoom.tools.ToolListener;
31

    
32
import com.iver.andami.PluginServices;
33
import com.iver.andami.ui.mdiManager.IWindow;
34
import com.iver.andami.ui.mdiManager.WindowInfo;
35

    
36
/**
37
 * Panel que contiene el panel con la vista a georreferenciar
38
 * 
39
 * 22/12/2007
40
 * @author Nacho Brodin (nachobrodin@gmail.com)
41
 */
42
public class ViewDialog extends BaseZoomView implements IWindow {
43
        private static final long         serialVersionUID = 1L;
44
        private ZoomCursorGraphicLayer    zoomCursorGraphic = null;
45
        private ToolListener              zoomCursorGraphicListener = null;
46
        private int                       w = 640;
47
        private int                       h = 100;
48
        private int                       posX = 0;
49
        private int                       posY = 0;
50
        
51
        /**
52
         * Constructor.
53
         * Crea la composici?n de controles de zoom.
54
         * @param posX Posici?n en X
55
         * @param posY Posici?n en Y
56
         * @param w Tama?o en pixeles de ancho
57
         * @param h Tama?o en pixeles de alto
58
         */
59
        public ViewDialog(int posX, int posY, int w, int h, ToolListener zoomCursorGraphicListener) {
60
                setPosition(posX, posY);
61
                setWindowsSize(w, h);
62
                this.zoomCursorGraphicListener = zoomCursorGraphicListener;
63
                init();
64
        }
65
        
66
        /**
67
         * Asigna la posici?n de la ventana
68
         * @param posX Posici?n en X
69
         * @param posY Posici?n en Y
70
         */
71
        public void setPosition(int posX, int posY) {
72
                this.posX = posX;
73
                this.posY = posY;
74
        }
75
        
76
        /**
77
         * Asigna el tama?o de la ventana
78
         * @param w Tama?o en pixeles de ancho
79
         * @param h Tama?o en pixeles de alto
80
         */
81
        public void setWindowsSize(int w, int h) {
82
                this.w = w;
83
                this.h = h;
84
        }
85
        
86
        /**
87
         * Asigna el valor para el flag minxMaxyUL. Este flag informa de que la esquina 
88
         * superior izquierda corresponde con el valor de m?nimo X y m?ximo Y. En caso 
89
         * de ser false esta esquina ser?a de m?nimo X y m?nimo Y.
90
         * @param v
91
         */
92
        public void setMinxMaxyUL(boolean v) {
93
                getCanvas().setMinxMaxyUL(v);
94
        }
95
        
96
        /**
97
         * Inicializaci?n de los componentes gr?ficos
98
         */
99
        private void init() {
100
                setLayout(new BorderLayout());
101
                add(getControl(), BorderLayout.CENTER);
102
                getZoomCursorGraphicLayer();
103
        }
104
        
105
        /**
106
         * Asigna los par?metros de dibujado para el raster
107
         * @param img Buffer con un ?rea de datos
108
         * @param ext Rectangle2D del ?rea de datos dada 
109
         * @param pixelSize Tama?o de pixel
110
         * @param center Punto del ?rea de datos donde se quiere centrar el dibujado del buffer
111
         */
112
        public void setDrawParams(BufferedImage img, Rectangle2D ext, double pixelSize, Point2D center) {
113
                getControl().setDrawParams(img, ext, pixelSize, center) ;
114
        }
115
        
116
        /**
117
         * Obtiene el panel de control de zoom de coordenadas pixel
118
         * @return
119
         */
120
        public ViewControl getControl() {
121
                if(zoomPixelControl == null)
122
                        zoomPixelControl = new ViewControl(ViewControl.RIGHT_CONTROL);
123
                return zoomPixelControl;
124
        }
125
        
126
        /**
127
         * Registra un objeto IExtensionRequest para que no se aplique un escalado sobre
128
         * el buffer pasado por par?metro. Alternativamente a la aplicaci?n de este escalado
129
         * se ejecutar? el m?todo request del interfaz para que el cliente pueda pasar un 
130
         * nuevo buffer con escala 1:1 y con la extensi?n correspondiente al zoom.
131
         * @param er
132
         */
133
        public void setExtensionRequest(IExtensionRequest er) {
134
                zoomPixelControl.setExtensionRequest(er);
135
        }
136
        
137
        /*
138
         * (non-Javadoc)
139
         * @see org.gvsig.rastertools.georeferencing.view.BaseZoomView#addGraphicLayer(org.gvsig.rastertools.georeferencing.ui.zoom.IGraphicLayer)
140
         */
141
        public void addGraphicLayer(IGraphicLayer graphicLayer) {
142
                getControl().setGraphicLayer(graphicLayer);
143
        }
144
                
145
        /**
146
         * Obtiene el la capa gr?fica con la ventana de zoom
147
         * @return
148
         */
149
        public ZoomCursorGraphicLayer getZoomCursorGraphicLayer() {
150
                if(zoomCursorGraphic == null) {
151
                        zoomCursorGraphic = new ZoomCursorGraphicLayer(w / 2, h / 2, 20, 10, zoomCursorGraphicListener);
152
                        zoomCursorGraphic.setCanvas(getControl().getCanvas());
153
                        getControl().setGraphicLayer(zoomCursorGraphic);
154
                }
155
                return zoomCursorGraphic;
156
        }
157
                
158
        /**
159
         * Activa o desactiva el mostrado de informaci?n
160
         * @param showInfo
161
         */
162
        public void setShowInfo(boolean show) {
163
                zoomPixelControl.getCanvas().setShowInfo(show);
164
        }
165
        
166
        /**
167
         * Asigna el ancho y el alto de la ventana del cursor
168
         * @param w Ancho
169
         * @param h Alto
170
         */
171
        public void setZoomCursorSize(int w, int h) {
172
                getZoomCursorGraphicLayer().setCursorSize(w, h);
173
        }
174
        
175
        /**
176
         * Obtiene las coordenadas de la ventana de zoom. Las coordenadas son devueltas
177
         * en referencia a las coordenadas del mundo. 
178
         * @return
179
         */
180
        public Rectangle2D getCursorWorldCoordinates() {
181
                Rectangle2D r = getZoomCursorGraphicLayer().getCursorViewCoordinates();
182
                Point2D p1 = zoomPixelControl.getCanvas().viewCoordsToWorld(new Point2D.Double(r.getX(), r.getY()));
183
                Point2D p2 = zoomPixelControl.getCanvas().viewCoordsToWorld(new Point2D.Double(r.getX() + r.getWidth(), r.getY() + r.getHeight()));
184
                return new Rectangle2D.Double(        Math.min(p1.getX(), p2.getX()), 
185
                                                                                Math.max(p1.getY(), p2.getY()), 
186
                                                                                Math.abs(p2.getX() - p1.getX()), 
187
                                                                                Math.abs(p2.getY() - p1.getY()));
188
        }
189
        
190
        /**
191
         * Obtiene las coordenadas de la ventana de zoom. Las coordenadas son devueltas
192
         * en referencia a las coordenadas del mundo. Esta llamada ajusta el tama?o de la ventana a la 
193
         * proporci?n pasada por par?metro. Es decir, si pasamos una proporci?n en la que el ancho es 3 veces 
194
         * mayor que el alto se ajustar? el zoom a esta proporci?n ya que presupone que la ventana de
195
         * destino del zoom va a tener esas proporciones.
196
         * @return
197
         */
198
        public Rectangle2D getCursorAdjustedWorldCoordinates(int wWindow, int hWindow) {
199
                Rectangle2D r = getZoomCursorGraphicLayer().getCursorViewCoordinates();
200

    
201
                double x = r.getX(), y = r.getY(), w = r.getWidth(), h = r.getHeight();
202
                if(wWindow < hWindow) { //Si la de destino es m?s alta que ancha
203
                        if((r.getWidth() / r.getHeight()) >= (wWindow / hWindow)) {
204
                                h = (hWindow * r.getWidth()) / wWindow;
205
                                y = r.getCenterY() - (h / 2);
206
                        } else {
207
                                w = (wWindow * r.getHeight()) / hWindow;
208
                                x = r.getCenterX() - (w / 2);
209
                        }
210
                } else { //Si la de destino es m?s ancha que alta
211
                        if((r.getWidth() / r.getHeight()) <= (wWindow / hWindow)) {
212
                                w = (wWindow * r.getHeight()) / hWindow;
213
                                x = r.getCenterX() - (w / 2);
214
                        } else {
215
                                h = (hWindow * r.getWidth()) / wWindow;
216
                                y = r.getCenterY() - (h / 2);
217
                        }
218
                }
219
                r = new Rectangle2D.Double(x, y + h, w, h);
220
                Point2D p1 = zoomPixelControl.getCanvas().viewCoordsToWorld(new Point2D.Double(r.getX(), r.getY()));
221
                Point2D p2 = zoomPixelControl.getCanvas().viewCoordsToWorld(new Point2D.Double(r.getX() + r.getWidth(), r.getY() + r.getHeight()));
222
                return new Rectangle2D.Double(        Math.min(p1.getX(), p2.getX()), 
223
                                                                                Math.max(p1.getY(), p2.getY()), 
224
                                                                                Math.abs(p2.getX() - p1.getX()), 
225
                                                                                Math.abs(p2.getY() - p1.getY()));
226
        }
227
        
228
        /**
229
         * Obtiene el extent del canvas en coordenadas del mundo real
230
         * @return Rectangle2D
231
         */
232
        public Rectangle2D getViewExtent() {
233
                return zoomPixelControl.getCanvas().getExtent();
234
        }
235
        
236
        /*
237
         * (non-Javadoc)
238
         * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
239
         */
240
        public WindowInfo getWindowInfo() {
241
                WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE);
242
                //if (getClippingPanel().getFLayer() != null)
243
                        //m_viewinfo.setAdditionalInfo(getClippingPanel().getFLayer().getName());
244
                m_viewinfo.setTitle(PluginServices.getText(this, "view_panel"));
245
                m_viewinfo.setX(posX);
246
                m_viewinfo.setY(posY);
247
                m_viewinfo.setHeight(h);
248
                m_viewinfo.setWidth(w);
249
                return m_viewinfo;
250
        }
251
}
252