svn-gvsig-desktop / tags / Root_gvSIG_CAD_Layout_version / applications / appgvSIG / src / com / iver / cit / gvsig / gui / MapOverview.java @ 1648
History | View | Annotate | Download (5.34 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.Graphics; |
62 |
import java.awt.Graphics2D; |
63 |
import java.awt.geom.AffineTransform; |
64 |
import java.awt.geom.Line2D; |
65 |
import java.awt.geom.Point2D; |
66 |
import java.awt.geom.Rectangle2D; |
67 |
|
68 |
|
69 |
/**
|
70 |
* DOCUMENT ME!
|
71 |
*
|
72 |
* @author FJP TODO To change the template for this generated type comment go
|
73 |
* to Window - Preferences - Java - Code Generation - Code and
|
74 |
* Comments
|
75 |
*/
|
76 |
public class MapOverview extends MapControl implements ViewPortListener { |
77 |
private MapControl m_MapAssoc;
|
78 |
boolean first = true; |
79 |
|
80 |
/**
|
81 |
* Crea un nuevo MapOverview.
|
82 |
*
|
83 |
* @param mapAssoc DOCUMENT ME!
|
84 |
*/
|
85 |
public MapOverview(MapControl mapAssoc) {
|
86 |
super();
|
87 |
|
88 |
// super.vp.setBackColor(new Color(230,230,230));
|
89 |
m_MapAssoc = mapAssoc; |
90 |
|
91 |
// setModel((FMap) m_MapAssoc.getMapContext().clone()); // Lo inicializamos con
|
92 |
// los mismos temas que tenga el grande.
|
93 |
MapOverviewListener movl = new MapOverviewListener(this); |
94 |
addMapTool("zoomtopoint", new PointBehavior(movl)); |
95 |
setCursor(movl.getCursor()); |
96 |
|
97 |
pushTool("zoomtopoint");
|
98 |
} |
99 |
|
100 |
/**
|
101 |
* DOCUMENT ME!
|
102 |
*
|
103 |
* @return DOCUMENT ME!
|
104 |
*/
|
105 |
public FMap getAssociatedMapContext() {
|
106 |
return m_MapAssoc.getMapContext();
|
107 |
} |
108 |
|
109 |
/* (non-Javadoc)
|
110 |
* @see com.iver.cit.opensig.gui.IMapExtentListener#extentChanged(java.awt.geom.Rectangle2D)
|
111 |
*/
|
112 |
public void extentChanged(ExtentEvent evExtent) { |
113 |
// Nos llega el nuevo extent del FMap asociado, as? que dibujamos nuestro
|
114 |
// rect?ngulo para mostrar la zona de dibujo del otro mapa.
|
115 |
repaint(); |
116 |
} |
117 |
|
118 |
/**
|
119 |
* Recalcula el extent a aplicar de las capas que estan a?adidas.
|
120 |
*/
|
121 |
public void refreshExtent() { |
122 |
try {
|
123 |
this.getMapContext().getViewPort().setExtent(this.getMapContext().getFullExtent()); |
124 |
} catch (DriverException e1) {
|
125 |
e1.printStackTrace(); |
126 |
} |
127 |
} |
128 |
|
129 |
/* (non-Javadoc)
|
130 |
* @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
|
131 |
*/
|
132 |
protected void paintComponent(Graphics g) { |
133 |
super.paintComponent(g);
|
134 |
|
135 |
if ((m_MapAssoc.getMapContext().getViewPort().getExtent() != null) && |
136 |
(getMapContext().getViewPort().getExtent() != null)) {
|
137 |
if (first) {
|
138 |
first = false;
|
139 |
repaint(); |
140 |
|
141 |
return;
|
142 |
} else {
|
143 |
first = true;
|
144 |
} |
145 |
|
146 |
ViewPort vp = getMapContext().getViewPort(); |
147 |
ViewPort vpOrig = m_MapAssoc.getMapContext().getViewPort(); |
148 |
Graphics2D g2 = (Graphics2D) g; |
149 |
g2.setColor(Color.black);
|
150 |
g2.setXORMode(Color.white);
|
151 |
|
152 |
// Dibujamos el extent del mapa asociado.
|
153 |
g2.setTransform(vp.getAffineTransform()); |
154 |
|
155 |
g2.fill(vpOrig.getAdjustedExtent()); |
156 |
// dibujamos las l?neas vertical y horizontal
|
157 |
Point2D pRightUp = vp.toMapPoint(getWidth(), 0); |
158 |
Line2D.Double linVert = new Line2D.Double(vpOrig.getExtent() |
159 |
.getCenterX(), |
160 |
vp.getExtent().getMinY(), vpOrig.getExtent().getCenterX(), |
161 |
pRightUp.getY()); |
162 |
Line2D.Double linHoriz = new Line2D.Double(vp.getExtent().getMinX(), |
163 |
vpOrig.getExtent().getCenterY(), pRightUp.getX(), |
164 |
vpOrig.getExtent().getCenterY()); |
165 |
|
166 |
g2.draw(linVert); |
167 |
g2.draw(linHoriz); |
168 |
|
169 |
g2.setTransform(new AffineTransform()); |
170 |
|
171 |
// System.out.println("Dibujo el extent " + m_MapAssoc.getExtent().toString());
|
172 |
} |
173 |
} |
174 |
|
175 |
/**
|
176 |
* DOCUMENT ME!
|
177 |
*
|
178 |
* @param model DOCUMENT ME!
|
179 |
*/
|
180 |
public void setModel(FMap model) { |
181 |
this.setMapContext(model);
|
182 |
m_MapAssoc.getMapContext().getViewPort().addViewPortListener(this);
|
183 |
getMapContext().getViewPort().addViewPortListener(this);
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
|
188 |
*/
|
189 |
public void backColorChanged(ColorEvent e) { |
190 |
} |
191 |
} |