svn-gvsig-desktop / trunk / extensions / extGPS / src / org / gvsig / gps / panel / GPSConfigPanel.java @ 4827
History | View | Annotate | Download (14.9 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 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 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: GPSConfigPanel.java 4827 2006-04-12 06:51:56Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.8 2006-04-12 06:49:47 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.7 2006/04/11 13:19:51 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.6 2006/04/10 17:13:28 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.5 2006/04/10 14:09:46 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.4 2006/04/10 11:21:52 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.3 2006/04/07 12:45:55 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.2 2006/04/07 08:27:48 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.1 2006/04/06 10:35:14 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
*
|
71 |
*/
|
72 |
package org.gvsig.gps.panel; |
73 |
|
74 |
import gnu.io.CommPortIdentifier; |
75 |
|
76 |
import java.awt.Component; |
77 |
import java.util.Enumeration; |
78 |
|
79 |
import javax.swing.JButton; |
80 |
import javax.swing.JComboBox; |
81 |
import javax.swing.JLabel; |
82 |
import javax.swing.JOptionPane; |
83 |
import javax.swing.JPanel; |
84 |
import javax.swing.JTextField; |
85 |
import javax.swing.SwingConstants; |
86 |
|
87 |
import org.gvsig.gps.tools.PointCalibrate; |
88 |
|
89 |
import com.iver.andami.PluginServices; |
90 |
import com.iver.andami.ui.mdiManager.SingletonView; |
91 |
import com.iver.andami.ui.mdiManager.View; |
92 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
93 |
import com.iver.cit.gvsig.fmap.MapControl; |
94 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
95 |
import com.iver.utiles.XMLEntity; |
96 |
|
97 |
public class GPSConfigPanel extends JPanel implements SingletonView{ |
98 |
public static String viewModel = "GPSConfigPanel"; |
99 |
private JComboBox cmbPorts = null; |
100 |
private JPanel pnlPortConfig = null; |
101 |
private JTextField txtSampleRate; |
102 |
private JLabel lblSampleRate; |
103 |
private JLabel lblPort; |
104 |
private JLabel lblPortSpeed = null; |
105 |
private JComboBox cmbPortSpeed = null; |
106 |
private JButton btnOk = null; |
107 |
private JButton btnCancel = null; |
108 |
private GPSControlPanel control;
|
109 |
private JComboBox cmbDataBits = null; |
110 |
private JLabel lblDataBits = null; |
111 |
private JLabel lblStopBits = null; |
112 |
private JComboBox cmbStopBits = null; |
113 |
private JComboBox cmbParity = null; |
114 |
private JLabel lblParity = null; |
115 |
private String[] parities = new String[] { "even", "odd", "mark", "space", "none" }; |
116 |
private JLabel lblCalibrate = null; |
117 |
private JButton btnCalibrate = null; |
118 |
private JComboBox cmbViews = null; |
119 |
private JLabel lblMillis = null; |
120 |
|
121 |
|
122 |
/**
|
123 |
* This is the default constructor
|
124 |
*/
|
125 |
public GPSConfigPanel(GPSControlPanel control) {
|
126 |
super();
|
127 |
this.control = control;
|
128 |
initialize(); |
129 |
} |
130 |
|
131 |
/**
|
132 |
* This method initializes this
|
133 |
*
|
134 |
* @return void
|
135 |
*/
|
136 |
private void initialize() { |
137 |
lblCalibrate = new JLabel(); |
138 |
lblCalibrate.setBounds(8, 8, 313, 112); |
139 |
lblCalibrate.setText(PluginServices.getText(this, "html_recalibrate_receiver")); |
140 |
this.setLayout(null); |
141 |
this.setSize(329, 384); |
142 |
this.add(getPnlPortConfig(), null); |
143 |
this.add(getBtnOk(), null); |
144 |
this.add(getBtnCancel(), null); |
145 |
this.add(lblCalibrate, null); |
146 |
this.add(getBtnCalibrate(), null); |
147 |
this.add(getCmbViews(), null); |
148 |
} |
149 |
|
150 |
public ViewInfo getViewInfo() {
|
151 |
ViewInfo m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE);
|
152 |
m_viewInfo.setTitle(PluginServices.getText(this, "gps_settings")); |
153 |
m_viewInfo.setWidth(this.getWidth()+8); |
154 |
m_viewInfo.setHeight(this.getHeight()+8); |
155 |
return m_viewInfo;
|
156 |
} |
157 |
|
158 |
/**
|
159 |
* This method initializes jPanel
|
160 |
*
|
161 |
* @return javax.swing.JPanel
|
162 |
*/
|
163 |
private JPanel getPnlPortConfig() { |
164 |
if (pnlPortConfig == null) { |
165 |
lblMillis = new JLabel(); |
166 |
lblMillis.setBounds(230, 31, 89, 20); |
167 |
lblMillis.setText(PluginServices.getText(this, "milliseconds")); |
168 |
lblParity = new JLabel(); |
169 |
lblParity.setBounds(10, 146, 150, 20); |
170 |
lblParity.setHorizontalAlignment(SwingConstants.RIGHT);
|
171 |
lblParity.setText(PluginServices.getText(this, "parity")+":"); |
172 |
lblStopBits = new JLabel(); |
173 |
lblStopBits.setBounds(10, 123, 150, 20); |
174 |
lblStopBits.setHorizontalAlignment(SwingConstants.RIGHT);
|
175 |
lblStopBits.setText(PluginServices.getText(this, "stop_bits")+":"); |
176 |
lblDataBits = new JLabel(); |
177 |
lblDataBits.setBounds(10, 100, 150, 20); |
178 |
lblDataBits.setHorizontalAlignment(SwingConstants.RIGHT);
|
179 |
lblDataBits.setText(PluginServices.getText(this, "data_bits")+":"); |
180 |
lblPortSpeed = new JLabel(); |
181 |
lblPortSpeed.setBounds(10, 77, 150, 20); |
182 |
lblPortSpeed.setHorizontalAlignment(SwingConstants.RIGHT);
|
183 |
lblPortSpeed.setText(PluginServices.getText(this, "port_speed")+":"); |
184 |
pnlPortConfig = new JPanel(); |
185 |
pnlPortConfig.setLayout(null);
|
186 |
pnlPortConfig.setBounds(0, 170, 329, 179); |
187 |
pnlPortConfig.setBorder(javax.swing.BorderFactory.createTitledBorder( |
188 |
null, PluginServices.getText(this, "port_config"), |
189 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
190 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
191 |
pnlPortConfig.add(getTxtSampleRate(), null);
|
192 |
pnlPortConfig.add(getCmbPorts(), null);
|
193 |
lblSampleRate = new JLabel(); |
194 |
lblSampleRate.setBounds(10, 31, 150, 20); |
195 |
lblSampleRate.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
196 |
lblSampleRate.setText(PluginServices.getText(this, "sample_rate")+":"); |
197 |
lblPort = new JLabel(); |
198 |
lblPort.setBounds(10, 54, 150, 20); |
199 |
lblPort.setText(PluginServices.getText(this, "port")+":"); |
200 |
lblPort.setHorizontalAlignment(SwingConstants.RIGHT);
|
201 |
pnlPortConfig.add(lblSampleRate, null);
|
202 |
pnlPortConfig.add(lblPort, null);
|
203 |
pnlPortConfig.add(lblPortSpeed, null);
|
204 |
pnlPortConfig.add(getCmbPortSpeed(), null);
|
205 |
pnlPortConfig.add(getCmbDataBits(), null);
|
206 |
pnlPortConfig.add(getCmbStopBits(), null);
|
207 |
pnlPortConfig.add(getCmbParity(), null);
|
208 |
pnlPortConfig.add(lblDataBits, null);
|
209 |
pnlPortConfig.add(lblStopBits, null);
|
210 |
pnlPortConfig.add(lblParity, null);
|
211 |
pnlPortConfig.add(lblMillis, null);
|
212 |
} |
213 |
return pnlPortConfig;
|
214 |
} |
215 |
|
216 |
private JTextField getTxtSampleRate() { |
217 |
if (txtSampleRate == null) { |
218 |
txtSampleRate = new JTextField(); |
219 |
txtSampleRate.setBounds(165, 31, 60, 20); |
220 |
XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
|
221 |
if (!xml.contains("gps-sampleRate")) |
222 |
xml.putProperty("gps-sampleRate", 2000); |
223 |
txtSampleRate.setText(xml.getStringProperty("gps-sampleRate"));
|
224 |
} |
225 |
return txtSampleRate;
|
226 |
} |
227 |
|
228 |
/**
|
229 |
* This method initializes jComboBox
|
230 |
*
|
231 |
* @return javax.swing.JComboBox
|
232 |
*/
|
233 |
private JComboBox getCmbPorts() { |
234 |
if (cmbPorts == null) { |
235 |
cmbPorts = new JComboBox(); |
236 |
cmbPorts.setBounds(165, 54, 154, 20); |
237 |
XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
|
238 |
String portName = null; |
239 |
if (xml.contains("gps-serialPortSpeed")) |
240 |
portName = xml.getStringProperty("gps-serialPortSpeed");
|
241 |
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
|
242 |
while (portList.hasMoreElements()) {
|
243 |
CommPortIdentifier port = (CommPortIdentifier) portList.nextElement(); |
244 |
cmbPorts.addItem(port.getName()); |
245 |
if (portName != null && portName.equals(port.getName())) { |
246 |
cmbPorts.setSelectedIndex(cmbPorts.getItemCount()-1);
|
247 |
} |
248 |
} |
249 |
} |
250 |
return cmbPorts;
|
251 |
} |
252 |
|
253 |
/**
|
254 |
* This method initializes jComboBox
|
255 |
*
|
256 |
* @return javax.swing.JComboBox
|
257 |
*/
|
258 |
private JComboBox getCmbPortSpeed() { |
259 |
if (cmbPortSpeed == null) { |
260 |
cmbPortSpeed = new JComboBox(); |
261 |
cmbPortSpeed.setBounds(165, 77, 154, 20); |
262 |
cmbPortSpeed.setEditable(false);
|
263 |
XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
|
264 |
String[] speeds = new String[] { |
265 |
"75" , "110" , "134" , "150" , "300", |
266 |
"600" , "1200" , "1800" , "2400" , "4800", |
267 |
"9600" , "14400", "19200", "38400","57600", |
268 |
"115200"
|
269 |
}; |
270 |
int speed = xml.getIntProperty("gps-serialPortSpeed"); |
271 |
for (int i = 0; i < speeds.length; i++) { |
272 |
cmbPortSpeed.addItem(speeds[i]); |
273 |
if (Integer.parseInt(speeds[i]) == speed) |
274 |
cmbPortSpeed.setSelectedIndex(i); |
275 |
} |
276 |
|
277 |
} |
278 |
return cmbPortSpeed;
|
279 |
} |
280 |
|
281 |
/**
|
282 |
* This method initializes btnOk
|
283 |
*
|
284 |
* @return javax.swing.JButton
|
285 |
*/
|
286 |
private JButton getBtnOk() { |
287 |
if (btnOk == null) { |
288 |
btnOk = new JButton(); |
289 |
btnOk.setBounds(78, 353, 85, 25); |
290 |
btnOk.setText(PluginServices.getText(this, "ok")); |
291 |
btnOk.addActionListener(new java.awt.event.ActionListener() {
|
292 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
293 |
ok(); |
294 |
} |
295 |
}); |
296 |
} |
297 |
return btnOk;
|
298 |
} |
299 |
|
300 |
/**
|
301 |
* This method initializes btnCancel
|
302 |
*
|
303 |
* @return javax.swing.JButton
|
304 |
*/
|
305 |
private JButton getBtnCancel() { |
306 |
if (btnCancel == null) { |
307 |
btnCancel = new JButton(); |
308 |
btnCancel.setBounds(163, 353, 85, 25); |
309 |
btnCancel.addActionListener(new java.awt.event.ActionListener() {
|
310 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
311 |
cancel(); |
312 |
} |
313 |
}); |
314 |
btnCancel.setText(PluginServices.getText(this, "cancel")); |
315 |
} |
316 |
return btnCancel;
|
317 |
} |
318 |
|
319 |
private void cancel() { |
320 |
PluginServices.getMDIManager().closeView(this);
|
321 |
} |
322 |
|
323 |
private void ok() { |
324 |
try {
|
325 |
control.setSampleRate(Integer.parseInt(txtSampleRate.getText()));
|
326 |
control.setPortSpeed(Integer.parseInt((String) cmbPortSpeed.getSelectedItem())); |
327 |
control.setPortDataBits(Integer.parseInt((String) cmbDataBits.getSelectedItem())); |
328 |
control.setPortStopBits((String) cmbStopBits.getSelectedItem());
|
329 |
control.setPortParity(parities[cmbParity.getSelectedIndex()]); |
330 |
String portName = (String) cmbPorts.getSelectedItem(); |
331 |
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
|
332 |
boolean portFound = false; |
333 |
while (portList.hasMoreElements()) {
|
334 |
CommPortIdentifier port = (CommPortIdentifier) portList.nextElement(); |
335 |
if (port.getName().equals(portName)) {
|
336 |
control.setPort(port); |
337 |
portFound = true;
|
338 |
break;
|
339 |
} |
340 |
} |
341 |
if (!portFound) throw new Exception(); |
342 |
PluginServices.getMDIManager().closeView(this);
|
343 |
} catch (Exception e) { |
344 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this, "config_error")); |
345 |
} |
346 |
} |
347 |
|
348 |
/**
|
349 |
* This method initializes jComboBox
|
350 |
*
|
351 |
* @return javax.swing.JComboBox
|
352 |
*/
|
353 |
private JComboBox getCmbDataBits() { |
354 |
if (cmbDataBits == null) { |
355 |
cmbDataBits = new JComboBox(); |
356 |
cmbDataBits.setBounds(165, 100, 154, 20); |
357 |
String[] dataBitsValues; |
358 |
XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
|
359 |
dataBitsValues = new String[] { "5", "6", "7", "8" }; |
360 |
int dataBits = xml.getIntProperty("gps-serialPortDataBits"); |
361 |
for (int i = 0; i < dataBitsValues.length; i++) { |
362 |
cmbDataBits.addItem(dataBitsValues[i]); |
363 |
if (Integer.parseInt(dataBitsValues[i]) == dataBits) |
364 |
cmbDataBits.setSelectedIndex(i); |
365 |
} |
366 |
} |
367 |
return cmbDataBits;
|
368 |
} |
369 |
|
370 |
/**
|
371 |
* This method initializes jComboBox1
|
372 |
*
|
373 |
* @return javax.swing.JComboBox
|
374 |
*/
|
375 |
private JComboBox getCmbStopBits() { |
376 |
if (cmbStopBits == null) { |
377 |
cmbStopBits = new JComboBox(); |
378 |
cmbStopBits.setBounds(165, 123, 154, 20); |
379 |
cmbStopBits.setEditable(false);
|
380 |
|
381 |
XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
|
382 |
String stopBits = xml.getStringProperty("gps-serialPortStopBits"); |
383 |
|
384 |
String[] stopBitsValues = new String[] { "1", "1.5", "2" }; |
385 |
for (int i = 0; i < stopBitsValues.length; i++) { |
386 |
cmbStopBits.addItem(stopBitsValues[i]); |
387 |
if (stopBitsValues[i].equals(stopBits))
|
388 |
cmbStopBits.setSelectedIndex(i); |
389 |
} |
390 |
} |
391 |
return cmbStopBits;
|
392 |
} |
393 |
|
394 |
/**
|
395 |
* This method initializes jComboBox2
|
396 |
*
|
397 |
* @return javax.swing.JComboBox
|
398 |
*/
|
399 |
private JComboBox getCmbParity() { |
400 |
if (cmbParity == null) { |
401 |
cmbParity = new JComboBox(); |
402 |
cmbParity.setBounds(165, 146, 154, 20); |
403 |
cmbParity.setEditable(false);
|
404 |
XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
|
405 |
|
406 |
String parity = xml.getStringProperty("gps-serialPortParities"); |
407 |
|
408 |
for (int i = 0; i < parities.length; i++) { |
409 |
cmbParity.addItem(PluginServices.getText(this, parities[i]));
|
410 |
if (parities[i].equals(parity))
|
411 |
cmbParity.setSelectedIndex(i); |
412 |
} |
413 |
} |
414 |
return cmbParity;
|
415 |
} |
416 |
|
417 |
/**
|
418 |
* This method initializes btnCalibrate
|
419 |
*
|
420 |
* @return javax.swing.JButton
|
421 |
*/
|
422 |
private JButton getBtnCalibrate() { |
423 |
if (btnCalibrate == null) { |
424 |
btnCalibrate = new JButton(); |
425 |
btnCalibrate.setBounds(225, 147, 96, 20); |
426 |
btnCalibrate.addActionListener(new java.awt.event.ActionListener() {
|
427 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
428 |
calibrate((String)cmbViews.getSelectedItem());
|
429 |
} |
430 |
}); |
431 |
btnCalibrate.setText(PluginServices.getText(this, "calibrate")); |
432 |
|
433 |
} |
434 |
return btnCalibrate;
|
435 |
} |
436 |
|
437 |
/**
|
438 |
* Sets the tool that catches a point in the view specified by the viewName
|
439 |
* parameter.
|
440 |
* @param viewName
|
441 |
*/
|
442 |
protected void calibrate(String viewName) { |
443 |
if (viewName!=null) { |
444 |
View[] views = PluginServices.getMDIManager().getAllViews(); |
445 |
for (int i = 0; i < views.length; i++) { |
446 |
if ((views[i] instanceof com.iver.cit.gvsig.gui.View) |
447 |
&& (views[i].getViewInfo().getTitle().equals(viewName))){ |
448 |
com.iver.cit.gvsig.gui.View v = (com.iver.cit.gvsig.gui.View) views[i]; |
449 |
|
450 |
String toolName = "gpsCalibrator"; |
451 |
MapControl mc = v.getMapControl(); |
452 |
String currentTool = v.getMapControl().getTool();
|
453 |
PointCalibrate calibrator = new PointCalibrate(v, currentTool);
|
454 |
mc.addMapTool(toolName, new PointBehavior(calibrator));
|
455 |
mc.setTool(toolName); |
456 |
PluginServices.getMDIManager().addView(v); |
457 |
return;
|
458 |
} |
459 |
} |
460 |
} |
461 |
} |
462 |
|
463 |
/**
|
464 |
* This method initializes cmbViews
|
465 |
*
|
466 |
* @return javax.swing.JComboBox
|
467 |
*/
|
468 |
private JComboBox getCmbViews() { |
469 |
if (cmbViews == null) { |
470 |
cmbViews = new JComboBox(); |
471 |
cmbViews.setBounds(8, 127, 313, 17); |
472 |
cmbViews.setToolTipText(PluginServices.getText(this, "select_the_view_to_do_calibration")); |
473 |
} |
474 |
cmbViews.setEnabled(false);
|
475 |
cmbViews.removeAll(); |
476 |
View[] aViews = PluginServices.getMDIManager().getAllViews(); |
477 |
for (int i = 0; i < aViews.length; i++) { |
478 |
if (aViews[i] instanceof com.iver.cit.gvsig.gui.View) { |
479 |
cmbViews.addItem(aViews[i].getViewInfo().getTitle()); |
480 |
cmbViews.setEnabled(true);
|
481 |
} |
482 |
} |
483 |
btnCalibrate.setEnabled(cmbViews.isEnabled()); |
484 |
return cmbViews;
|
485 |
} |
486 |
|
487 |
public Object getViewModel() { |
488 |
return viewModel;
|
489 |
} |
490 |
} |