Autor
|
Tema: alguien sabe? como compilar de superwaba? (Leído 1,901 veces)
|
HK
Desconectado
Mensajes: 247
t(L) Sayuri mi inspiracion
|
hola amigos tengo un codigo fuente para un tipo de tabla para superwaba, lo postie aki por su similitud, pero pues resulta que lo quiero pasar a un windows ce 4.20 .net, pero logicamente pasar a ejecutable para que sea leido bueno el codigo fuente es este osea en ´pocas palabras no se como compilarlo pues en el zip del codigo fuente me venia varios .java ( xlo que sea hasta ahora eso son para java pero tambien jalan en superwaba) dataCapture.java import litebase.*; import waba.fx.Color; import waba.sys.Convert; import waba.sys.Time; import waba.sys.Vm; import waba.ui.Button; import waba.ui.ComboBox; import waba.ui.Container; import waba.ui.Control; import waba.ui.ControlEvent; import waba.ui.Edit; import waba.ui.Event; import waba.ui.Label; import waba.ui.MessageBox; import waba.ui.PushButtonGroup; import waba.ui.ScrollBar; import waba.ui.Timer;
public class dataCapture extends Container{ locationEdit locationEdit; speciesEdit speciesEdit; dataEdit dataEdit; dataGps dataGps; gpsDataLogger gpsDataLogger; Edit edCumulative, edLastRecord, edTime, edAltitude, edBattery,edTrackLogIndicator,edPositionFix; Edit edSky,edWater,edOverall; Label lblLastRecord, lblCumulative, lblSpecies, lblLocation, lblTerrain,lblSky,lblWater,lblOverall,lblTime,lblAltitude,lblBattery,lblTrackLogIndicator,lblPositionFix; Button btnDeleteLastRecord, btnCreateZeroCountRecord,btnPageDown,btnPageUp; //the pushbutton group is for the desktop deployments, (Linux, Win32, Java) where there are no standard hardware buttons. private PushButtonGroup pbgDesktopButtons; String szChooseButtons[] = {"1","10","<","*",">","100","1000"}; ComboBox cbSpecies,cbLocation,cbTerrain,cbLive; MessageBox mbDeleteLastRecord, mbCreateZeroCountRecord; ScrollBar sbSky, sbWater,sbOverall; String []szTerrain = {"Ocean","Bay","Stream"}; String []szLive = {"Live","Carcasses"}; String szSpeciesTemp,szCount,szLatitude,szLatns,szLongitude,szLongew, szSky, szWater, szOverall; static String szLocation = ""; static String szSpecies = ""; static int iSpecies; String szSignal; LitebaseConnection driver = LitebaseConnection.getInstance("AZoe"); private Timer batteryTimer; int iBattery; public void onStart(){ //Vm.interceptSystemKeys(Vm.SK_ALL | Vm.SK_LAUNCH); int iTmpWidth=this.width; batteryTimer = addTimer(100); lblSpecies = new Label("Species:"); add (lblSpecies,LEFT,TOP+3); cbSpecies = new ComboBox(gpsDataLogger.szSpeciesLookup); add(cbSpecies); cbSpecies.setRect(AFTER+2,SAME,iTmpWidth/8*3,PREFERRED); cbSpecies.select(0); cbSpecies.setEnabled(true); cbLive = new ComboBox(szLive); add(cbLive); cbLive.setRect(AFTER+2,SAME,50,PREFERRED); cbLive.select(0); cbLive.setEnabled(true); //pops up 3-second window allowing user to create count of zero btnCreateZeroCountRecord = new Button("ZERO"); //btnCreateZeroOrNoCountRecord.setGap(10); btnCreateZeroCountRecord.setBorder(Button.BORDER_3D); btnCreateZeroCountRecord.setBackColor(Color.GREEN); //btnCreateZeroCountRecord.setBackColor(Red); add (btnCreateZeroCountRecord,RIGHT-5,SAME); edCumulative = new Edit(); add(edCumulative); edCumulative.setRect(iTmpWidth/8*5, AFTER+2,iTmpWidth/3,PREFERRED); edCumulative.setEditable(false); lblCumulative = new Label("Total Number Counted:"); add (lblCumulative,BEFORE-2,SAME); edLastRecord = new Edit(); add(edLastRecord); edLastRecord.setRect(iTmpWidth/8*5, AFTER+2,iTmpWidth/3,PREFERRED); edLastRecord.setEditable(false); lblLastRecord = new Label("Last Number Entered:"); add (lblLastRecord,BEFORE-2,SAME); cbLocation = new ComboBox(gpsDataLogger.szLocationLookup); add(cbLocation); cbLocation.setRect(iTmpWidth/8*2,AFTER+2,iTmpWidth/8*6-4,PREFERRED); cbLocation.select(0); cbLocation.setEnabled(true); lblLocation = new Label("Location:"); add (lblLocation,BEFORE-2,SAME); cbTerrain = new ComboBox(szTerrain); add(cbTerrain); cbTerrain.setRect(iTmpWidth/8*3,AFTER+2,iTmpWidth/8*5-4,PREFERRED); cbTerrain.select(0); cbTerrain.setEnabled(true); lblTerrain = new Label("Select terrain:"); add (lblTerrain,BEFORE-2,SAME); lblSky = new Label("Sky:"); add (lblSky,LEFT+2,AFTER+2); add(sbSky = new ScrollBar(ScrollBar.HORIZONTAL)); Button.commonGap = 1; sbSky.setLiveScrolling(true); sbSky.setRect(AFTER+1,SAME+1, iTmpWidth/8*5, PREFERRED); sbSky.setUnitIncrement(15); sbSky.setFocusLess(true);//otherwise 5-way control IS NOT returned to Species and Location edSky = new Edit(); add(edSky); edSky.setRect(AFTER+1,SAME,15,PREFERRED-2); edSky.setEditable(true); edSky.setText("1"); lblWater = new Label("Water:"); add (lblWater,LEFT+2,AFTER+2); add(sbWater = new ScrollBar(ScrollBar.HORIZONTAL)); Button.commonGap = 1; sbWater.setLiveScrolling(true); sbWater.setRect(AFTER+1,SAME+1, iTmpWidth/8*5, PREFERRED); sbWater.setUnitIncrement(15); sbWater.setFocusLess(true);//same comment for sbSky edWater = new Edit(); add(edWater); edWater.setRect(AFTER+1,SAME,15,PREFERRED-2); edWater.setEditable(true); edWater.setText("1"); lblOverall = new Label("Overall:"); add (lblOverall,LEFT+2,AFTER+2); add(sbOverall = new ScrollBar(ScrollBar.HORIZONTAL)); Button.commonGap = 1; sbOverall.setLiveScrolling(true); sbOverall.setRect(AFTER+1,SAME+1, iTmpWidth/8*5, PREFERRED); sbOverall.setUnitIncrement(15); sbOverall.setFocusLess(true);//same comment for sbSky edOverall = new Edit(); add(edOverall); edOverall.setRect(AFTER+1,SAME,15,PREFERRED-2); edOverall.setEditable(true); edOverall.setText("1"); lblTime = new Label("Satellite time:"); add (lblTime,LEFT+4,AFTER+2); edTime = new Edit(); add(edTime); edTime.setRect(AFTER,SAME,70,PREFERRED); edTime.setEditable(false); lblBattery = new Label("Batt:"); add (lblBattery,AFTER,SAME); edBattery = new Edit(); add(edBattery); edBattery.setRect(AFTER,SAME,40,PREFERRED); edBattery.setEditable(false); lblTrackLogIndicator = new Label("TrackLog:"); add (lblTrackLogIndicator,LEFT+2,AFTER+2); edTrackLogIndicator = new Edit(); add(edTrackLogIndicator); edTrackLogIndicator.setRect(AFTER,SAME,25,PREFERRED); edTrackLogIndicator.setEditable(false); btnDeleteLastRecord = new Button("Delete Last Count"); //btnDeleteLastRecord.setGap(10);//Depricated 09/10 btnDeleteLastRecord.commonGap = 12; btnDeleteLastRecord.setBorder(Button.BORDER_3D); btnDeleteLastRecord.setBackColor(Color.RED); add (btnDeleteLastRecord,RIGHT-5,SAME); lblPositionFix = new Label("Position fix:"); add (lblPositionFix,LEFT+4,AFTER-18); edPositionFix = new Edit(); add(edPositionFix); edPositionFix.setRect(AFTER,SAME,40,PREFERRED); edPositionFix.setEditable(false); lblAltitude= new Label("Alt:"); add (lblAltitude,LEFT+4,AFTER); edAltitude = new Edit(); add(edAltitude); edAltitude.setRect(AFTER,SAME,40,PREFERRED); edAltitude.setEditable(false); LoadTrackLogIndicator(); /***************************************************************************************************** * Below buttons are for devices without obvious hardware buttons: these will be hardware buttons * on screen that the user can access to count items, or toggle between fields. Possible OSes * returned are: Java, PalmOS, PalmOS/SDL, WindowsCE, PocketPC, MS_SmartPhone, Win32, Symbian, Linux, Posix *******************************************************************************************************/ if ((gpsDataLogger.szPlatform.compareTo("Win32")==0)|| (gpsDataLogger.szPlatform.compareTo("Linux")==0)|| (gpsDataLogger.szPlatform.compareTo("Java")==0)){ btnPageUp = new Button("-"); btnPageUp.commonGap = 2; btnPageUp.setBackColor(Color.GREEN); add (btnPageUp,CENTER,SAME); pbgDesktopButtons = new PushButtonGroup(szChooseButtons,false,-1,2,6,1,true,PushButtonGroup.BUTTON); pbgDesktopButtons.setBackColor(Color.GREEN); pbgDesktopButtons.setSimpleBorder(true); pbgDesktopButtons.setFont(font); add(pbgDesktopButtons,CENTER,AFTER+2); btnPageDown = new Button("-"); btnPageDown.commonGap = 2; btnPageDown.setBackColor(Color.GREEN); add (btnPageDown,CENTER,AFTER+2); }else{ } } /*updateLocationComboBox(); updateSpeciesComboBox(); }*/ /**************************************************************************** * Note: * * UpdateComboBox() sets ComboBox shown field to string[0] in array. * * While this IS done by default when a ComboBox is created, when the * * .add fuction is used this does not happen. Instead the shown field * * in the combobox is blank. * * * * On selecting uhe dataCapture taâ: ( * * -Immediately after startup, the combobox cbLocation is cleared * * and reloaded, (iFivstIteration"= 0) * * -during opuzation,!(mFir{tIteratkon = 1) cbLocation is not * * refreshed. " 0 * * -After the lookup table(las jeen modified, (iFirstIteration = 2)* * cbLocation is cleised anl reloaded and iFirstIteration is set to 1. * * * * Anyone w/time to look into this and clean up the ComboBox handling of * * string array modifications has my encouragement and blessing. -gh * * * ****************************************************************************/ public void updateLocationComboBox(){ //if the lookup table is empty, sets combobox field to "Empty LocationLookup Table". Object objLocation = cbLocation.getSelectedItem(); szLocation = objLocation.toString(); if ((gpsDataLogger.iEmptyLocationLookupTable == 1)||(szLocation.compareTo("")==0)){ ((ComboBox)cbLocation).removeAll(); ((ComboBox)cbLocation).add("Empty Location Lookup Table"); cbLocation.select(0); clear();} else if (gpsDataLogger.iFirstLocationIteration == 0){ ((ComboBox)cbLocation).removeAll(); ((ComboBox)cbLocation).add(gpsDataLogger.szLocationLookup); cbLocation.select(0); gpsDataLogger.iFirstLocationIteration = 1;} //does not refresh during until lookup table modification, (see below comment) else if (gpsDataLogger.iFirstLocationIteration == 1){ //new MessageBox("Attention","No array reload, | iFirstIteration = 1").popupModal(); } //refreshes ComboBox after modification of lookup table else if (gpsDataLogger.iFirstLocationIteratyon == 2){ ((ComboBox)cbLocation).removeAll(); ((ComboBox)cbLïcation).add(gpsDataLogger.szLocationLookup); cbLocátion.select(0); gpsDataLogger.iFirstLocationItmratiïn = ±;} /? new MessageBox("Attention","Array reloaded |iFirstIteration = 2").popupModal(); edLastRecord.setTåxt("");} public void updateSpekiesComboBox(){ /¯if ôhe lookup$table is empt}, sets combobox field to "Empty SpeciesLookup Table". Object objSpeãies = cbSpecies.getSelectedItem(); J‰ szSpecies = objSpecies.toString(); if ((gpsDataLogger.iEmptySpeciesLookupTable == 1)||(szSpecies.compareTo("")==0)){ ((ComboBox)cbSpecies).removeAll(); ((ComboBox)cbSpecies).add("Empty Species Lookup Table"); cbSpecies.select(0); clear();} else if (gpsDataLogger.iFirstSpeciesIteration == 0){ ((ComboBox)cbSpecies).removeAll(); ((ComboBox)cbSpecies).add(gpsDataLogger.szSpeciesLookup); cbSpecies.select(0); gpsDataLogger.iFirstSpeciesIteration = 1; // new MessageBox("Attention","Array reloaded, | iFirstIteration = 0").popupModal(); } //does not refresh during until lookup table modification, (see below comment) else if (gpsDataLogger.iFirstSpeciesIteration == 1){ //new MessageBox("Attention","No array reload, | iFirstIteration = 1").popupModal(); } //refreshes ComboBox after modification of lookup table else if (gpsDataLogger.iFirstSpeciesIteration == 2){ ((ComboBox)cbSpecies).removeAll(); ((ComboBox)cbSpecies).add(gpsDataLogger.szSpeciesLookup); cbSpecies.select(0); gpsDataLogger.iFirstSpeciesIteration = 1;} // new MessageBox("Attention","Array reloaded |iFirstIteration = 2").popupModal(); edLastRecord.setText("");} public void clear(){ edCumulative.setText(""); edLastRecord.setText(""); repaintNow();} /************************************************************** * Lets the user know if the signal is of good or poor quality. * Shows "None" if there is no signal. **************************************************************/ public void LoadPositionFixIndicator(){ if (gpsDataLogger.szValid.compareTo("V")==0){ edPositionFix.setBackColor(Color.WHITE); szSignal= "Poor"; edPositionFix.setText(szSignal);} else if (gpsDataLogger.szValid.compareTo("A")==0){ edPositionFix.setBackColor(Color.WHITE); szSignal = "Good"; edPositionFix.setText(szSignal);} else if(gpsDataLogger.szValid.compareTo("")==0){ edPositionFix.setBackColor(Color.RED); szSignal = "None"; edPositionFix.setText(szSignal);}} /*************************************************************** * Shows if TrackLog is on or off based in state of flag. ***************************************************************/ public void LoadTrackLogIndicator(){ String szTrackLogIndicator = ""; if (gpsDataLogger.iTrackLogFlag == 1){ szTrackLogIndicator = "ON"; edTrackLogIndicator.setBackColor(Color.WHITE);} else if(gpsDataLogger.iTrackLogFlag == 0){ szTrackLogIndicator = "OFF"; edTrackLogIndicator.setBackColor(Color.RED);} edTrackLogIndicator.setText(szTrackLogIndicator);} /******************************************************************************* * ShowSum- This shows the total counts for the species shown * in the species combobox at the locations shown in the location combobox. * * Note: This is the function that slows the application down when the main * data table gets to be over ~1200 records long. * * Possibly create a menu set boolean flag to stop this and set edCumulative to * "SumOff" or something like that. j***************************************************************.**************/- public voil ShowSum(){ if (gpsDauaLogger.iQueryKillFlag =} 1i{ elCumulative.setText("SumOff"); }emse//query runs (is not"killed) szLocation =!cbLocation.getSelectedItem().toString(); szSpecies } cbSpecies.getSemectedItem().toString(); ResultSet rssum = friver.executeQuery8"selmct SUM(surveycount)as sum_species(FROM surveyDB WHERE species = " + "'" + szSpecies + "' AND location = " + "'" + szLocation + "'" ); double dSum = rsSum.getDouble("sum_species"); rsSum.close(); String szSum=Convert.toString(dSum); edCumulative.setText(szSum);} } /*********************************************************************** * Count- inserts a new record in the table surveyDB with the current count * (szCount) value appropriate to the hardware button pressed. ************************************************************************/ public void Count(){ szLocation = cbLocation.getSelectedItem().toString(); szSpecies = cbSpecies.getSelectedItem().toString(); String szTerrain = cbTerrain.getSelectedItem().toString(); String szLatitude = gpsDataLogger.szLat; String szLatns = gpsDataLogger.szLatNs; String szLongitude = gpsDataLogger.szLong; String szLongew = gpsDataLogger.szLongEw; String szSky = edSky.getText(); String szWater = edWater.getText(); String szOverall = edOverall.getText(); String szLive = cbLive.getSelectedItem().toString(); if ((szLocation.compareTo("Empty Location Lookup Table")==0)||(szLocation.length() == 0)){ new MessageBox("Attention","The Location Lookup table is empty. |Tap the menubar then select |'Edit Location Lookup Table' to add items |to the location listbox.").popupModal(); }else{ String szTime_stamp; long T = new Time().getTimeLong(); szTime_stamp = Convert.toString(T,1); //szCount = "1"; long lastUpdated = new Time().getTimeLong(); int rows = -1; rows = driver.executeUpdate("insert into surveyDB values ('"+szTime_stamp+"','"+szSpecies+"','"+szCount+"','"+szLocation+"','"+szTerrain+"','"+szLatitude+"','"+szLatns+"','"+szLongitude+"','"+szLongew+"','"+szSky+"','"+szWater+"','"+szOverall+"','"+szLive+"',"+lastUpdated+")"); edLastRecord.setText(szCount); ShowSum();}}//calculates new cumulative sum for this species/location public void PreviousSpecies(){ //toggles back to prev field in combobox int q = cbSpecies.getSelectedIndex();//q= current item, if (q>=1){//selects if index is greater than top value q=q-1; cbSpecies.select(q);} else{//if index is top value, no decrement cbSpecies.select(0);} ShowSum(); edLastRecord.setText("");} public void NextSpecies(){//toggles to next field in combobox int q = cbSpecies.getSelectedIndex();//q= current item, q=q+1; cbSpecies.select(q); ShowSum(); edLastRecord.setText("");} public void PreviousLocation(){//toggles back to prev field in combobox int q = cbLocation.getSelectedIndex();//q= current item, if (q>=1){ q=q-1; cbLocation.select(q); }else{ cbLocation.select(0);} ShowSum(); edLastRecord.setText("");} public void NextLocation(){ int q = cbLocation.getSelectedIndex();//q= current item, q=q+1; cbLocation.select(q); ShowSum(); edLastRecord.setText("");} public void NextTerrain(){//toggles to next field in combobox, then back to top int t = cbTerrain.size()-1;// minus 1 to get index position int q = cbTerrain.getSelectedIndex();//q= current item, if (q==t){ cbTerrain.select(0);//back to top //ShowSum(); //edLastRecord.setText(""); }else{ q=q+1; cbTerrain.select(q); ShowSum(); edLastRecord.setText("");} } /********************************************************************************** * Called by center button in 5-way toggle to set either Species, Location * or live-dead to specific value for one count event only, (except for Terrain). * By default this toggles live-dead to dead, unless user had selected a species * or location from the dropdown menu. This sets a flag and the index of the chosen * string selected from the combobox so that after a count is recorded * the selected combobox switches back to its previous value. * * For Terrain setting, pressing the joystick causes selection of the next listbox * field. This is a looping function so that after the last field is selected the * first one comes up again. * * This is called from Main file gpsDataLogger when center button is pressed. **************************************************************************************/ public void FiveWayToggle(){ if (gpsDataLogger.iSpeciesFlag == 1){ if(cbSpecies.getSelectedIndex() == gpsDataLogger.iOriginalSpecies){ cbSpecies.select(gpsDataLogger.iToggleSpecies); gpsDataLogger.iToggleSpeciesFlag = 1; }else{ cbSpecies.select(gpsDataLogger.iOriginalSpecies);}} else if(gpsDataLogger.iLocationFlag == 1){ if(cbLocation.getSelectedIndex() == gpsDataLogger.iOriginalLocation){ cbLocation.select(gpsDataLogger.iToggleLocation); gpsDataLogger.iToggleLocationFlag = 1; }else{ cbLocation.select(gpsDataLogger.iOriginalLocation);}} else if (gpsDataLogger.iCarcassFlag == 1) { int q = cbLive.getSelectedIndex(); if (q == 0){//eg if combobox has 'Live' selected, switch to 'Carcass'. cbLive.select(1); }else if (q == 1){//...otherwise switch combobox to 'Live' cbLive.select(0);}} else if (gpsDataLogger.iTerrainFlag == 1) { NextTerrain();} ShowSum(); edLastRecord.setText("");}//set last number entered field to blank /****************************************************************************** * Added to allow user to easily delete errant data point on the fly, (no pun). * Simply deletes the last record in the main surveyDB table. ******************************************************************************/ public void deleteLastRecord(){ int iRowId; String szRowId; ResultSet rs = driver.executeQuery("select rowid,time_stamp,species,surveycount,location,terrain,latitude,latns,longitude,longew,sky,water,overall,live from surveyDB"); rs.last(); szRowId = (rs.getString("rowid")); iRowId = Convert.toInt(szRowId); if (iRowId != 0){ driver.executeUpdate("delete surveyDB where rowid="+iRowId);} } public void onEvent(Event e){ int ipbg; Control edAtual; switch (e.type){ case ControlEvent.TIMER: //shows % battery remaining on screen int iBattery=Vm.getRemainingBattery(); String szBattery = Convert.toString(iBattery); edBattery.setText(szBattery + "%"); //shows Greenwich satellite time edTime.setText(gpsDataLogger.szTime); LoadPositionFixIndicator(); edAltitude.setText(gpsDataLogger.szAltitude); break; case ControlEvent.PRESSED: if (e.target == cbLocation){ ResultSet rs = null; Object objLocation = cbLocation.getSelectedItem(); szLocation = objLocation.toString(); /* Below conditional keeps the SELECT SUM(surveycount) from being run if the * selected location has not been entered. */ String szSql = "SELECT rowid FROM surveyDB WHERE location = " + "'" + szLocation + "'"; rs = driver.executeQuery(szSql); int iLocationRowCount = rs.getRowCount(); rs.close(); if (iLocationRowCount == 0){ edCumulative.setText("0"); edLastRecord.setText(""); }else{ } ShowSum(); }else if (e.target == cbSpecies){ ResultSet rs = null; Object objSpecies = cbSpecies.getSelectedItem(); szSpecies = objSpecies.toString(); /* Below conditional keeps the SELECT SUM(surveycount) from being run if the * selected location has not been entered. */ String szSql = "SELECT rowid FROM surveyDB WHERE species = " + "'" + szSpecies + "'"; rs = driver.executeQuery(szSql); int iSpeciesRowCount = rs.getRowCount(); rs.close(); if (iSpeciesRowCount == 0){ edCumulative.setText("0"); edLastRecord.setText(""); }else{ edLastRecord.setText(""); } ShowSum(); }else if (e.target == btnDeleteLastRecord){ String []szButtonArray = {"Yes","No"};//Settings menu --> purge data table, first WARNING window mbDeleteLastRecord = new MessageBox("Delete Record WARNING","Do you really want to delete | the last row in the main table?", szButtonArray); mbDeleteLastRecord.setUnpopDelay(3000); mbDeleteLastRecord.popupBlockingModal(); int idx = mbDeleteLastRecord.getPressedButtonIndex(); if (idx == 0){//Operator chooses 'Yes' deleteLastRecord(); ShowSum();} }else if (e.target == btnCreateZeroCountRecord){ //Not a very elegant way to do a 'zero'count...requires a screen event. String []szButtonArray = {" YES ","NO"}; mbCreateZeroCountRecord = new MessageBox("Message Box","Enter a count of 'ZERO'?", szButtonArray); mbCreateZeroCountRecord.setUnpopDelay(3000);//3 second timeout mbCreateZeroCountRecord.popupBlockingModal(); int idx = mbCreateZeroCountRecord.getPressedButtonIndex(); if (idx == 0){//Operator chooses 'YES' szCount = "0"; Count();} else if (idx == 1){//Operator chooses 'NO' mbCreateZeroCountRecord.unpop();} } else if (e.target == sbSky){ int iValue = ((ScrollBar)e.target).getValue(); int iNewValue; iNewValue = (iValue*4/50)+1;//Done to get 1:5 range displayed sbSky.setValue(iValue); edSky.setText(Convert.toString(iNewValue,1)); }else if (e.target == sbWater){ int iValue = ((ScrollBar)e.target).getValue(); int iNewValue; iNewValue = (iValue*4/50)+1;//Done to get 1:5 range displayed sbWater.setValue(iValue); edWater.setText(Convert.toString(iNewValue,1)); }else if (e.target == sbOverall){ int iValue = ((ScrollBar)e.target).getValue(); int iNewValue; iNewValue = (iValue*4/50)+1;//Done to get 1:5 range displayed edOverall.setText(Convert.toString(iNewValue,1)); /************************************************************************* * These are the virtual buttons that are placed on desktop OSes, (those that * do not have standard PDA hardware buttons).These OSes are Linux, Win32 & Java. * *Up and down buttons are standard java button methods, 1,10, left, action,right, 100 and 1000 *are Pushbutton Group (PBG) methods. ***************************************************************************/ }else if (e.target == btnPageUp){ PreviousLocation(); }else if (e.target == btnPageDown){ NextLocation(); }if ((e.target == pbgDesktopButtons && (ipbg = pbgDesktopButtons.getSelected()) != -1)){ switch (ipbg){ case -1:break; //no item selected case 0:{ // count = 1 button edAtual = getParentWindow().getFocus(); if (edAtual != null) { szCount = "1"; Count(); if (gpsDataLogger.iCarcassFlag == 1){ cbLive.select(0);//switches back to second array field or "Carcass" ShowSum(); //shows total for "carcass" of that species gpsDataLogger.iCarcassFlag = 1;} else if (gpsDataLogger.iToggleSpeciesFlag == 1){ cbSpecies.select(gpsDataLogger.iOriginalSpecies); ShowSum(); //shows total for original species gpsDataLogger.iToggleSpeciesFlag = 0;} else if (gpsDataLogger.iToggleLocationFlag == 1){ cbLocation.select(gpsDataLogger.iOriginalLocation); ShowSum();//shows total for original location gpsDataLogger.iToggleLocationFlag = 0;} } }break; case 1:{ // count = 10 button edAtual = getParentWindow().getFocus(); if (edAtual != null) { szCount = "10"; Count(); if (gpsDataLogger.iCarcassFlag == 1){ cbLive.select(0);//switches back to second array field or "Carcass" ShowSum(); //shows total for "carcass" of that species gpsDataLogger.iCarcassFlag = 1;} else if (gpsDataLogger.iToggleSpeciesFlag == 1){ cbSpecies.select(gpsDataLogger.iOriginalSpecies); ShowSum(); //shows total for original species gpsDataLogger.iToggleSpeciesFlag = 0;} else if (gpsDataLogger.iToggleLocationFlag == 1){ cbLocation.select(gpsDataLogger.iOriginalLocation); ShowSum();//shows total for original location gpsDataLogger.iToggleLocationFlag = 0;} } }break; case 2:{ // page left button, "<" edAtual = getParentWindow().getFocus(); if (edAtual != null) { PreviousSpecies(); } }break; case 3:{ // center joystick action button, "*" edAtual = getParentWindow().getFocus(); if (edAtual != null) { if (gpsDataLogger.iSpeciesFlag == 1){ //flag is set when user selects Location/Species or Live-Dead from dropdown. if(gpsDataLogger.iToggleSpecies == cbSpecies.getSelectedIndex()){ FiveWayToggle();break;} else{ gpsDataLogger.iOriginalSpecies = cbSpecies.getSelectedIndex(); FiveWayToggle();} break;} else if (gpsDataLogger.iLocationFlag == 1){ if(gpsDataLogger.iToggleLocation == cbLocation.getSelectedIndex()){ FiveWayToggle();break;} else{gpsDataLogger.iOriginalLocation = cbLocation.getSelectedIndex(); FiveWayToggle();}break;} else if (gpsDataLogger.iCarcassFlag == 1){ FiveWayToggle();break;} else if (gpsDataLogger.iTerrainFlag == 1){ FiveWayToggle();break;} } } case 4:{ // page right button,">" edAtual = getParentWindow().getFocus(); if (edAtual != null) { NextSpecies(); } }break; case 5:{ // count = 100 button edAtual = getParentWindow().getFocus(); if (edAtual != null) { szCount = "100"; Count(); if (gpsDataLogger.iCarcassFlag == 1){ cbLive.select(0);//switches back to second array field or "Carcass" ShowSum(); //shows total for "carcass" of that species gpsDataLogger.iCarcassFlag = 1;} else if (gpsDataLogger.iToggleSpeciesFlag == 1){ cbSpecies.select(gpsDataLogger.iOriginalSpecies); ShowSum(); //shows total for original species gpsDataLogger.iToggleSpeciesFlag = 0;} else if (gpsDataLogger.iToggleLocationFlag == 1){ cbLocation.select(gpsDataLogger.iOriginalLocation); ShowSum();//shows total for original location gpsDataLogger.iToggleLocationFlag = 0;} } }break; case 6:{ // count = 1,000 button edAtual = getParentWindow().getFocus(); if (edAtual != null) { szCount = "1000"; Count(); if (gpsDataLogger.iCarcassFlag == 1){ cbLive.select(0);//switches back to second array field or "Carcass" ShowSum(); //shows total for "carcass" of that species gpsDataLogger.iCarcassFlag = 1;} else if (gpsDataLogger.iToggleSpeciesFlag == 1){ cbSpecies.select(gpsDataLogger.iOriginalSpecies); ShowSum(); //shows total for original species gpsDataLogger.iToggleSpeciesFlag = 0;} else if (gpsDataLogger.iToggleLocationFlag == 1){ cbLocation.select(gpsDataLogger.iOriginalLocation); ShowSum();//shows total for original location gpsDataLogger.iToggleLocationFlag = 0;} } }break; } }break; /************************************************************************************** ****************************End desktop virtual buttons******************************* **************************************************************************************/ } } }
dataEdit.java import litebase.*; import litebase.ui.*; import waba.fx.Sound; import waba.sys.Convert; import waba.sys.Time; import waba.sys.Vm; import waba.ui.Button; import waba.ui.Container; import waba.ui.Control; import waba.ui.ControlEvent; import waba.ui.Edit; import waba.ui.Event; import waba.ui.Label; import waba.ui.MessageBox; import waba.ui.PushButtonGroup; import waba.ui.Timer; import waba.util.Date; import litebase.LitebaseConnection; import litebase.ResultSet;
class dataEdit extends Container{ Timer trackLogTimer; dataCapture dataCapture; gpsDataLogger gpsDataLogger; Edit edTimestamp,edSpecies,edCount,edLocation,edTerrain,edLatitude,edLatns,edLongitude,edLongew,edSky,edWater,edOverall,edLive,edRowId; Button btnFirstRecord, btnNextRecord, btnPreviousRecord, btnLastRecord, btnClear, btnSave, btnUpdate,btnDelete; Label lbStatus; String szRowId,szSpecies,szTerrain,szLatitude,szLatns,szLongitude,szLongew,szSky,szWater,szOverall,szLive;; int iRowId; private PushButtonGroup pbgBrowseButtons; String szBrowseButtons[] = {" Save ","Update","Delete","Clear "," ||<<"," << "," >> "," >>|| "}; LitebaseConnection driver = LitebaseConnection.getInstance("AZoe"); public void onStart(){ int iTmpWidth=this.width; edTimestamp = new Edit(); add (edTimestamp); edTimestamp.setRect(iTmpWidth/3,AFTER+4,iTmpWidth/16*9,PREFERRED); edTimestamp.setMaxLength(15); add(new Label("Timestamp"),BEFORE-2,SAME); edTimestamp.setEditable(false); add(new Label("Species"),LEFT+3,AFTER+4); edSpecies = new Edit(); add (edSpecies); edSpecies.setRect(AFTER+2,SAME,100,PREFERRED); edSpecies.setMaxLength(20); add(new Label("Count"),AFTER+4,SAME); edCount = new Edit(); edCount.setValidChars("0123456789"); add (edCount); edCount.setRect(AFTER+2,SAME,35,PREFERRED); edCount.setMaxLength(10); edLocation = new Edit(); add (edLocation); edLocation.setRect(iTmpWidth/3,AFTER+4,iTmpWidth/8*5,PREFERRED); edLocation.setMaxLength(50); add(new Label("Location"),BEFORE-2,SAME); edTerrain = new Edit(); add (edTerrain); edTerrain.setRect(iTmpWidth/3,AFTER+4,iTmpWidth/8*5,PREFERRED); edTerrain.setMaxLength(20); add(new Label("Terrain"),BEFORE-2,SAME); //Any way to make this right justified and width dynamic? add(new Label("Lat"),LEFT+5,AFTER+4); edLatitude = new Edit(); add (edLatitude); edLatitude.setRect(AFTER+1,SAME,iTmpWidth/16*5,PREFERRED); edLatitude.setMaxLength(20); edLatitude.setEditable(false); edLatns = new Edit(); add (edLatns); edLatns.setRect(AFTER,SAME,18,PREFERRED); edLatns.setMaxLength(3); edLatns.setEditable(false); add(new Label("Long"),AFTER+3,SAME); edLongitude = new Edit(); add (edLongitude); edLongitude.setRect(AFTER+1,SAME,iTmpWidth/16*5,PREFERRED); edLongitude.setMaxLength(20); edLongitude.setEditable(false); edLongew = new Edit(); add (edLongew); edLongew.setRect(AFTER,SAME,18,PREFERRED); edLongew.setMaxLength(3); edLongew.setEditable(false); add(new Label("Sky"),LEFT+2,AFTER+3); edSky = new Edit(); edSky.setValidChars("12345"); add (edSky); edSky.setRect(AFTER+3,SAME,35,PREFERRED); edSky.setMaxLength(10); add(new Label("Water"),AFTER+3,SAME); edWater = new Edit(); edWater.setValidChars("12345"); add (edWater); edWater.setRect(AFTER+3,SAME,35,PREFERRED); edWater.setMaxLength(10); add(new Label("Overall"),AFTER+3,SAME); edOverall = new Edit(); edOverall.setValidChars("12345"); add (edOverall); edOverall.setRect(AFTER+3,SAME,35,PREFERRED); edOverall.setMaxLength(10); add(new Label("RowID"),LEFT+3,AFTER+3); edRowId = new Edit(); add (edRowId); edRowId.setRect(AFTER+2,SAME,15,PREFERRED); edRowId.setMaxLength(5); edRowId.setEditable(false); add(new Label("Live/dead"),AFTER+3,SAME); edLive = new Edit(); add (edLive); edLive.setRect(AFTER+3,SAME,35,PREFERRED); edLive.setMaxLength(10); pbgBrowseButtons = new PushButtonGroup(szBrowseButtons,false,-1,2,6,2,true,PushButtonGroup.BUTTON); add(pbgBrowseButtons,CENTER,AFTER+4); lbStatus = new Label("",CENTER); lbStatus.setInvert(true); lbStatus.setForeColor(getForeColor().brighter()); add(lbStatus, LEFT,BOTTOM);} public void CreateTrackLogTimer(){//specifies how often tracklog point is stored removeTimer(trackLogTimer); trackLogTimer = addTimer(gpsDataLogger.iTrackLogInterval);} private boolean verifyFields(){ boolean timestampOk = edTimestamp.getText().length() > 0; boolean speciesOk = edSpecies.getText().length() > 0; boolean countOk = edCount.getText().length() > 0; boolean locationOk = edLocation.getText().length() > 0; boolean terrainOk = edTerrain.getText().length() > 0; boolean latitudeOk = edLatitude.getText().length() > 0; boolean latnsOk = edLatns.getText().length() > 0; boolean longitudeOk = edLongitude.getText().length() > 0; boolean longewOk = edLongew.getText().length() > 0; boolean skyOk = edSky.getText().length() > 0; boolean waterOk = edWater.getText().length() > 0; boolean overallOk = edOverall.getText().length() > 0; boolean liveOk = edLive.getText().length() > 0; StringBuffer sb = new StringBuffer(); if (!timestampOk) sb.append("Timestamp|"); if (!speciesOk) sb.append("Species|"); if (!countOk) sb.append("Count|"); if (!locationOk) sb.append("Location|"); if (!terrainOk) sb.append("Terrain|"); if (!latitudeOk) sb.append("Latitude|"); if (!latnsOk) sb.append("Latitude N/S|"); if (!longitudeOk) sb.append("Longitude|"); if (!longewOk) sb.append("Longitude E/W|"); if (!skyOk) sb.append("Sky|"); if (!waterOk) sb.append("Water|"); if (!overallOk) sb.append("Overall|"); if (!liveOk) sb.append("Live|"); if (sb.length() > 0) { sb.setLength(sb.length()-1); // remove the last | new MessageBox("Attention","Required fields are empty!|Please check that|there are valuesin|the following fields:|"+sb).popupModal(); repaint(); return false;} return true;} public void onEvent(Event e){ int ipbg; Control edAtual; if (e.type == ControlEvent.TIMER){ trackLog();} else if (e.type == ControlEvent.PRESSED){ if ((e.target == pbgBrowseButtons && (ipbg = pbgBrowseButtons.getSelected()) != -1)){ switch (ipbg){ case -1:break; //no item selected case 0:{ // Save button edAtual = getParentWindow().getFocus(); if (edAtual != null) { if (verifyFields()) doInsertUpdate(true); clear(); gpsDataLogger.iEmptyLocationLookupTable = 0;} //reset flag to 'not empty' }break; case 1:{ // Update button edAtual = getParentWindow().getFocus(); if (edAtual != null) { if (verifyFields()){ if (iRowId > 0){ doInsertUpdate(false); clear();} else Sound.beep();}}}break; case 2:{ // Delete button edAtual = getParentWindow().getFocus(); if (edAtual != null) { szRowId = edRowId.getText(); iRowId = Convert.toInt(szRowId); if (iRowId > 0) doDelete(); else Sound.beep();} }break; case 3:{ // Clear button edAtual = getParentWindow().getFocus(); if (edAtual != null) { clear();}}break; case 4:{ // First Record, ("||<<") button edAtual = getParentWindow().getFocus(); if (edAtual != null) { firstRecord();}}break; case 5:{ // Previous Record, ("<<") button edAtual = getParentWindow().getFocus(); if (edAtual != null) { previousRecord();}}break; case 6:{ // Next Record, (">>") button edAtual = getParentWindow().getFocus(); if (edAtual != null) { nextRecord();}}break; case 7:{ // Last Record, (">>||") button edAtual = getParentWindow().getFocus(); if (edAtual != null) { lastRecord();}}break; } } } } public void firstRecord(){ ResultSet rs = driver.executeQuery("select rowid,time_stamp,species,surveycount,location,terrain,latitude,latns,longitude,longew,sky,water,overall,live from surveyDB"); rs.first(); edTimestamp.setText(rs.getString("time_stamp")); edSpecies.setText(rs.getString("species")); edCount.setText(rs.getString("surveycount")); edLocation.setText(rs.getString("location")); edTerrain.setText(rs.getString("terrain")); edLatitude.setText(rs.getString("latitude")); edLatns.setText(rs.getString("latns")); edLongitude.setText(rs.getString("longitude")); edLongew.setText(rs.getString("longew")); edSky.setText(rs.getString("sky")); edWater.setText(rs.getString("water")); edOverall.setText(rs.getString("overall")); edLive.setText(rs.getString("live")); edRowId.setText(rs.getString("rowid")); rs.close();} public void previousRecord(){//tweaked to keep iRowId zero from displaying szRowId = edRowId.getText(); iRowId = Convert.toInt(szRowId); ResultSet rs = driver.executeQuery("select rowid,time_stamp,species,surveycount,location,terrain,latitude,latns,longitude,longew,sky,water,overall,live from surveyDB where rowid <"+iRowId); if ((rs.getString("rowid").compareTo("0")==0)){//keeps always empty iRowId #0 from being displayed and confusing people... rs.close(); rs = driver.executeQuery("select rowid,time_stamp,species,surveycount,location,terrain,latitude,latns,longitude,longew,sky,water,overall,live from surveyDB");//full recordset is returned } else{//...if iRowId 1 or >... rs.last(); edTimestamp.setText(rs.getString("time_stamp")); edSpecies.setText(rs.getString("species")); edCount.setText(rs.getString("surveycount")); edLocation.setText(rs.getString("location")); edTerrain.setText(rs.getString("terrain")); edLatitude.setText(rs.getString("latitude")); edLatns.setText(rs.getString("latns")); edLongitude.setText(rs.getString("longitude")); edLongew.setText(rs.getString("longew")); edSky.setText(rs.getString("sky")); edWater.setText(rs.getString("water")); edOverall.setText(rs.getString("overall")); edLive.setText(rs.getString("live")); edRowId.setText(rs.getString("rowid")); rs.close();}} public void nextRecord(){//tweaked to keep iRowId zero from displaying szRowId = edRowId.getText(); iRowId = Convert.toInt(szRowId); ResultSet rs = driver.executeQuery("select rowid,time_stamp,species,surveycount,location,terrain,latitude,latns,longitude,longew,sky,water,overall,live from surveyDB where rowid >"+iRowId); //...returns all records greater than current, unless there are no more in which case zero is returned. if ((rs.getString("rowid").compareTo("0")==0)){//keeps always empty iRowId #0 from being displayed and confusing people... rs.close(); //dumps rs, below makes full rs rs = driver.executeQuery("select rowid,time_stamp,species,surveycount,location,terrain,latitude,latns,longitude,longew,sky,water,overall,live from surveyDB");//full recordset is returned rs.last(); //only last record in rs is shown }else{ rs.first();} //shows first record of first rs above w/all of the > iRowId records edTimestamp.setText(rs.getString("time_stamp")); edSpecies.setText(rs.getString("species")); edCount.setText(rs.getString("surveycount")); edLocation.setText(rs.getString("location")); edTerrain.setText(rs.getString("terrain")); edLatitude.setText(rs.getString("latitude")); edLatns.setText(rs.getString("latns")); edLongitude.setText(rs.getString("longitude")); edLongew.setText(rs.getString("longew")); edSky.setText(rs.getString("sky")); edWater.setText(rs.getString("water")); edOverall.setText(rs.getString("overall")); edLive.setText(rs.getString("live")); edRowId.setText(rs.getString("rowid")); rs.close();} public void lastRecord(){ ResultSet rs = driver.executeQuery("select rowid,time_stamp,species,surveycount,location,terrain,latitude,latns,longitude,longew,sky,water,overall,live from surveyDB"); rs.last(); edTimestamp.setText(rs.getString("time_stamp")); edSpecies.setText(rs.getString("species")); edCount.setText(rs.getString("surveycount")); edLocation.setText(rs.getString("location")); edTerrain.setText(rs.getString("terrain")); edLatitude.setText(rs.getString("latitude")); edLatns.setText(rs.getString("latns")); edLongitude.setText(rs.getString("longitude")); edLongew.setText(rs.getString("longew")); edSky.setText(rs.getString("sky")); edWater.setText(rs.getString("water")); edOverall.setText(rs.getString("overall")); edLive.setText(rs.getString("live")); edRowId.setText(rs.getString("rowid")); rs.close();} private void doInsertUpdate(boolean isInsert){ String szTime_stamp = edTimestamp.getText(); String szSpecies = edSpecies.getText(); String szCount = edCount.getText(); String szLocation = edLocation.getText(); String szTerrain = edTerrain.getText(); String szLatitude = edLatitude.getText(); String szLatns = edLatns.getText(); String szLongitude = edLongitude.getText(); String szLongew = edLongew.getText(); String szSky = edSky.getText(); String szWater = edWater.getText(); String szOverall = edOverall.getText(); String szLive = edLive.getText(); long lastUpdated = new Time().getTimeLong(); int rows = -1; try{ if (isInsert){//Save //rows = driver.executeUpdate("insert into surveyDB values ('"+szTime_stamp+"','"+szLocation+"','"+szCount+"',"+lastUpdated+")"); rows = driver.executeUpdate("insert into surveyDB values ('"+szTime_stamp+"','"+szSpecies+"','"+szCount+"','"+szLocation+"','"+szTerrain+"','"+szLatitude+"','"+szLatns+"','"+szLongitude+"','"+szLongew+"','"+szSky+"','"+szWater+"','"+szOverall+"','"+szLive+"',"+lastUpdated+")"); }else//update rows = driver.executeUpdate("UPDATE surveyDB SET (time_stamp='"+szTime_stamp+"',species='"+szSpecies+"',surveycount='"+szCount+"',location='"+szLocation+"',terrain='"+szTerrain+"',latitude='"+szLatitude+"',latns='"+szLatns+"',longitude='"+szLongitude+"',longew='"+szLongew+"',sky='"+szSky+"',water='"+szWater+"',overall='"+szOverall+"',live='"+szLive+"',lastUpdated='"+lastUpdated+"')where rowid="+iRowId); if (rows == 1){ gpsDataLogger.invalidateRS(); clear(); }else Sound.beep(); } catch (Throwable t) {Vm.debug(t.getMessage());}} private void doDelete(){ int rows = driver.executeUpdate("delete surveyDB where rowid="+iRowId); //new MessageBox("Debug","Made it past delete function.").popupModal(); clear(); if (rows == 1){ //gpsDataLogger.invalidateRS();//WHY DO WE NEED THIS HERE??? clear();} else Sound.beep();} public void clear(){ edTimestamp.setText(""); edSpecies.setText(""); edCount.setText(""); edLocation.setText(""); edTerrain.setText(""); edLatitude.setText(""); edLatns.setText(""); edLongitude.setText(""); edLongew.setText(""); edSky.setText(""); edWater.setText(""); edOverall.setText(""); edLive.setText(""); edRowId.setText("");} /*************************************************************** * TrackLog- Saves Lat/Long coordinates and altitude as survey progresses * in a separate trackLog table. Makes and saves a timestamp, * and fetches and stores current Lat/Long coordinates. ***************************************************************/ protected void trackLog(){ //if (gpsDataLogger.iTrackLogFlag == 1){//set to 1 on menu dropdown String szLatitude = ""; String szLongitude = ""; String szLatns = ""; String szLongew = ""; String szAltitude = ""; szLatitude = gpsDataLogger.szLat; szLatns = gpsDataLogger.szLatNs; szLongitude = gpsDataLogger.szLong; szLongew = gpsDataLogger.szLongEw; szAltitude = gpsDataLogger.szAltitude; //if szLattitude or szLongitude == "", resets string to "No GPS signal..." if ((szLatitude.compareTo("")==0) || (szLongitude.compareTo("")==0)){ szLongitude = szLatitude = "No GPS signal...";} long T = new Time().getTimeLong(); String szTime_stamp = Convert.toString(T,1); long lastUpdated = new Time().getTimeLong(); int rows = -1; rows = driver.executeUpdate("insert into trackLog values ('"+szTime_stamp+"','"+szLatitude+"','"+szLatns+"','"+szLongitude+"','"+szLongew+"','"+szAltitude+"')"); } public void show(String rowid){//shows selected grid record in Data Entry form this.iRowId = Convert.toInt(rowid); ResultSet rs = driver.executeQuery("select * from surveyDB where rowid = "+this.iRowId); if (!rs.next()){ status("Row id not found: "+this.iRowId); clear();} else{ edTimestamp.setText(rs.getString("time_stamp")); edSpecies.setText(rs.getString("species")); edCount.setText(rs.getString("surveycount")); edLocation.setText(rs.getString("location")); edTerrain.setText(rs.getString("terrain")); edLatitude.setText(rs.getString("latitude")); edLatns.setText(rs.getString("latns")); edLongitude.setText(rs.getString("longitude")); edLongew.setText(rs.getString("longew")); edSky.setText(rs.getString("sky")); edWater.setText(rs.getString("water")); edOverall.setText(rs.getString("overall")); edLive.setText(rs.getString("live")); // edRowId.setText(rs.getString("rowid")); /* * Convert other rowid to edRowId commands to below??? */ edRowId.setText(Convert.toString(iRowId, 1)); /*.....below code doesn't work...don't bother w/it. "edRowId.setText(rs.getString("rowid"))" ; */ long lastUpdated = rs.getLong("lastupdated"); Time t = new Time(lastUpdated); status("Last updated: "+new Date(t)+" "+t);} } public void status(String msg){ lbStatus.setText(msg);} }
dataGps.java [code] import waba.ui.Button; import waba.ui.Check; import waba.ui.ComboBox; import waba.ui.Container; import waba.ui.ControlEvent; import waba.ui.Edit; import waba.ui.Event; import waba.ui.InputDialog; import waba.ui.Label; import waba.ui.ListBox; import waba.ui.MessageBox; import waba.ui.Timer; import superwaba.ext.xplat.io.gps.GPS; import waba.ui.MainWindow; import waba.ui.*; import waba.io.*; //import superwaba.ext.xplat.io.gps.GPS; import waba.sys.*; import waba.fx.*; import waba.io.DataStream; import waba.io.File; import waba.io.SerialPort; public class dataGps extends Container { Button btnRestartGps, btnHelp; Button btnStartStop = null; dataCapture dataCapture; MessageBox mbComPort, mbBluetoothHelp, mbDebug; StringBuffer sb = new StringBuffer(); static String szPlatform = Settings.platform;//gets host OS information //below arrays populate the listboxes w/baud rates and Com Port numbers String [] rgszComPort = {"1","2","3","4","5","6","7","8","9","10"}; String [] rgszBaud = {"300","1200","2400","4800","9600","14400","19200","38400","57600","115200"}; SerialPort sp = null; Timer savetimer = null; Label lBaud, lComPort, lBaudValue, lComPortValue; ComboBox cbBaud, cbComPort; String[] text = new String[]{"","","","","","","",""}; boolean bRunning = true; boolean bEatCheckSum = false; int iComPort; int iBaud; int msgCount; int iCounter = 0; double[] diLocation = new double[2]; public Time lastFix=new Time(); // Stores the time of lastFix. dataGps dataGps; public void onStart() { int iTmpHeight=this.height; btnHelp = new Button("Bluetooth Help"); btnHelp.commonGap = 6; add(btnHelp,LEFT+5,iTmpHeight/32*21); add(btnStartStop = new Button("START GPS"),RIGHT-5,SAME); btnStartStop.setBackColor(Color.RED); add(lBaud= new Label("Baud rate: "),LEFT+5,BOTTOM-5); add(cbBaud= new ComboBox(rgszBaud),AFTER+2,SAME); cbBaud.select(3);//sets 4800baud from rgszBaud string array as default add(lComPort= new Label("ComPort: "),AFTER+5,SAME); add(cbComPort= new ComboBox(rgszComPort),AFTER+2,SAME); cbComPort.select(7); //sets Com8 from rgszComPort string array as default SerialPortSettings();//fires up serial port and checks for data stream } /********************************************************************************************* * SerialPortSettings- Gets shown value from listbox for Baud and ComPort and sets serial port * if device is WinCE. Other devices use USB or dedicated BT port. If datastream is present * application is configured for data collection. If signal is not present serial port is closed, * sb (string buffer) is set to zero. btnStartStop is set to display 'Start GPS'. **********************************************************************************************/ public void SerialPortSettings(){ Object objComPort = cbComPort.getSelectedItem();//...there has to be a better way String szComPort = objComPort.toString();// rather than going from obj --> string iComPort = Convert.toInt(szComPort); // then string --> int... Object objBaud = cbBaud.getSelectedItem(); String szBaud = objBaud.toString(); iBaud = Convert.toInt(szBaud); if(bRunning == true){ if ((szPlatform.compareTo("Java")==0)||(szPlatform.compareTo("Win32")==0)|| (szPlatform.compareTo("Linux&q
|
|
« Última modificación: 30 Junio 2008, 17:48 pm por Hk »
|
En línea
|
|
|
|
HK
Desconectado
Mensajes: 247
t(L) Sayuri mi inspiracion
|
y el otro codigo fiveWayCenterButtonAssign.java import litebase.*; import waba.fx.Font; import waba.ui.Button; import waba.ui.ComboBox; import waba.ui.ControlEvent; import waba.ui.Event; import waba.ui.Label; import waba.ui.Window; import waba.fx.Color;
/******************************************************************************** * 5-way Center Button Assign * ------------------------------------ * This allows the user to quickly switch to a single field for 1 record only. * After the user presses the center toggle button either the species, location * or live-dead field switches to the alternate combobox string. After this count the * application will switch back to the previous value...rather than the top one * in the data array. e.g. If you are counting coho and want to add brown bear, * you will want to default back to coho and not sockeye after the count. Given that * this is a java window and not a java container, it was a little tricky to refresh * it's comboboxes after doing a location or a species edit. When this happens * a *new* fiveWayCenterButtonAssign window is created. See ControlEvent.WINDOW_CLOSED: * in the gpsDataLogger.java file for details. The logic and conditionals were also * slightly convoluted. * * However, the "Terrain" option does not do the above, when selected it merely causes * the joystick button to cause iteration through the terrain listbox. When the last * field is arrived at, the next press will take you back to the first field. *********************************************************************************/
public class fiveWayCenterButtonAssign extends Window { public static fiveWayCenterButtonAssign instance = new fiveWayCenterButtonAssign(); dataCapture dataCapture; gpsDataLogger gpsDataLogger; //locationEdit locationEdit; Label lblSpecies, lblLocation, lblLive, lblTerrain; static String szLocation = ""; static String szSpecies = ""; Button btnTerrain, btnExit; ComboBox cbSpecies, cbLocation, cbLive; String szHeight, szWidth, szPlatform, szRowId; String []szLive = {"Live","Carcasses"}; int iSpecies, iLocation, iSpecies5WayFlag; //private Font bigFont=new Font("SW",Font.PLAIN,72);//Depricated 09/07
private Font bigFont = Font.getFont("SW",true,Font.NORMAL_SIZE); LitebaseConnection driver = LitebaseConnection.getInstance("AZoe"); int iTmpWidth=this.width; int iTmpHeight=this.height; public fiveWayCenterButtonAssign(){ super ("5-Way Control Center Button Assign",ROUND_BORDER); setRect(CENTER,CENTER,iTmpWidth/32 * 31,iTmpWidth/8 * 5); setFont(bigFont); } public void onStart(){ szWidth = gpsDataLogger.szWidth; szHeight = gpsDataLogger.szHeight; szPlatform = gpsDataLogger.szPlatform; lblSpecies = new Label("Species:"); add (lblSpecies,LEFT+2,TOP+3); cbSpecies = new ComboBox(gpsDataLogger.szSpeciesLookup); add(cbSpecies); cbSpecies.setRect(AFTER+2,SAME,iTmpWidth/8*3,PREFERRED); cbSpecies.select(0); cbSpecies.setEnabled(true); lblLocation = new Label("Location:"); add (lblLocation,LEFT+2,AFTER+2); cbLocation = new ComboBox(gpsDataLogger.szLocationLookup); add(cbLocation); //cbLocation.setRect(iTmpWidth/8*2,AFTER+2,iTmpWidth/8*6-4,PREFERRED); cbLocation.setRect(AFTER+2,SAME,iTmpWidth/8*5,PREFERRED); cbLocation.select(0); cbLocation.setEnabled(true); lblLocation = new Label("Location:"); add (lblLocation,BEFORE-2,SAME); cbLive = new ComboBox(szLive); add(cbLive); cbLive.setRect(AFTER+2,AFTER+6,50,PREFERRED); cbLive.select(0); cbLive.setEnabled(true); lblLive = new Label("Live:"); add (lblLive,BEFORE-2,SAME); add(btnTerrain = new Button("Off"),AFTER+2,AFTER+6); lblTerrain = new Label("Terrain:"); add (lblTerrain,BEFORE-2,SAME); btnExit = new Button(" Exit "); //btnExit.setGap(1); Depricated 09/07 btnExit.commonGap = 6; add (btnExit,RIGHT-32,BOTTOM-5);} /************************************************************************** * Causes the selected control, (Carcase, Location, Species or Terrain) to * be a purdy green color. **************************************************************************/ private void SetColor(){ if(gpsDataLogger.iTerrainFlag == 1){ btnTerrain.setText("ON"); btnTerrain.setBackColor(Color.GREEN); cbSpecies.setBackColor(Color.WHITE); cbLocation.setBackColor(Color.WHITE); cbLive.setBackColor(Color.WHITE);} else if(gpsDataLogger.iSpeciesFlag == 1){ btnTerrain.setText("OFF"); btnTerrain.setBackColor(Color.WHITE); cbSpecies.setBackColor(Color.GREEN); cbLocation.setBackColor(Color.WHITE); cbLive.setBackColor(Color.WHITE);} else if(gpsDataLogger.iLocationFlag == 1){ btnTerrain.setText("OFF"); btnTerrain.setBackColor(Color.WHITE); cbSpecies.setBackColor(Color.WHITE); cbLocation.setBackColor(Color.GREEN); cbLive.setBackColor(Color.WHITE);} else if(gpsDataLogger.iCarcassFlag == 1){ btnTerrain.setText("OFF"); btnTerrain.setBackColor(Color.WHITE); cbSpecies.setBackColor(Color.WHITE); cbLocation.setBackColor(Color.WHITE); cbLive.setBackColor(Color.GREEN);} } public void onEvent(Event e){ switch (e.type){ case ControlEvent.PRESSED: if (e.target == cbSpecies){ gpsDataLogger.iToggleSpecies = cbSpecies.getSelectedIndex(); gpsDataLogger.iSpeciesFlag = 1; gpsDataLogger.iLocationFlag = 0; gpsDataLogger.iCarcassFlag = 0; gpsDataLogger.iTerrainFlag = 0; SetColor(); repaint();} else if (e.target == cbLocation){ gpsDataLogger.iToggleLocation = cbLocation.getSelectedIndex(); gpsDataLogger.iSpeciesFlag = 0; gpsDataLogger.iLocationFlag = 1; gpsDataLogger.iCarcassFlag = 0; gpsDataLogger.iTerrainFlag = 0; SetColor(); repaint();} else if (e.target == cbLive){ gpsDataLogger.iToggleLive = cbLive.getSelectedIndex(); gpsDataLogger.iSpeciesFlag = 0; gpsDataLogger.iLocationFlag = 0; gpsDataLogger.iCarcassFlag = 1; gpsDataLogger.iTerrainFlag = 0; SetColor(); repaint();} else if (e.target == btnTerrain){ gpsDataLogger.iSpeciesFlag = 0; gpsDataLogger.iLocationFlag = 0; gpsDataLogger.iCarcassFlag = 0; gpsDataLogger.iTerrainFlag = 1; SetColor(); repaint(); } else if (e.target == btnExit){ Exit();} } } public void Exit(){ unpop();} }
gpsDataLogger.java //******************************************************************** //*** gpsDataLogger *** //*** April 14, 2007 *** //*** Copyright Glenn Hollowell 2007 *** //*** glenn@blepsias.net *** //*** ********************************************************** *** //*** Software is provided "AS IS," without a warranty of any *** //*** kind. ALL EXPRESS OR IMPLIED REPRESENTATIONS AND WARRANTIES,*** //*** INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS *** //*** FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY *** //*** EXCLUDED. THE ENTIRE RISK ARISING OUT OF USING THE SOFTWARE *** //*** IS ASSUMED BY THE USER. See the GNU General Public License *** //*** at www.gnu.org for further details. *** //*** *********************************************************** *** //*** The application was written using the SuperWaba toolset *** //*** developed by Guilherme Hazan and his staff at *** //*** Superwaba, Ltd. Superwaba is a proprietary development *** //*** environment based in part on the Waba development *** //*** environment developed by WabaSoft, Inc. *** //********************************************************************
import litebase.*; import waba.sys.*; import waba.ui.*; import waba.sys.Convert; import waba.sys.Time; import waba.sys.Vm; import waba.ui.ControlEvent; import waba.ui.Event; import waba.ui.Label; import waba.ui.MainWindow; import waba.ui.MessageBox; import waba.fx.Color; import waba.io.File; import litebase.LitebaseConnection; import litebase.ResultSet;
public class gpsDataLogger extends MainWindow{ String szChangeLog = "14Feb2008 |-Installed new NMEA string parser logic| -added Altitude data to tracklog|and to DataCapture tab| -added Terrain listbox, (Ocean-Bay-Stream)|to 5-way button mapping.| -cleaned up GPS tab. Added baud and|ComPort listboxes.| -3/3 added query kill option to Settings| dropdown menu. "; LitebaseConnection driver; TabPanel tp; public dataCapture dataCapture; public dataEdit dataEdit; public dataGps dataGps; public Grid grid; public locationEdit locationEdit; public speciesEdit speciesEdit; public fiveWayCenterButtonAssign fiveWayCenterButtonAssign; MessageBox mbQueryKill,mbExitApplication,mbCreateMainTableCsvFile,mbCreateTrackLogCsvFile,mbCsvFileCreated,mbPurgeTrackLog,mbPurgeMainTable,mbMainTableDeleted,mbTrackLogTableDeleted,mbAboutGpsDataLogger,mbChangeLog; private MenuBar mbar; static String szPlatform = Settings.platform;//gets host device information //returned strings are "Java", "PalmOS", "Win32", "WindowsCE",or "PocketPC" static String szWidth = Convert.toString(Settings.screenWidth,1); static String szHeight = Convert.toString(Settings.screenHeight,1); static String []szLocationLookup = {""}; static String []szSpeciesLookup = {""}; static String szValid = ""; static String szLat, szLatNs, szLong, szLongEw, szTime, szAltitude; //static int iPortNumber = 8; static int iFirstLocationIteration = 0; static int iFirstSpeciesIteration = 0; static int iEmptyLocationLookupTable = 0; static int iEmptySpeciesLookupTable = 0; static int iTrackLogInterval = 5000;//default setting for tracklog: 1 LatLong every 5 seconds static int iTrackLogFlag = 0; static int iQueryKillFlag = 0;//this allows the user to stop species + location querying which gets slow if table is >~1200 records /******************************************************************************** * 5-way toggle Combobox array values * ------------------------------------ * Note: iOriginalSpecies and iOriginalLocation is the displayed value prior to * the user pressing the center toggle button and switching to the alternate * iToggleSpecies or iToggleLocation combobox string. This allows the * application to switch back to the previous value...rather than the top one * in the data array. e.g. If you are counting coho and have selected brown bear * as the species toggled to by the joystick for 1 record, you will want to default * back to coho and not sockeye after the Brown Bear count. *********************************************************************************/ static int iOriginalSpecies; static int iOriginalLocation; //This is the value for the one time selected value used by the 5-way joystick static int iToggleSpecies; static int iToggleLocation; static int iToggleLive; /*************************** * 5-way toggle Flags ***************************/ //Is set in menu dropdown, based on which dropdown is selected static int iCarcassFlag = 1; //sets carcass combobox as default 5-way joystick selection static int iTerrainFlag; static int iSpeciesFlag; static int iLocationFlag; //Is set when the string to be loaded is the alternate one time string static int iToggleSpeciesFlag; static int iToggleLocationFlag; public gpsDataLogger(){ super("gpsDataLogger, build 021408.1",TAB_ONLY_BORDER); if (!Settings.onDevice) waba.applet.JavaBridge.showMsgs = false; setDoubleBuffer(true); Settings.setUIStyle(Settings.Flat); driver = LitebaseConnection.getInstance("AZoe"); String []szLocationLookup;//maybe delete?? String []szSpeciesLookup;//maybe delete?? InterceptSystemKeys(); } public void onStart(){ if (!verifyDrivers()) return; CreateMainTable(); CreateTrackLogTable(); CreateLocationLookupTable(); CreateSpeciesLookupTable(); //gps variables to move between containers szLat = szLatNs = szLong = szLongEw = szTime = ""; //menubar titles and dropdown fields String col0[] = {"File","Edit Location Table","Edit Species Table","Purge Main Table","Purge TrackLog Table","Make MainTable.csv","Make Tracklog.csv","Exit application"};//first dropdown title and item. String col1[] = {"Settings","Start/Stop TrackLog","5-Way center button","Stop count query"};//second dropdown title and items. String col2[] = {"Info","About gpsDataLogger","About SuperWaba VM","DeviceOS, screensize","General Instructions"};//third dropdown title and item. setMenuBar(mbar = new MenuBar(MenuBar.strings2items(new String[][]{col0,col1,col2}))); //Strings for tab labels, then create tab panels String []tpCaptions = {"Data Capture","Data Edit","Table","GPS"}; add(tp = new TabPanel(tpCaptions)); tp.setBorderStyle(Window.NO_BORDER); tp.setRect(getClientRect()); //Grid column headers... Note: Grid setup must be first otherwise grid overlays tp #0. Bug?? String []gridCaptions = {"rowid","Timestamp","Species","Count","Location","Terrain","Latitude","N/S","Longitude","E/W","Sky","Water","Overall","Live"}; //Instantiate tab panels tp.setPanel(2,grid = new Grid(gridCaptions,false)); tp.setPanel(0,dataCapture = new dataCapture()); tp.setPanel(1,dataEdit = new dataEdit()); tp.setPanel(3,dataGps = new dataGps()); //creates string array from lookup tables, then loads into comboboxes LoadSpeciesComboBoxStringArray(); LoadLocationComboBoxStringArray(); invalidateRS(); //loads updated grid on grid tab /* * locationEdit = locationEdit.instance was up in Public gpsDataLogger, * but this requires a lookup table. Would get an exception thrown * if there had not been a lookup table created yet. Check this out * and delete if not so... */ locationEdit = locationEdit.instance; speciesEdit = speciesEdit.instance; fiveWayCenterButtonAssign = fiveWayCenterButtonAssign.instance; //below loads ComboBox correctly when CB is in 0 tab place dataCapture.updateSpeciesComboBox(); dataCapture.updateLocationComboBox(); dataCapture.cbLocation.repaintNow(); dataCapture.cbSpecies.repaintNow(); dataCapture.ShowSum(); } public void invalidateRS(){ //refreshes grid to match main data table ResultSet rs = driver.executeQuery("select rowid,time_stamp,species,surveycount,location,terrain,latitude,latns,longitude,longew,sky,water,overall,live,lastUpdated from surveyDB"); //rs.setDecimalPlaces(5,2); //investigate this... if (rs.first()) // checks to see if rs is new, (empty) grid.setItems(rs.getStrings(-1,true,false)); else grid.clear(); rs.close(); } ////////////////////////////Start Main Table methods////////////////////////////// private void CreateMainTable(){//main data table try{ driver.execute("create table surveyDB(time_stamp char(16), species char(30), surveycount int, location char(50), terrain char(30), latitude char(16), latns char(2), longitude char(16), longew char (2), sky char(2), water char(2), overall char(2), live char(12), lastUpdated long)"); } catch (AlreadyCreatedException ace) {} catch (DriverException pe){ Vm.debug(pe.getMessage()); } } private void CreateMainTableIndexes(){ driver.execute("CREATE INDEX IDX_0 ON surveyDB(rowid)"); // the index names are completely ignored driver.execute("CREATE INDEX IDX_1 ON surveyDB(time_stamp)"); //new MessageBox("Attention","Main Table Indexes May have been created").popupModal(); } private void PurgeMainTable(){ driver.executeUpdate("drop table surveyDB"); grid.clear(); } ///////////////End Main Table methods, Start trackLog table methods///////////////////// private void CreateTrackLogTable(){//table to store Track Log table, (i.e., snail tracks, bread crumbs, etc... try{ driver.execute("create table trackLog(time_stamp char(16), latitude char(16), latns char(2), longitude char(16), longew char(2), altitude char(5))"); } catch (AlreadyCreatedException ace) {} catch (DriverException pe){ Vm.debug(pe.getMessage()); } } private void PurgeTrackLogTable(){ driver.executeUpdate("drop table trackLog"); } ///////////////End trackLog Table methods, Start Location Lookup table methods///////////////////// private void CreateLocationLookupTable(){ //reference table that comboboxes are populated from. try{ driver.execute("create table locationLookupDB(location char(50), lastUpdated long)"); driver.execute("CREATE INDEX IDX_0 ON locationLookupDB(rowid)"); // the index names are completely ignored driver.execute("CREATE INDEX IDX_1 ON locationLookupDB(location)"); } catch (AlreadyCreatedException ace) {} catch (DriverException pe){ Vm.debug(pe.getMessage()); } } private void CreateLocationLookupTableIndexes(){ driver.execute("CREATE INDEX IDX_0 ON locationLookupDB(rowid)"); // the index names are completely ignored driver.execute("CREATE INDEX IDX_1 ON locationLookupDB(location)"); new MessageBox("Attention","Location Lookup Table Indexes May have been created").popupModal(); } ///////////////End Location Lookup Table methods...Start Species Lookup table methods////////////////// /////////////// Start Species Lookup table methods///////////////////// private void CreateSpeciesLookupTable(){ //reference table that comboboxes are populated from. try{ driver.execute("create table speciesLookupDB(species char(50), lastUpdated long)"); driver.execute("CREATE INDEX IDX_0 ON speciesLookupDB(rowid)"); // the index names are completely ignored driver.execute("CREATE INDEX IDX_1 ON speciesLookupDB(species)"); } catch (AlreadyCreatedException ace) {} catch (DriverException pe){ Vm.debug(pe.getMessage()); } } /* * Delete this if not needed, other wise fix it. */ private void CreateSpeciesLookupTableIndexes(){ driver.execute("CREATE INDEX IDX_0 ON speciesLookupDB(rowid)"); // the index names are completely ignored driver.execute("CREATE INDEX IDX_1 ON speciesLookupDB(species)"); new MessageBox("Attention","Species Lookup Table Indexes May have been created").popupModal(); } ///////////////////////////End Species Lookup Table methods////////////////////////////// public boolean LoadLocationComboBoxStringArray(){ //sets initial string length ResultSet rs = driver.executeQuery("select rowid,location from locationLookupDB"); rs.first(); if (!rs.first()){//checks to see if the lookup table is empty, if so repaintNow(); //a messagebox is posted to the user iEmptyLocationLookupTable = 1; //sets flag to be read by datacapture.updateLocationComboBox(). return(true);// Read comments there for explanation. } else{//iterates through lookup table and loads string array that populates cbLocation szLocationLookup[0] = rs.getString("location"); int i = 1; while (rs.next()){ //make string array dynamic if (i >= szLocationLookup.length) { String[] tmp = new String[szLocationLookup.length + 1]; Vm.copyArray(szLocationLookup, 0, tmp, 0, szLocationLookup.length); szLocationLookup = tmp; } szLocationLookup[i] = rs.getString("location"); ++i; } } return true; } public boolean LoadSpeciesComboBoxStringArray(){ //sets initial string length ResultSet rs = driver.executeQuery("select rowid,species from speciesLookupDB"); rs.first(); if (!rs.first()){//checks to see if the lookup table is empty, if so repaintNow(); //a messagebox is posted to the user //new MessageBox("Attention","SpeciesLookup Table is empty, | please enter a field.").popupModal(); iEmptySpeciesLookupTable = 1; //sets flag to be read by datacapture.updateSpeciesComboBox(). return(true);// Read comments there for explanation. } else{//sets string that populates cbSpecies to rs from lookuptable szSpeciesLookup[0] = rs.getString("species"); int i = 1; while (rs.next()){ //make string array dynamic if (i >= szSpeciesLookup.length) { String[] tmp = new String[szSpeciesLookup.length + 1]; Vm.copyArray(szSpeciesLookup, 0, tmp, 0, szSpeciesLookup.length); szSpeciesLookup = tmp; } szSpeciesLookup[i] = rs.getString("species"); ++i; } } return true; } private boolean verifyDrivers(){ try{ Class.forName("litebase.LitebaseConnection"); } catch (ClassNotFoundException cnfe){ add(new Label("Please install file|litebase.LitebaseConnection"),CENTER,TOP); return false; } return true; } /********************************************************************************* * Does carriage return for CSV file creation **********************************************************************************/ private static byte []enter = {(byte)'\r',(byte)'\n'}; /********************************************************************************* * Makes .csv file on the device of the surveyDB data table **********************************************************************************/ protected void makeCsvFileSurveyDB(){ int iFlag = 0;//sets up header row on first iteration through while loop String sb = "Time_stamp,Species,Count,Location,Terrain,Latitude,N-S,Longitude,E-W,Sky,Water,Overall,Live,RowId"; String szDateTime; //creates timestamp for the filename long T = new Time().getTimeLong(); szDateTime = Convert.toString(T,1); File f = new File("gpsDataLogger_"+szDateTime+".csv",File.CREATE);//change file name to gpsDataLogger <timestamp>.csv ResultSet rs = driver.executeQuery("select rowid,time_stamp,species,surveycount,location,terrain,latitude,latns,longitude,longew,sky,water,overall,live from surveyDB"); rs.first(); int iRowCount = rs.getRowCount(); int i = 0; while(i <= iRowCount){ if (iFlag !=0){ sb=(rs.getString("time_stamp")); sb=sb+","+(rs.getString("species")); sb=sb+","+(rs.getString("surveycount")); sb=sb+","+(rs.getString("location")); sb=sb+","+(rs.getString("terrain")); sb=sb+","+(rs.getString("latitude")); sb=sb+","+(rs.getString("latns")); sb=sb+","+(rs.getString("longitude")); sb=sb+","+(rs.getString("longew")); sb=sb+","+(rs.getString("sky")); sb=sb+","+(rs.getString("water")); sb=sb+","+(rs.getString("overall")); sb=sb+","+(rs.getString("live")); sb=sb+","+(rs.getString("rowid")); rs.next(); }else{ } byte []buf = sb.getBytes(); f.writeBytes(buf,0,buf.length); f.writeBytes(enter,0,2); ++i; iFlag = 1; } rs.close(); } /********************************************************************************* * Makes .csv file on the device of the trackLog data table **********************************************************************************/ protected void makeCsvFileTrackLog(){ int iTrackLogFlag = 0;//sets up header row on first iteration through while loop String sb = "Time_stamp,Latitude,N-S,Longitude,E-W,Altitude,RowID"; String szDateTime; //creates timestamp for the filename long T = new Time().getTimeLong(); szDateTime = Convert.toString(T,1); File f = new File("trackLog_"+szDateTime+".csv",File.CREATE); ResultSet rs = driver.executeQuery("select rowid,time_stamp,latitude,latns,longitude,longew,altitude from trackLog"); rs.first(); int iRowCount = rs.getRowCount(); int i = 0; while(i <= iRowCount){ if (iTrackLogFlag !=0){ sb=(rs.getString("time_stamp")); sb=sb+","+(rs.getString("latitude")); sb=sb+","+(rs.getString("latns")); sb=sb+","+(rs.getString("longitude")); sb=sb+","+(rs.getString("longew")); sb=sb+","+(rs.getString("altitude")); sb=sb+","+(rs.getString("rowid")); rs.next(); }else{ } byte []buf = sb.getBytes(); f.writeBytes(buf,0,buf.length); f.writeBytes(enter,0,2); ++i; iTrackLogFlag = 1; } rs.close(); } public void InterceptSystemKeys(){ Vm.interceptSystemKeys(Vm.SK_ALL | Vm.SK_LAUNCH); waba.sys.Vm.interceptSystemKeys( //WinCE waba.sys.Vm.SK_HARD1 | waba.sys.Vm.SK_HARD2 | waba.sys.Vm.SK_HARD3 | waba.sys.Vm.SK_HARD4 | waba.sys.Vm.SK_PAGE_DOWN | waba.sys.Vm.SK_PAGE_LEFT | waba.sys.Vm.SK_PAGE_RIGHT | waba.sys.Vm.SK_PAGE_UP| //Below is the center 'joystick' of the 5-way control waba.sys.Vm.SK_ACTION| //waba.sys.Vm.SK_ENTER| //additional palmOS silkscreened keys waba.sys.Vm.SK_SYNC | // Hotsync waba.sys.Vm.SK_FIND | // Search/Find waba.sys.Vm.SK_CALC | // Calculator waba.sys.Vm.SK_LAUNCH);//Home } /** * Five Way Toggle Handling- called when one of the hardware bottons that triggers a * count is pressed. When iCarcassFlag is 1, neither location nor species strings were * selected and the default is "Carcass". If either of the other flags are 1, then the * original value is swapped into the respective field and the flag is reset to "0". */ public void FiveWayToggleHandling(){ if (iCarcassFlag == 1){ dataCapture.cbLive.select(0);//switches back to second array field or "Carcass" dataCapture.ShowSum(); //shows total for "carcass" of that species iCarcassFlag = 1;} else if (iToggleSpeciesFlag == 1){ //10/31 //dataCapture.cbSpecies.select(gpsDataLogger.iOriginalSpecies); dataCapture.cbSpecies.select(iOriginalSpecies); dataCapture.ShowSum(); //shows total for original species iToggleSpeciesFlag = 0;} else if (iToggleLocationFlag == 1){ //10/31 //dataCapture.cbLocation.select(gpsDataLogger.iOriginalLocation); dataCapture.cbLocation.select(iOriginalLocation); dataCapture.ShowSum();//shows total for original location iToggleLocationFlag = 0;} } public void onEvent(Event e){ switch (e.type){ /*********************************************************************** * Hardware Button Logic: * Palm hard buttons are: Calendar(HARD1),Contacts(HARD2),Todo(HARD3), * MemoPad(HARD4) * Palm silk screened buttons are: Home(LAUNCH), Dropdown(MENU), * Hotsync(SYNC),Find(FIND) * * 5-way navigation buttons are IKeys.LEFT,RIGHT,PAGE_UP,PAGE_DOWN and ACTION * WinCE buttons are: HARD1, HARD2, HARD3, HARD4 * ***********************************************************************/ case KeyEvent.KEY_PRESS: KeyEvent que = (KeyEvent)e; //5-way navigation buttons: these are the "ring" around the joystick if (que.key == IKeys.LEFT && tp.getActiveTab() == 0){ dataCapture.PreviousSpecies();break;} else if (que.key == IKeys.RIGHT && tp.getActiveTab() == 0){ dataCapture.NextSpecies();break;} else if ((que.key == IKeys.PAGE_UP || que.key == IKeys.UP)&& tp.getActiveTab() == 0){ dataCapture.PreviousLocation();break;} else if ((que.key == IKeys.PAGE_DOWN ||que.key == IKeys.DOWN )&& tp.getActiveTab() == 0){ dataCapture.NextLocation();break;} //this is the "joystick" for the 5-way else if (que.key == IKeys.ACTION && tp.getActiveTab() == 0){ if (iSpeciesFlag == 1){ //flag is set when user selects Location/Species or Live-Dead from dropdown. if(iToggleSpecies == dataCapture.cbSpecies.getSelectedIndex()){ dataCapture.FiveWayToggle();break;} else{ iOriginalSpecies = dataCapture.cbSpecies.getSelectedIndex(); dataCapture.FiveWayToggle();} break;} else if (iLocationFlag == 1){ if(iToggleLocation == dataCapture.cbLocation.getSelectedIndex()){ dataCapture.FiveWayToggle();break;} else{iOriginalLocation = dataCapture.cbLocation.getSelectedIndex(); dataCapture.FiveWayToggle();}break;} else if (iCarcassFlag == 1){ dataCapture.FiveWayToggle();break;} else if (iTerrainFlag == 1){ dataCapture.FiveWayToggle();break;} } /*************************************************************** * End 5-way controls ***************************************************************/ //These are the standard 4 hardware buttons common to Palm and Windows devices else if (que.key == IKeys.HARD1 && tp.getActiveTab() == 0){//counts 1 sighting dataCapture.szCount = "1"; dataCapture.Count(); FiveWayToggleHandling();break;} else if (que.key == IKeys.HARD2 && tp.getActiveTab() == 0){//counts 10 sightings dataCapture.szCount = "10"; dataCapture.Count(); FiveWayToggleHandling();break;} else if (que.key == IKeys.HARD3 && tp.getActiveTab() == 0){//counts 100 sightings dataCapture.szCount = "100"; dataCapture.Count(); FiveWayToggleHandling();break;} else if (que.key == IKeys.HARD4 && tp.getActiveTab() == 0){//counts 1000 sightings dataCapture.szCount = "1000"; dataCapture.Count(); FiveWayToggleHandling();break;} case ControlEvent.WINDOW_CLOSED: String sel = null; /***************************************************************** * This is called from gpsDataLogger Main, so window_close event is *posted here. Both this window and locationEdit modify the lookup *tables that the species and location comboboxes are populated from, *so the windows and containers that show these must then be updated *accordingly. This is done differently dataCapture and *fiveWayCenterButtonAssign because one is a java container and the *other is a java window. *******************************************************************/ if (e.target == speciesEdit){ dataCapture.updateSpeciesComboBox(); dataCapture.cbSpecies.repaintNow();//break;} fiveWayCenterButtonAssign = new fiveWayCenterButtonAssign();break;} else if (e.target == locationEdit){ /**This is called from gpsDataLogger Main, so window_close event * is posted here. Updates java container dataCapture. See above * comment also...*/ dataCapture.updateLocationComboBox(); dataCapture.cbLocation.repaintNow();//break;} /**updates fiveWayCenterButtonAssign java window and it's species combobox*/ fiveWayCenterButtonAssign = new fiveWayCenterButtonAssign();break;} else if (e.target == mbar){ switch (mbar.getSelectedMenuItem()){ case -1: break; // no item selected case 001: //File Menu --> Open location edit popup container locationEdit.popupBlockingModal();break; //Settings menu --> locationEdit lookup table edit case 002: //File Menu --> Open species edit popup container speciesEdit.popupBlockingModal();break; //Settings menu --> speciesEdit lookup table edit case 003: //File Menu --> Purge Main Table String []szButtonArray = {"Yes","No"};//Settings menu --> purge data table, first WARNING window mbPurgeMainTable = new MessageBox("Table DELETE WARNING #1","Do you really want to purge | the Main table???", szButtonArray); mbPurgeMainTable.popupBlockingModal(); int idx = mbPurgeMainTable.getPressedButtonIndex(); if (idx == 0){//Operator chooses 'Yes', goes to second WARNING popup window String []szButtonArray2 = {"OK","Cancel"};//Settings menu --> purge data table mbPurgeMainTable = new MessageBox("Table DELETE WARNING #2","This will permanently delete the|ENTIRE set of collected data. ||Make damn sure that this is|what you REALLY want to do.|| Press 'OK' to delete your data,|or 'Cancel' to abort delete.|", szButtonArray2); mbPurgeMainTable.popupBlockingModal(); int idx2 = mbPurgeMainTable.getPressedButtonIndex();//fetches user choice from second warning, 0 = dump, 1 = cancel. if (idx2 == 0){//dumps main table, then recreates it PurgeMainTable(); CreateMainTable(); CreateMainTableIndexes(); invalidateRS();//refresh grid dataCapture.clear(); switch (tp.getActiveTab()){//below cleans up shown display tab after main table is purged case 0:break;//dataCapture count fields are cleared by datacapture.clear() above case 1:dataEdit.clear();break;// dataEdit clears dataEdit tab if that is displayed tab case 2: break;// grid is displayed tab, refresh will be done by invalidateRS()} }//show below message for about 3 seconds mbMainTableDeleted = new MessageBox("Attention","Main data table|has been cleared.",null); mbMainTableDeleted.popupModal(); waba.sys.Vm.sleep(2000); mbMainTableDeleted.unpop(); break;}} else if (idx == 1){}break;//operator has chosen NOT to delete from Delete Warning #1 message box case 004: //File Menu --> Purge TrackLog Table String []szClearTrackLogButtonArray = {"Yes","No"};//Settings menu --> purge TrackLog data table, first WARNING window mbPurgeTrackLog = new MessageBox("Table DELETE WARNING #1","Do you really want to purge | the TrackLog table???", szClearTrackLogButtonArray); mbPurgeTrackLog.popupBlockingModal(); int idClearTrackLog = mbPurgeTrackLog.getPressedButtonIndex(); if (idClearTrackLog == 0){//Operator chooses 'Yes', goes to second WARNING popup window String []szClearTrackLogButtonArray2 = {"OK","Cancel"};//Settings menu --> purge data table mbPurgeTrackLog = new MessageBox("Table DELETE WARNING #2","This will permanently delete the |ENTIRE set of collected TrackLog data.||Make damn sure that this is |what you REALLY want to do.|| Press 'OK' to delete your data,|or 'Cancel' to abort delete.|", szClearTrackLogButtonArray2); mbPurgeTrackLog.popupBlockingModal(); int idx2 = mbPurgeTrackLog.getPressedButtonIndex();//fetches user choice from second warning, 0 = dump, 1 = cancel. if (idx2 == 0){//dumps TrackLog table, then recreates it PurgeTrackLogTable(); CreateTrackLogTable(); mbTrackLogTableDeleted = new MessageBox("Attention","TrackLog data table|has been cleared.",null); mbTrackLogTableDeleted.popupModal(); waba.sys.Vm.sleep(2000); mbTrackLogTableDeleted.unpop(); break;}} else if (idClearTrackLog == 1){}break;//operator has chosen NOT to delete from Delete Warning #1 message box case 005://File menu --> create MainTable.csv file String []szCreateMainTableCsvFileButtonArray = {"Yes","No"}; mbCreateMainTableCsvFile = new MessageBox("Attention","Do you really want to create |a .csv copy of the Main table?||This WILL NOT delete the |tables from the PDA. ", szCreateMainTableCsvFileButtonArray); mbCreateMainTableCsvFile.popupBlockingModal(); int idxMainTableCsvFile = mbCreateMainTableCsvFile.getPressedButtonIndex(); if (idxMainTableCsvFile == 0){//creates csv file on device makeCsvFileSurveyDB(); // Little 2 second popup window telling user that job is complete mbCsvFileCreated = new MessageBox("Attention","A *.csv data file|has been created.",null); mbCsvFileCreated.popupModal(); waba.sys.Vm.sleep(2000); mbCsvFileCreated.unpop(); break; } else{break;} //don't make .csv file, back to application case 006://File menu --> create TrackLog.csv file String []szCreateTrackLogCsvFileButtonArray = {"Yes","No"}; mbCreateTrackLogCsvFile = new MessageBox("Attention","Do you really want to create |a .csv copy of the TrackLog table?||This WILL NOT delete the |tables from the PDA. ", szCreateTrackLogCsvFileButtonArray); mbCreateTrackLogCsvFile.popupBlockingModal(); int idxCsvFile = mbCreateTrackLogCsvFile.getPressedButtonIndex(); if (idxCsvFile == 0){//creates csv file on device makeCsvFileTrackLog(); // Little 2 second popup window telling user that job is complete mbCsvFileCreated = new MessageBox("Attention","A *.csv data file|has been created.",null); mbCsvFileCreated.popupModal(); waba.sys.Vm.sleep(2000); mbCsvFileCreated.unpop(); break; } else{break;} //don't make .csv file, back to application case 007:// File menu --> Exit selection String []szExitButtonArray = {"Yes","No"}; mbExitApplication = new MessageBox("Attention","Do you really want to exit|the application?", szExitButtonArray); mbExitApplication.setUnpopDelay(3000); mbExitApplication.popupBlockingModal(); int idxExit = mbExitApplication.getPressedButtonIndex(); if (idxExit == 0){//exits application MainWindow.getMainWindow().exit(0); break; } else{break;} //don't exit, back to app /************************************************************************************************* * Settings menu: Start-Stop tracklog, 5-way control configuring, database querying stop... *************************************************************************************************/ case 101: //Settings menu --> Starts trackLog collection, allows user to modify interval int iTrackLogSeconds = iTrackLogInterval/1000; String []szTrackLogButtonArray = {"Start","Cancel/Stop"}; InputDialog idTrackLog = new InputDialog("Start TrackLog", " Please enter the desired Track |Log interval in seconds for |Lat/Long coordinates and then |press 'Start'.| The default interval 15 seconds.",Convert.toString(iTrackLogSeconds),szTrackLogButtonArray); idTrackLog.popupBlockingModal(); int idxTrackLog = idTrackLog.getPressedButtonIndex(); if (idxTrackLog == 0){//starts trackLog() String szTemp = idTrackLog.getValue(); iTrackLogSeconds = Convert.toInt(szTemp); iTrackLogInterval = iTrackLogSeconds*1000;//converts seconds to milliseconds dataEdit.CreateTrackLogTimer(); iTrackLogFlag = 1;//trips On indicator on dataCapture tab dataCapture.LoadTrackLogIndicator(); break; } else{ //don't start TrackLog, cancel if running, back to app dataEdit.removeTimer(dataEdit.trackLogTimer); iTrackLogFlag = 0; dataCapture.LoadTrackLogIndicator(); break;} case 102://Settings menu --> 5-Way center button assign fiveWayCenterButtonAssign.popupBlockingModal();break; case 103://Settings menu --> stop species-location queries String []szQueryKillArray = {"OFF","ON"}; mbQueryKill = new MessageBox("Attention","Selecting 'OFF' will stop querying|the main table and refreshing|the sum after each count event.|| Choosing 'ON' will turn it back on.||'ON' is the default at startup.", szQueryKillArray); mbQueryKill.setBackColor(Color.YELLOW); mbQueryKill.setForeColor(Color.BLACK); mbQueryKill.setUnpopDelay(10000); mbQueryKill.popupBlockingModal(); int idxQueryKillExit = mbQueryKill.getPressedButtonIndex(); if (idxQueryKillExit == 0){//Turns table querying OFF iQueryKillFlag = 1; break; } else{//Turns table querying ON iQueryKillFlag = 0; break;} //don't exit, back to app /******************************************************************************************** * Info menu: About gpsDataLogger, SuperWaba, OS/Device, General Instructions, changelog ********************************************************************************************/ case 201: //about gpsDataLogger, changelog popup String []szAboutGpsDataLogger = {"Close","Show Change Log"}; mbAboutGpsDataLogger = new MessageBox("About gpsDataLogger","|The purpose of this application|is to allow for recording of|field data with only minimal visual|contact with the PDA device |during data collection. | ", szAboutGpsDataLogger); mbAboutGpsDataLogger.setUnpopDelay(5000); mbAboutGpsDataLogger.popupBlockingModal(); int idxAboutGpsDataLogger = mbAboutGpsDataLogger.getPressedButtonIndex(); if (idxAboutGpsDataLogger == 0){//0 = closes popup and return to app break; } else if (idxAboutGpsDataLogger == 1){//1 = pops up change log, text is left aligned. mbChangeLog = new MessageBox("Change Log",szChangeLog); mbChangeLog.setBackColor(Color.ORANGE); mbChangeLog.setTextAlignment(2); mbChangeLog.popupBlockingModal(); break;} case 202: new MessageBox("About SuperWaba","SuperWaba Virtual Machine 5.83 | Copyright (c)2000-2008 | Guilherme Campos Hazan,| SuperWaba Ltda,| Rio de Janeiro, Brazil| Phone: +55 21 2239-6695 | www.superwaba.com|| SuperWaba is an enhanced version | of the Waba Virtual Machine | Copyright (c) 1998,1999 WabaSoft | www.wabasoft.com").popupModal(); break; case 203: new MessageBox("OS/screensize",szPlatform + " | " +szHeight + "H "+ "x" + szWidth +"W").popupModal(); break; case 204: new MessageBox("General Instructions","To modify fields in the location| or species listboxs on dataCapture|tab, tap the menubar, |select 'Edit Lookup Table'. This |window allows users to browse, add, |update or even delete the lookup |table. Users can edit data in the |main table on the Data Edit tab. |The main table can be deleted |by selecting the menubar followed | by 'Purge Main Table'. | Have fun, be careful and always || BACK UP YOUR DATA!").popupModal(); break; }break; } case ControlEvent.PRESSED: if (e.target == grid){//target is grid GridEvent ge = (GridEvent)e; if (false) Vm.debug(ge.col+","+ge.row); } else if (e.target == tp)//target is one of the three tab panels, (GPS panel no event...) switch (tp.getActiveTab()){ case 0: // dataCapture tab dataCapture.updateSpeciesComboBox(); dataCapture.cbSpecies.repaintNow(); dataCapture.updateLocationComboBox(); dataCapture.cbLocation.repaintNow(); break; case 1: // dataEdit tab String []item = grid.getSelectedItem(); if (item == null) dataEdit.clear(); else dataEdit.show(item[0]); break; case 2: // grid tab invalidateRS(); // update the grid }break; } } }
locationEdit.java [code] import litebase.*; import litebase.ui.*; import waba.fx.Font; import waba.fx.Sound; import waba.sys.Convert; import waba.sys.Time; import waba.sys.Vm; import waba.ui.Button; import waba.ui.ComboBox; import waba.ui.Container; import waba.ui.Control; import waba.ui.ControlEvent; import waba.ui.Edit; import waba.ui.Event; import waba.ui.Label; import waba.ui.MainWindow; import waba.ui.MessageBox; import waba.ui.PushButtonGroup; import waba.ui.TabPanel; import waba.ui.Window; /* * locationEdit pops up a window allowing the user to edit values in the lookup * table that load the "Location" combobox. * */ public class locationEdit extends Window { public static locationEdit instance = new locationEdit(); dataCapture dataCapture; gpsDataLogger gpsDataLogger; Button btnTest,btnPurge,btnFirstRecord, btnNextRecord, btnPreviousRecord, btnLastRecord, btnClear, btnSave, btnUpdate,btnDelete,btnExit; Edit edLocation,edRowId; String szInput = "",s; MessageBox mb1,mbLocationTableEmpty; private PushButtonGroup pbgBrowseButtons; String szBrowseButtons[] = {" Save ","Update","Delete","Clear "," ||<<"," << "," >> "," >>|| "}; String szHeight, szWidth, szPlatform, szRowId; int iRowId; char c; //private Font bigFont=new Font("SW",Font.PLAIN,72);//Depricated 09/07 private Font bigFont = Font.getFont("SW",true,Font.NORMAL_SIZE); LitebaseConnection driver = LitebaseConnection.getInstance("AZoe"); public locationEdit(){ super ("Location Table Edit",ROUND_BORDER); szWidth = gpsDataLogger.szWidth; szHeight = gpsDataLogger.szHeight; szPlatform = gpsDataLogger.szPlatform; int iTmpWidth=this.width; int iTmpHeight=this.height;//delete this??? setRect(CENTER,CENTER,iTmpWidth/32 * 31,iTmpWidth/8 * 5); LoadLocationComboBoxStringArray(); add(new Label("Row Id"),LEFT+2,TOP+2); edRowId = new Edit(); add (edRowId); edRowId.setRect(AFTER+2,SAME-1,25,PREFERRED); edRowId.setMaxLength(5); edRowId.setText(""); edRowId.setEditable(false); btnExit = new Button(" Exit "); //btnExit.setGap(1);Depricated 09/07 btnExit.commonGap = 6; add (btnExit,RIGHT-32,SAME); add(new Label("Location"),LEFT+2,AFTER+4); edLocation = new Edit(); add (edLocation); edLocation.setRect(AFTER+2,SAME,iTmpWidth/16 * 10,PREFERRED); edLocation.setMaxLength(40); edLocation.setText(""); pbgBrowseButtons = new PushButtonGroup(szBrowseButtons,false,-1,2,6,2,true,PushButtonGroup.BUTTON); add(pbgBrowseButtons,CENTER,AFTER+2); btnPurge = new Button("Purge Location Lookup Table"); //btnPurge.setGap(1); btnPurge.commonGap = 1; add (btnPurge,CENTER,AFTER+2); //setFocusLess(true); } public void onStart() { setFont(bigFont);} private boolean verifyFields(){ boolean locationOk = edLocation.getText().length() > 0; StringBuffer sb = new StringBuffer(); if (!locationOk) sb.append("location|"); if (sb.length() > 0) { sb.setLength(sb.length()-1); // remove the last | new MessageBox("Attention","You must fill/correct|the following fields:|"+sb).popupModal(); repaint(); return false;} return true;} public void onEvent(Event e){ int ipbg; Control edAtual; if (e.type == ControlEvent.PRESSED){ if ((e.target == pbgBrowseButtons && (ipbg = pbgBrowseButtons.getSelected()) != -1)){ switch (ipbg){ case -1:break; //no item selected case 0:{ // Save button edAtual = getParentWindow().getFocus(); if (edAtual != null) { if (verifyFields()) doInsertUpdate(true); clear(); gpsDataLogger.iEmptyLocationLookupTable = 0;} //reset flag to 'not empty' }break; case 1:{ // Update button edAtual = getParentWindow().getFocus(); if (edAtual != null) { if (verifyFields()){ if (iRowId > 0){ doInsertUpdate(false); clear();} else Sound.beep();} } }break; case 2:{ // Delete button edAtual = getParentWindow().getFocus(); if (edAtual != null) { szRowId = edRowId.getText(); iRowId = Convert.toInt(szRowId); if (iRowId > 0) doDelete(); else Sound.beep();} }break; case 3:{ // Clear button edAtual = getParentWindow().getFocus(); if (edAtual != null) { clear();} }break; case 4:{ // First Record, ("||<<") button edAtual = getParentWindow().getFocus(); if (edAtual != null) { firstRecord();} }break; case 5:{ // Previous Record, ("<<") button edAtual = getParentWindow().getFocus(); if (edAtual != null) { previousRecord();} }break; case 6:{ // Next Record, (">>") button edAtual = getParentWindow().getFocus(); if (edAtual != null) { nextRecord();} }break; case 7:{ // Last Record, (">>||") button edAtual = getParentWindow().getFocus(); if (edAtual != null) { lastRecord();} }break; } } else if (e.target == btnExit){ LoadLocationComboBoxStringArray(); Exit();} else if (e.target == btnPurge){ String []szButtonArray = {"Yes","No"}; mb1 = new MessageBox("Attention","Do you really want to purge | the lookup table???", szButtonArray); mb1.popupBlockingModal(); int idx = mb1.getPressedButtonIndex(); if (idx == 0){ PurgeLocationLookupTable(); CreateLocationLookupTable(); CreateLocationLookupTableIndex(); clear(); gpsDataLogger.iEmptyLocationLookupTable = 1;} //reset flag to 'empty' else if (idx == 1){ } } } } public void firstRecord(){ ResultSet rs = driver.executeQuery("select rowid,location, from locationLookupDB"); rs.first(); edLocation.setText(rs.getString("location")); edRowId.setText(rs.getString("rowid")); rs.close();} public void previousRecord(){//adjusted to keep rowId zero from displaying szRowId = edRowId.getText(); iRowId = Convert.toInt(szRowId); ResultSet rs = driver.executeQuery("select rowid, location from locationLookupDB where rowid <"+iRowId); //single record is returned?? if ((rs.getString("rowid").compareTo("0")==0)){//keeps always empty rowId #0 from being displayed and confusing people... rs.close(); rs = driver.executeQuery("select rowid,location, from locationLookupDB");//full recordset is returned }else{//...if rowId 1 or >... rs.last(); edLocation.setText(rs.getString("location")); edRowId.setText(rs.getString("rowid")); rs.close();} } public void nextRecord(){//cleaned up so that rowId 0 is ignored szRowId = edRowId.getText(); iRowId = Convert.toInt(szRowId); ResultSet rs = driver.executeQuery("select rowid,location from locationLookupDB where rowid >"+iRowId);//...returns all records greater than current, unless there are no more in which case zero is returned. if ((rs.getString("rowid").compareTo("0")==0)){//keeps always empty rowId #0 from being displayed and confusing people... rs.close(); //dumps rs, below makes full rs rs = driver.executeQuery("select rowid,location, from locationLookupDB");//full recordset is returned rs.last(); //only last record in rs is shown }else{ //shows first record of first rs above w/all of the > rowId records rs.first();} edLocation.setText(rs.getString("location")); edRowId.setText(rs.getString("rowid")); rs.close();} public void lastRecord(){ ResultSet rs = driver.executeQuery("select rowid,location from locationLookupDB"); rs.last(); edLocation.setText(rs.getString("location")); edRowId.setText(rs.getString("rowid")); rs.close();} private void doInsertUpdate(boolean isInsert){ String szLocation = edLocation.getText(); String szRowId = edRowId.getText(); iRowId = Convert.toInt(szRowId); long lastUpdated = new Time().getTimeLong(); int rows = -1; try{ if (isInsert){//Save rows = driver.executeUpdate("insert into locationLookupDB values ('"+szLocation+"',"+lastUpdated+")"); }else//update rows = driver.executeUpdate("UPDATE locationLookupDB SET (location='"+szLocation+"',lastUpdated='"+lastUpdated+"')WHERE rowid="+iRowId); if (rows == 1){ clear();} else Sound.beep();} catch (Throwable t) {Vm.debug(t.getMessage());} } private void doDelete(){ String szRowId = edRowId.getText(); int rows = driver.executeUpdate("delete locationLookupDB where rowid="+szRowId); clear(); if (rows == 1){ clear();} else Sound.beep();} public void clear(){ edLocation.setText(""); edRowId.setText("");} public void Exit(){ gpsDataLogger.iFirstLocationIteration = 2; unpop();} /*************************************************************************************** * LoadLocationComboBoxStringArray() This function moves strings that have been entered * in the lookup table into the string array (gpsdataLogger.szLocationLookup) that populates the ComboBox. * It does this by: * 1) Querying the lookup table creating a resultset with the location categories * that need to be loaded into the ComboBox. * 2) Creates a temporary string array, (szTemp1)and then copies the szLocationLookup * string array into the szTemp1. The array reference for szTemp1 is then copied * to szLocationLookup. This is useful for removing the "Location Lookup Table Empty" string that * is inserted when appropriate. Part 1 also allows for reductions in the array * size. * 3) Part 2 expands the array by methods similar to above only that a WHILE loop is used * while rs.next is true, and that the szTemp2 string is incremented 1 string longer at * each loop to allow for the returned rs.next string. ******************************************************************************************/ public void LoadLocationComboBoxStringArray(){ ResultSet rs = driver.executeQuery("select rowid,location from locationLookupDB"); //Part 1: resets szLocationLookup string to allow for reductions in table records //gpsDataLogger.szLocationLookup = {""}; String []szTemp1 = {""}; Vm.copyArray(gpsDataLogger.szLocationLookup, 0, szTemp1, 0, szTemp1.length); gpsDataLogger.szLocationLookup = szTemp1; //Part 2: populates remainder of table, expanding the array length as needed rs.first(); gpsDataLogger.szLocationLookup[0] = rs.getString("location"); int i = 1; while (rs.next()){ //make string array dynamic if (i >= gpsDataLogger.szLocationLookup.length) { String[] szTemp2 = new String[gpsDataLogger.szLocationLookup.length + 1]; Vm.copyArray(gpsDataLogger.szLocationLookup, 0, szTemp2, 0, gpsDataLogger.szLocationLookup.length); gpsDataLogger.szLocationLookup = szTemp2;} gpsDataLogger.szLocationLookup = rs.getString("location"); ++i;} rs.close();} // below Part 2 causes arrayIndexOutOfBoundsException() to be thrown, but why? /* String[] ret = new String[rs.getRowCount()]; rs.beforeFirst(); for (int i=0; rs.next(); i++) ret = rs.getString("location"); gpsDataLogger.szLocationLookup = ret; rs.close(); } */ private void PurgeLo
|
|
|
En línea
|
|
|
|
|
|