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