Statistics
| Revision:

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

History | View | Annotate | Download (5.69 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 com.iver.cit.gvsig.fmap.ColorEvent;
50
import com.iver.cit.gvsig.fmap.DriverException;
51
import com.iver.cit.gvsig.fmap.ExtentEvent;
52
import com.iver.cit.gvsig.fmap.FMap;
53
import com.iver.cit.gvsig.fmap.MapControl;
54
import com.iver.cit.gvsig.fmap.ViewPort;
55
import com.iver.cit.gvsig.fmap.ViewPortListener;
56
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
57
import com.iver.cit.gvsig.gui.toolListeners.MapOverviewListener;
58
import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener;
59

    
60
import java.awt.Color;
61
import java.awt.Cursor;
62
import java.awt.Graphics;
63
import java.awt.Graphics2D;
64
import java.awt.geom.AffineTransform;
65
import java.awt.geom.Line2D;
66
import java.awt.geom.Point2D;
67
import java.awt.geom.Rectangle2D;
68

    
69

    
70
/**
71
 * DOCUMENT ME!
72
 *
73
 * @author FJP TODO To change the template for this generated type comment go
74
 *                    to Window - Preferences - Java - Code Generation - Code and
75
 *                    Comments
76
 */
77
public class MapOverview extends MapControl implements ViewPortListener {
78
        private MapControl m_MapAssoc;
79
        boolean first = true;
80

    
81
        /**
82
         * Crea un nuevo MapOverview.
83
         *
84
         * @param mapAssoc DOCUMENT ME!
85
         */
86
        public MapOverview(MapControl mapAssoc) {
87
                super();
88

    
89
                // super.vp.setBackColor(new Color(230,230,230));
90
                m_MapAssoc = mapAssoc;
91

    
92
                // setModel((FMap) m_MapAssoc.getMapContext().clone()); // Lo inicializamos con
93
                // los mismos temas que tenga el grande.
94
                MapOverviewListener movl = new MapOverviewListener(this);
95
                addMapTool("zoomtopoint", new PointBehavior(movl));
96
                setCursor(movl.getCursor());
97

    
98
                setTool("zoomtopoint");
99
        }
100

    
101
        /**
102
         * DOCUMENT ME!
103
         *
104
         * @return DOCUMENT ME!
105
         */
106
        public FMap getAssociatedMapContext() {
107
                return m_MapAssoc.getMapContext();
108
        }
109

    
110
        /* (non-Javadoc)
111
         * @see com.iver.cit.opensig.gui.IMapExtentListener#extentChanged(java.awt.geom.Rectangle2D)
112
         */
113
        public void extentChanged(ExtentEvent evExtent) {
114
                // Nos llega el nuevo extent del FMap asociado, as? que dibujamos nuestro 
115
                // rect?ngulo para mostrar la zona de dibujo del otro mapa.
116
                repaint();
117
        }
118

    
119
        /**
120
         * Recalcula el extent a aplicar de las capas que estan a?adidas.
121
         */
122
        public void refreshExtent() {
123
                try {
124
                if (this.getMapContext().getFullExtent()!=null){
125
                                this.getMapContext().getViewPort().setExtent(this.getMapContext().getFullExtent());
126
                }else{
127
                        delModel();
128
                }
129
                } catch (DriverException e1) {
130
                        e1.printStackTrace();
131
                }
132
        }
133

    
134
        /* (non-Javadoc)
135
         * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
136
         */
137
        protected void paintComponent(Graphics g) {
138
                super.paintComponent(g);
139
                        if ((m_MapAssoc.getMapContext().getViewPort().getExtent() != null) &&
140
                                        (getMapContext().getViewPort().getExtent() != null)) {
141
                                if (first) {
142
                                        first = false;
143
                                        repaint();
144

    
145
                                        return;
146
                                } else {
147
                                        first = true;
148
                                }
149

    
150
                                ViewPort vp = getMapContext().getViewPort();
151
                                ViewPort vpOrig = m_MapAssoc.getMapContext().getViewPort();
152
                                Graphics2D g2 = (Graphics2D) g;
153
                                g2.setColor(Color.black);
154
                                g2.setXORMode(Color.white);
155

    
156
                                // Dibujamos el extent del mapa asociado.
157
                                g2.setTransform(vp.getAffineTransform());
158

    
159
                                g2.fill(vpOrig.getAdjustedExtent());
160
                                // dibujamos las l?neas vertical y horizontal
161
                                Point2D pRightUp = vp.toMapPoint(getWidth(), 0);
162
                                Line2D.Double linVert = new Line2D.Double(vpOrig.getExtent()
163
                                                                                                                                .getCenterX(),
164
                                                vp.getExtent().getMinY(), vpOrig.getExtent().getCenterX(),
165
                                                pRightUp.getY());
166
                                Line2D.Double linHoriz = new Line2D.Double(vp.getExtent().getMinX(),
167
                                                vpOrig.getExtent().getCenterY(), pRightUp.getX(),
168
                                                vpOrig.getExtent().getCenterY());
169

    
170
                                g2.draw(linVert);
171
                                g2.draw(linHoriz);
172

    
173
                                g2.setTransform(new AffineTransform());
174

    
175
                                // System.out.println("Dibujo el extent " + m_MapAssoc.getExtent().toString());
176
                        }
177
                
178
        }
179

    
180
        /**
181
         * DOCUMENT ME!
182
         *
183
         * @param model DOCUMENT ME!
184
         */
185
        public void setModel(FMap model) {
186
                this.setMapContext(model);
187
                m_MapAssoc.getMapContext().getViewPort().addViewPortListener(this);
188
                getMapContext().getViewPort().addViewPortListener(this);
189
        }
190
        private void delModel(){
191
                this.getMapContext().getViewPort().setExtent(null);
192
                m_MapAssoc.getMapContext().getViewPort().removeViewPortListener(this);
193
                getMapContext().getViewPort().removeViewPortListener(this);
194
        }
195

    
196
        /**
197
         * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
198
         */
199
        public void backColorChanged(ColorEvent e) {
200
        }
201
}