root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toolListeners / StatusBarListener.java @ 9956
History | View | Annotate | Download (6.65 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 |
import org.gvsig.gui.beans.controls.combolabel.ComboCoords; |
49 |
|
50 |
import com.iver.andami.PluginServices; |
51 |
import com.iver.andami.ui.mdiFrame.MainFrame; |
52 |
import com.iver.cit.gvsig.fmap.MapContext; |
53 |
import com.iver.cit.gvsig.fmap.MapControl; |
54 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
55 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
56 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
57 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener; |
58 |
import com.iver.cit.gvsig.project.documents.layout.Attributes; |
59 |
|
60 |
|
61 |
/**
|
62 |
* DOCUMENT ME!
|
63 |
*
|
64 |
* @author Vicente Caballero Navarro
|
65 |
*/
|
66 |
public class StatusBarListener implements PointListener { |
67 |
private MapControl mapControl = null; |
68 |
private NumberFormat nf = null; |
69 |
|
70 |
/**
|
71 |
* Crea un nuevo StatusBarListener.
|
72 |
*
|
73 |
* @param mc DOCUMENT ME!
|
74 |
*/
|
75 |
public StatusBarListener(MapControl mc) {
|
76 |
mapControl = mc; |
77 |
nf = NumberFormat.getInstance();
|
78 |
nf.setMaximumFractionDigits(2);
|
79 |
} |
80 |
|
81 |
/**
|
82 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
83 |
*/
|
84 |
public Cursor getCursor() { |
85 |
return null; |
86 |
} |
87 |
|
88 |
/**
|
89 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
90 |
*/
|
91 |
public boolean cancelDrawing() { |
92 |
return false; |
93 |
} |
94 |
|
95 |
/**
|
96 |
* 050211, jmorell: M?todo modificado para mejorar la manera de mostrar las
|
97 |
* coordenadas geod?sicas en la barra de estado. Muestra Lat y Lon y aumenta
|
98 |
* el n?mero de decimales para cuando trabajemos en coordenadas geod?sicas.
|
99 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
100 |
*/
|
101 |
public void point(PointEvent event) throws BehaviorException { |
102 |
String[] axisText = new String[2]; |
103 |
axisText[0] = "X = "; |
104 |
axisText[1] = "Y = "; |
105 |
Point2D p = mapControl.getMapContext().getViewPort().toMapPoint(event.getPoint());
|
106 |
setFractionDigits(p); |
107 |
axisText = setCoorDisplayText(axisText); |
108 |
MainFrame mF = PluginServices.getMainFrame(); |
109 |
|
110 |
if (mF != null){ |
111 |
|
112 |
mF.getStatusBar().setMessage("units",
|
113 |
PluginServices.getText(this, FConstant.NAMES[mapControl.getMapContext().getViewPort().getDistanceUnits()]));
|
114 |
// FJP: No se debe llamar a setControlValue desde aqu?, porque
|
115 |
// cambia la escala, y con ella el viewPort (adem?s, de
|
116 |
// la vista que no es).
|
117 |
// mF.getStatusBar().setControlValue("scale",String.valueOf(mapControl.getMapContext().getScaleView()));
|
118 |
// Fin
|
119 |
mF.getStatusBar().setMessage("projection", mapControl.getViewPort().getProjection().getAbrev());
|
120 |
|
121 |
String[] coords=getCoords(p); |
122 |
// mF.getStatusBar().setMessage("x",
|
123 |
// axisText[0] + coords[0]);
|
124 |
// mF.getStatusBar().setMessage("y",
|
125 |
// axisText[1] + coords[1]);
|
126 |
ComboCoords combocoords=(ComboCoords)PluginServices.getMainFrame().getComponentByName("coords");
|
127 |
combocoords.setLabelX(axisText[0]);
|
128 |
combocoords.setLabelY(axisText[1]);
|
129 |
combocoords.setValueX(coords[0]);
|
130 |
combocoords.setValueY(coords[1]);
|
131 |
} |
132 |
} |
133 |
|
134 |
/**
|
135 |
* Aumenta el n?mero de decimales visibles cuando trabajamos con coordeandas
|
136 |
* geod?sicas. En concreto se a?aden 8 decimales, con lo que logramos una
|
137 |
* definici?n subm?trica.
|
138 |
* 050211, jmorell.
|
139 |
* @param p
|
140 |
*/
|
141 |
public void setFractionDigits(Point2D p) { |
142 |
IProjection iProj = mapControl.getMapContext().getProjection(); |
143 |
if (!iProj.isProjected()) {
|
144 |
nf.setMaximumFractionDigits(8);
|
145 |
} else {
|
146 |
nf.setMaximumFractionDigits(2);
|
147 |
} |
148 |
} |
149 |
|
150 |
/**
|
151 |
* Cambia X e Y por Lat y Lon enb la barra de estado cuando trabajamos con
|
152 |
* coordenadas geod?sicas.
|
153 |
* 050211, jmorell.
|
154 |
* @param p
|
155 |
*/
|
156 |
public String[] setCoorDisplayText(String[] axisText) { |
157 |
IProjection iProj = mapControl.getMapContext().getProjection(); |
158 |
if (!iProj.isProjected() || mapControl.getViewPort().getDistanceUnits()==Attributes.NAMES.length-1) { |
159 |
axisText[0] = "Lon = "; |
160 |
axisText[1] = "Lat = "; |
161 |
} else {
|
162 |
axisText[0] = "X = "; |
163 |
axisText[1] = "Y = "; |
164 |
} |
165 |
return axisText;
|
166 |
} |
167 |
private String formatDegrees(double d) { |
168 |
String signo = d<0 ? "-" : ""; |
169 |
d = Math.abs(d);
|
170 |
long grado = 0; |
171 |
double minuto = 0; |
172 |
double segundo = 0; |
173 |
|
174 |
grado = (long)(d);
|
175 |
minuto = (d - grado) * 60;
|
176 |
segundo = (minuto - (long) minuto)*60; |
177 |
// System.out.println("Grados: " + grado);
|
178 |
// System.out.println("Minutos: " + minuto);
|
179 |
// System.out.println("Segundos: " + segundo);
|
180 |
return signo+grado+"? "+(long) minuto+"' "+(long)segundo+"''"; |
181 |
} |
182 |
public String[] getCoords(Point2D p) { |
183 |
String[] coords=new String[2]; |
184 |
IProjection iProj = mapControl.getMapContext().getProjection(); |
185 |
if (!iProj.isProjected()) {
|
186 |
coords[0]=String.valueOf(formatDegrees(p.getX())); |
187 |
coords[1]=String.valueOf(formatDegrees(p.getY())); |
188 |
} else {
|
189 |
if (mapControl.getViewPort().getDistanceUnits()==Attributes.NAMES.length-1) { |
190 |
Point2D pgeo=iProj.toGeo(p);
|
191 |
coords[0]=String.valueOf(formatDegrees(pgeo.getX())); |
192 |
coords[1]=String.valueOf(formatDegrees(pgeo.getY())); |
193 |
}else {
|
194 |
coords[0]=String.valueOf(nf.format((p.getX()/MapContext.CHANGEM[mapControl.getViewPort().getDistanceUnits()])*MapContext.CHANGEM[mapControl.getViewPort().getMapUnits()])); |
195 |
coords[1]=String.valueOf(nf.format((p.getY()/MapContext.CHANGEM[mapControl.getViewPort().getDistanceUnits()])*MapContext.CHANGEM[mapControl.getViewPort().getMapUnits()])); |
196 |
} |
197 |
} |
198 |
return coords;
|
199 |
} |
200 |
public void pointDoubleClick(PointEvent event) throws BehaviorException { |
201 |
// TODO Auto-generated method stub
|
202 |
|
203 |
} |
204 |
|
205 |
} |