root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / MapOverview.java @ 38562
History | View | Annotate | Download (10.9 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 | 29598 | jpiera | package org.gvsig.app.project.documents.view; |
48 | 7304 | caballero | |
49 | 13327 | jmvivo | import java.awt.BasicStroke; |
50 | 7304 | caballero | import java.awt.Color; |
51 | import java.awt.Graphics; |
||
52 | import java.awt.Graphics2D; |
||
53 | import java.awt.geom.AffineTransform; |
||
54 | import java.awt.geom.Line2D; |
||
55 | import java.awt.geom.Point2D; |
||
56 | import java.awt.geom.Rectangle2D; |
||
57 | import java.awt.image.BufferedImage; |
||
58 | |||
59 | import org.cresques.cts.IProjection; |
||
60 | 29598 | jpiera | import org.gvsig.app.project.documents.view.toolListeners.MapOverviewChangeZoomListener; |
61 | import org.gvsig.app.project.documents.view.toolListeners.MapOverviewListener; |
||
62 | import org.gvsig.app.project.documents.view.toolListeners.MapOverviewPanListener; |
||
63 | 24759 | jmvivo | import org.gvsig.fmap.dal.exception.ReadException; |
64 | 21743 | vcaballero | import org.gvsig.fmap.geom.primitive.Envelope; |
65 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.MapContext; |
66 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
67 | import org.gvsig.fmap.mapcontext.events.ColorEvent; |
||
68 | import org.gvsig.fmap.mapcontext.events.ExtentEvent; |
||
69 | import org.gvsig.fmap.mapcontext.events.ProjectionEvent; |
||
70 | import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener; |
||
71 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
72 | 21743 | vcaballero | import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
73 | import org.gvsig.fmap.mapcontrol.tools.Behavior.DraggerBehavior; |
||
74 | import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior; |
||
75 | import org.gvsig.fmap.mapcontrol.tools.Behavior.RectangleBehavior; |
||
76 | 7304 | caballero | |
77 | |||
78 | |||
79 | /**
|
||
80 | 20098 | jmvivo | * <p>Lightweight <code>MapControl</code> that uses another <code>MapControl</code>'s <code>MapContext</code>, and updates
|
81 | * any rectangular extent selected, to the associated <code>MapControl</code>.</p>
|
||
82 | 21359 | vcaballero | *
|
83 | 20098 | jmvivo | * <p>Both <code>MapControl</code> instances work in the same projection. And, always, the not undefined <i>adjusted extent</i>
|
84 | * of the associated one, will be enhanced as a red-bordered grey-filled rectangle in this one. Furthermore, draws a horizontal and vertical
|
||
85 | * this component's width or height, black lines centered in that rectangle.</p>
|
||
86 | 7304 | caballero | *
|
87 | 20098 | jmvivo | * @author FJP
|
88 | 7304 | caballero | */
|
89 | public class MapOverview extends MapControl implements ViewPortListener { |
||
90 | 20098 | jmvivo | /**
|
91 | 31496 | jjdelcerro | *
|
92 | */
|
||
93 | private static final long serialVersionUID = -2849739771493279542L; |
||
94 | |||
95 | /**
|
||
96 | 20098 | jmvivo | * <p>Associated <code>MapControl</code> instance that this component represents its overview.</p>
|
97 | */
|
||
98 | 7304 | caballero | private MapControl m_MapAssoc;
|
99 | 21359 | vcaballero | |
100 | 20098 | jmvivo | /**
|
101 | * <p>Determines that's the first time this component is going to be painted.</p>
|
||
102 | */
|
||
103 | 7304 | caballero | boolean first = true; |
104 | 20098 | jmvivo | |
105 | /**
|
||
106 | * <p>Tool listener used to apply a <i>zoom out</i> operation in this component graphical information.</p>
|
||
107 | */
|
||
108 | 7304 | caballero | private MapOverviewListener movl;
|
109 | 21359 | vcaballero | |
110 | 20098 | jmvivo | /**
|
111 | * <p>Tool listener used to allow user work with this component applying <i>pan</i> operations.</p>
|
||
112 | */
|
||
113 | 7304 | caballero | private MapOverviewPanListener movpl;
|
114 | 21359 | vcaballero | |
115 | 20098 | jmvivo | /**
|
116 | * <p>Tool listener used to allow user work with this component applying <i>pan</i> operations.</p>
|
||
117 | */
|
||
118 | 7304 | caballero | private MapOverviewChangeZoomListener movczl;
|
119 | 21359 | vcaballero | |
120 | 20098 | jmvivo | /**
|
121 | * <p>Rectangular area selected in this component, that will be the extent of the associated <code>MapControl</code> instance.</p>
|
||
122 | */
|
||
123 | 21743 | vcaballero | private Envelope extent;
|
124 | 21359 | vcaballero | |
125 | 20098 | jmvivo | /**
|
126 | * <p>Double buffer used to paint this component graphical information.</p>
|
||
127 | */
|
||
128 | 7304 | caballero | private BufferedImage image; |
129 | |||
130 | /**
|
||
131 | 20098 | jmvivo | * <p>Creates a <code>MapOverview</code> instance associated to <code>mapAssoc</code>.</p>
|
132 | 7304 | caballero | *
|
133 | 20098 | jmvivo | * @param mapAssoc <code>MapControl</code> this component will be the overview
|
134 | 7304 | caballero | */
|
135 | public MapOverview(MapControl mapAssoc) {
|
||
136 | super();
|
||
137 | this.setName("MapOverview"); |
||
138 | // super.vp.setBackColor(new Color(230,230,230));
|
||
139 | m_MapAssoc = mapAssoc; |
||
140 | |||
141 | // setModel((FMap) m_MapAssoc.getMapContext().clone()); // Lo inicializamos con
|
||
142 | // los mismos temas que tenga el grande.
|
||
143 | movl = new MapOverviewListener(this); |
||
144 | movpl = new MapOverviewPanListener(this); |
||
145 | movczl = new MapOverviewChangeZoomListener(this); |
||
146 | 30337 | jpiera | addBehavior( |
147 | 7304 | caballero | "zoomtopoint",
|
148 | new Behavior[]{ |
||
149 | new PointBehavior(movl),
|
||
150 | new RectangleBehavior(movczl),
|
||
151 | new DraggerBehavior(movczl),
|
||
152 | new DraggerBehavior(movpl)
|
||
153 | } |
||
154 | ); |
||
155 | |||
156 | 23642 | vcaballero | // setCursor(movl.getCursor());
|
157 | 7304 | caballero | |
158 | setTool("zoomtopoint");
|
||
159 | 23642 | vcaballero | getGrid().setShowGrid(false);
|
160 | getGrid().setAdjustGrid(false);
|
||
161 | 7304 | caballero | } |
162 | |||
163 | /**
|
||
164 | 20098 | jmvivo | * @see MapControl#getMapContext()
|
165 | 7304 | caballero | */
|
166 | public MapContext getAssociatedMapContext() {
|
||
167 | return m_MapAssoc.getMapContext();
|
||
168 | } |
||
169 | 20098 | jmvivo | |
170 | /**
|
||
171 | * <p>Gets the <code>MapControl</code> instance that wrappers.</p>
|
||
172 | 21359 | vcaballero | *
|
173 | 20098 | jmvivo | * @return the <code>MapControl</code> instance that wrappers
|
174 | */
|
||
175 | 7304 | caballero | public MapControl getAssociatedMapControl(){
|
176 | return m_MapAssoc;
|
||
177 | } |
||
178 | |||
179 | 20098 | jmvivo | /*
|
180 | * (non-Javadoc)
|
||
181 | * @see com.iver.cit.gvsig.fmap.ViewPortListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
|
||
182 | 7304 | caballero | */
|
183 | public void extentChanged(ExtentEvent evExtent) { |
||
184 | // Nos llega el nuevo extent del FMap asociado, as? que dibujamos nuestro
|
||
185 | // rect?ngulo para mostrar la zona de dibujo del otro mapa.
|
||
186 | repaint(); |
||
187 | } |
||
188 | |||
189 | /**
|
||
190 | 20098 | jmvivo | * <p>If this had no extent, calls {@link #delModel() #delModel()}, otherwise recalculates this
|
191 | * component's view port extent as the union of all extents of all layers of this map.</p>
|
||
192 | 7304 | caballero | */
|
193 | public void refreshExtent() { |
||
194 | try {
|
||
195 | 21501 | vcaballero | if (this.getMapContext().getFullEnvelope()!=null){ |
196 | this.getMapContext().getViewPort().setEnvelope(this.getMapContext().getFullEnvelope()); |
||
197 | 7304 | caballero | }else{
|
198 | delModel(); |
||
199 | } |
||
200 | 21359 | vcaballero | } catch (ReadException e1) {
|
201 | 7304 | caballero | e1.printStackTrace(); |
202 | } |
||
203 | } |
||
204 | 21359 | vcaballero | |
205 | 20098 | jmvivo | /**
|
206 | * <p>Repaints this component updating its <i>extent</i>.</p>
|
||
207 | 21359 | vcaballero | *
|
208 | 20098 | jmvivo | * @param r the new extent
|
209 | */
|
||
210 | 21743 | vcaballero | public void refreshOverView(Envelope r){ |
211 | 7304 | caballero | extent=r; |
212 | repaint(); |
||
213 | } |
||
214 | |||
215 | 20098 | jmvivo | /**
|
216 | * <p>Paints this component's graphical information using a 8-bit RGBA color double buffer, drawing a red-bordered
|
||
217 | * grey-filled rectangle enhancing the extent selected, and a horizontal and vertical this component's width or
|
||
218 | * height, black lines centered in that rectangle.</p>
|
||
219 | */
|
||
220 | 7304 | caballero | protected void paintComponent(Graphics g) { |
221 | 23642 | vcaballero | getGrid().setShowGrid(false);
|
222 | getGrid().setAdjustGrid(false);
|
||
223 | 7304 | caballero | super.paintComponent(g);
|
224 | 31496 | jjdelcerro | |
225 | if ((m_MapAssoc.getMapContext().getViewPort().getEnvelope() != null) && |
||
226 | (getMapContext().getViewPort().getEnvelope() != null)) {
|
||
227 | 7304 | caballero | if (first) {
|
228 | first = false;
|
||
229 | repaint(); |
||
230 | return;
|
||
231 | } |
||
232 | image = new BufferedImage(this.getWidth(), this.getHeight(), |
||
233 | BufferedImage.TYPE_INT_ARGB);
|
||
234 | ViewPort vp = getMapContext().getViewPort(); |
||
235 | 31496 | jjdelcerro | Envelope extentView=vp.getAdjustedEnvelope(); |
236 | 7304 | caballero | ViewPort vpOrig = m_MapAssoc.getMapContext().getViewPort(); |
237 | 24759 | jmvivo | if (extent==null) { |
238 | 31496 | jjdelcerro | extent=vpOrig.getAdjustedEnvelope(); |
239 | 24759 | jmvivo | } |
240 | 7304 | caballero | // Dibujamos el extent del mapa asociado.
|
241 | Graphics2D g2 = (Graphics2D) image.getGraphics(); |
||
242 | g2.setTransform(vp.getAffineTransform()); |
||
243 | 13327 | jmvivo | |
244 | g2.setStroke(new BasicStroke((float) vp.getDist1pixel())); |
||
245 | |||
246 | 7304 | caballero | g2.setColor(Color.red);
|
247 | 21743 | vcaballero | Rectangle2D extentToDraw=new Rectangle2D.Double(extent.getMinimum(0),extent.getMinimum(1),extent.getLength(0),extent.getLength(1)); |
248 | g2.draw(extentToDraw); |
||
249 | 7304 | caballero | g2.setColor(new Color(100,100,100,100)); |
250 | 21743 | vcaballero | g2.fill(extentToDraw); |
251 | 7304 | caballero | // dibujamos las l?neas vertical y horizontal
|
252 | Point2D pRightUp = vp.toMapPoint(getWidth(), 0); |
||
253 | |||
254 | 21743 | vcaballero | Line2D.Double linVert = new Line2D.Double(extentToDraw.getCenterX(), |
255 | extentView.getMinimum(1), extentToDraw.getCenterX(),
|
||
256 | 7304 | caballero | pRightUp.getY()); |
257 | 21743 | vcaballero | Line2D.Double linHoriz = new Line2D.Double(extentView.getMinimum(0), |
258 | extentToDraw.getCenterY(), pRightUp.getX(), |
||
259 | extentToDraw.getCenterY()); |
||
260 | 7304 | caballero | |
261 | g2.setColor(Color.darkGray);
|
||
262 | g2.draw(linVert); |
||
263 | g2.draw(linHoriz); |
||
264 | g.drawImage(image,0,0,this); |
||
265 | g2.setTransform(new AffineTransform()); |
||
266 | extent=null;
|
||
267 | } |
||
268 | |||
269 | } |
||
270 | |||
271 | /**
|
||
272 | 20098 | jmvivo | * <p>Sets a <code>MapContext</code> to this component, configuring it to manage view port events produced
|
273 | * in the associated <code>MapControl</code> and this one's view port.</p>
|
||
274 | 21359 | vcaballero | *
|
275 | 20098 | jmvivo | * <p>This <code>MapContext</code>'s projection will be the same as the associated <code>MapControl</code>'s one.</p>
|
276 | 21359 | vcaballero | *
|
277 | 20098 | jmvivo | * <p>Setting the model includes the following steps:
|
278 | * <ul>
|
||
279 | * <li><b>1.-</b> set <code>model</code> as the <code>MapContext</code> of <code>this</code>.</li>
|
||
280 | * <li><b>2.-</b> set as <code>model</code> projection, the associated <code>MapControl<code>'s projection.</li>
|
||
281 | * <li><b>3.-</b> set <code>this</code> as <i>view port</i> listener of the associated <code>MapControl</code>'s <i>view port</i>.</li>
|
||
282 | * <li><b>4.-</b> set <code>this</code> as <i>view port</i> listener of this <code>MapContext</code>'s <i>view port</i></li>
|
||
283 | * </ul>
|
||
284 | * </p>
|
||
285 | 7304 | caballero | *
|
286 | 21359 | vcaballero | * @param model data to set
|
287 | 7304 | caballero | */
|
288 | public void setModel(MapContext model) { |
||
289 | this.setMapContext(model);
|
||
290 | model.setProjection(m_MapAssoc.getMapContext().getProjection()); |
||
291 | m_MapAssoc.getMapContext().getViewPort().addViewPortListener(this);
|
||
292 | getMapContext().getViewPort().addViewPortListener(this);
|
||
293 | } |
||
294 | 21359 | vcaballero | |
295 | 20098 | jmvivo | /**
|
296 | * <p>Removes this component as listener of the the associated <code>MapControl</code> and this one's view port. Besides,
|
||
297 | * removes the extent.</p>
|
||
298 | */
|
||
299 | 7304 | caballero | private void delModel(){ |
300 | 21501 | vcaballero | this.getMapContext().getViewPort().setEnvelope(null); |
301 | 7304 | caballero | m_MapAssoc.getMapContext().getViewPort().removeViewPortListener(this);
|
302 | getMapContext().getViewPort().removeViewPortListener(this);
|
||
303 | } |
||
304 | |||
305 | 20098 | jmvivo | /*
|
306 | * (non-Javadoc)
|
||
307 | 7304 | caballero | * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
|
308 | */
|
||
309 | public void backColorChanged(ColorEvent e) { |
||
310 | 31496 | jjdelcerro | // do nothing
|
311 | 7304 | caballero | } |
312 | |||
313 | 20098 | jmvivo | /**
|
314 | * @see ViewPortListener#projectionChanged(ProjectionEvent)
|
||
315 | *
|
||
316 | * @see MapControl#setProjection(IProjection)
|
||
317 | */
|
||
318 | 7304 | caballero | public void projectionChanged(ProjectionEvent e) { |
319 | super.setProjection(e.getNewProjection());
|
||
320 | |||
321 | } |
||
322 | |||
323 | 20098 | jmvivo | /**
|
324 | * <p>Unimplemented.</p>
|
||
325 | 21359 | vcaballero | *
|
326 | 20098 | jmvivo | * <p>Can't change the projection, because must be the same as the one of the
|
327 | * associated <code>MapControl</code> instance.</p>
|
||
328 | */
|
||
329 | 7304 | caballero | public void setProjection(IProjection proj) { |
330 | //No permitimos cambiar la proyeccion
|
||
331 | //ya que debe ser la misma que la del
|
||
332 | //MapControl asociado
|
||
333 | return;
|
||
334 | } |
||
335 | } |