Example usage for org.joda.time DateTime toString

List of usage examples for org.joda.time DateTime toString

Introduction

In this page you can find the example usage for org.joda.time DateTime toString.

Prototype

public String toString(String pattern) 

Source Link

Document

Output the instant using the specified format pattern.

Usage

From source file:de.dmarcini.submatix.android4.full.utils.SPX42LogManager.java

License:Open Source License

  /**
 * //from w w  w. j a  v a2s. co m
 * Gib eine Liste mit Logs fr ein Gert zurck
 * 
 * Project: SubmatixBTLoggerAndroid Package: de.dmarcini.submatix.android4.utils
 * 
 * 
 * Stand: 28.08.2013
 * 
 * @param _deviceId
 * @param res
 * @param descOrder
 *          Absteigende Sortierung?
 * @return Vector mit ReadLogItemObj
 */
@SuppressLint( "DefaultLocale" )
public Vector<ReadLogItemObj> getDiveListForDevice( int _deviceId, Resources res, boolean descOrder )
{
  String sql;
  Cursor cu;
  String orderPhrase = " ";
  Vector<ReadLogItemObj> diveHeadList = new Vector<ReadLogItemObj>();
  //
  if( ApplicationDEBUG.DEBUG ) Log.d( TAG, "getDiveListForDevice..." );
  if( _deviceId < 0 )
  {
    Vector<Integer> lst = getDeviceIdList();
    if( lst != null && lst.size() > 0 )
    {
      _deviceId = lst.get( 0 );
    }
    else
    {
      return( null );
    }
  }
  if( descOrder )
  {
    orderPhrase = "desc";
  }
  // @formatter:off
  sql = String.format( Locale.ENGLISH, "select %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s from %s where %s=%d order by %s %s;", 
          ProjectConst.H_DIVEID,                     // 0 
          ProjectConst.H_FILEONMOBILE,               // 1
          ProjectConst.H_DIVENUMBERONSPX,            // 2
          ProjectConst.H_FILEONSPX,                  // 3
          ProjectConst.H_DEVICESERIAL,               // 4
          ProjectConst.H_STARTTIME,                  // 5
          ProjectConst.H_HADSEND,                    // 6
          ProjectConst.H_FIRSTTEMP,                  // 7
          ProjectConst.H_LOWTEMP,                    // 8
          ProjectConst.H_MAXDEPTH,                   // 9
          ProjectConst.H_SAMPLES,                    // 10
          ProjectConst.H_DIVELENGTH,                 // 11
          ProjectConst.H_UNITS,                      // 12
          ProjectConst.H_NOTES,                      // 13
          ProjectConst.H_GEO_LON,                    // 14
          ProjectConst.H_GEO_LAT,                    // 15
          ProjectConst.H_TABLE_DIVELOGS,             // Tabelle
          ProjectConst.H_DEVICEID, _deviceId,        // nur Gertenummer
          ProjectConst.H_DIVENUMBERONSPX,            // Ordne nach Tauchlog-Nummer auf SPX
          orderPhrase);           
  // @formatter:on
  cu = dBase.rawQuery( sql, null );
  if( ApplicationDEBUG.DEBUG ) Log.d( TAG, "getDiveListForDevice had <" + cu.getCount() + "> results." );
  if( cu.moveToFirst() )
  {
    do
    {
      long startTm = cu.getLong( 5 );
      DateTime startDateTime = new DateTime( startTm );
      String detailText = String.format( res.getString( R.string.logread_saved_format ), cu.getInt( 9 ) / 10.0, res.getString( R.string.app_unit_depth_metric ),
              cu.getInt( 11 ) / 60, cu.getInt( 11 ) % 60 );
      String itemName = String.format( "#%03d: %s", cu.getInt( 2 ), startDateTime.toString( FragmentCommonActivity.localTimeFormatter ) );
      ReadLogItemObj rlo = new ReadLogItemObj();
      rlo.isSaved = true;
      rlo.itemName = itemName;
      rlo.itemNameOnSPX = cu.getString( 3 );
      rlo.itemDetail = detailText;
      rlo.dbId = cu.getInt( 0 );
      rlo.numberOnSPX = cu.getInt( 2 );
      rlo.startTimeMilis = startTm;
      rlo.isMarked = false;
      rlo.tagId = -1;
      rlo.fileOnMobile = cu.getString( 1 );
      rlo.firstTemp = cu.getFloat( 7 );
      rlo.lowTemp = cu.getFloat( 8 );
      rlo.maxDepth = cu.getInt( 9 );
      rlo.countSamples = cu.getInt( 10 );
      rlo.diveLen = cu.getInt( 11 );
      rlo.units = cu.getString( 12 );
      rlo.notes = cu.getString( 13 );
      rlo.geoLon = cu.getString( 14 );
      rlo.geoLat = cu.getString( 15 );
      if( rlo.notes == null || rlo.notes.isEmpty() )
      {
        rlo.notes = " ";
      }
      diveHeadList.add( rlo );
    }
    while( cu.moveToNext() );
    //
    // Cursor schliessen
    //
    cu.close();
    if( ApplicationDEBUG.DEBUG ) Log.d( TAG, "getDiveListForDevice: OK" );
    return( diveHeadList );
  }
  return( null );
}

