root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / MapOverview.java @ 7771
History | View | Annotate | Download (7.08 KB)
1 | 7304 | caballero | /*
|
---|---|---|---|
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.project.documents.view; |
||
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.MapContext; |
||
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.PointBehavior; |
||
71 | import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleBehavior; |
||
72 | 7771 | caballero | import com.iver.cit.gvsig.project.documents.view.toolListeners.MapOverviewChangeZoomListener; |
73 | import com.iver.cit.gvsig.project.documents.view.toolListeners.MapOverviewListener; |
||
74 | import com.iver.cit.gvsig.project.documents.view.toolListeners.MapOverviewPanListener; |
||
75 | 7304 | caballero | |
76 | |||
77 | /**
|
||
78 | * DOCUMENT ME!
|
||
79 | *
|
||
80 | * @author FJP TODO To change the template for this generated type comment go
|
||
81 | * to Window - Preferences - Java - Code Generation - Code and
|
||
82 | * Comments
|
||
83 | */
|
||
84 | public class MapOverview extends MapControl implements ViewPortListener { |
||
85 | private MapControl m_MapAssoc;
|
||
86 | boolean first = true; |
||
87 | private MapOverviewListener movl;
|
||
88 | private MapOverviewPanListener movpl;
|
||
89 | private MapOverviewChangeZoomListener movczl;
|
||
90 | private Rectangle2D extent; |
||
91 | private BufferedImage image; |
||
92 | |||
93 | /**
|
||
94 | * Crea un nuevo MapOverview.
|
||
95 | *
|
||
96 | * @param mapAssoc DOCUMENT ME!
|
||
97 | */
|
||
98 | public MapOverview(MapControl mapAssoc) {
|
||
99 | super();
|
||
100 | this.setName("MapOverview"); |
||
101 | // super.vp.setBackColor(new Color(230,230,230));
|
||
102 | m_MapAssoc = mapAssoc; |
||
103 | |||
104 | // setModel((FMap) m_MapAssoc.getMapContext().clone()); // Lo inicializamos con
|
||
105 | // los mismos temas que tenga el grande.
|
||
106 | movl = new MapOverviewListener(this); |
||
107 | movpl = new MapOverviewPanListener(this); |
||
108 | movczl = new MapOverviewChangeZoomListener(this); |
||
109 | addMapTool( |
||
110 | "zoomtopoint",
|
||
111 | new Behavior[]{ |
||
112 | new PointBehavior(movl),
|
||
113 | new RectangleBehavior(movczl),
|
||
114 | new DraggerBehavior(movczl),
|
||
115 | new DraggerBehavior(movpl)
|
||
116 | } |
||
117 | ); |
||
118 | |||
119 | setCursor(movl.getCursor()); |
||
120 | |||
121 | setTool("zoomtopoint");
|
||
122 | } |
||
123 | |||
124 | /**
|
||
125 | * DOCUMENT ME!
|
||
126 | *
|
||
127 | * @return DOCUMENT ME!
|
||
128 | */
|
||
129 | public MapContext getAssociatedMapContext() {
|
||
130 | return m_MapAssoc.getMapContext();
|
||
131 | } |
||
132 | public MapControl getAssociatedMapControl(){
|
||
133 | return m_MapAssoc;
|
||
134 | } |
||
135 | |||
136 | /* (non-Javadoc)
|
||
137 | * @see com.iver.cit.opensig.gui.IMapExtentListener#extentChanged(java.awt.geom.Rectangle2D)
|
||
138 | */
|
||
139 | public void extentChanged(ExtentEvent evExtent) { |
||
140 | // Nos llega el nuevo extent del FMap asociado, as? que dibujamos nuestro
|
||
141 | // rect?ngulo para mostrar la zona de dibujo del otro mapa.
|
||
142 | repaint(); |
||
143 | } |
||
144 | |||
145 | /**
|
||
146 | * Recalcula el extent a aplicar de las capas que estan a?adidas.
|
||
147 | */
|
||
148 | public void refreshExtent() { |
||
149 | try {
|
||
150 | if (this.getMapContext().getFullExtent()!=null){ |
||
151 | this.getMapContext().getViewPort().setExtent(this.getMapContext().getFullExtent()); |
||
152 | }else{
|
||
153 | delModel(); |
||
154 | } |
||
155 | } catch (DriverException e1) {
|
||
156 | e1.printStackTrace(); |
||
157 | } |
||
158 | } |
||
159 | public void refreshOverView(Rectangle2D r){ |
||
160 | extent=r; |
||
161 | repaint(); |
||
162 | } |
||
163 | |||
164 | protected void paintComponent(Graphics g) { |
||
165 | super.paintComponent(g);
|
||
166 | if ((m_MapAssoc.getMapContext().getViewPort().getExtent() != null) && |
||
167 | (getMapContext().getViewPort().getExtent() != null)) {
|
||
168 | if (first) {
|
||
169 | first = false;
|
||
170 | repaint(); |
||
171 | return;
|
||
172 | } |
||
173 | image = new BufferedImage(this.getWidth(), this.getHeight(), |
||
174 | BufferedImage.TYPE_INT_ARGB);
|
||
175 | ViewPort vp = getMapContext().getViewPort(); |
||
176 | Rectangle2D extentView=vp.getAdjustedExtent();
|
||
177 | ViewPort vpOrig = m_MapAssoc.getMapContext().getViewPort(); |
||
178 | if (extent==null) |
||
179 | extent=vpOrig.getAdjustedExtent(); |
||
180 | // Dibujamos el extent del mapa asociado.
|
||
181 | Graphics2D g2 = (Graphics2D) image.getGraphics(); |
||
182 | g2.setTransform(vp.getAffineTransform()); |
||
183 | g2.setColor(Color.red);
|
||
184 | g2.draw(extent); |
||
185 | g2.setColor(new Color(100,100,100,100)); |
||
186 | g2.fill(extent); |
||
187 | // dibujamos las l?neas vertical y horizontal
|
||
188 | Point2D pRightUp = vp.toMapPoint(getWidth(), 0); |
||
189 | |||
190 | Line2D.Double linVert = new Line2D.Double(extent.getCenterX(), |
||
191 | extentView.getMinY(), extent.getCenterX(), |
||
192 | pRightUp.getY()); |
||
193 | Line2D.Double linHoriz = new Line2D.Double(extentView.getMinX(), |
||
194 | extent.getCenterY(), pRightUp.getX(), |
||
195 | extent.getCenterY()); |
||
196 | |||
197 | g2.setColor(Color.darkGray);
|
||
198 | g2.draw(linVert); |
||
199 | g2.draw(linHoriz); |
||
200 | g.drawImage(image,0,0,this); |
||
201 | g2.setTransform(new AffineTransform()); |
||
202 | extent=null;
|
||
203 | } |
||
204 | |||
205 | } |
||
206 | |||
207 | /**
|
||
208 | * DOCUMENT ME!
|
||
209 | *
|
||
210 | * @param model DOCUMENT ME!
|
||
211 | */
|
||
212 | public void setModel(MapContext model) { |
||
213 | this.setMapContext(model);
|
||
214 | model.setProjection(m_MapAssoc.getMapContext().getProjection()); |
||
215 | m_MapAssoc.getMapContext().getViewPort().addViewPortListener(this);
|
||
216 | getMapContext().getViewPort().addViewPortListener(this);
|
||
217 | } |
||
218 | private void delModel(){ |
||
219 | this.getMapContext().getViewPort().setExtent(null); |
||
220 | m_MapAssoc.getMapContext().getViewPort().removeViewPortListener(this);
|
||
221 | getMapContext().getViewPort().removeViewPortListener(this);
|
||
222 | } |
||
223 | |||
224 | /**
|
||
225 | * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
|
||
226 | */
|
||
227 | public void backColorChanged(ColorEvent e) { |
||
228 | } |
||
229 | |||
230 | public void projectionChanged(ProjectionEvent e) { |
||
231 | super.setProjection(e.getNewProjection());
|
||
232 | |||
233 | } |
||
234 | |||
235 | public void setProjection(IProjection proj) { |
||
236 | //No permitimos cambiar la proyeccion
|
||
237 | //ya que debe ser la misma que la del
|
||
238 | //MapControl asociado
|
||
239 | return;
|
||
240 | } |
||
241 | } |