Statistics
| Revision:

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

History | View | Annotate | Download (4.87 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

    
56
import com.iver.cit.gvsig.fmap.ColorEvent;
57
import com.iver.cit.gvsig.fmap.ExtentEvent;
58
import com.iver.cit.gvsig.fmap.FMap;
59
import com.iver.cit.gvsig.fmap.MapControl;
60
import com.iver.cit.gvsig.fmap.ViewPort;
61
import com.iver.cit.gvsig.fmap.ViewPortListener;
62
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
63
import com.iver.cit.gvsig.gui.toolListeners.MapOverviewListener;
64
import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener;
65

    
66

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

    
77
        /**
78
         * Crea un nuevo MapOverview.
79
         *
80
         * @param mapAssoc DOCUMENT ME!
81
         */
82
        public MapOverview(MapControl mapAssoc) {
83
                super();
84
                // super.vp.setBackColor(new Color(230,230,230));
85
                m_MapAssoc = mapAssoc;
86

    
87
                // setModel((FMap) m_MapAssoc.getMapContext().clone()); // Lo inicializamos con
88
                // los mismos temas que tenga el grande.
89

    
90
                MapOverviewListener movl = new MapOverviewListener(this);
91
                addMapTool("zoomtopoint", new PointBehavior(movl));
92
                setCursor(movl.getCursor());
93

    
94
                setTool("zoomtopoint");
95
        }
96

    
97
        /**
98
         * DOCUMENT ME!
99
         *
100
         * @return DOCUMENT ME!
101
         */
102
        public FMap getAssociatedMapContext() {
103
                return m_MapAssoc.getMapContext();
104
        }
105

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

    
115
        /* (non-Javadoc)
116
         * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
117
         */
118
        protected void paintComponent(Graphics g) {
119
                super.paintComponent(g);
120

    
121
                if ((m_MapAssoc.getMapContext().getViewPort().getExtent() != null) &&
122
                                (getMapContext().getViewPort().getExtent() != null)) {
123
                        ViewPort vp = getMapContext().getViewPort();
124
                        ViewPort vpOrig = m_MapAssoc.getMapContext().getViewPort();
125
                        Graphics2D g2 = (Graphics2D) g;
126
                        g2.setColor(Color.black);
127
                        g2.setXORMode(Color.white);
128

    
129
                        // Dibujamos el extent del mapa asociado.
130
                        g2.setTransform(vp.getAffineTransform());
131
                        g2.fill(vpOrig.getExtent());
132

    
133
                        // dibujamos las l?neas vertical y horizontal
134
                        Point2D pRightUp = vp.toMapPoint(getWidth(), 0);
135
                        Line2D.Double linVert = new Line2D.Double(vpOrig.getExtent()
136
                                                                                                                        .getCenterX(),
137
                                        vp.getExtent().getMinY(), vpOrig.getExtent().getCenterX(),
138
                                        pRightUp.getY());
139
                        Line2D.Double linHoriz = new Line2D.Double(vp.getExtent().getMinX(),
140
                                        vpOrig.getExtent().getCenterY(), pRightUp.getX(),
141
                                        vpOrig.getExtent().getCenterY());
142

    
143
                        g2.draw(linVert);
144
                        g2.draw(linHoriz);
145

    
146
                        g2.setTransform(new AffineTransform());
147

    
148
                        // System.out.println("Dibujo el extent " + m_MapAssoc.getExtent().toString());
149
                }
150
        }
151

    
152
        /**
153
         * DOCUMENT ME!
154
         *
155
         * @param model DOCUMENT ME!
156
         */
157
        public void setModel(FMap model) {
158
                this.setMapContext(model);
159
                m_MapAssoc.getMapContext().getViewPort().addViewPortListener(this);
160
                getMapContext().getViewPort().addViewPortListener(this);
161
        }
162

    
163
        /**
164
         * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
165
         */
166
        public void backColorChanged(ColorEvent e) {
167
        }
168
}