From source file:de.dmarcini.submatix.android4.full.utils.SPX42LogManager.java

License:Open Source License

  /**
 * /*w ww .  ja v  a2  s.  co  m*/
 * Gib ein Headerobjekt fr einene bestimmten Tauchgang zurck
 * 
 * Project: SubmatixBTLoggerAndroid Package: de.dmarcini.submatix.android4.full.utils
 * 
 * Stand: 01.02.2014
 * 
 * @param dbId
 * @param res
 * @return Headerobjekt
 */
public ReadLogItemObj getLogObjForDbId( int dbId, Resources res )
{
  String sql;
  Cursor cu;
  ReadLogItemObj rlo = new ReadLogItemObj();
  //
  if( ApplicationDEBUG.DEBUG ) Log.d( TAG, "getLogObjForDbId..." );
  if( dbId < 1 )
  {
    return( null );
  }
  // @formatter:off
  sql = String.format( Locale.ENGLISH, "select %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s from %s where %s=%d", 
          ProjectConst.H_DIVEID,                     // 0 
          ProjectConst.H_FILEONMOBILE,               // 1
          ProjectConst.H_DIVENUMBERONSPX,            // 2
          ProjectConst.H_FILEONSPX,                  // 3
          ProjectConst.H_DEVICESERIAL,               // 4
          ProjectConst.H_STARTTIME,                  // 5
          ProjectConst.H_HADSEND,                    // 6
          ProjectConst.H_FIRSTTEMP,                  // 7
          ProjectConst.H_LOWTEMP,                    // 8
          ProjectConst.H_MAXDEPTH,                   // 9
          ProjectConst.H_SAMPLES,                    // 10
          ProjectConst.H_DIVELENGTH,                 // 11
          ProjectConst.H_UNITS,                      // 12
          ProjectConst.H_NOTES,                      // 13
          ProjectConst.H_GEO_LON,                    // 14
          ProjectConst.H_GEO_LAT,                    // 15
          ProjectConst.H_TABLE_DIVELOGS,             // Tabelle
          ProjectConst.H_DIVEID, dbId               // fr Dive-ID
          );           
  // @formatter:on
  cu = dBase.rawQuery( sql, null );
  if( ApplicationDEBUG.DEBUG ) Log.d( TAG, "getLogObjForDbId had <" + cu.getCount() + "> results." );
  if( cu.moveToFirst() )
  {
    long startTm = cu.getLong( 5 );
    DateTime startDateTime = new DateTime( startTm );
    String detailText = String.format( res.getString( R.string.logread_saved_format ), cu.getInt( 9 ) / 10.0, res.getString( R.string.app_unit_depth_metric ),
            cu.getInt( 11 ) / 60, cu.getInt( 11 ) % 60 );
    String itemName = String.format( "#%03d: %s", cu.getInt( 2 ), startDateTime.toString( FragmentCommonActivity.localTimeFormatter ) );
    rlo.isSaved = true;
    rlo.itemName = itemName;
    rlo.itemNameOnSPX = cu.getString( 3 );
    rlo.itemDetail = detailText;
    rlo.dbId = cu.getInt( 0 );
    rlo.numberOnSPX = cu.getInt( 2 );
    rlo.startTimeMilis = startTm;
    rlo.isMarked = false;
    rlo.tagId = -1;
    rlo.fileOnMobile = cu.getString( 1 );
    rlo.firstTemp = cu.getFloat( 7 );
    rlo.lowTemp = cu.getFloat( 8 );
    rlo.maxDepth = cu.getInt( 9 );
    rlo.countSamples = cu.getInt( 10 );
    rlo.diveLen = cu.getInt( 11 );
    rlo.units = cu.getString( 12 );
    rlo.notes = cu.getString( 13 );
    rlo.geoLon = cu.getString( 14 );
    rlo.geoLat = cu.getString( 15 );
    if( rlo.notes == null || rlo.notes.isEmpty() )
    {
      rlo.notes = " ";
    }
    //
    // Cursor schliessen
    //
    cu.close();
    if( ApplicationDEBUG.DEBUG ) Log.d( TAG, "getLogObjForDbId: OK" );
    return( rlo );
  }
  return( null );
}

