Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / MapOverview.java @ 5653

History | View | Annotate | Download (6.67 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 com.iver.cit.gvsig.fmap.ColorEvent;
59
import com.iver.cit.gvsig.fmap.DriverException;
60
import com.iver.cit.gvsig.fmap.ExtentEvent;
61
import com.iver.cit.gvsig.fmap.FMap;
62
import com.iver.cit.gvsig.fmap.MapControl;
63
import com.iver.cit.gvsig.fmap.ViewPort;
64
import com.iver.cit.gvsig.fmap.ViewPortListener;
65
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
66
import com.iver.cit.gvsig.fmap.tools.Behavior.DraggerBehavior;
67
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
68
import com.iver.cit.gvsig.fmap.tools.Behavior.MoveBehavior;
69
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
70
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleBehavior;
71
import com.iver.cit.gvsig.gui.toolListeners.MapOverviewChangeZoomListener;
72
import com.iver.cit.gvsig.gui.toolListeners.MapOverviewListener;
73
import com.iver.cit.gvsig.gui.toolListeners.MapOverviewPanListener;
74

    
75

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

    
92
        /**
93
         * Crea un nuevo MapOverview.
94
         *
95
         * @param mapAssoc DOCUMENT ME!
96
         */
97
        public MapOverview(MapControl mapAssoc) {
98
                super();
99

    
100
                // super.vp.setBackColor(new Color(230,230,230));
101
                m_MapAssoc = mapAssoc;
102

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

    
120
                setTool("zoomtopoint");
121
        }
122

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

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

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

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

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

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

    
204
        }
205

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

    
222
        /**
223
         * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
224
         */
225
        public void backColorChanged(ColorEvent e) {
226
        }
227
}