Statistics
| Revision:

svn-gvsig-desktop / trunk / examples / exaExampleCenterViewToPoint / src / org / gvsig / examples / example1 / infotool / tool / InfoToolListenerImpl.java @ 13669

History | View | Annotate | Download (5.81 KB)

1

    
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
5
 *
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
 * as published by the Free Software Foundation; either version 2
9
 * 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
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42

    
43
package org.gvsig.examples.example1.infotool.tool;
44

    
45
import java.awt.Cursor;
46
import java.awt.Image;
47
import java.awt.Point;
48
import java.awt.Toolkit;
49
import java.awt.geom.Point2D;
50
import java.awt.geom.Rectangle2D;
51

    
52
import javax.swing.ImageIcon;
53

    
54
import org.gvsig.examples.example1.centerViewToPoint.CenterViewToPointExtension;
55
import org.gvsig.examples.example1.infotool.tool.gui.InfoWindowExample;
56

    
57
import com.iver.andami.PluginServices;
58
import com.iver.cit.gvsig.fmap.MapControl;
59
import com.iver.cit.gvsig.fmap.core.IGeometry;
60
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
61
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
62
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
63
import com.iver.cit.gvsig.fmap.layers.FLayer;
64
import com.iver.cit.gvsig.fmap.layers.FLayerGenericVectorial;
65
import com.iver.cit.gvsig.fmap.layers.GraphicLayer;
66
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
67
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
68
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
69
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener;
70
import com.iver.cit.gvsig.project.documents.view.toolListeners.InfoListener;
71

    
72

    
73
/**
74
 * Implementation of the interface PointListener as tool
75
 * of information and center the extent to that point.
76
 *
77
 * @author Vicente Caballero Navarro
78
 */
79
public class InfoToolListenerImpl implements PointListener {
80
    private final Image icentertopoint = new ImageIcon(MapControl.class.getResource(
81
                "images/InfoCursor.gif")).getImage();
82
    private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(icentertopoint,
83
            new Point(16, 16), "");
84
    private MapControl mapControl;
85
    private InfoListener infoListener;
86
    /**
87
     * Create a new InfoToolListenerImpl.
88
     *
89
     * @param mapControl MapControl.
90
     */
91
    public InfoToolListenerImpl(MapControl mapControl) {
92
        this.mapControl = mapControl;
93
        infoListener=new InfoListener(mapControl);
94
    }
95

    
96
    /* (non-Javadoc)
97
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
98
     */
99
    public void point(PointEvent event) {
100
             FLayer[] layers=mapControl.getMapContext().getLayers().getActives();
101
         if (layers[0] instanceof FLayerGenericVectorial){
102
                     if (layers[0].getProperty("CapaDePruebaCSV")!=null){
103
                             Point2D centerPoint = mapControl.getViewPort().toMapPoint(event.getPoint());
104
                     zoomToCoordinates(centerPoint);
105
                     drawPoint(centerPoint);
106
                     InfoWindowExample iwe=new InfoWindowExample();
107
                     PluginServices.getMDIManager().addWindow(iwe);
108
                     }
109
              } else {
110
             try {
111
                                infoListener.point(event);
112
                        } catch (BehaviorException e) {
113
                                e.printStackTrace();
114
                        }
115
         }
116

    
117
    }
118

    
119
    private void drawPoint(Point2D center) {
120
        GraphicLayer lyr = mapControl.getMapContext().getGraphicsLayer();
121
        lyr.clearAllGraphics();
122

    
123
        FSymbol theSymbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT,
124
                CenterViewToPointExtension.COLOR);
125
        int idSymbol = lyr.addSymbol(theSymbol);
126
        IGeometry geom = ShapeFactory.createPoint2D(center.getX(), center.getY());
127
        FGraphic theGraphic = new FGraphic(geom, idSymbol);
128
        lyr.addGraphic(theGraphic);
129
        mapControl.drawGraphics();
130
        mapControl.drawMap(false);
131
    }
132

    
133
    private void zoomToCoordinates(Point2D center) {
134
        Rectangle2D oldExtent = mapControl.getViewPort().getAdjustedExtent();
135
        double oldCenterX = oldExtent.getCenterX();
136
        double oldCenterY = oldExtent.getCenterY();
137
        double movX = center.getX() - oldCenterX;
138
        double movY = center.getY() - oldCenterY;
139
        double upperLeftCornerX = oldExtent.getMinX() + movX;
140
        double upperLeftCornerY = oldExtent.getMinY() + movY;
141
        double width = oldExtent.getWidth();
142
        double height = oldExtent.getHeight();
143
        Rectangle2D extent = new Rectangle2D.Double(upperLeftCornerX,
144
                upperLeftCornerY, width, height);
145
        mapControl.getViewPort().setExtent(extent);
146
        mapControl.getMapContext().clearAllCachingImageDrawnLayers();
147
    }
148

    
149
    /* (non-Javadoc)
150
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
151
     */
152
    public Cursor getCursor() {
153
        return cur;
154
    }
155

    
156
    /* (non-Javadoc)
157
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
158
     */
159
    public boolean cancelDrawing() {
160
        return true;
161
    }
162

    
163
    /* (non-Javadoc)
164
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#pointDoubleClick(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
165
     */
166
    public void pointDoubleClick(PointEvent event) {
167
    }
168
}