From source file:de.dmarcini.submatix.pclogger.gui.MainCommGUI.java

License:Open Source License

/**
 * Decodiere die Nachricht ber einen Logverzeichniseintrag Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui
 * //from w ww  . j  a  v a2  s .  c  om
 * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 05.05.2012
 * @param entryMsg
 * @return
 */
private String decodeLogDirEntry(String entryMsg) {
    // Message etwa so <~41:21:9_4_10_20_44_55.txt:22>
    String[] fields;
    String fileName;
    int number, max;
    int day, month, year, hour, minute, second;
    //
    // Felder aufteilen
    fields = fieldPatternDp.split(entryMsg);
    if (fields.length < 4) {
        lg.error("recived message for logdir has lower than 4 fields. It is wrong! Abort!");
        return (null);
    }
    // Wandel die Nummerierung in Integer um
    try {
        number = Integer.parseInt(fields[1], 16);
        max = Integer.parseInt(fields[3], 16);
    } catch (NumberFormatException ex) {
        lg.error("Fail to convert Hex to int: " + ex.getLocalizedMessage());
        return (null);
    }
    fileName = fields[2];
    // verwandle die Dateiangabe in eine lesbare Datumsangabe
    // Format des Strings ist ja
    // TAG_MONAT_JAHR_STUNDE_MINUTE_SEKUNDE
    // des Beginns der Aufzeichnung
    fields = fieldPatternUnderln.split(fields[2]);
    try {
        day = Integer.parseInt(fields[0]);
        month = Integer.parseInt(fields[1]);
        year = Integer.parseInt(fields[2]) + 2000;
        hour = Integer.parseInt(fields[3]);
        minute = Integer.parseInt(fields[4]);
        second = Integer.parseInt(fields[5]);
    } catch (NumberFormatException ex) {
        lg.error("Fail to convert Hex to int: " + ex.getLocalizedMessage());
        return (null);
    }
    // So, die Angaben des SPX sind immer im Localtime-Format
    // daher werde ich die auch so interpretieren
    // Die Funktion macht das in der default-Lokalzone, sollte also
    // da sein, wio der SPX auch ist... (schwieriges Thema)
    DateTime tm = new DateTime(year, month, day, hour, minute, second);
    DateTimeFormatter fmt = DateTimeFormat.forPattern(timeFormatterString);
    return (String.format("%d;%s;%s;%d;%d", number, fileName, tm.toString(fmt), max, tm.getMillis()));
}

From source file:de.dmarcini.submatix.pclogger.gui.spx42FileManagerPanel.java

License:Open Source License

