root / trunk / extensions / extCenterViewToPoint / src / com / iver / gvsig / centerviewtopoint / gui / InputCoordinatesPanel.java @ 13881
History | View | Annotate | Download (11.1 KB)
1 | 3525 | caballero | /*
|
---|---|---|---|
2 | * Created on 08-nov-2005
|
||
3 | *
|
||
4 | * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
5 | *
|
||
6 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
7 | *
|
||
8 | * This program is free software; you can redistribute it and/or
|
||
9 | * modify it under the terms of the GNU General Public License
|
||
10 | * as published by the Free Software Foundation; either version 2
|
||
11 | * of the License, or (at your option) any later version.
|
||
12 | *
|
||
13 | * This program is distributed in the hope that it will be useful,
|
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
16 | * GNU General Public License for more details.
|
||
17 | *
|
||
18 | * You should have received a copy of the GNU General Public License
|
||
19 | * along with this program; if not, write to the Free Software
|
||
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
21 | *
|
||
22 | * For more information, contact:
|
||
23 | *
|
||
24 | * Generalitat Valenciana
|
||
25 | * Conselleria d'Infraestructures i Transport
|
||
26 | * Av. Blasco Ib??ez, 50
|
||
27 | * 46010 VALENCIA
|
||
28 | * SPAIN
|
||
29 | *
|
||
30 | * +34 963862235
|
||
31 | * gvsig@gva.es
|
||
32 | * www.gvsig.gva.es
|
||
33 | *
|
||
34 | * or
|
||
35 | *
|
||
36 | * IVER T.I. S.A
|
||
37 | * Salamanca 50
|
||
38 | * 46005 Valencia
|
||
39 | * Spain
|
||
40 | *
|
||
41 | * +34 963163400
|
||
42 | * dac@iver.es
|
||
43 | */
|
||
44 | package com.iver.gvsig.centerviewtopoint.gui; |
||
45 | |||
46 | import java.awt.Color; |
||
47 | import java.awt.Component; |
||
48 | 6124 | jaume | import java.awt.event.ActionEvent; |
49 | import java.awt.event.ActionListener; |
||
50 | 3525 | caballero | import java.awt.event.MouseEvent; |
51 | import java.awt.geom.Point2D; |
||
52 | import java.awt.geom.Rectangle2D; |
||
53 | 9214 | fdiaz | import java.util.prefs.Preferences; |
54 | 3525 | caballero | |
55 | import javax.swing.JDialog; |
||
56 | 6123 | jaume | import javax.swing.JLabel; |
57 | 3525 | caballero | import javax.swing.JOptionPane; |
58 | import javax.swing.JPanel; |
||
59 | import javax.swing.JTextField; |
||
60 | |||
61 | import org.cresques.cts.IProjection; |
||
62 | 6124 | jaume | import org.gvsig.gui.beans.AcceptCancelPanel; |
63 | 3525 | caballero | |
64 | import com.iver.andami.PluginServices; |
||
65 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
66 | 6880 | cesar | import com.iver.andami.ui.mdiManager.WindowInfo; |
67 | 6878 | cesar | import com.iver.cit.gvsig.fmap.MapContext; |
68 | 3525 | caballero | import com.iver.cit.gvsig.fmap.MapControl; |
69 | 10841 | caballero | import com.iver.cit.gvsig.fmap.core.FShape; |
70 | 3525 | caballero | import com.iver.cit.gvsig.fmap.core.IGeometry; |
71 | import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
||
72 | 10841 | caballero | import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
73 | import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
||
74 | 3525 | caballero | import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
75 | import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
||
76 | import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
||
77 | import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
||
78 | 6123 | jaume | import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
79 | 7771 | caballero | import com.iver.cit.gvsig.project.documents.view.toolListeners.InfoListener; |
80 | 3525 | caballero | import com.iver.gvsig.centerviewpoint.CenterViewToPointExtension; |
81 | |||
82 | /**
|
||
83 | * The InputCoordinatesPanel class creates a JPanel where the
|
||
84 | * user can input the coordinates of the point of reference
|
||
85 | * for center the View.
|
||
86 | 6123 | jaume | *
|
87 | 3525 | caballero | * @author jmorell
|
88 | */
|
||
89 | 6877 | cesar | public class InputCoordinatesPanel extends JPanel implements IWindow { |
90 | 3525 | caballero | private static final long serialVersionUID = 1L; |
91 | private JLabel labelX = null; |
||
92 | private JTextField textX = null; |
||
93 | private JLabel labelY = null; |
||
94 | private JTextField textY = null; |
||
95 | private MapControl mapControl;
|
||
96 | 6880 | cesar | private WindowInfo viewInfo = null; |
97 | 3525 | caballero | private String firstCoordinate; |
98 | private String secondCoordinate; |
||
99 | private Point2D center; |
||
100 | private GraphicLayer lyr;
|
||
101 | private ColorChooserPanel colorPanel;
|
||
102 | 6124 | jaume | private AcceptCancelPanel okCancelPanel = null; |
103 | 3525 | caballero | /**
|
104 | * This is the default constructor
|
||
105 | */
|
||
106 | 6878 | cesar | public InputCoordinatesPanel(MapContext mapContext) {
|
107 | 3525 | caballero | super();
|
108 | this.mapControl = new MapControl(); |
||
109 | mapControl.setMapContext(mapContext); |
||
110 | lyr=mapControl.getMapContext().getGraphicsLayer(); |
||
111 | initializeCoordinates(); |
||
112 | initialize(); |
||
113 | } |
||
114 | 11154 | cesar | |
115 | /**
|
||
116 | * Sets the proper text for the first and second coordinate labels,
|
||
117 | * depending on the kind of selected projection.
|
||
118 | *
|
||
119 | */
|
||
120 | 3525 | caballero | private void initializeCoordinates() { |
121 | IProjection proj = mapControl.getProjection(); |
||
122 | String projName = proj.getAbrev();
|
||
123 | if (projName.equals("EPSG:23030") || projName.equals("EPSG:27492") || projName.equals("EPSG:42101") || projName.equals("EPSG:42304")) { |
||
124 | firstCoordinate = "X";
|
||
125 | secondCoordinate = "Y";
|
||
126 | } else if (projName.equals("EPSG:4230") || projName.equals("EPSG:4326")) { |
||
127 | firstCoordinate = "Lon";
|
||
128 | secondCoordinate = "Lat";
|
||
129 | } else {
|
||
130 | System.out.println("Proyecci?n: " + projName); |
||
131 | System.out.println("Proyecci?n no soportada."); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | 11154 | cesar | /**
|
136 | * Move the view's extent so that the specified point gets
|
||
137 | * centered.
|
||
138 | *
|
||
139 | * @throws Exception
|
||
140 | */
|
||
141 | 3525 | caballero | private void zoomToCoordinates() throws Exception { |
142 | try{
|
||
143 | Rectangle2D oldExtent = mapControl.getViewPort().getAdjustedExtent();
|
||
144 | double oldCenterX = oldExtent.getCenterX();
|
||
145 | double oldCenterY = oldExtent.getCenterY();
|
||
146 | double centerX = (new Double((String)textX.getText())).doubleValue(); |
||
147 | double centerY = (new Double((String)textY.getText())).doubleValue(); |
||
148 | center=new Point2D.Double(centerX,centerY); |
||
149 | double movX = centerX-oldCenterX;
|
||
150 | double movY = centerY-oldCenterY;
|
||
151 | double upperLeftCornerX = oldExtent.getMinX()+movX;
|
||
152 | double upperLeftCornerY = oldExtent.getMinY()+movY;
|
||
153 | double width = oldExtent.getWidth();
|
||
154 | double height = oldExtent.getHeight();
|
||
155 | Rectangle2D extent = new Rectangle2D.Double(upperLeftCornerX, upperLeftCornerY, width, height); |
||
156 | mapControl.getViewPort().setExtent(extent); |
||
157 | }catch (NumberFormatException e) { |
||
158 | throw new Exception(); |
||
159 | } |
||
160 | 6123 | jaume | |
161 | 3525 | caballero | } |
162 | |||
163 | /**
|
||
164 | * This method initializes this
|
||
165 | 6123 | jaume | *
|
166 | 3525 | caballero | * @return void
|
167 | */
|
||
168 | private void initialize() { |
||
169 | labelY = new JLabel(); |
||
170 | labelY.setBounds(10, 35, 28, 20); |
||
171 | labelY.setText(secondCoordinate + ":");
|
||
172 | labelX = new JLabel(); |
||
173 | labelX.setBounds(10, 10, 28, 20); |
||
174 | labelX.setText(firstCoordinate + ":");
|
||
175 | this.setLayout(null); |
||
176 | 6136 | jaume | this.setSize(307, 100); |
177 | 3525 | caballero | this.add(labelX, null); |
178 | this.add(getTextX(), null); |
||
179 | this.add(labelY, null); |
||
180 | this.add(getTextY(), null); |
||
181 | this.add(getColorPanel());
|
||
182 | 6124 | jaume | this.add(getOkCancelPanel(), null); |
183 | 3525 | caballero | } |
184 | |||
185 | /**
|
||
186 | 6123 | jaume | * This method initializes textX
|
187 | *
|
||
188 | * @return javax.swing.JTextField
|
||
189 | */
|
||
190 | 3525 | caballero | private JTextField getTextX() { |
191 | if (textX == null) { |
||
192 | textX = new JTextField(); |
||
193 | 6136 | jaume | textX.setBounds(40, 10, 260, 20); |
194 | 6123 | jaume | textX.addActionListener(new java.awt.event.ActionListener() {
|
195 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
196 | 3525 | caballero | textX.transferFocus(); |
197 | } |
||
198 | }); |
||
199 | } |
||
200 | return textX;
|
||
201 | } |
||
202 | |||
203 | /**
|
||
204 | 6123 | jaume | * This method initializes textY
|
205 | *
|
||
206 | * @return javax.swing.JTextField
|
||
207 | */
|
||
208 | 3525 | caballero | private JTextField getTextY() { |
209 | if (textY == null) { |
||
210 | textY = new JTextField(); |
||
211 | 6136 | jaume | textY.setBounds(40, 35, 260, 20); |
212 | 6123 | jaume | textY.addActionListener(new java.awt.event.ActionListener() {
|
213 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
214 | 3525 | caballero | textY.transferFocus(); |
215 | } |
||
216 | }); |
||
217 | } |
||
218 | return textY;
|
||
219 | } |
||
220 | |||
221 | /* (non-Javadoc)
|
||
222 | * @see com.iver.andami.ui.mdiManager.View#getViewInfo()
|
||
223 | */
|
||
224 | 6880 | cesar | public WindowInfo getWindowInfo() {
|
225 | 3525 | caballero | // TODO Auto-generated method stub
|
226 | if (viewInfo == null) { |
||
227 | 6880 | cesar | viewInfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
228 | 3525 | caballero | viewInfo.setTitle(PluginServices.getText(this,"Centrar_la_Vista_sobre_un_punto")); |
229 | 6136 | jaume | viewInfo.setWidth(this.getWidth()+8); |
230 | viewInfo.setHeight(this.getHeight());
|
||
231 | 3525 | caballero | } |
232 | return viewInfo;
|
||
233 | } |
||
234 | 11154 | cesar | /**
|
235 | * Opens the infoByPoint dialog for the selected point.
|
||
236 | *
|
||
237 | */
|
||
238 | 3525 | caballero | private void openInfo(){ |
239 | InfoListener infoListener=new InfoListener(mapControl);
|
||
240 | MouseEvent e=new MouseEvent((Component)(((CenterViewToPointExtension)PluginServices.getExtension(CenterViewToPointExtension.class)).getView()),MouseEvent.BUTTON1,MouseEvent.ACTION_EVENT_MASK,MouseEvent.MOUSE_CLICKED,500,400,1,true); |
||
241 | Point2D centerPixels=mapControl.getViewPort().fromMapPoint(center.getX(),center.getY());
|
||
242 | PointEvent pe=new PointEvent(centerPixels,e);
|
||
243 | try {
|
||
244 | infoListener.point(pe); |
||
245 | } catch (BehaviorException e1) {
|
||
246 | // TODO Auto-generated catch block
|
||
247 | e1.printStackTrace(); |
||
248 | } |
||
249 | if (mapControl.getMapContext().getLayers().getActives().length==0){ |
||
250 | 5509 | jaume | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"no_hay_ninguna_capa_seleccionada")+" \n"+ |
251 | 5258 | jmvivo | PluginServices.getText(this,"debe_seleccionar_las_capas_de_las_que_quiera_obtener_informacion")); |
252 | 3525 | caballero | } |
253 | } |
||
254 | 11154 | cesar | |
255 | /**
|
||
256 | * Draws the selected point on the view.
|
||
257 | *
|
||
258 | * @param color
|
||
259 | */
|
||
260 | 3525 | caballero | private void drawPoint(Color color){ |
261 | CenterViewToPointExtension.COLOR=color; |
||
262 | lyr.clearAllGraphics(); |
||
263 | 10841 | caballero | ISymbol theSymbol = SymbologyFactory.createDefaultSymbolByShapeType(FShape.POINT,color); |
264 | 3525 | caballero | int idSymbol = lyr.addSymbol(theSymbol);
|
265 | IGeometry geom = ShapeFactory.createPoint2D(center.getX(),center.getY()); |
||
266 | FGraphic theGraphic = new FGraphic(geom, idSymbol);
|
||
267 | lyr.addGraphic(theGraphic); |
||
268 | mapControl.drawGraphics(); |
||
269 | |||
270 | } |
||
271 | |||
272 | 6123 | jaume | |
273 | 3525 | caballero | /**
|
274 | 6123 | jaume | * This method initializes jPanel
|
275 | *
|
||
276 | * @return javax.swing.JPanel
|
||
277 | 3525 | caballero | */
|
278 | private JPanel getColorPanel() { |
||
279 | if (colorPanel==null){ |
||
280 | colorPanel=new ColorChooserPanel();
|
||
281 | colorPanel.setAlpha(250);
|
||
282 | colorPanel.setColor(CenterViewToPointExtension.COLOR); |
||
283 | 6136 | jaume | colorPanel.setBounds(new java.awt.Rectangle(40,59,123,24)); |
284 | 3525 | caballero | } |
285 | return colorPanel;
|
||
286 | } |
||
287 | 6124 | jaume | |
288 | /**
|
||
289 | * This method initializes okCancelPanel
|
||
290 | *
|
||
291 | * @return javax.swing.JPanel
|
||
292 | */
|
||
293 | private AcceptCancelPanel getOkCancelPanel() {
|
||
294 | if (okCancelPanel == null) { |
||
295 | ActionListener okAction, cancelAction;
|
||
296 | okAction = new java.awt.event.ActionListener() {
|
||
297 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
298 | try{
|
||
299 | zoomToCoordinates(); |
||
300 | }catch (Exception e1) { |
||
301 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"formato_de_numero_incorrecto")); |
||
302 | return;
|
||
303 | } |
||
304 | // y sale.
|
||
305 | if (PluginServices.getMainFrame() == null) |
||
306 | ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
||
307 | else
|
||
308 | 6880 | cesar | PluginServices.getMDIManager().closeWindow(InputCoordinatesPanel.this); |
309 | 9214 | fdiaz | Preferences prefs = Preferences.userRoot().node( "gvsig.centerViewToPoint" ); |
310 | if( prefs.get("showInfo", "True").equalsIgnoreCase("True")){ |
||
311 | openInfo(); |
||
312 | } |
||
313 | 6124 | jaume | drawPoint(((ColorChooserPanel)getColorPanel()).getColor()); |
314 | } |
||
315 | }; |
||
316 | cancelAction = new ActionListener() { |
||
317 | public void actionPerformed(ActionEvent e) { |
||
318 | closeThis(); |
||
319 | } |
||
320 | }; |
||
321 | okCancelPanel = new AcceptCancelPanel(okAction, cancelAction);
|
||
322 | 6136 | jaume | okCancelPanel.setBounds(new java.awt.Rectangle(40, 88, 260, 30)); |
323 | 6124 | jaume | } |
324 | return okCancelPanel;
|
||
325 | } |
||
326 | |||
327 | 11154 | cesar | /**
|
328 | * Close the window.
|
||
329 | *
|
||
330 | */
|
||
331 | 6124 | jaume | private void closeThis() { |
332 | 6880 | cesar | PluginServices.getMDIManager().closeWindow(this);
|
333 | 6124 | jaume | |
334 | } |
||
335 | |||
336 | |||
337 | 3525 | caballero | } // @jve:decl-index=0:visual-constraint="103,18" |