Revision 4753

View differences:

trunk/extensions/extGPS/src/org/gvsig/gps/GPSDriver.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.3  2006-04-06 10:34:46  jaume
46
* Revision 1.4  2006-04-07 08:27:48  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.3  2006/04/06 10:34:46  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.1  2006/04/05 17:08:18  jaume
50 53
* *** empty log message ***
51 54
*
......
104 107
	private long lastSampleTime;
105 108
	private boolean eventsEnabled;
106 109

  
110
	private boolean stop;
111

  
107 112
	private static GPSDriver instance = null;
108 113
	
109 114
	/**
......
171 176
					line = new StringBuffer();
172 177
					line.append(str.substring(i+1,str.length()));
173 178
				}
179
//				if (stop)
180
//					break;
174 181
			}
175 182
		} catch (IOException e) {
176 183
			e.printStackTrace();
......
196 203
					line = new StringBuffer();
197 204
					line.append(str.substring(i+1,str.length()));
198 205
				}
206
//				if (stop)
207
//					break;
199 208
			}
200 209
		} catch (IOException e) {
201 210
			e.printStackTrace();
202 211
		}
203
		
212
		inputStream = null;
213
		outputStream = null;
204 214
	}
205 215
	
206 216
	private void analyzeMessage(String line) {
......
281 291
			if (myPortId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
282 292
				if (myPortId.getName().equals(args[0])) {
283 293
					try {
284
						GPSDriver reader = GPSDriver.getInstance();
285
						reader.setPort(myPortId, Integer.parseInt(args[1]), SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
286
						reader.setSampleRate(100);
287
						reader.addEventListener(new GPSEventListener() {
294
						GPSDriver driver = GPSDriver.getInstance();
295
						driver.setPort(myPortId, Integer.parseInt(args[1]), SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
296
						driver.setSampleRate(100);
297
						driver.addEventListener(new GPSEventListener() {
288 298
							public void unhandledMessage(String msg) {
289 299
								System.out.println("UNHANDLED: "+msg);
290 300
							}
......
322 332
							}
323 333
							
324 334
						});
325
						reader.start();
335
						driver.start();
326 336
					} catch (PortInUseException e) {
327 337
						System.err.println("Port busy");
328 338
					}
......
339 349
			if (inputStream != null) {
340 350
				try {
341 351
					inputStream.close();
342
					inputStream = null;
343 352
				}
344 353
				catch (IOException e) {}
345 354
			}
......
353 362
			serialPort.close();
354 363
			serialPort = null;
355 364
		}
365
		stop = true;
356 366
	}
357 367
	
358 368
}
trunk/extensions/extGPS/src/org/gvsig/gps/GPSExtension.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.4  2006-04-06 10:34:58  jaume
46
* Revision 1.5  2006-04-07 08:27:48  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.4  2006/04/06 10:34:58  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.3  2006/04/05 17:08:18  jaume
50 53
* *** empty log message ***
51 54
*
......
66 69
import java.awt.geom.Point2D;
67 70
import java.util.ArrayList;
68 71

  
72
import org.cresques.cts.ICoordTrans;
73
import org.cresques.cts.IProjection;
74
import org.cresques.cts.ProjectionPool;
75
import org.cresques.cts.gt2.CoordSys;
76
import org.cresques.cts.gt2.CoordTrans;
69 77
import org.gvsig.gps.panel.GPSControlPanel;
70 78
import org.gvsig.gps.panel.TestPanel;
71 79

  
......
89 97
	}
90 98

  
91 99
	public void execute(String actionCommand) {
92
		
93
		PluginServices.getMDIManager().addView(new GPSControlPanel());
100
		PluginServices.getMDIManager().addView(GPSControlPanel.getInstance());
94 101
	}
95 102

  
96 103
	public boolean isEnabled() {
......
133 140
		for (int i = 0; i < views.length; i++) {
134 141
			MapControl mc = views[i].getMapControl();
135 142
			GraphicLayer graph = mc.getMapContext().getGraphicsLayer();
143
			
144
			// Remove old graphics
136 145
			graph.clearAllGraphics();
137 146
			graph.clearSymbolsGraphics();
138 147
			
148
			// Obtain the current view's projection
149
			IProjection reqProj = mc.getProjection();
150
			
151
			// the geodesic projection
152
			IProjection latLonProj = ProjectionPool.get("EPSG:4326");
153
			
154
			// create a translator from geodesic to the current view's projection
155
			ICoordTrans ct = new CoordTrans((CoordSys) latLonProj, (CoordSys) reqProj);
156
			
157
			Point2D pDst = new Point2D.Double();
158
			
159
			// reproject the point
160
			pDst = ct.convert(location, pDst);
161
			
162
			// add and draw the FSymbol to the reprojected location.
139 163
			graph.addSymbol(symbol);
140
			graph.addGraphic(new FGraphic(ShapeFactory.createPoint2D(new FPoint2D(location)), 0));
164
			graph.addGraphic(new FGraphic(ShapeFactory.createPoint2D(new FPoint2D(pDst)), 0));
141 165
			mc.drawGraphics();
142 166
		}
143 167
	}
trunk/extensions/extGPS/src/org/gvsig/gps/panel/GPSControlPanel.java
43 43
 *
44 44
 * $Id$
45 45
 * $Log$
46
 * Revision 1.7  2006-04-06 10:35:48  jaume
46
 * Revision 1.8  2006-04-07 08:27:48  jaume
47 47
 * *** empty log message ***
48 48
 *
49
 * Revision 1.7  2006/04/06 10:35:48  jaume
50
 * *** empty log message ***
51
 *
49 52
 * Revision 1.5  2006/04/05 17:08:18  jaume
50 53
 * *** empty log message ***
51 54
 *
......
70 73
import gnu.io.SerialPort;
71 74

  
72 75
import java.awt.geom.Point2D;
76
import java.util.ArrayList;
73 77
import java.util.Enumeration;
78
import java.util.Hashtable;
74 79

  
80
import javax.swing.DefaultCellEditor;
75 81
import javax.swing.JButton;
82
import javax.swing.JComponent;
76 83
import javax.swing.JLabel;
77 84
import javax.swing.JOptionPane;
78 85
import javax.swing.JPanel;
79 86
import javax.swing.JScrollPane;
80 87
import javax.swing.JTable;
81
import javax.swing.SwingConstants;
88
import javax.swing.ListSelectionModel;
89
import javax.swing.event.TableColumnModelListener;
90
import javax.swing.event.TableModelEvent;
82 91
import javax.swing.table.AbstractTableModel;
92
import javax.swing.table.DefaultTableColumnModel;
93
import javax.swing.table.JTableHeader;
94
import javax.swing.table.TableCellRenderer;
83 95
import javax.swing.table.TableColumn;
96
import javax.swing.table.TableColumnModel;
84 97

  
85
import org.cresques.cts.ICoordTrans;
86
import org.cresques.cts.IProjection;
87
import org.cresques.cts.ProjectionPool;
88
import org.cresques.cts.gt2.CoordSys;
89
import org.cresques.cts.gt2.CoordTrans;
90 98
import org.gvsig.gps.GPSDriver;
91 99
import org.gvsig.gps.GPSExtension;
92 100
import org.gvsig.gps.listeners.GPSEventListener;
93 101

  
94 102
import com.iver.andami.PluginServices;
95
import com.iver.andami.ui.mdiManager.View;
103
import com.iver.andami.plugins.Extension;
104
import com.iver.andami.ui.mdiManager.SingletonView;
96 105
import com.iver.andami.ui.mdiManager.ViewInfo;
97 106
import com.iver.utiles.XMLEntity;
98

  
99
public class GPSControlPanel extends JPanel implements View {
107
/**
108
 * Singleton view that allows the user to monitorize and configure the
109
 * status of the GPS.
110
 * 
111
 * @author jaume dominguez faus - jaume.dominguez@iver.es
112
 */