private void fillDiveTable(String cDevice) {
    DateTime dateTime;
    long javaTime;
    int row = 0;/*from w w w  .  j  a va 2s.c om*/
    int dbId = -1;
    //
    device = cDevice;
    if (device != null) {
        lg.debug("search dive list for device <" + device + ">...");
        // Eine Liste der Dives lesen
        lg.debug("read dive list for device from DB...");
        Vector<String[]> entrys = dbUtil.getDiveListForDeviceLog(device);
        if (entrys.size() < 1) {
            lg.info("no dives for device <" + device + "/" + dbUtil.getAliasForNameConn(device)
                    + "> found in DB.");
            return;
        }
        //
        // Objekt fr das Modell erstellen
        // [0] DIVENUMBERONSPX
        // [1] Start Datum und Zeiten localisiert
        // [2] Max Tiefe
        // [3] Lnge
        // [4] DBID (ab 04 zeigt die Tabelle mit dem Tabellenmodell DiveExportTableModel nix mehr an!)
        String[][] diveEntrys = new String[entrys.size()][5];
        // die erfragten details zurechtrcken
        for (Enumeration<String[]> enu = entrys.elements(); enu.hasMoreElements();) {
            // Felder sind:
            // [0] H_DIVEID,
            // [1] H_H_DIVENUMBERONSPX
            // [2] H_STARTTIME als unix timestamp
            String[] origSet = enu.nextElement();
            // zusammenbauen fuer Anzeige
            // SPX-DiveNumber fr vierstellige Anzeige
            diveEntrys[row][1] = String.format("%4s", origSet[1]);
            // Die UTC-Zeit als ASCII/UNIX wieder zu der originalen Zeit fr Java zusammenbauen
            try {
                // Die Tauchgangszeit formatieren
                javaTime = Long.parseLong(origSet[2]) * 1000;
                dbId = Integer.parseInt(origSet[0]);
                dateTime = new DateTime(javaTime);
                diveEntrys[row][4] = origSet[0];
                diveEntrys[row][0] = origSet[1];
                diveEntrys[row][1] = dateTime
                        .toString(LangStrings.getString("MainCommGUI.timeFormatterString"));
                // jetzt will ich alle Kopfdaten, die gespeichert sind
                // [0] H_DIVEID,
                // [1] H_DIVENUMBERONSPX,
                // [2] H_FILEONSPX,
                // [3] H_DEVICEID,
                // [4] H_STARTTIME,
                // [5] H_HADSEND,
                // [6] H_FIRSTTEMP,
                // [7] H_LOWTEMP,
                // [8] H_MAXDEPTH,
                // [9] H_SAMPLES,
                // [10] H_DIVELENGTH,
                // [11] H_UNITS,
                String[] headers = dbUtil.getHeadDiveDataFromIdAsSTringLog(dbId);
                if (headers[11].equals("METRIC")) {
                    diveEntrys[row][2] = headers[8] + " m";
                } else {
                    diveEntrys[row][2] = headers[8] + " ft";
                }
                diveEntrys[row][3] = headers[10] + " min";
            } catch (NumberFormatException ex) {
                lg.error("Number format exception (value=<" + origSet[1] + ">: <" + ex.getLocalizedMessage()
                        + ">");
                diveEntrys[row][0] = "error";
            } finally {
                row++;
            }
        }
        // aufrumen
        entrys.clear();
        entrys = null;
        // die Tabelle initialisieren
        String[] title = new String[5];
        title[0] = LangStrings.getString("fileManagerPanel.diveListHeaders.numberOnSpx");
        title[1] = LangStrings.getString("fileManagerPanel.diveListHeaders.startTime");
        title[2] = LangStrings.getString("fileManagerPanel.diveListHeaders.maxDepth");
        title[3] = LangStrings.getString("fileManagerPanel.diveListHeaders.diveLen");
        title[4] = LangStrings.getString("fileManagerPanel.diveListHeaders.dbId");
        FileManagerTableModel mTable = new FileManagerTableModel(diveEntrys, title);
        dataViewTable.setModel(mTable);
        // jetzt noch die rechte Spalte verschnern. Rechtsbndig und schmal bitte!
        DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
        rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
        TableColumn column = dataViewTable.getColumnModel().getColumn(0);
        column.setPreferredWidth(60);
        column.setMaxWidth(120);
        column.setCellRenderer(rightRenderer);
    } else {
        lg.debug("no device found....");
    }
}

From source file:de.dmarcini.submatix.pclogger.gui.spx42LogGraphPanel.java

License:Open Source License

/**
 * Anhand des Alias des Gertes die Tauchgangsliste fllen Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui
 * /*www. j  av a  2s  .  c  o  m*/
 * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 02.07.2012
 * @param deviceAlias
 */
@SuppressWarnings("unchecked")
private void fillDiveComboBox(String cDevice) {
    String device;
    DateTime dateTime;
    long javaTime;
    //
    device = cDevice;
    if (device != null) {
        lg.debug("search dive list for device <" + device + ">...");
        releaseGraph();
        // Eine Liste der Dives lesen
        lg.debug("read dive list for device from DB...");
        Vector<String[]> entrys = databaseUtil.getDiveListForDeviceLog(device);
        if (entrys.size() < 1) {
            lg.info("no dives for device <" + cDevice + "/" + databaseUtil.getAliasForNameConn(device)
                    + "> found in DB.");
            clearDiveComboBox();
            return;
        }
        //
        // Objekt fr das Modell erstellen
        Vector<String[]> diveEntrys = new Vector<String[]>();
        // die erfragten details zurechtrcken
        // Felder sind:
        // H_DIVEID,
        // H_H_DIVENUMBERONSPX
        // H_STARTTIME,
        for (Enumeration<String[]> enu = entrys.elements(); enu.hasMoreElements();) {
            String[] origSet = enu.nextElement();
            // zusammenbauen fuer Anzeige
            String[] elem = new String[3];
            // SPX-DiveNumber etwas einrcken, fr vierstellige Anzeige
            elem[0] = origSet[0];
            elem[1] = String.format("%4s", origSet[1]);
            // Die UTC-Zeit als ASCII/UNIX wieder zu der originalen Zeit fr Java zusammenbauen
            try {
                javaTime = Long.parseLong(origSet[2]) * 1000;
                dateTime = new DateTime(javaTime);
                elem[2] = dateTime.toString(LangStrings.getString("MainCommGUI.timeFormatterString"));
            } catch (NumberFormatException ex) {
                lg.error("Number format exception (value=<" + origSet[1] + ">: <" + ex.getLocalizedMessage()
                        + ">");
                elem[1] = "error";
            }
            diveEntrys.add(elem);
        }
        // aufrumen
        entrys.clear();
        entrys = null;
        // die box initialisieren
        LogListComboBoxModel listBoxModel = new LogListComboBoxModel(diveEntrys);
        diveSelectComboBox.setModel(listBoxModel);
        if (diveEntrys.size() > 0) {
            diveSelectComboBox.setSelectedIndex(0);
        }
    } else {
        lg.debug("no device found....");
    }
}

