Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / toolListeners / CircleMeasureListener.java @ 38605

History | View | Annotate | Download (4.26 KB)

1 14821 jmvivo
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2 7771 caballero
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23 14821 jmvivo
 *   Av. Blasco Ib��ez, 50
24 7771 caballero
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41 29596 jpiera
package org.gvsig.app.project.documents.view.toolListeners;
42 7771 caballero
43
44
import java.awt.Image;
45
import java.awt.geom.Point2D;
46
import java.text.NumberFormat;
47
48 29596 jpiera
import org.gvsig.andami.PluginServices;
49 20994 jmvivo
import org.gvsig.fmap.mapcontext.MapContext;
50
import org.gvsig.fmap.mapcontext.ViewPort;
51
import org.gvsig.fmap.mapcontrol.MapControl;
52
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
53
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent;
54
import org.gvsig.fmap.mapcontrol.tools.Listeners.CircleListener;
55
56 7771 caballero
57
58
/**
59 20098 jmvivo
 * <p>Listener for tools that measure using a circular area, displaying
60
 *   its radius at the status bar of the application's main frame.</p>
61 7771 caballero
 *
62 20098 jmvivo
 * @see CircleListener
63
 *
64 7771 caballero
 * @author Laura
65
 */
66
public class CircleMeasureListener implements CircleListener {
67 20098 jmvivo
        /**
68
         * The image to display when the cursor is active.
69
         */
70 14821 jmvivo
        private final Image img = PluginServices.getIconTheme().get("cursor-query-distance").getImage();
71 20098 jmvivo
72
        /**
73
         * The cursor used to work with this tool listener.
74 20334 vcaballero
         *
75 20098 jmvivo
         * @see #getCursor()
76
         */
77 23642 vcaballero
//        private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(img,
78
//                        new Point(16, 16), "");
79 20098 jmvivo
80
        /**
81
         * Reference to the <code>MapControl</code> object that uses.
82
         */
83 7771 caballero
        private MapControl mapCtrl;
84
85
        /**
86 20098 jmvivo
         * <p>Creates a new listener for measure circular areas.</p>
87 7771 caballero
         *
88 20334 vcaballero
         * @param mc the <code>MapControl</code> object where the measures are made
89 7771 caballero
         */
90
        public CircleMeasureListener(MapControl mc) {
91
                this.mapCtrl = mc;
92
        }
93
94 20098 jmvivo
        /*
95
         * (non-Javadoc)
96 7771 caballero
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.CircleListener#circle(com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent)
97
         */
98
        public void circle(MeasureEvent event) throws BehaviorException {
99
                double dist = 0;
100
                double distAll = 0;
101
102
                ViewPort vp = mapCtrl.getMapContext().getViewPort();
103
104
                for (int i = 0; i < (event.getXs().length - 1); i++) {
105
                        dist = 0;
106
107
                        Point2D p = new Point2D.Double(event.getXs()[i].doubleValue(),
108
                                        event.getYs()[i].doubleValue());
109
                        Point2D p2 = new Point2D.Double(event.getXs()[i + 1].doubleValue(),
110
                                        event.getYs()[i + 1].doubleValue());
111
112
                        ///dist = vp.toMapDistance((int) p.distance(p2));
113
                        dist = vp.distanceWorld(p, p2);
114
                        distAll += dist;
115
                }
116
                //System.out.println("Distancia = " + dist + " Distancia Total = " +
117
                //        (distAll));
118
                NumberFormat nf = NumberFormat.getInstance();
119
        nf.setMaximumFractionDigits(2);
120
        if (PluginServices.getMainFrame() != null)
121
        {
122 20334 vcaballero
                double[] trans2Meter=MapContext.getDistanceTrans2Meter();
123 7771 caballero
            PluginServices.getMainFrame().getStatusBar().setMessage("4",
124 20334 vcaballero
                            "Dist:" + nf.format(dist/trans2Meter[mapCtrl.getViewPort().getDistanceUnits()]) + "");
125 7771 caballero
                    PluginServices.getMainFrame().getStatusBar().setMessage("5",
126 20334 vcaballero
                            "Total:" + nf.format(distAll/trans2Meter[mapCtrl.getViewPort().getDistanceUnits()]) + "");
127 7771 caballero
        }
128
        }
129
130 20098 jmvivo
        /*
131
         * (non-Javadoc)
132 23642 vcaballero
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getImageCursor()
133 7771 caballero
         */
134 23642 vcaballero
        public Image getImageCursor() {
135
                return img;
136 7771 caballero
        }
137
138 20098 jmvivo
        /*
139
         * (non-Javadoc)
140 7771 caballero
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
141
         */
142
        public boolean cancelDrawing() {
143
                return false;
144
        }
145
}