Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toolListeners / StatusBarListener.java @ 6247

History | View | Annotate | Download (4.86 KB)

1 1103 fjp
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
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
 *   Av. Blasco Ib??ez, 50
24
 *   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 1007 vcaballero
package com.iver.cit.gvsig.gui.toolListeners;
42
43 1065 fernando
import java.awt.Cursor;
44
import java.awt.geom.Point2D;
45
import java.text.NumberFormat;
46
47 1438 jmorell
import org.cresques.cts.IProjection;
48
49 1007 vcaballero
import com.iver.andami.PluginServices;
50 1024 fjp
import com.iver.andami.ui.mdiFrame.MainFrame;
51 2544 caballero
import com.iver.cit.gvsig.fmap.FMap;
52 1223 fernando
import com.iver.cit.gvsig.fmap.MapControl;
53 2544 caballero
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
54 1007 vcaballero
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
55
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
56 1065 fernando
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener;
57 1007 vcaballero
58
59
/**
60
 * DOCUMENT ME!
61
 *
62
 * @author Vicente Caballero Navarro
63
 */
64 1065 fernando
public class StatusBarListener implements PointListener {
65 1223 fernando
        private MapControl mapControl = null;
66 1012 vcaballero
        private NumberFormat nf = null;
67 1007 vcaballero
68
        /**
69
         * Crea un nuevo StatusBarListener.
70
         *
71
         * @param mc DOCUMENT ME!
72
         */
73 1223 fernando
        public StatusBarListener(MapControl mc) {
74 1007 vcaballero
                mapControl = mc;
75
                nf = NumberFormat.getInstance();
76
                nf.setMaximumFractionDigits(2);
77
        }
78
79
        /**
80
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
81
         */
82
        public Cursor getCursor() {
83
                return null;
84
        }
85
86
        /**
87
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
88
         */
89
        public boolean cancelDrawing() {
90
                return false;
91
        }
92
93
        /**
94 1438 jmorell
         * 050211, jmorell: M?todo modificado para mejorar la manera de mostrar las
95
         * coordenadas geod?sicas en la barra de estado. Muestra Lat y Lon y aumenta
96
         * el n?mero de decimales para cuando trabajemos en coordenadas geod?sicas.
97 1065 fernando
         * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
98 1007 vcaballero
         */
99 1065 fernando
        public void point(PointEvent event) throws BehaviorException {
100 1438 jmorell
                String[] axisText = new String[2];
101
                axisText[0] = "X = ";
102
                axisText[1] = "Y = ";
103 1007 vcaballero
                Point2D p = mapControl.getMapContext().getViewPort().toMapPoint(event.getPoint());
104 1438 jmorell
                setFractionDigits(p);
105
                axisText = setCoorDisplayText(axisText);
106 1024 fjp
                MainFrame mF = PluginServices.getMainFrame();
107 4226 caballero
108 1024 fjp
                if (mF != null)
109
                {
110 2710 fjp
            mF.getStatusBar().setMessage("1",
111
                    FConstant.NAMES[mapControl.getMapContext().getViewPort().getDistanceUnits()]);
112
            mF.getStatusBar().setMessage("6", "1:"+mapControl.getMapContext().getScaleView());
113 4226 caballero
            mF.getStatusBar().setMessage("7", mapControl.getViewPort().getProjection().getAbrev());
114
115 1024 fjp
                        mF.getStatusBar().setMessage("2",
116 2544 caballero
                                        axisText[0] + String.valueOf(nf.format(p.getX()/FMap.CHANGEM[mapControl.getViewPort().getDistanceUnits()])));
117 1024 fjp
                        mF.getStatusBar().setMessage("3",
118 2544 caballero
                                        axisText[1] + String.valueOf(nf.format(p.getY()/FMap.CHANGEM[mapControl.getViewPort().getDistanceUnits()])));
119 1024 fjp
                }
120 1007 vcaballero
        }
121 4226 caballero
122 1438 jmorell
        /**
123 4226 caballero
         * Aumenta el n?mero de decimales visibles cuando trabajamos con coordeandas
124 1438 jmorell
         * geod?sicas. En concreto se a?aden 8 decimales, con lo que logramos una
125
         * definici?n subm?trica.
126
         * 050211, jmorell.
127
         * @param p
128
         */
129
        private void setFractionDigits(Point2D p) {
130
                IProjection iProj = mapControl.getMapContext().getProjection();
131
                if (iProj.getAbrev().equals("EPSG:4326") || iProj.getAbrev().equals("EPSG:4230")) {
132
                        nf.setMaximumFractionDigits(8);
133
                } else {
134
                        nf.setMaximumFractionDigits(2);
135
                }
136
        }
137 4226 caballero
138 1438 jmorell
        /**
139
         * Cambia X e Y por Lat y Lon enb la barra de estado cuando trabajamos con
140
         * coordenadas geod?sicas.
141
         * 050211, jmorell.
142
         * @param p
143
         */
144
        private String[] setCoorDisplayText(String[] axisText) {
145
                IProjection iProj = mapControl.getMapContext().getProjection();
146
                if (iProj.getAbrev().equals("EPSG:4326") || iProj.getAbrev().equals("EPSG:4230")) {
147
                        axisText[0] = "Lon = ";
148
                        axisText[1] = "Lat = ";
149
                } else {
150
                        axisText[0] = "X = ";
151
                        axisText[1] = "Y = ";
152
                }
153
                return axisText;
154
        }
155
156 4226 caballero
        public void pointDoubleClick(PointEvent event) throws BehaviorException {
157
                // TODO Auto-generated method stub
158
159
        }
160
161 1007 vcaballero
}