From source file:de.dmarcini.submatix.pclogger.gui.spx42LoglistPanel.java

License:Open Source License

@Override
public void valueChanged(ListSelectionEvent ev) {
    // Wen die Selektion der Liste verndert wurde...
    int fIndex, spxNumber, dbId, savedUnits;
    ////from  w  w w  . j a  v  a 2  s  .  c  o  m
    if (ev.getSource().equals(logListField)) {
        if (!ev.getValueIsAdjusting()) {
            // Das Ende der Serie, jetzt guck ich mal nach der ersten markierten...
            lg.debug("ist last or once change...");
            fIndex = logListField.getSelectedIndex();
            lg.debug(String.format("first selected Index: %d ", fIndex));
            spxNumber = ((LogDirListModel) logListField.getModel()).getLognumberAt(fIndex);
            if (spxNumber == -1) {
                diveDateShowLabel.setText("-");
                diveTimeShowLabel.setText("-");
                return;
            }
            dbId = ((LogDirListModel) logListField.getModel()).getDbIdAt(fIndex);
            lg.debug(String.format("number on SPX: %d, DBID: %d, readable Name: %s, filename: %s", spxNumber,
                    dbId, ((LogDirListModel) logListField.getModel()).getLogNameAt(fIndex),
                    logDirDataHash.get(spxNumber).fileNameOnSPX));
            // erst mal die allgemeinen Daten des Dives anzeigen
            fileNameShowLabel.setText(logDirDataHash.get(spxNumber).fileNameOnSPX);
            // Zeitstempel fr Datum und Zeitanzeige nutzen
            DateTime dt = new DateTime(logDirDataHash.get(spxNumber).timeStamp);
            // Landesspezifische Formatierung
            DateTimeFormatter fmtDate = DateTimeFormat.forPattern(timeFormatterStringDate);
            DateTimeFormatter fmtTime = DateTimeFormat.forPattern(timeFormatterStringTime);
            // setze Datum und Zeit
            diveDateShowLabel.setText(dt.toString(fmtDate));
            diveTimeShowLabel.setText(dt.toString(fmtTime));
            // Jetzt schau ich mal, ob da was in der Datenbank zu finden ist
            // Ja, der ist in der Datenbank erfasst!
            String[] headers = databaseUtil.getHeadDiveDataFromIdAsSTringLog(dbId);
            if (headers != null) {
                diveNotesShowLabel.setText(databaseUtil.getNotesForIdLog(dbId));
                // Was war gespeichert?
                if (headers[11].equals("METRIC")) {
                    savedUnits = ProjectConst.UNITS_METRIC;
                } else {
                    savedUnits = ProjectConst.UNITS_IMPERIAL;
                }
                if ((SpxPcloggerProgramConfig.unitsProperty == ProjectConst.UNITS_DEFAULT)
                        || SpxPcloggerProgramConfig.unitsProperty == savedUnits) {
                    //
                    // alles wie gespeichert anzeigen
                    //
                    if (savedUnits == ProjectConst.UNITS_METRIC) {
                        // Maximale Tiefe anzeigen
                        diveMaxDepthShowLabel.setText(String.format("%s %s", headers[8], metricLength));
                        // klteste Temperatur anzeigen
                        diveLowTempShowLabel.setText(String.format("%s %s", headers[7], metricTemperature));
                    } else {
                        // Maximale Tiefe anzeigen
                        diveMaxDepthShowLabel.setText(String.format("%s %s", headers[8], imperialLength));
                        // klteste Temperatur anzeigen
                        diveLowTempShowLabel.setText(String.format("%s %s", headers[7], imperialTemperature));
                    }
                    remarksLabel.setText(" ");
                } else {
                    //
                    // hier wird es schwierig == umrechnen
                    //
                    try {
                        double depth = Double.parseDouble(headers[8].trim());
                        double temp = Double.parseDouble(headers[7].trim());
                        if (savedUnits == ProjectConst.UNITS_METRIC) {
                            // Maximale Tiefe anzeigen
                            // imperial -> metrisch
                            // 1 foot == 30,48 cm == 0.3048 Meter
                            diveMaxDepthShowLabel
                                    .setText(String.format("%2.1f %s", (depth / 0.3048), imperialLength));
                            // klteste Temperatur anzeigen
                            // imperial -> metrisch
                            // t C = (9?5 t + 32) F
                            diveLowTempShowLabel.setText(String.format("%d %s",
                                    Math.round(((9.0 / 5.0) * temp) + 32.0), imperialTemperature));
                        } else {
                            // Maximale Tiefe anzeigen
                            // metrisch-> imperial konvertieren
                            // 1 foot == 30,48 cm == 0.3048 Meter
                            diveMaxDepthShowLabel
                                    .setText(String.format("%2.1f %s", (depth * 0.3048), metricLength));
                            // klteste Temperatur anzeigen
                            // metrisch-> imperial konvertieren
                            // t F = 5?9 (t  32) C
                            diveLowTempShowLabel.setText(String.format("%d %s",
                                    Math.round((5.0 / 9.0) * (temp - 32)), metricTemperature));
                        }
                        remarksLabel.setText(LangStrings.getString("spx42LogGraphPanel.remarksLabel.computed"));
                    } catch (NumberFormatException ex) {
                        lg.error("NumberFormatException while compute temperature/depth for showing: <"
                                + ex.getLocalizedMessage() + ">");
                        diveMaxDepthShowLabel.setText("-");
                        diveLengthShowLabel.setText("-");
                        diveLowTempShowLabel.setText("-");
                        diveNotesShowLabel.setText("-");
                        remarksLabel.setText(" ");
                    }
                }
                // Lnge des Tauchgangs anzeigen
                diveLengthShowLabel.setText(String.format("%s %s", headers[10], timeMinutes));
            } else {
                diveMaxDepthShowLabel.setText("-");
                diveLengthShowLabel.setText("-");
                diveLowTempShowLabel.setText("-");
                diveNotesShowLabel.setText("-");
                remarksLabel.setText(" ");
            }
        }
    }
}

