Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / georeferencing / Georeferencing.java @ 17727

History | View | Annotate | Download (3.97 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;
20

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

    
25
import org.gvsig.rastertools.georeferencing.ui.table.GCPTablePanel;
26
import org.gvsig.rastertools.georeferencing.ui.zoom.ControlsPanel;
27
import org.gvsig.rastertools.georeferencing.view.ViewPanel;
28

    
29
import com.iver.andami.PluginServices;
30
import com.iver.andami.ui.mdiFrame.MDIFrame;
31
import com.iver.andami.ui.mdiManager.IWindow;
32
import com.iver.andami.ui.mdiManager.WindowInfo;
33
import com.iver.cit.gvsig.fmap.ViewPort;
34
import com.iver.cit.gvsig.project.documents.view.gui.IView;
35

    
36
/**
37
 * Clase principal para la georreferenciaci?n. Se encarga de la inicializaci?n
38
 * de la funcionalidad. Las acciones a realizar son:
39
 * <UL>
40
 * <LI>Creaci?n de las ventanas si no han sido creadas previamente</LI>
41
 * </UL>
42
 * 26/12/2007
43
 * @author Nacho Brodin nachobrodin@gmail.com
44
 */
45
public class Georeferencing {
46
        private static GCPTablePanel          table = null;
47
        private static ControlsPanel          zooms = null;
48
        private static ViewPanel              view = null;
49
        private static final int              smallWindowsHeight = 100;
50
        private static final double           smallWindowsWidthPercent = 0.5;
51
        
52
        public Georeferencing() {
53
                
54
        }
55
        
56
        public void initialize() {
57
                MDIFrame p = (MDIFrame)PluginServices.getMainFrame();
58
                IWindow[] windowList = PluginServices.getMDIManager().getAllWindows();
59
                BufferedImage img = null;
60
                ViewPort vp = null;
61
                for (int i = 0; i < windowList.length; i++) {
62
                        if(windowList[i] instanceof IView) {
63
                                WindowInfo info = windowList[i].getWindowInfo();
64
                                info.setX(0);
65
                                info.setY(0);
66
                                info.setWidth(p.getWidth() / 2);
67
                                info.setHeight(p.getHeight() - 138 - smallWindowsHeight);
68
                                
69
                                img = ((IView)windowList[i]).getMapControl().getImage();
70
                                vp = ((IView)windowList[i]).getMapControl().getViewPort();
71
                        }
72
                }
73
                int w = p.getWidth() >> 1;
74
                if(zooms != null)
75
                        PluginServices.getMDIManager().closeWindow(zooms);
76
                if(view != null)
77
                        PluginServices.getMDIManager().closeWindow(view);
78
                if(table != null)
79
                        PluginServices.getMDIManager().closeWindow(table);
80
                
81
                zooms = new ControlsPanel(0, p.getHeight() - 138 - smallWindowsHeight, (int)(p.getWidth() * smallWindowsWidthPercent), smallWindowsHeight);
82
                table = new GCPTablePanel((int)(p.getWidth() * smallWindowsWidthPercent), p.getHeight() - 138 - smallWindowsHeight, (int)(p.getWidth() * (1 - smallWindowsWidthPercent)), smallWindowsHeight);
83
                view = new ViewPanel(w, 0, w, p.getHeight() - 178 - smallWindowsHeight);
84
                
85
                setMapParams(img, vp);
86
                
87
                PluginServices.getMDIManager().addWindow(view);
88
                PluginServices.getMDIManager().addWindow(table);
89
                PluginServices.getMDIManager().addWindow(zooms);
90
        }
91
        
92
        /**
93
         * Obtiene y asigna los par?metros para el control de zoom del mapa
94
         * @param img BufferedImage
95
         * @param vp ViewPort
96
         */
97
        public void setMapParams(BufferedImage img, ViewPort vp) {
98
                if(zooms != null && img != null && vp != null) {
99
                        Rectangle2D r = vp.getAdjustedExtent();
100
                        int w = vp.getImageWidth();
101
                        zooms.setMapDrawParams(img, r, r.getWidth() / w, new Point2D.Double(r.getCenterX(), r.getCenterY()));
102
                        zooms.getMapGraphicLayer();
103
                }
104
        }
105
}