Permalink
Browse files

Update method issues corrected to handle modified JGps library and ne…

…w number formatter.
  • Loading branch information...
1 parent a314f88 commit 12609a09965001f3fd9ab166278c8b8095ca39c4 javarobots74 committed Apr 12, 2012
Showing with 63 additions and 52 deletions.
  1. +8 −0 src/ui/GpsDataLogger.form
  2. +55 −52 src/ui/GpsDataLogger.java
@@ -70,6 +70,14 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="mStopMenuItemActionPerformed"/>
</Events>
</MenuItem>
+ <MenuItem class="javax.swing.JCheckBoxMenuItem" name="mConsoleDebugOutputCheckBoxMenuItem">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Console Debug Output"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="mConsoleDebugOutputCheckBoxMenuItemActionPerformed"/>
+ </Events>
+ </MenuItem>
</SubComponents>
</Menu>
</SubComponents>
View
@@ -1,4 +1,3 @@
-
package ui;
import commonutilities.swing.ComponentPosition;
@@ -7,20 +6,21 @@
import gps.calculations.DistanceConversion;
import gps.calculations.NavigationCalculations;
import gps.data.GpsDataModel;
+import gps.debug.Debug;
import gps.nmea.NmeaSentences;
import gps.nmea.SelectedSentences;
import gps.nmea.SentenceParser;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.text.NumberFormat;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
+import util.formating.NumberFormating;
import util.rxtx.GpsSerialDataListener;
import util.rxtx.RxTxUtilities;
@@ -38,7 +38,9 @@
private List<Coordinate> mLoggedCoordinates;
private double mLogAboveSpeed = 5;
- /** Creates new form GpsDataLogger */
+ /**
+ * Creates new form GpsDataLogger
+ */
@SuppressWarnings("LeakingThisInConstructor")
public GpsDataLogger() {
initComponents();
@@ -57,8 +59,7 @@ public GpsDataLogger() {
BufferedImage image = null;
try {
image = ImageIO.read(this.getClass().getResource("/images/compass.png"));
- } catch (IOException e){
-
+ } catch (IOException e) {
}
this.setIconImage(image);
@@ -68,17 +69,17 @@ public GpsDataLogger() {
selectedSentences.setParseGSA(true);
selectedSentences.setParseVTG(true);
selectedSentences.setParseRMC(false);
- for (NmeaSentences sentence : EnumSet.allOf(NmeaSentences.class)){
+ for (NmeaSentences sentence : EnumSet.allOf(NmeaSentences.class)) {
JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(sentence.toString());
menuItem.setSelected(selectedSentences.isParse(sentence));
mNMEASentenceMenu.add(menuItem);
}
}
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
+ /**
+ * This method is called from within the constructor to initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is always
+ * regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
@@ -104,6 +105,7 @@ private void initComponents() {
mSerialPortMenu = new javax.swing.JMenu();
mStartMenuItem = new javax.swing.JMenuItem();
mStopMenuItem = new javax.swing.JMenuItem();
+ mConsoleDebugOutputCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("GPS Data Logger");
@@ -195,6 +197,14 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
});
mToolsMenu.add(mStopMenuItem);
+ mConsoleDebugOutputCheckBoxMenuItem.setText("Console Debug Output");
+ mConsoleDebugOutputCheckBoxMenuItem.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ mConsoleDebugOutputCheckBoxMenuItemActionPerformed(evt);
+ }
+ });
+ mToolsMenu.add(mConsoleDebugOutputCheckBoxMenuItem);
+
mMenuBar.add(mToolsMenu);
setJMenuBar(mMenuBar);
@@ -259,7 +269,7 @@ private void mExitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN
}//GEN-LAST:event_mExitMenuItemActionPerformed
private void mStartMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mStartMenuItemActionPerformed
- if (!mSelectedCom.isEmpty()){
+ if (!mSelectedCom.isEmpty()) {
try {
mStartMenuItem.setEnabled(false);
mStopMenuItem.setEnabled(true);
@@ -280,7 +290,7 @@ private void mStopMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN
private void mClearCoordinatesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mClearCoordinatesMenuItemActionPerformed
int clearResponse = JOptionPane.showConfirmDialog(this, "Do you wish to clear all logged coordinates?", "Clear Coordinates", JOptionPane.YES_NO_OPTION);
- if (clearResponse == JOptionPane.YES_OPTION){
+ if (clearResponse == JOptionPane.YES_OPTION) {
mLoggedCoordinates.clear();
}
}//GEN-LAST:event_mClearCoordinatesMenuItemActionPerformed
@@ -289,7 +299,7 @@ private void mSaveKmlMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(("Keyhole Markup Language"), "kml");
chooser.setFileFilter(filter);
- if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION){
+ if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
//Create the KML object
Kml kml = new Kml();
@@ -313,11 +323,15 @@ private void mLogAboveSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//
mLogAboveSpeed = (double) mLogAboveSpinner.getValue();
}//GEN-LAST:event_mLogAboveSpinnerStateChanged
+ private void mConsoleDebugOutputCheckBoxMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mConsoleDebugOutputCheckBoxMenuItemActionPerformed
+ Debug.setConsoleOutput(mConsoleDebugOutputCheckBoxMenuItem.isSelected());
+ }//GEN-LAST:event_mConsoleDebugOutputCheckBoxMenuItemActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel mAltitudeLabel;
private javax.swing.JLabel mAverageSpeedLabel;
private javax.swing.JMenuItem mClearCoordinatesMenuItem;
+ private javax.swing.JCheckBoxMenuItem mConsoleDebugOutputCheckBoxMenuItem;
private javax.swing.JMenuItem mExitMenuItem;
private javax.swing.JMenu mFileMenu;
private javax.swing.JLabel mFixModeLabel;
@@ -339,87 +353,76 @@ private void mLogAboveSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//
@Override
public void update(Observable o, Object arg) {
- if (o instanceof GpsDataModel){
-
- System.out.println("Update Data Logger");
+ if (o instanceof GpsDataModel) {
+ NumberFormating numberFormatter = new NumberFormating();
+ Debug.debugOut("Update Data Logger");
- GpsDataModel model = (GpsDataModel)o;
-
- //Create number formatter preventing decimals
- NumberFormat numberFormatter = NumberFormat.getNumberInstance();
- numberFormatter.setMaximumFractionDigits(4);
+ GpsDataModel model = (GpsDataModel) o;
//Get coordinate
gps.data.Coordinate coordinate = model.getGGACoordinate();
-
- //Build latitude
- StringBuilder latitudeBuilder = new StringBuilder(numberFormatter.format(coordinate.getLatitude()));
- latitudeBuilder.deleteCharAt(1);
- latitudeBuilder.insert(2, " ");
-
- //Build longitude
- StringBuilder longitudeBuilder = new StringBuilder(numberFormatter.format(coordinate.getLongitude()));
- longitudeBuilder.deleteCharAt(2);
- longitudeBuilder.insert(3, " ");
+ String latitudeString = numberFormatter.formatLatitudeValue(coordinate.getLatitude(), 4);
+ String longitudeString = numberFormatter.formatLongitudeValue(coordinate.getLongitude(), 4);
//Set Latitude and longitude labels
- mLatitudeLabel.setText("Latitude: " + latitudeBuilder.toString() + " " + coordinate.getLatitudeHemisphere().getHemisphere());
- mLongitudeLabel.setText("Longitude: " + longitudeBuilder.toString() + " " + coordinate.getLongitudeHemisphere().getHemisphere());
-
- numberFormatter.setMaximumFractionDigits(0);
+ mLatitudeLabel.setText("Latitude: " + latitudeString + " " + coordinate.getLatitudeHemisphere().getHemisphere());
+ mLongitudeLabel.setText("Longitude: " + longitudeString + " " + coordinate.getLongitudeHemisphere().getHemisphere());
//Set altitude and speed
- mAltitudeLabel.setText("Altitude: " + numberFormatter.format(DistanceConversion.metersToFeet(model.getGGAHeightAboveSeaLevel())));
- numberFormatter.setMaximumFractionDigits(2);
+ mAltitudeLabel.setText("Altitude: " + numberFormatter.formatValue(DistanceConversion.metersToFeet(model.getGGAHeightAboveSeaLevel()),0));
double speed = model.getVTGSpeedInKilometers() * .621371192;
- mSpeedLabel.setText("Speed: " + numberFormatter.format(speed));
+ mSpeedLabel.setText("Speed: " + numberFormatter.formatValue(speed,2));
//Set fix mode
mFixModeLabel.setText("Fix Mode: " + model.getGsaFixMode());
//Set up lat and lon for logging
NavigationCalculations navCalc = NavigationCalculations.getInstance();
- double longitude = navCalc.degreesMinutesToDegrees(longitudeBuilder.toString());
- double latitude = navCalc.degreesMinutesToDegrees(latitudeBuilder.toString());
- if (coordinate.getLongitudeHemisphere().getHemisphere().equals("W")){
+ double longitude = navCalc.degreesMinutesToDegrees(latitudeString);
+ double latitude = navCalc.degreesMinutesToDegrees(longitudeString);
+ if (coordinate.getLongitudeHemisphere().getHemisphere().equals("W")) {
longitude = longitude * -1;
}
- if (coordinate.getLatitudeHemisphere().getHemisphere().equals("S")){
+ if (coordinate.getLatitudeHemisphere().getHemisphere().equals("S")) {
latitude = latitude * -1;
}
//Log coordinate if log all or speed cut off is met
- if ((mLogAllCheckBox.isSelected() || speed >= mLogAboveSpeed) && model.isLogCoordinate()){
+ if ((mLogAllCheckBox.isSelected() || speed >= mLogAboveSpeed) && model.isLogCoordinate()) {
+ Debug.debugOut("Coordinate logged");
logCoordinate(longitude, latitude, model.getGGAHeightAboveSeaLevel());
model.setLogCoordinate(false);
}
//Perform averaging
mNumberMeasurements++;
mTotalForSpeedAverage += speed;
- double speedAverage = mTotalForSpeedAverage/mNumberMeasurements;
- mAverageSpeedLabel.setText("Average Speed: " + numberFormatter.format(speedAverage));
+ double speedAverage = mTotalForSpeedAverage / mNumberMeasurements;
+ mAverageSpeedLabel.setText("Average Speed: " + numberFormatter.formatValue(speedAverage,2));
}
}
- private void logCoordinate(double longitude, double latitude, double altitude){
+
+
+ private void logCoordinate(double longitude, double latitude, double altitude) {
mSaveLabel.setText("Logging");
SaveTimer timer = new SaveTimer((mSaveLabel));
Coordinate loggedCoordinate = new Coordinate(longitude, latitude, altitude);
mLoggedCoordinates.add(loggedCoordinate);
timer.execute();
}
- private void initAvailablePorts(){
+ private void initAvailablePorts() {
List<String> availablePorts = RxTxUtilities.getAvailablePorts();
ButtonGroup comButtonGroup = new ButtonGroup();
- for (String portName : availablePorts){
+ for (String portName : availablePorts) {
JCheckBoxMenuItem item = new JCheckBoxMenuItem(portName);
item.addActionListener(new java.awt.event.ActionListener() {
+
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
- mSelectedCom = ((JCheckBoxMenuItem)evt.getSource()).getText();
+ mSelectedCom = ((JCheckBoxMenuItem) evt.getSource()).getText();
}
});
comButtonGroup.add(item);
@@ -428,10 +431,11 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
/**
- * @param args the command line arguments
- */
+ * @param args the command line arguments
+ */
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
+
@Override
public void run() {
try {
@@ -445,5 +449,4 @@ public void run() {
}
});
}
-
}

0 comments on commit 12609a0

Please sign in to comment.