From source file:de.dmarcini.submatix.pclogger.utils.UDDFFileCreateClass.java

License:Open Source License

  /**
 * Erzeuge die XML-Datei (UDDF) Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.utils
 * //from  ww  w  . j  a va2s  .  c om
 * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 30.08.2012
 * @param exportDir
 * @param diveNums
 * @return Dateiobjekt fr UDDF-Datei
 * @throws Exception
 */
public File createXML( File exportDir, int[] diveNums ) throws Exception
{
  Element rootNode = null;
  String msg = null;
  String fileName = null;
  File retFile = null;
  File saveFile = null;
  //
  lg.debug( "create uddf file..." );
  if( sqliteDbUtil == null || !sqliteDbUtil.isOpenDB() )
  {
    throw new Exception( "database not initiated" );
  }
  //
  // Daten vom ersten Tauchgang auslesen
  //
  headData = sqliteDbUtil.getHeadDiveDataFromIdLog( diveNums[0] );
  // die Tauchzeit rausbekommen
  long diveTimeUnix = ( getDiveTime() ) * 1000L;
  DateTime dateTime = new DateTime( diveTimeUnix );
  // den Export-Dateinamen machen
  if( diveNums.length == 1 )
  {
    fileName = String.format( "%s%s%s-dive-from-%s.uddf", exportDir.getAbsolutePath(), File.separatorChar, sqliteDbUtil.getDeviceIdLog( diveNums[0] ),
            dateTime.toString( "yyyy-MM-dd-hh-mm" ) );
  }
  else
  {
    fileName = String.format( "%s%s%s-dive-from-%s-plus-%d.uddf", exportDir.getAbsolutePath(), File.separatorChar, sqliteDbUtil.getDeviceIdLog( diveNums[0] ),
            dateTime.toString( "yyyy-MM-dd-hh-mm" ), diveNums.length );
  }
  saveFile = new File( fileName );
  //
  // Erzeuge Dokument neu
  //
  uddfDoc = builder.newDocument();
  // Root-Element erzeugen
  rootNode = uddfDoc.createElement( "uddf" );
  rootNode.setAttribute( "version", ProjectConst.UDDFVERSION );
  uddfDoc.appendChild( rootNode );
  // Programmname einfgen
  rootNode.appendChild( uddfDoc.createComment( ProjectConst.CREATORPROGRAM ) );
  // Appliziere Generator
  rootNode.appendChild( makeGeneratorNode( uddfDoc ) );
  // appliziere Gasdefinitionen
  rootNode.appendChild( makeGasdefinitions( uddfDoc, diveNums ) );
  // appliziere profiledata
  rootNode.appendChild( makeProfilesData( uddfDoc, diveNums ) );
  uddfDoc.normalizeDocument();
  try
  {
    // mach eine Datei aus dem DOM-Baum
    retFile = domToFile( saveFile, uddfDoc );
  }
  catch( TransformerException ex )
  {
    msg = "transformer Exception " + ex.getLocalizedMessage();
    lg.error( "createXML: <" + msg + ">" );
    return( null );
  }
  catch( IOException ex )
  {
    msg = "IOException " + ex.getLocalizedMessage();
    lg.error( "createXML: <" + msg + ">" );
    return( null );
  }
  catch( Exception ex )
  {
    msg = "allgemeine Exception " + ex.getLocalizedMessage();
    lg.error( "createXML: <" + msg + ">" );
    return( null );
  }
  return( retFile );
}

