root / branches / gvSIG_03_SLD / applications / appgvSIG / src / com / iver / cit / gvsig / gui / MapOverview.java @ 2106
History | View | Annotate | Download (5.34 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 | 962 | vcaballero | import com.iver.cit.gvsig.fmap.ColorEvent; |
50 | 1307 | vcaballero | import com.iver.cit.gvsig.fmap.DriverException; |
51 | 842 | vcaballero | import com.iver.cit.gvsig.fmap.ExtentEvent; |
52 | import com.iver.cit.gvsig.fmap.FMap; |
||
53 | 1223 | fernando | import com.iver.cit.gvsig.fmap.MapControl; |
54 | 842 | vcaballero | import com.iver.cit.gvsig.fmap.ViewPort; |
55 | 962 | vcaballero | import com.iver.cit.gvsig.fmap.ViewPortListener; |
56 | 1221 | fernando | import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
57 | 842 | vcaballero | import com.iver.cit.gvsig.gui.toolListeners.MapOverviewListener; |
58 | 1009 | vcaballero | import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener; |
59 | 842 | vcaballero | |
60 | 1307 | vcaballero | 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 | 842 | vcaballero | |
68 | 1307 | vcaballero | |
69 | 842 | vcaballero | /**
|
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 | 1223 | fernando | public class MapOverview extends MapControl implements ViewPortListener { |
77 | private MapControl m_MapAssoc;
|
||
78 | 1307 | vcaballero | boolean first = true; |
79 | 842 | vcaballero | |
80 | /**
|
||
81 | * Crea un nuevo MapOverview.
|
||
82 | *
|
||
83 | * @param mapAssoc DOCUMENT ME!
|
||
84 | */
|
||
85 | 1223 | fernando | public MapOverview(MapControl mapAssoc) {
|
86 | 842 | vcaballero | super();
|
87 | 1307 | vcaballero | |
88 | 982 | fjp | // super.vp.setBackColor(new Color(230,230,230));
|
89 | 842 | vcaballero | m_MapAssoc = mapAssoc; |
90 | 944 | vcaballero | |
91 | 842 | vcaballero | // setModel((FMap) m_MapAssoc.getMapContext().clone()); // Lo inicializamos con
|
92 | // los mismos temas que tenga el grande.
|
||
93 | MapOverviewListener movl = new MapOverviewListener(this); |
||
94 | 1221 | fernando | addMapTool("zoomtopoint", new PointBehavior(movl)); |
95 | 842 | vcaballero | setCursor(movl.getCursor()); |
96 | |||
97 | setTool("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 | 1307 | vcaballero | /**
|
119 | * Recalcula el extent a aplicar de las capas que estan a?adidas.
|
||
120 | */
|
||
121 | public void refreshExtent() { |
||
122 | 1311 | vcaballero | try {
|
123 | this.getMapContext().getViewPort().setExtent(this.getMapContext().getFullExtent()); |
||
124 | } catch (DriverException e1) {
|
||
125 | e1.printStackTrace(); |
||
126 | 1307 | vcaballero | } |
127 | } |
||
128 | |||
129 | 842 | vcaballero | /* (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 | 1307 | vcaballero | if (first) {
|
138 | first = false;
|
||
139 | repaint(); |
||
140 | |||
141 | return;
|
||
142 | } else {
|
||
143 | first = true;
|
||
144 | } |
||
145 | |||
146 | 842 | vcaballero | 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 | 1307 | vcaballero | g2.fill(vpOrig.getAdjustedExtent()); |
156 | 842 | vcaballero | // 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 | 944 | vcaballero | |
175 | 871 | vcaballero | /**
|
176 | * DOCUMENT ME!
|
||
177 | *
|
||
178 | 944 | vcaballero | * @param model DOCUMENT ME!
|
179 | 871 | vcaballero | */
|
180 | 944 | vcaballero | public void setModel(FMap model) { |
181 | this.setMapContext(model);
|
||
182 | 1201 | fernando | m_MapAssoc.getMapContext().getViewPort().addViewPortListener(this);
|
183 | getMapContext().getViewPort().addViewPortListener(this);
|
||
184 | 842 | vcaballero | } |
185 | 962 | vcaballero | |
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 | 871 | vcaballero | } |