svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / toolListeners / MapOverviewListener.java @ 45732
History | View | Annotate | Download (4.72 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40558 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | 40558 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40558 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.app.project.documents.view.toolListeners; |
||
25 | |||
26 | import java.awt.Image; |
||
27 | import java.awt.event.MouseEvent; |
||
28 | import java.awt.geom.Point2D; |
||
29 | import java.awt.geom.Rectangle2D; |
||
30 | |||
31 | import org.gvsig.andami.PluginServices; |
||
32 | import org.gvsig.app.gui.styling.SymbolSelector; |
||
33 | import org.gvsig.app.project.documents.view.MapOverview; |
||
34 | import org.gvsig.fmap.geom.GeometryLocator; |
||
35 | import org.gvsig.fmap.geom.GeometryManager; |
||
36 | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
||
37 | import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
||
38 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
39 | import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
||
40 | import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent; |
||
41 | import org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener; |
||
42 | import org.slf4j.Logger; |
||
43 | import org.slf4j.LoggerFactory; |
||
44 | |||
45 | |||
46 | |||
47 | /**
|
||
48 | * <p>Listener for changes of the zoom caused by selecting a point on the associated {@link MapOverview MapOverview} object
|
||
49 | * by a single click of the button 1 of the mouse.</p>
|
||
50 | *
|
||
51 | * <p>Updates the extent of its <code>ViewPort</code> with a <i>zoom out</i> operation, and enables/disables controls for
|
||
52 | * managing the data.</p>
|
||
53 | *
|
||
54 | * @see ViewPort
|
||
55 | *
|
||
56 | * @author Vicente Caballero Navarro
|
||
57 | */
|
||
58 | public class MapOverviewListener implements PointListener { |
||
59 | private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
||
60 | private static final Logger logger = LoggerFactory.getLogger(MapOverviewListener.class); |
||
61 | /**
|
||
62 | * The image to display when the cursor is active.
|
||
63 | */
|
||
64 | private final Image izoomout = PluginServices.getIconTheme().get("cursor-crux").getImage(); |
||
65 | |||
66 | /**
|
||
67 | * The cursor used to work with this tool listener.
|
||
68 | *
|
||
69 | * @see #getCursor()
|
||
70 | */
|
||
71 | // private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(izoomout,
|
||
72 | // new Point(16, 16), "");
|
||
73 | |||
74 | /**
|
||
75 | * Reference to the <code>MapControl</code> object that uses.
|
||
76 | */
|
||
77 | protected MapOverview mapControl;
|
||
78 | |||
79 | /**
|
||
80 | * <p>Creates a new listener for zooming out the extent of the associated {@link MapOverview MapOverview} object.</p>
|
||
81 | *
|
||
82 | * @param mapControl the <code>MapControl</code> object which represents the <code>MapOverview</code>
|
||
83 | */
|
||
84 | public MapOverviewListener(MapOverview mapControl) {
|
||
85 | this.mapControl = mapControl;
|
||
86 | } |
||
87 | |||
88 | /*
|
||
89 | * (non-Javadoc)
|
||
90 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
||
91 | */
|
||
92 | public void point(PointEvent event) { |
||
93 | ViewPort vp = mapControl.getMapContext().getViewPort(); |
||
94 | |||
95 | if (vp.getExtent() != null && |
||
96 | mapControl.getAssociatedMapContext().getViewPort().getExtent()!=null) {
|
||
97 | Point2D p = vp.toMapPoint(event.getPoint());
|
||
98 | Rectangle2D r = (Rectangle2D) mapControl.getAssociatedMapContext() |
||
99 | .getViewPort().getExtent().clone(); |
||
100 | |||
101 | r.setRect(p.getX() - (r.getWidth() / 2),
|
||
102 | p.getY() - (r.getHeight() / 2), r.getWidth(), r.getHeight());
|
||
103 | |||
104 | if (event.getEvent().getButton()!=MouseEvent.BUTTON1) { |
||
105 | try {
|
||
106 | (this.mapControl).getAssociatedMapContext()
|
||
107 | .getViewPort().setEnvelope(geomManager.createEnvelope(r.getX(),r.getY(),r.getMaxX(),r.getMaxY(), SUBTYPES.GEOM2D)); |
||
108 | } catch (CreateEnvelopeException e) {
|
||
109 | logger.error("Error creating the envelope", e);
|
||
110 | } |
||
111 | PluginServices.getMainFrame().enableControls(); |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 | |||
116 | /*
|
||
117 | * (non-Javadoc)
|
||
118 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getImageCursor()
|
||
119 | */
|
||
120 | public Image getImageCursor() { |
||
121 | return izoomout;
|
||
122 | } |
||
123 | |||
124 | /*
|
||
125 | * (non-Javadoc)
|
||
126 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
||
127 | */
|
||
128 | public boolean cancelDrawing() { |
||
129 | return true; |
||
130 | } |
||
131 | |||
132 | /*
|
||
133 | * (non-Javadoc)
|
||
134 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#pointDoubleClick(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
||
135 | */
|
||
136 | public void pointDoubleClick(PointEvent event) throws BehaviorException { |
||
137 | // TODO Auto-generated method stub
|
||
138 | |||
139 | } |
||
140 | } |