From source file:de.dmarcini.submatix.pclogger.utils.UDDFFileCreateClass.java

License:Open Source License

  /**
 * Tauchgang Teibaum bauen Project: SubmatixXMLTest Package: de.dmarcini.bluethooth.submatix.xml
 * /*from   w  w  w  .  ja v a  2s.  c  o  m*/
 * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 25.10.2011
 * @param doc
 *          Document Objekt
 * @param diveNumber
 *          Nummer des Tauchganges in der Datenbank
 * @return Teilbaum Tauchgang
 */
private Node makeDiveNode( Document doc, int diveNum )
{
  // TODO Swasser/Salzwasser Dichte eintragen (Datenbankfeld einrichten)
  Element diveNode, dateNode, yNode, mNode, dNode;
  Element timeNode, hNode, minNode;
  Element dnNode, atNode, ltNode, gdNode, deNode, noNode, txNode;
  String year, month, day, hour, minute;
  String temperature, lowesttemp;
  String greatestdepth;
  String density;
  long diveTimeUnix;
  DateTime dateTime;
  //
  // die Zeitstrings basteln
  //
  diveTimeUnix = ( getDiveTime() ) * 1000L;
  dateTime = new DateTime( diveTimeUnix );
  year = dateTime.toString( "yyyy" );
  month = dateTime.toString( "MM" );
  day = dateTime.toString( "dd" );
  hour = dateTime.toString( "hh" );
  minute = dateTime.toString( "mm" );
  // Stsart (Luft) Temperatur
  temperature = getFirstTempForDive();
  // kltesten Punkt
  lowesttemp = getLowestTempForDive();
  // grteTiefe
  greatestdepth = getGreatestDepthForDive();
  // Dichte des Wassers
  density = "1034.0";
  diveNode = doc.createElement( "dive" );
  diveNode.setAttribute( "id", String.valueOf( diveNum ) );
  // # date
  dateNode = doc.createElement( "date" );
  // ## date -> year
  yNode = doc.createElement( "year" );
  yNode.appendChild( doc.createTextNode( year ) );
  dateNode.appendChild( yNode );
  // ## date -> month
  mNode = doc.createElement( "month" );
  mNode.appendChild( doc.createTextNode( month ) );
  dateNode.appendChild( mNode );
  // ## date -> day
  dNode = doc.createElement( "day" );
  dNode.appendChild( doc.createTextNode( day ) );
  dateNode.appendChild( dNode );
  diveNode.appendChild( dateNode );
  // # time
  timeNode = doc.createElement( "time" );
  // ## time -> hour
  hNode = doc.createElement( "hour" );
  hNode.appendChild( doc.createTextNode( hour ) );
  timeNode.appendChild( hNode );
  // ## time -> minute
  minNode = doc.createElement( "minute" );
  minNode.appendChild( doc.createTextNode( minute ) );
  timeNode.appendChild( minNode );
  diveNode.appendChild( timeNode );
  // # divenumber
  dnNode = doc.createElement( "divenumber" );
  dnNode.appendChild( doc.createTextNode( String.valueOf( diveNum ) ) );
  diveNode.appendChild( dnNode );
  // # airtemp
  atNode = doc.createElement( "airtemperature" );
  atNode.appendChild( doc.createTextNode( temperature ) );
  diveNode.appendChild( atNode );
  // # lowesttemp
  ltNode = doc.createElement( "lowesttemperature" );
  ltNode.appendChild( doc.createTextNode( lowesttemp ) );
  diveNode.appendChild( ltNode );
  // # greatestdepth
  gdNode = doc.createElement( "greatestdepth" );
  gdNode.appendChild( doc.createTextNode( greatestdepth ) );
  diveNode.appendChild( gdNode );
  // # density
  deNode = doc.createElement( "density" );
  deNode.appendChild( doc.createTextNode( density ) );
  diveNode.appendChild( deNode );
  // # notes
  noNode = doc.createElement( "notes" );
  txNode = doc.createElement( "text" );
  if( diveComment != null )
  {
    txNode.appendChild( doc.createTextNode( diveComment ) );
  }
  else
  {
    txNode.appendChild( doc.createTextNode( "" ) );
  }
  noNode.appendChild( txNode );
  diveNode.appendChild( noNode );
  // Teilbaum einhngen
  diveNode.appendChild( makeSamplesForDive( doc, diveNum ) );
  return( diveNode );
}