113
public class GPSControlPanel extends JPanel implements SingletonView {
100 114
	private boolean alreadyStarted;
101 115
	private GPSDriver gps;
102 116
    private JPanel centerPanel = null;
......
107 121
	private JButton btnStart = null;
108 122
	private JButton btnPause = null;
109 123
	private JButton btnStop = null;
110
	private JLabel lblPort;
111
	private JLabel lblPosValue;
112 124
	private JLabel lblPos;
113 125
	private JButton btnConfig = null;
114 126
	private CommPortIdentifier port;
......
117 129
	private int stopBits;
118 130
	private int parity;
119 131
	
132
	private final static Extension thisExtension = PluginServices.getExtension(GPSExtension.class);
133
	private final static String kPos = PluginServices.getText(thisExtension, "UTM_position");
134
	private final static String kMsg = PluginServices.getText(thisExtension, "unknown_message");
135
	private final static String kSignalLevel = PluginServices.getText(thisExtension, "signal_stregth");
136
	private final static String kStatus = PluginServices.getText(thisExtension, "status");
137
	private final static String kSpeed = PluginServices.getText(thisExtension, "speed");
138
	private final static String kCourse = PluginServices.getText(thisExtension, "course");
139
	private final static String kEstErr = PluginServices.getText(thisExtension, "estimated_error");
140
	private final static String kHeight = PluginServices.getText(thisExtension, "height");
141
	private final static String kPosPrecision = PluginServices.getText(thisExtension, "position_precision");
142
	private final static String kHorPrecision = PluginServices.getText(thisExtension, "horizontal_precision");
143
	private final static String kVerPrecision = PluginServices.getText(thisExtension, "vertical_precision");
144
	
145
	
146
	private static GPSControlPanel instance;
147
	
120 148

  
121
	public GPSControlPanel() {
149
	private GPSControlPanel() {
122 150
		super();
123 151
		gps = GPSDriver.getInstance();
152
		
153
		setUp();
154
		initialize();
155
		refreshTable();
156
	}
157
	
158
	private void refreshTable() {
159
		model.putValue(kPos , PluginServices.getText(this, "unknown"));
160
		model.putValue(PluginServices.getText(this, "port"), (port!=null) ? port.getName() : PluginServices.getText(this, "not_yet_set"));
161
		model.putValue(PluginServices.getText(this, "speed")+" (bps)", portSpeed+"");
162
		
163
	}
164

  
165
	private void setUp() {
124 166
		XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
125
		
126 167
		// Try to restore last port used
127 168
		String portName = null;
128
		if (!xml.contains("gps-lastSerialPortName")) {
129
			portName = xml.getStringProperty("gps-lastSerialPortSpeed");
169
		if (xml.contains("gps-serialPortName")) {
170
			portName = xml.getStringProperty("gps-serialPortName");
130 171
		}
131 172
		Enumeration portList = CommPortIdentifier.getPortIdentifiers();
132 173
		while (portName!=null && portList.hasMoreElements()) {
......
140 181
		if (!xml.contains("gps-serialPortDataBits"))
141 182
			xml.putProperty("gps-serialPortDataBits" , "8");
142 183
		if (!xml.contains("gps-serialPortStopBits")) 
143
			xml.putProperty("gps-serialPortStopBits", stopBits);
184
			xml.putProperty("gps-serialPortStopBits", "1");
144 185
		if (!xml.contains("gps-serialPortParities"))
145 186
			xml.putProperty("gps-serialPortParities", "none");
146 187
		
147
		portSpeed = xml.getIntProperty("gps-serialPortSpeed");
148
		dataBits = xml.getIntProperty("gps-serialPortDataBits");
188
		setPortSpeed(xml.getIntProperty("gps-serialPortSpeed"));
189
		setPortDataBits(xml.getIntProperty("gps-serialPortDataBits"));
149 190
		setPortStopBits(xml.getStringProperty("gps-serialPortStopBits"));
150 191
		setPortParity(xml.getStringProperty("gps-serialPortParities"));
151
		initialize();
152 192
	}
153 193

  
194
	public static GPSControlPanel getInstance() {
195
		if (instance == null)
196
			instance = new GPSControlPanel();
197
		return instance;
198
	}
199

  
154 200
	/**
155 201
	 * This method initializes this
156 202
	 * 
157 203
	 * @return void
158 204
	 */
159 205
	private void initialize() {
160
		lblPosValue = new JLabel();
161
		lblPosValue.setBounds(156, 25, 223, 20);
162
		lblPosValue.setFont(new java.awt.Font("MS Sans Serif", java.awt.Font.BOLD, 11));
163
		lblPos = new JLabel();
164
		lblPos.setText("Pos:");
165
		lblPos.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
166
		lblPos.setBounds(10, 25, 143, 20);
167 206
		this.setLayout(null);
168
		this.setSize(391, 433);
207
		this.setSize(572, 433);
169 208
		this.add(getCenterPanel(), java.awt.BorderLayout.CENTER);
170 209
		this.add(getNorthPanel(), java.awt.BorderLayout.NORTH);
171 210
		this.add(getBtnStart(), null);
......
175 214
	}
176 215

  
177 216
	public ViewInfo getViewInfo() {
178
		ViewInfo m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE |
179
				ViewInfo.MAXIMIZABLE | ViewInfo.RESIZABLE);
217
		ViewInfo m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE);
180 218
		m_viewInfo.setTitle(PluginServices.getText(this, "gps_control_panel"));
181 219
		m_viewInfo.setWidth(this.getWidth()+8);
182 220
		m_viewInfo.setHeight(this.getHeight()+8);
......
197 235
								  null, PluginServices.getText(this, "gps_status"),
198 236
								  javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, 
199 237
								  javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
200
			centerPanel.setSize(383, 291);
201
			centerPanel.setLocation(5, 111);
238
			centerPanel.setSize(572, 291);
239
			centerPanel.setLocation(0, 111);
202 240
			centerPanel.add(getJScrollPane(), java.awt.BorderLayout.NORTH);
203 241
			centerPanel.add(getBtnConfig(), null);
204 242
		}
......
214 252
		if (northPanel == null) {
215 253
			northPanel = new JPanel();
216 254
			northPanel.setLayout(null);
217
			northPanel.setSize(385, 105);
218
			northPanel.setLocation(0, 2);
219
			northPanel.add(lblPos, null);
220
			northPanel.add(lblPosValue, null);
221
			northPanel.add(lblPort, null);
255
			northPanel.setSize(572, 112);
256
			northPanel.setLocation(0, 0);
222 257
		}
223 258
		return northPanel;
224 259
	}
......
238 273
	private JScrollPane getJScrollPane() {
239 274
		if (jScrollPane == null) {
240 275
			jScrollPane = new JScrollPane();
241
			jScrollPane.setSize(370, 231);
276
			jScrollPane.setSize(560, 231);
242 277
			jScrollPane.setLocation(5, 25);
243 278
			jScrollPane.setViewportView(getTblStatus());
244 279
		}
......
253 288
	private JTable getTblStatus() {
254 289
		if (tblStatus == null) {
255 290
			tblStatus = new JTable();
256
			TableColumn column = null;
257
			for (int i = 0; i < tblStatus.getColumnCount(); i++) {
258
			    column = tblStatus.getColumnModel().getColumn(i);
259
			    int width = (int) (tblStatus.getWidth()*0.3);
260
			    if (i==0) {
261
			    	column.setWidth(width); 			    	
262
			    } else {
263
			    	column.setWidth(tblStatus.getWidth()-width);
264
			    }
265
			}
266
			tblStatus.setTableHeader(null);
291
			tblStatus.setShowHorizontalLines(false);
292
			
267 293
			model = new StatusTableModel();
268 294
			tblStatus.setModel(model);
269 295
		}
......
279 305
		if (btnStart == null) {
280 306
			btnStart = new JButton();
281 307
			btnStart.setText("start");
282
			btnStart.setBounds(75, 405, 70, 20);
308
			btnStart.setBounds(214, 407, 70, 20);
283 309
			btnStart.addActionListener(new java.awt.event.ActionListener() { 
284 310
				public void actionPerformed(java.awt.event.ActionEvent e) {    
285 311
					start();
......
297 323
	private JButton getBtnPause() {
298 324
		if (btnPause == null) {
299 325
			btnPause = new JButton();
300
			btnPause.setBounds(150, 405, 70, 20);
301
			btnPause.setText("sause");
326
			btnPause.setBounds(289, 407, 70, 20);
327
			btnPause.setText("pause");
302 328
			btnPause.addActionListener(new java.awt.event.ActionListener() { 
303 329
				public void actionPerformed(java.awt.event.ActionEvent e) {    
304 330
					gps.silence();
......
316 342
	private JButton getBtnStop() {
317 343
		if (btnStop == null) {
318 344
			btnStop = new JButton();
319
			btnStop.setBounds(270, 405, 70, 21);
345
			btnStop.setBounds(409, 407, 70, 21);
320 346
			btnStop.setText("stop");
321 347
			btnStop.addActionListener(new java.awt.event.ActionListener() { 
322 348
				public void actionPerformed(java.awt.event.ActionEvent e) {    
323 349
					gps.closePort();
324 350
				}
325 351
			});
352
			alreadyStarted = false;
326 353
		}
327 354
		return btnStop;
328 355
	}
356

  
357
	protected void refresh() {
358
		this.repaint();
359
	}
329 360
	
330 361
	public void start() {
331 362
		if (!alreadyStarted && port!=null) {
......
334 365
				gps.setPort(port, portSpeed, dataBits, stopBits, parity); 
335 366
				
336 367
				gps.addEventListener(new GPSEventListener() {
337
					
368
					private TableModelEvent e = new TableModelEvent(model);
338 369
					public void unhandledMessage(String message) {
339
						System.out.println("unhandledMessage"+": "+message+"\n");
340
						lblPosValue.setText(message);
370
						model.putValue(kMsg, message);
371
						tblStatus.tableChanged(e);
341 372
					}
342 373
					
343 374
					public void connectionLost() {
344
						System.out.println("connectionLost");
375
						model.putValue(kStatus, PluginServices.getText(this, "off"));
376
						tblStatus.tableChanged(e);
345 377
					}
346 378
					
347 379
					public void connectionEstablished() {
348
						System.out.println("connectionEstablished");
380
						model.putValue(kStatus, PluginServices.getText(this, "on"));
381
						tblStatus.tableChanged(e);
349 382
					}
350 383
					
351 384
					public void newLonLatPositionReceived(double lon, double lat) {
352
						IProjection reqProj = ProjectionPool.get("EPSG:23030");
353
						IProjection latLonProj = ProjectionPool.get("EPSG:4326");            	
354
						ICoordTrans ct = new CoordTrans((CoordSys) latLonProj, (CoordSys) reqProj);
355
						Point2D pDst = new Point2D.Double();
356
						Point2D pSrc = new Point2D.Double(lon, lat);
357
						pDst = ct.convert(pSrc, pDst);
358
						lblPosValue.setText("("+pDst.getX()+", "+pDst.getY()+")");
359
						
360
						GPSExtension ext = (GPSExtension) PluginServices.getExtension(GPSExtension.class);
361
						ext.drawSymbol(null, null, pDst);
385
						Point2D p = new Point2D.Double(lon, lat);
386
						model.putValue(kPos, "("+lon+", "+lat+")");
387
						tblStatus.tableChanged(e);	
388
						// esto igual ho hauria de canviar.
389
						((GPSExtension) thisExtension).drawSymbol(null, null, p);
362 390
					}
363 391
					
364 392
					public void signalLevelChanged(float level) {
393
						model.putValue(kSignalLevel , level+"");
394
						tblStatus.tableChanged(e);
365 395
					}
366 396
					
367 397
					public void speedChanged(float speed, short course) {
398
						model.putValue(kSpeed, speed+"");
399
						model.putValue(kCourse, course+"?");
400
						tblStatus.tableChanged(e);
368 401
					}
369 402
					
370
					public void estimatedPosErrorChanged(double f) {
403
					public void estimatedPosErrorChanged(double err) {
404
						model.putValue(kEstErr, err+"");
405
						tblStatus.tableChanged(e);
371 406
					}
372 407
					
373 408
					public void heightChanged(float height) {
409
						model.putValue(kHeight, height+"");
410
						tblStatus.tableChanged(e);
374 411
					}
375 412
					
376 413
					public void precisionChanged(float pDop, float hDop, float vDop) {
414
						model.putValue(kPosPrecision, pDop+"");
415
						model.putValue(kHorPrecision, hDop+"");
416
						model.putValue(kVerPrecision, vDop+"");
417
						tblStatus.tableChanged(e);
377 418
					}
378 419
					
379 420
				});
......
394 435
		if (btnConfig == null) {
395 436
			btnConfig = new JButton();
396 437
			btnConfig.setBounds(265, 263, 70, 20);
438
			btnConfig.addActionListener(new java.awt.event.ActionListener() { 
439
				public void actionPerformed(java.awt.event.ActionEvent e) {    
440
					config();
441
				}
442
			});
397 443
			btnConfig.setText(PluginServices.getText(this, "config"));
398 444
		}
399 445
		return btnConfig;
400 446
	}
401 447

  
402 448
	/**
449
	 * Opens the config dialog.
450
	 */
451
	protected void config() {
452
		PluginServices.getMDIManager().addView(new GPSConfigPanel(this));		
453
	}
454

  
455
	/**
403 456
	 * Sets the port to be monitorized.
404 457
	 * @param port
405 458
	 */
406 459
	public void setPort(CommPortIdentifier port) {
460
		XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
461
		xml.putProperty("gps-serialPortName", port.getName());
407 462
		this.port = port;
408 463
	}
409 464

  
......
468 523
			this.parity = SerialPort.PARITY_SPACE;
469 524
		}
470 525
	}
471
} 
472 526

  
527
	public Object getViewModel() {
528
		return "GPS Control Panel";
529
	}
530
}  //  @jve:decl-index=0:visual-constraint="10,10" 
531

  
532

  
473 533
class StatusTableModel extends AbstractTableModel {
474
	private String[] keys, values;
534
	private ArrayList keys = new ArrayList();
535
	private ArrayList values = new ArrayList();
536
	private Hashtable index = new Hashtable();
475 537
	
476
	public void setTableData(String[] keys, String[] values) {
477
		this.keys = keys;
478
		this.values = values;
538
	public void putRow(int rowIndex, String[] cellValues) {
539
		keys.set(rowIndex, cellValues[0]);
540
		values.set(rowIndex, cellValues[1]);
479 541
	}
480 542
	
543
	public int putValue(String key, String value) {
544
		if (index.containsKey(key)) {
545
			int i = ((Integer)index.get(key)).intValue();
546
			values.set(i, value);
547
			return i;
548
		}
549
		return addRow(new String[] {key, value});
550
	}
551
	
552
	
553
	public void clear() {
554
		index.clear();
555
		keys.clear();
556
		values.clear();
557
	}
558
	
559
	public int addRow(String[] cellValues) {
560
		index.put(cellValues[0], new Integer(keys.size()));
561
		keys.add(cellValues[0]);
562
		values.add(cellValues[1]);
563
		return keys.size()-1;
564
	}
565
	
481 566
	public int getColumnCount() {
482 567
		return 2;
483 568
	}
484 569

  
485 570
	public int getRowCount() {
486 571
		if (keys==null) return 0;
487
		return keys.length;
572
		return keys.size();
488 573
	}
489 574

  
490 575
	public Object getValueAt(int rowIndex, int columnIndex) {
491 576
		if (columnIndex == 0) 
492
			return values[rowIndex];
577
			return keys.get(rowIndex);
493 578
		else if (columnIndex == 1)
494
			return keys[rowIndex];
579
			return values.get(rowIndex);
495 580
		return null;
496 581
	}
497 582
	
trunk/extensions/extGPS/src/org/gvsig/gps/panel/GPSConfigPanel.java
43 43
 *
44 44
 * $Id$
45 45
 * $Log$
46
 * Revision 1.1  2006-04-06 10:35:14  jaume
46
 * Revision 1.2  2006-04-07 08:27:48  jaume
47 47
 * *** empty log message ***
48 48
 *
49
 * Revision 1.1  2006/04/06 10:35:14  jaume
50
 * *** empty log message ***
49 51
 *
52
 *
50 53
 */
51 54
package org.gvsig.gps.panel;
52 55

  
......
85 88
	private JComboBox cmbStopBits = null;
86 89
	private JComboBox cmbParity = null;
87 90
	private JLabel lblParity = null;
91
	private String[] parities = new String[] { "even", "odd", "mark", "space", "none" };
92
	
88 93

  
89 94
	/**
90 95
	 * This is the default constructor
......
124 129
	private JPanel getPnlPortConfig() {
125 130
		if (pnlPortConfig == null) {
126 131
			lblParity = new JLabel();
127
			lblParity.setBounds(10, 146, 112, 20);
132
			lblParity.setBounds(10, 146, 84, 20);
128 133
			lblParity.setHorizontalAlignment(SwingConstants.RIGHT);
129 134
			lblParity.setText(PluginServices.getText(this, "parity")+":");
130 135
			lblStopBits = new JLabel();
131
			lblStopBits.setBounds(10, 123, 112, 20);
136
			lblStopBits.setBounds(10, 123, 84, 20);
132 137
			lblStopBits.setHorizontalAlignment(SwingConstants.RIGHT);
133 138
			lblStopBits.setText(PluginServices.getText(this, "stop_bits")+":");
134 139
			lblDataBits = new JLabel();
135
			lblDataBits.setBounds(10, 100, 112, 20);
140
			lblDataBits.setBounds(10, 100, 84, 20);
136 141
			lblDataBits.setHorizontalAlignment(SwingConstants.RIGHT);
137 142
			lblDataBits.setText(PluginServices.getText(this, "data_bits")+":");
138 143
			lblPortSpeed = new JLabel();
139
			lblPortSpeed.setBounds(10, 77, 112, 20);
144
			lblPortSpeed.setBounds(10, 77, 84, 20);
140 145
			lblPortSpeed.setHorizontalAlignment(SwingConstants.RIGHT);
141 146
			lblPortSpeed.setText(PluginServices.getText(this, "port_speed")+":");
142 147
			pnlPortConfig = new JPanel();
......
149 154
			pnlPortConfig.add(getTxtSampleRate(), null);
150 155
			pnlPortConfig.add(getCmbPorts(), null);
151 156
			lblSampleRate = new JLabel();
152
			lblSampleRate.setBounds(10, 31, 112, 20);
157
			lblSampleRate.setBounds(10, 31, 84, 20);
153 158
			lblSampleRate.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
154 159
			lblSampleRate.setText(PluginServices.getText(this, "sample_rate")+":");
155 160
			lblPort = new JLabel();
156
			lblPort.setBounds(10, 54, 112, 20);
161
			lblPort.setBounds(10, 54, 84, 20);
157 162
			lblPort.setText(PluginServices.getText(this, "port")+":");
158 163
			lblPort.setHorizontalAlignment(SwingConstants.RIGHT);
159 164
			pnlPortConfig.add(lblSampleRate, null);
......
173 178
	private JTextField getTxtSampleRate() {
174 179
		if (txtSampleRate == null) {
175 180
			txtSampleRate = new JTextField();
176
			txtSampleRate.setBounds(126, 31, 111, 20);
181
			txtSampleRate.setBounds(101, 31, 136, 20);
177 182
			txtSampleRate.addKeyListener(new java.awt.event.KeyAdapter() { 
178 183
				public void keyTyped(java.awt.event.KeyEvent e) {    
179 184
//					try {
......
197 202
	private JComboBox getCmbPorts() {
198 203
		if (cmbPorts == null) {
199 204
			cmbPorts = new JComboBox();
200
			cmbPorts.setBounds(126, 54, 111, 20);
205
			cmbPorts.setBounds(101, 54, 136, 20);
201 206
			XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
202
			String portName = xml.getStringProperty("gps-lastSerialPortSpeed");
207
			String portName = null;
208
			if (xml.contains("gps-serialPortSpeed"))
209
				portName = xml.getStringProperty("gps-serialPortSpeed");
203 210
			Enumeration portList = CommPortIdentifier.getPortIdentifiers();
204 211
			while (portList.hasMoreElements()) {
205 212
				CommPortIdentifier port = (CommPortIdentifier) portList.nextElement();
......
220 227
	private JComboBox getCmbPortSpeed() {
221 228
		if (cmbPortSpeed == null) {
222 229
			cmbPortSpeed = new JComboBox();
223
			cmbPortSpeed.setBounds(126, 77, 111, 20);
230
			cmbPortSpeed.setBounds(101, 77, 136, 20);
224 231
			cmbPortSpeed.setEditable(false);
225 232
			XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
226 233
			String[] speeds = new String[] {
......
248 255
	private JButton getBtnOk() {
249 256
		if (btnOk == null) {
250 257
			btnOk = new JButton();
251
			btnOk.setBounds(53, 183, 70, 25);
258
			btnOk.setBounds(38, 183, 85, 25);
252 259
			btnOk.setText(PluginServices.getText(this, "ok"));
253 260
			btnOk.addActionListener(new java.awt.event.ActionListener() { 
254 261
				public void actionPerformed(java.awt.event.ActionEvent e) {    
......
267 274
	private JButton getBtnCancel() {
268 275
		if (btnCancel == null) {
269 276
			btnCancel = new JButton();
270
			btnCancel.setBounds(123, 183, 70, 25);
277
			btnCancel.setBounds(123, 183, 85, 25);
271 278
			btnCancel.addActionListener(new java.awt.event.ActionListener() { 
272 279
				public void actionPerformed(java.awt.event.ActionEvent e) {    
273 280
					cancel();
......
284 291
	
285 292
	protected void ok() {
286 293
		try {
287
			control.setPort((CommPortIdentifier) cmbPorts.getSelectedItem());
288 294
			control.setPortSpeed(Integer.parseInt((String) cmbPortSpeed.getSelectedItem()));
289 295
			control.setPortDataBits(Integer.parseInt((String) cmbDataBits.getSelectedItem()));
290 296
			control.setPortStopBits((String) cmbStopBits.getSelectedItem());
291
			control.setPortParity((String) cmbParity.getSelectedItem());
297
			control.setPortParity(parities[cmbParity.getSelectedIndex()]);
298
			String portName = (String) cmbPorts.getSelectedItem();
299
			Enumeration portList = CommPortIdentifier.getPortIdentifiers();
300
			boolean portFound = false;
301
			while (portList.hasMoreElements()) {
302
				CommPortIdentifier port = (CommPortIdentifier) portList.nextElement();
303
				if (port.getName().equals(portName)) {
304
					control.setPort(port);
305
					portFound = true;
306
					break;
307
				}
308
			}
309
			if (!portFound) throw new Exception();
292 310
			PluginServices.getMDIManager().closeView(this);
293 311
		} catch (Exception e) {
294 312
			JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this, "config_error"));
......
303 321
	private JComboBox getCmbDataBits() {
304 322
		if (cmbDataBits == null) {
305 323
			cmbDataBits = new JComboBox();
306
			cmbDataBits.setBounds(126, 100, 111, 20);
324
			cmbDataBits.setBounds(101, 100, 136, 20);
307 325
			String[] dataBitsValues;
308 326
			XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
309 327
			dataBitsValues = new String[] { "5", "6", "7", "8" };
......
325 343
	private JComboBox getCmbStopBits() {
326 344
		if (cmbStopBits == null) {
327 345
			cmbStopBits = new JComboBox();
328
			cmbStopBits.setBounds(126, 123, 111, 20);
346
			cmbStopBits.setBounds(101, 123, 136, 20);
329 347
			cmbStopBits.setEditable(false);
330 348
			
331 349
			XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
......
349 367
	private JComboBox getCmbParity() {
350 368
		if (cmbParity == null) {
351 369
			cmbParity = new JComboBox();
352
			cmbParity.setBounds(126, 146, 111, 20);
370
			cmbParity.setBounds(101, 146, 136, 20);
353 371
			cmbParity.setEditable(false);
354
			String[] parities = new String[] { "even", "odd", "mark", "space", "none" };
355 372
			XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
356 373
			
357 374
			String parity = xml.getStringProperty("gps-serialPortParities");

Also available in: Unified diff