Statistics
| Revision:

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

History | View | Annotate | Download (8.53 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.ViewControl;
28
import org.gvsig.rastertools.georeferencing.ui.zoom.layers.GCPsGraphicLayer;
29
import org.gvsig.rastertools.georeferencing.ui.zoom.layers.GPGraphic;
30
import org.gvsig.rastertools.georeferencing.ui.zoom.layers.ZoomCursorGraphicLayer;
31
import org.gvsig.rastertools.georeferencing.ui.zoom.tools.ToolListener;
32

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

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

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