From source file:de.escidoc.bwelabs.depositor.service.SessionManager.java

License:Open Source License

/**
 * Method creates a new configuration directory for a provided configuration with a currently time stamp as a name
 * and save a configuration file within it.
 * //from   ww  w . j a v  a 2 s .c o  m
 * @param configuration
 * @param configurationId
 * @return File with a created configuration directory.
 * @throws DepositorException
 */
public File saveInLocalFileSystem(Properties configuration) throws DepositorException {

    LOG.debug("saving configuration in local file system");
    DateTimeZone.setDefault(DateTimeZone.UTC);
    DateTime currentTime = new DateTime();
    DateTimeFormatter fmt = DateTimeFormat.forPattern(PATH_FORMAT);
    String configurationDirectoryName = currentTime.toString(fmt);
    File configurationDirectory = new File(baseDir, configurationDirectoryName);
    configurationDirectory.mkdirs();
    File configurationFile = new File(configurationDirectory, Constants.CONFIGURATION_FILE_NAME);
    FileOutputStream os = null;
    try {
        os = new FileOutputStream(configurationFile);
    } catch (FileNotFoundException e) {
        LOG.error(e.getMessage());
        throw new DepositorException(e.getMessage());
    }
    try {
        configuration.storeToXML(os, null);
        os.flush();
        os.close();
        synchronized (configurationDirPathes) {
            configurationDirPathes.put(configuration.getProperty(Configuration.PROPERTY_CONFIGURATION_ID),
                    configurationDirectoryName);
        }

    } catch (IOException e) {
        LOG.error(e.getMessage());
        throw new DepositorException(e.getMessage());
    }
    return configurationFile;
}

From source file:de.escidoc.bwelabs.depositor.service.SessionManager.java

License:Open Source License

/**
 * Method checks if a configuration with a provided id contains a property Monitoring Start Time. It put a time
 * stamp with a current time into a configuration contained in a map with configurations and in a configuration
 * file.//from   www.  j  a  v  a2  s  .  c  o  m
 * 
 * @deprecated Monitoring start time should not be needed in configuration.
 * @param configId
 */
@Deprecated
private void putMonitoringStartTimeIntoConfigurationIfMissing(String configId) {
    File configurationDirectory = new File(baseDir, configurationDirPathes.get(configId));
    Properties configuration = null;
    // if a configuration does not contain a calculated monitoring start
    // time,
    // put a calculated monitoring start time in to the configuration and
    // store the
    // configuration into a configuration file
    synchronized (configurations) {
        configuration = configurations.get(configId);
        String monitoringStartTime = configuration.getProperty(Constants.PROPERTY_MONITORING_START_TIME);
        if (monitoringStartTime == null) {
            DateTimeZone.setDefault(DateTimeZone.UTC);
            DateTime currentTime = new DateTime();
            DateTimeFormatter fmt = DateTimeFormat.forPattern(DATE_TIME_FORMAT);
            String timeStamp = currentTime.toString(fmt);
            configuration.put(Constants.PROPERTY_MONITORING_START_TIME, timeStamp);

            File configurationFile = new File(configurationDirectory, Constants.CONFIGURATION_FILE_NAME);
            configurationFile.delete();
            FileOutputStream os = null;
            try {
                os = new FileOutputStream(configurationFile);
            } catch (FileNotFoundException e) {
                LOG.error(e.getMessage());

            }
            try {
                configuration.storeToXML(os, null);
                if (os != null) {
                    os.flush();
                    os.close();
                }
            } catch (IOException e) {
                LOG.error(e.getMessage());

            }
        }
    }
}