Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toolListeners / StatusBarListener.java @ 7771

History | View | Annotate | Download (5.12 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.project.documents.view.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.MapContext;
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
                if (mF != null)
109
                {
110
            mF.getStatusBar().setMessage("units",
111
                    FConstant.NAMES[mapControl.getMapContext().getViewPort().getDistanceUnits()]);
112
            // FJP: No se debe llamar a setControlValue desde aqu?, porque
113
            // cambia la escala, y con ella el viewPort (adem?s, de
114
            // la vista que no es).
115
            // mF.getStatusBar().setControlValue("scale",String.valueOf(mapControl.getMapContext().getScaleView()));
116
            // Fin
117
                        mF.getStatusBar().setMessage("projection", mapControl.getViewPort().getProjection().getAbrev());
118

    
119
                        mF.getStatusBar().setMessage("x",
120
                                        axisText[0] + String.valueOf(nf.format(p.getX()/MapContext.CHANGEM[mapControl.getViewPort().getDistanceUnits()])));
121
                        mF.getStatusBar().setMessage("y",
122
                                        axisText[1] + String.valueOf(nf.format(p.getY()/MapContext.CHANGEM[mapControl.getViewPort().getDistanceUnits()])));
123
                }
124
        }
125

    
126
        /**
127
         * Aumenta el n?mero de decimales visibles cuando trabajamos con coordeandas
128
         * geod?sicas. En concreto se a?aden 8 decimales, con lo que logramos una
129
         * definici?n subm?trica.
130
         * 050211, jmorell.
131
         * @param p
132
         */
133
        private void setFractionDigits(Point2D p) {
134
                IProjection iProj = mapControl.getMapContext().getProjection();
135
                if (iProj.getAbrev().equals("EPSG:4326") || iProj.getAbrev().equals("EPSG:4230")) {
136
                        nf.setMaximumFractionDigits(8);
137
                } else {
138
                        nf.setMaximumFractionDigits(2);
139
                }
140
        }
141

    
142
        /**
143
         * Cambia X e Y por Lat y Lon enb la barra de estado cuando trabajamos con
144
         * coordenadas geod?sicas.
145
         * 050211, jmorell.
146
         * @param p
147
         */
148
        private String[] setCoorDisplayText(String[] axisText) {
149
                IProjection iProj = mapControl.getMapContext().getProjection();
150
                if (iProj.getAbrev().equals("EPSG:4326") || iProj.getAbrev().equals("EPSG:4230")) {
151
                        axisText[0] = "Lon = ";
152
                        axisText[1] = "Lat = ";
153
                } else {
154
                        axisText[0] = "X = ";
155
                        axisText[1] = "Y = ";
156
                }
157
                return axisText;
158
        }
159

    
160
        public void pointDoubleClick(PointEvent event) throws BehaviorException {
161
                // TODO Auto-generated method stub
162

    
163
        }
164

    
165
}