Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / MapOverview.java @ 6326

History | View | Annotate | Download (7.11 KB)

1
/*
2
 * Created on 21-jun-2004
3
 *
4
 * TODO To change the template for this generated file go to
5
 * Window - Preferences - Java - Code Generation - Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package com.iver.cit.gvsig.gui;
48

    
49
import java.awt.Color;
50
import java.awt.Graphics;
51
import java.awt.Graphics2D;
52
import java.awt.geom.AffineTransform;
53
import java.awt.geom.Line2D;
54
import java.awt.geom.Point2D;
55
import java.awt.geom.Rectangle2D;
56
import java.awt.image.BufferedImage;
57

    
58
import org.cresques.cts.IProjection;
59

    
60
import com.iver.cit.gvsig.fmap.ColorEvent;
61
import com.iver.cit.gvsig.fmap.DriverException;
62
import com.iver.cit.gvsig.fmap.ExtentEvent;
63
import com.iver.cit.gvsig.fmap.FMap;
64
import com.iver.cit.gvsig.fmap.MapControl;
65
import com.iver.cit.gvsig.fmap.ProjectionEvent;
66
import com.iver.cit.gvsig.fmap.ViewPort;
67
import com.iver.cit.gvsig.fmap.ViewPortListener;
68
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
69
import com.iver.cit.gvsig.fmap.tools.Behavior.DraggerBehavior;
70
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
71
import com.iver.cit.gvsig.fmap.tools.Behavior.MoveBehavior;
72
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
73
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleBehavior;
74
import com.iver.cit.gvsig.gui.toolListeners.MapOverviewChangeZoomListener;
75
import com.iver.cit.gvsig.gui.toolListeners.MapOverviewListener;
76
import com.iver.cit.gvsig.gui.toolListeners.MapOverviewPanListener;
77

    
78

    
79
/**
80
 * DOCUMENT ME!
81
 *
82
 * @author FJP TODO To change the template for this generated type comment go
83
 *                    to Window - Preferences - Java - Code Generation - Code and
84
 *                    Comments
85
 */
