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