root / trunk / extensions / extCenterViewToPoint / src / com / iver / gvsig / centerviewtopoint / gui / InputCoordinatesPanel.java @ 7771
History | View | Annotate | Download (10.3 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 | |||
54 | import javax.swing.JDialog; |
||
55 | 6123 | jaume | import javax.swing.JLabel; |
56 | 3525 | caballero | import javax.swing.JOptionPane; |
57 | import javax.swing.JPanel; |
||
58 | import javax.swing.JTextField; |
||
59 | |||
60 | import org.cresques.cts.IProjection; |
||
61 | 6124 | jaume | import org.gvsig.gui.beans.AcceptCancelPanel; |
62 | 3525 | caballero | |
63 | import com.iver.andami.PluginServices; |
||
64 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
65 | 6880 | cesar | import com.iver.andami.ui.mdiManager.WindowInfo; |
66 | 6878 | cesar | import com.iver.cit.gvsig.fmap.MapContext; |
67 | 3525 | caballero | import com.iver.cit.gvsig.fmap.MapControl; |
68 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
69 | import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
||
70 | import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
||
71 | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
||
72 | import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
||
73 | import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
||
74 | import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
||
75 | import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
||
76 | 6123 | jaume | import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
77 | 7771 | caballero | import com.iver.cit.gvsig.project.documents.view.toolListeners.InfoListener; |
78 | 3525 | caballero | import com.iver.gvsig.centerviewpoint.CenterViewToPointExtension; |
79 | |||
80 | /**
|
||
81 | * The InputCoordinatesPanel class creates a JPanel where the
|
||
82 | * user can input the coordinates of the point of reference
|
||
83 | * for center the View.
|
||
84 | 6123 | jaume | *
|
85 | 3525 | caballero | * @author jmorell
|
86 | */
|
||
87 | 6877 | cesar | public class InputCoordinatesPanel extends JPanel implements IWindow { |
88 | 3525 | caballero | private static final long serialVersionUID = 1L; |
89 | private JLabel labelX = null; |
||
90 | private JTextField textX = null; |
||
91 | private JLabel labelY = null; |
||
92 | private JTextField textY = null; |
||
93 | private MapControl mapControl;
|
||
94 | 6880 | cesar | private WindowInfo viewInfo = null; |
95 | 3525 | caballero | private String firstCoordinate; |
96 | private String secondCoordinate; |
||
97 | private Point2D center; |
||
98 | private GraphicLayer lyr;
|
||
99 | private ColorChooserPanel colorPanel;
|
||
100 | 6124 | jaume | private AcceptCancelPanel okCancelPanel = null; |
101 | 3525 | caballero | /**
|
102 | * This is the default constructor
|
||
103 | */
|
||
104 | 6878 | cesar | public InputCoordinatesPanel(MapContext mapContext) {
|
105 | 3525 | caballero | super();
|
106 | this.mapControl = new MapControl(); |
||
107 | mapControl.setMapContext(mapContext); |
||
108 | lyr=mapControl.getMapContext().getGraphicsLayer(); |
||
109 | initializeCoordinates(); |
||
110 | initialize(); |
||
111 | } |
||
112 | 6123 | jaume | |
113 | 3525 | caballero | private void initializeCoordinates() { |
114 | IProjection proj = mapControl.getProjection(); |
||
115 | String projName = proj.getAbrev();
|
||
116 | if (projName.equals("EPSG:23030") || projName.equals("EPSG:27492") || projName.equals("EPSG:42101") || projName.equals("EPSG:42304")) { |
||
117 | firstCoordinate = "X";
|
||
118 | secondCoordinate = "Y";
|
||
119 | } else if (projName.equals("EPSG:4230") || projName.equals("EPSG:4326")) { |
||
120 | firstCoordinate = "Lon";
|
||
121 | secondCoordinate = "Lat";
|
||
122 | } else {
|
||
123 | System.out.println("Proyecci?n: " + projName); |
||
124 | System.out.println("Proyecci?n no soportada."); |
||
125 | } |
||
126 | } |
||
127 | |||
128 | private void zoomToCoordinates() throws Exception { |
||
129 | try{
|
||
130 | Rectangle2D oldExtent = mapControl.getViewPort().getAdjustedExtent();
|
||
131 | double oldCenterX = oldExtent.getCenterX();
|
||
132 | double oldCenterY = oldExtent.getCenterY();
|
||
133 | double centerX = (new Double((String)textX.getText())).doubleValue(); |
||
134 | double centerY = (new Double((String)textY.getText())).doubleValue(); |
||
135 | center=new Point2D.Double(centerX,centerY); |
||
136 | double movX = centerX-oldCenterX;
|
||
137 | double movY = centerY-oldCenterY;
|
||
138 | double upperLeftCornerX = oldExtent.getMinX()+movX;
|
||
139 | double upperLeftCornerY = oldExtent.getMinY()+movY;
|
||
140 | double width = oldExtent.getWidth();
|
||
141 | double height = oldExtent.getHeight();
|
||
142 | Rectangle2D extent = new Rectangle2D.Double(upperLeftCornerX, upperLeftCornerY, width, height); |
||
143 | mapControl.getViewPort().setExtent(extent); |
||
144 | }catch (NumberFormatException e) { |
||
145 | throw new Exception(); |
||
146 | } |
||
147 | 6123 | jaume | |
148 | 3525 | caballero | } |
149 | |||
150 | /**
|
||
151 | * This method initializes this
|
||
152 | 6123 | jaume | *
|
153 | 3525 | caballero | * @return void
|
154 | */
|
||
155 | private void initialize() { |
||
156 | labelY = new JLabel(); |
||
157 | labelY.setBounds(10, 35, 28, 20); |
||
158 | labelY.setText(secondCoordinate + ":");
|
||
159 | labelX = new JLabel(); |
||
160 | labelX.setBounds(10, 10, 28, 20); |
||
161 | labelX.setText(firstCoordinate + ":");
|
||
162 | this.setLayout(null); |
||
163 | 6136 | jaume | this.setSize(307, 100); |
164 | 3525 | caballero | this.add(labelX, null); |
165 | this.add(getTextX(), null); |
||
166 | this.add(labelY, null); |
||
167 | this.add(getTextY(), null); |
||
168 | this.add(getColorPanel());
|
||
169 | 6124 | jaume | this.add(getOkCancelPanel(), null); |
170 | 3525 | caballero | } |
171 | |||
172 | /**
|
||
173 | 6123 | jaume | * This method initializes textX
|
174 | *
|
||
175 | * @return javax.swing.JTextField
|
||
176 | */
|
||
177 | 3525 | caballero | private JTextField getTextX() { |
178 | if (textX == null) { |
||
179 | textX = new JTextField(); |
||
180 | 6136 | jaume | textX.setBounds(40, 10, 260, 20); |
181 | 6123 | jaume | textX.addActionListener(new java.awt.event.ActionListener() {
|
182 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
183 | 3525 | caballero | textX.transferFocus(); |
184 | } |
||
185 | }); |
||
186 | } |
||
187 | return textX;
|
||
188 | } |
||
189 | |||
190 | /**
|
||
191 | 6123 | jaume | * This method initializes textY
|
192 | *
|
||
193 | * @return javax.swing.JTextField
|
||
194 | */
|
||
195 | 3525 | caballero | private JTextField getTextY() { |
196 | if (textY == null) { |
||
197 | textY = new JTextField(); |
||
198 | 6136 | jaume | textY.setBounds(40, 35, 260, 20); |
199 | 6123 | jaume | textY.addActionListener(new java.awt.event.ActionListener() {
|
200 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
201 | 3525 | caballero | textY.transferFocus(); |
202 | } |
||
203 | }); |
||
204 | } |
||
205 | return textY;
|
||
206 | } |
||
207 | |||
208 | /* (non-Javadoc)
|
||
209 | * @see com.iver.andami.ui.mdiManager.View#getViewInfo()
|
||
210 | */
|
||
211 | 6880 | cesar | public WindowInfo getWindowInfo() {
|
212 | 3525 | caballero | // TODO Auto-generated method stub
|
213 | if (viewInfo == null) { |
||
214 | 6880 | cesar | viewInfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
215 | 3525 | caballero | viewInfo.setTitle(PluginServices.getText(this,"Centrar_la_Vista_sobre_un_punto")); |
216 | 6136 | jaume | viewInfo.setWidth(this.getWidth()+8); |
217 | viewInfo.setHeight(this.getHeight());
|
||
218 | 3525 | caballero | } |
219 | return viewInfo;
|
||
220 | } |
||
221 | private void openInfo(){ |
||
222 | InfoListener infoListener=new InfoListener(mapControl);
|
||
223 | MouseEvent e=new MouseEvent((Component)(((CenterViewToPointExtension)PluginServices.getExtension(CenterViewToPointExtension.class)).getView()),MouseEvent.BUTTON1,MouseEvent.ACTION_EVENT_MASK,MouseEvent.MOUSE_CLICKED,500,400,1,true); |
||
224 | Point2D centerPixels=mapControl.getViewPort().fromMapPoint(center.getX(),center.getY());
|
||
225 | PointEvent pe=new PointEvent(centerPixels,e);
|
||
226 | try {
|
||
227 | infoListener.point(pe); |
||
228 | } catch (BehaviorException e1) {
|
||
229 | // TODO Auto-generated catch block
|
||
230 | e1.printStackTrace(); |
||
231 | } |
||
232 | if (mapControl.getMapContext().getLayers().getActives().length==0){ |
||
233 | 5509 | jaume | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"no_hay_ninguna_capa_seleccionada")+" \n"+ |
234 | 5258 | jmvivo | PluginServices.getText(this,"debe_seleccionar_las_capas_de_las_que_quiera_obtener_informacion")); |
235 | 3525 | caballero | } |
236 | } |
||
237 | private void drawPoint(Color color){ |
||
238 | CenterViewToPointExtension.COLOR=color; |
||
239 | lyr.clearAllGraphics(); |
||
240 | 6123 | jaume | FSymbol theSymbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT,color);
|
241 | 3525 | caballero | int idSymbol = lyr.addSymbol(theSymbol);
|
242 | IGeometry geom = ShapeFactory.createPoint2D(center.getX(),center.getY()); |
||
243 | FGraphic theGraphic = new FGraphic(geom, idSymbol);
|
||
244 | lyr.addGraphic(theGraphic); |
||
245 | mapControl.drawGraphics(); |
||
246 | |||
247 | } |
||
248 | |||
249 | 6123 | jaume | |
250 | 3525 | caballero | /**
|
251 | 6123 | jaume | * This method initializes jPanel
|
252 | *
|
||
253 | * @return javax.swing.JPanel
|
||
254 | 3525 | caballero | */
|
255 | private JPanel getColorPanel() { |
||
256 | if (colorPanel==null){ |
||
257 | colorPanel=new ColorChooserPanel();
|
||
258 | colorPanel.setAlpha(250);
|
||
259 | colorPanel.setColor(CenterViewToPointExtension.COLOR); |
||
260 | 6136 | jaume | colorPanel.setBounds(new java.awt.Rectangle(40,59,123,24)); |
261 | 3525 | caballero | } |
262 | return colorPanel;
|
||
263 | } |
||
264 | 6124 | jaume | |
265 | /**
|
||
266 | * This method initializes okCancelPanel
|
||
267 | *
|
||
268 | * @return javax.swing.JPanel
|
||
269 | */
|
||
270 | private AcceptCancelPanel getOkCancelPanel() {
|
||
271 | if (okCancelPanel == null) { |
||
272 | ActionListener okAction, cancelAction;
|
||
273 | okAction = new java.awt.event.ActionListener() {
|
||
274 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
275 | try{
|
||
276 | zoomToCoordinates(); |
||
277 | }catch (Exception e1) { |
||
278 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"formato_de_numero_incorrecto")); |
||
279 | return;
|
||
280 | } |
||
281 | // y sale.
|
||
282 | if (PluginServices.getMainFrame() == null) |
||
283 | ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
||
284 | else
|
||
285 | 6880 | cesar | PluginServices.getMDIManager().closeWindow(InputCoordinatesPanel.this); |
286 | 6124 | jaume | |
287 | openInfo(); |
||
288 | drawPoint(((ColorChooserPanel)getColorPanel()).getColor()); |
||
289 | } |
||
290 | }; |
||
291 | cancelAction = new ActionListener() { |
||
292 | public void actionPerformed(ActionEvent e) { |
||
293 | closeThis(); |
||
294 | } |
||
295 | }; |
||
296 | okCancelPanel = new AcceptCancelPanel(okAction, cancelAction);
|
||
297 | 6136 | jaume | okCancelPanel.setBounds(new java.awt.Rectangle(40, 88, 260, 30)); |
298 | 6124 | jaume | } |
299 | return okCancelPanel;
|
||
300 | } |
||
301 | |||
302 | private void closeThis() { |
||
303 | 6880 | cesar | PluginServices.getMDIManager().closeWindow(this);
|
304 | 6124 | jaume | |
305 | } |
||
306 | |||
307 | |||
308 | 3525 | caballero | } // @jve:decl-index=0:visual-constraint="103,18" |