Statistics
| Revision:

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

History | View | Annotate | Download (4.8 KB)

1
/* 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
package com.iver.cit.gvsig.gui.toolListeners;
42

    
43
import java.awt.Cursor;
44
import java.awt.geom.Point2D;
45
import java.text.NumberFormat;
46

    
47
import org.cresques.cts.IProjection;
48

    
49
import com.iver.andami.PluginServices;
50
import com.iver.andami.ui.mdiFrame.MainFrame;
51
import com.iver.cit.gvsig.fmap.FMap;
52
import com.iver.cit.gvsig.fmap.MapControl;
53
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
54
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
55
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
56
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener;
57

    
58

    
59
/**
60
 * DOCUMENT ME!
61
 *
62
 * @author Vicente Caballero Navarro
63
 */
64
public class StatusBarListener implements PointListener {
65
        private MapControl mapControl = null;
66
        private NumberFormat nf = null;
67

    
68
        /**
69
         * Crea un nuevo StatusBarListener.
70
         *
71
         * @param mc DOCUMENT ME!
72
         */
73
        public StatusBarListener(MapControl mc) {
74
                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
         * 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
         * @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) throws BehaviorException {
100
                String[] axisText = new String[2];
101
                axisText[0] = "X = ";
102
                axisText[1] = "Y = ";
103
                Point2D p = mapControl.getMapContext().getViewPort().toMapPoint(event.getPoint());
104
                setFractionDigits(p);
105
                axisText = setCoorDisplayText(axisText);
106
                MainFrame mF = PluginServices.getMainFrame();
107
                        
108
                PluginServices.getMainFrame().getStatusBar().setMessage("1",
109
                            FConstant.NAMES[mapControl.getMapContext().getViewPort().getDistanceUnits()]);
110
            PluginServices.getMainFrame().getStatusBar().setMessage("6", "1:"+mapControl.getMapContext().getScaleView());
111
                PluginServices.getMainFrame().getStatusBar().setMessage("7", mapControl.getViewPort().getProjection().getAbrev()); 
112

    
113
                
114
                if (mF != null)
115
                {
116
                        mF.getStatusBar().setMessage("2",
117
                                        axisText[0] + String.valueOf(nf.format(p.getX()/FMap.CHANGEM[mapControl.getViewPort().getDistanceUnits()])));
118
                        mF.getStatusBar().setMessage("3",
119
                                        axisText[1] + String.valueOf(nf.format(p.getY()/FMap.CHANGEM[mapControl.getViewPort().getDistanceUnits()])));
120
                }
121
        }
122
        
123
        /**
124
         * Aumenta el n?mero de decimales visibles cuando trabajamos con coordeandas 
125
         * geod?sicas. En concreto se a?aden 8 decimales, con lo que logramos una
126
         * definici?n subm?trica.
127
         * 050211, jmorell.
128
         * @param p
129
         */
130
        private void setFractionDigits(Point2D p) {
131
                IProjection iProj = mapControl.getMapContext().getProjection();
132
                if (iProj.getAbrev().equals("EPSG:4326") || iProj.getAbrev().equals("EPSG:4230")) {
133
                        nf.setMaximumFractionDigits(8);
134
                } else {
135
                        nf.setMaximumFractionDigits(2);
136
                }
137
        }
138
        
139
        /**
140
         * Cambia X e Y por Lat y Lon enb la barra de estado cuando trabajamos con
141
         * coordenadas geod?sicas.
142
         * 050211, jmorell.
143
         * @param p
144
         */
145
        private String[] setCoorDisplayText(String[] axisText) {
146
                IProjection iProj = mapControl.getMapContext().getProjection();
147
                if (iProj.getAbrev().equals("EPSG:4326") || iProj.getAbrev().equals("EPSG:4230")) {
148
                        axisText[0] = "Lon = ";
149
                        axisText[1] = "Lat = ";
150
                } else {
151
                        axisText[0] = "X = ";
152
                        axisText[1] = "Y = ";
153
                }
154
                return axisText;
155
        }
156

    
157
}