86
public class MapOverview extends MapControl implements ViewPortListener {
87
        private MapControl m_MapAssoc;
88
        boolean first = true;
89
        private MapOverviewListener movl;
90
        private MapOverviewPanListener movpl;
91
        private MapOverviewChangeZoomListener movczl;
92
        private Rectangle2D extent;
93
        private BufferedImage image;
94

    
95
        /**
96
         * Crea un nuevo MapOverview.
97
         *
98
         * @param mapAssoc DOCUMENT ME!
99
         */
100
        public MapOverview(MapControl mapAssoc) {
101
                super();
102
                this.setName("MapOverview");
103
                // super.vp.setBackColor(new Color(230,230,230));
104
                m_MapAssoc = mapAssoc;
105

    
106
                // setModel((FMap) m_MapAssoc.getMapContext().clone()); // Lo inicializamos con
107
                // los mismos temas que tenga el grande.
108
                movl = new MapOverviewListener(this);
109
                movpl = new MapOverviewPanListener(this);
110
                movczl = new MapOverviewChangeZoomListener(this);
111
                addMapTool(
112
                                "zoomtopoint",
113
                                new Behavior[]{
114
                                                new PointBehavior(movl),
115
                                                new RectangleBehavior(movczl),
116
                                                new DraggerBehavior(movczl),
117
                                                new DraggerBehavior(movpl)
118
                                }
119
                );
120

    
121
                setCursor(movl.getCursor());
122

    
123
                setTool("zoomtopoint");
124
        }
125

    
126
        /**
127
         * DOCUMENT ME!
128
         *
129
         * @return DOCUMENT ME!
130
         */
131
        public FMap getAssociatedMapContext() {
132
                return m_MapAssoc.getMapContext();
133
        }
134
        public MapControl getAssociatedMapControl(){
135
                return m_MapAssoc;
136
        }
137

    
138
        /* (non-Javadoc)
139
         * @see com.iver.cit.opensig.gui.IMapExtentListener#extentChanged(java.awt.geom.Rectangle2D)
140
         */
141
        public void extentChanged(ExtentEvent evExtent) {
142
                // Nos llega el nuevo extent del FMap asociado, as? que dibujamos nuestro
143
                // rect?ngulo para mostrar la zona de dibujo del otro mapa.
144
                repaint();
145
        }
146

    
147
        /**
148
         * Recalcula el extent a aplicar de las capas que estan a?adidas.
149
         */
150
        public void refreshExtent() {
151
                try {
152
                if (this.getMapContext().getFullExtent()!=null){
153
                                this.getMapContext().getViewPort().setExtent(this.getMapContext().getFullExtent());
154
                }else{
155
                        delModel();
156
                }
157
                } catch (DriverException e1) {
158
                        e1.printStackTrace();
159
                }
160
        }
161
        public void refreshOverView(Rectangle2D r){
162
                extent=r;
163
                repaint();
164
        }
165

    
166
        protected void paintComponent(Graphics g) {
167
                super.paintComponent(g);
168
                        if ((m_MapAssoc.getMapContext().getViewPort().getExtent() != null) &&
169
                                        (getMapContext().getViewPort().getExtent() != null)) {
170
                                if (first) {
171
                                        first = false;
172
                                        repaint();
173
                                        return;
174
                                }
175
                                image = new BufferedImage(this.getWidth(), this.getHeight(),
176
                                    BufferedImage.TYPE_INT_ARGB);
177
                                ViewPort vp = getMapContext().getViewPort();
178
                                Rectangle2D extentView=vp.getAdjustedExtent();
179
                                ViewPort vpOrig = m_MapAssoc.getMapContext().getViewPort();
180
                                if (extent==null)
181
                                        extent=vpOrig.getAdjustedExtent();
182
                                // Dibujamos el extent del mapa asociado.
183
                                Graphics2D g2 = (Graphics2D) image.getGraphics();
184
                                g2.setTransform(vp.getAffineTransform());
185
                                g2.setColor(Color.red);
186
                                g2.draw(extent);
187
                                g2.setColor(new Color(100,100,100,100));
188
                                g2.fill(extent);
189
                                // dibujamos las l?neas vertical y horizontal
190
                                Point2D pRightUp = vp.toMapPoint(getWidth(), 0);
191

    
192
                                Line2D.Double linVert = new Line2D.Double(extent.getCenterX(),
193
                                                extentView.getMinY(), extent.getCenterX(),
194
                                                pRightUp.getY());
195
                                Line2D.Double linHoriz = new Line2D.Double(extentView.getMinX(),
196
                                                extent.getCenterY(), pRightUp.getX(),
197
                                                extent.getCenterY());
198

    
199
                                g2.setColor(Color.darkGray);
200
                                g2.draw(linVert);
201
                                g2.draw(linHoriz);
202
                                g.drawImage(image,0,0,this);
203
                                g2.setTransform(new AffineTransform());
204
                                extent=null;
205
                        }
206

    
207
        }
208

    
209
        /**
210
         * DOCUMENT ME!
211
         *
212
         * @param model DOCUMENT ME!
213
         */
214
        public void setModel(FMap model) {
215
                this.setMapContext(model);
216
                model.setProjection(m_MapAssoc.getMapContext().getProjection());
217
                m_MapAssoc.getMapContext().getViewPort().addViewPortListener(this);
218
                getMapContext().getViewPort().addViewPortListener(this);
219
        }
220
        private void delModel(){
221
                this.getMapContext().getViewPort().setExtent(null);
222
                m_MapAssoc.getMapContext().getViewPort().removeViewPortListener(this);
223
                getMapContext().getViewPort().removeViewPortListener(this);
224
        }
225

    
226
        /**
227
         * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
228
         */
229
        public void backColorChanged(ColorEvent e) {
230
        }
231

    
232
        public void projectionChanged(ProjectionEvent e) {
233
                super.setProjection(e.getNewProjection());
234

    
235
        }
236

    
237
        public void setProjection(IProjection proj) {
238
                //No permitimos cambiar la proyeccion
239
                //ya que debe ser la misma que la del
240
                //MapControl asociado
241
                return;
242
        }
243
}