Example #1
0
 /** Return a time stamp string accurate to sec: yyyy-mm-dd hh:mm:ss */
 public static String getCurrentTimeStamp() {
   GregorianCalendar calendar = new java.util.GregorianCalendar();
   int y = calendar.get(Calendar.YEAR);
   int m = calendar.get(Calendar.MONTH) + 1; // zero-based for months
   int d = calendar.get(Calendar.DAY_OF_MONTH);
   int h = calendar.get(Calendar.HOUR_OF_DAY);
   int min = calendar.get(Calendar.MINUTE);
   int sec = calendar.get(Calendar.SECOND);
   String sy = String.valueOf(y);
   String sm = m < 10 ? "0" + m : String.valueOf(m);
   String sd = d < 10 ? "0" + d : String.valueOf(d);
   String sh = h < 10 ? "0" + h : String.valueOf(h);
   String smin = min < 10 ? "0" + min : String.valueOf(min);
   String ssec = sec < 10 ? "0" + sec : String.valueOf(sec);
   return new StringBuffer()
       .append(sy)
       .append("-")
       .append(sm)
       .append("-")
       .append(sd)
       .append(" ")
       .append(sh)
       .append(":")
       .append(smin)
       .append(":")
       .append(ssec)
       .toString();
 }
Example #2
0
 /**
  * Set calendar to this week's Monday; set year and week combo boxes to the currently set date;
  * set the date labels appropriately; and, refresh the review table.
  */
 private void updateYearWeekDates() {
   yearWeekCalendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
   yearWeekCalendar.set(Calendar.HOUR_OF_DAY, 0);
   yearWeekCalendar.set(Calendar.MINUTE, 0);
   yearWeekCalendar.set(Calendar.SECOND, 0);
   yearWeekCalendar.set(Calendar.MILLISECOND, 0);
   yearCB.setSelectedItem(yearWeekCalendar.get(Calendar.YEAR));
   weekCB.setSelectedItem(yearWeekCalendar.get(Calendar.WEEK_OF_YEAR));
   fromDate.setDate(yearWeekCalendar);
   yearWeekCalendar.add(Calendar.DAY_OF_MONTH, 7);
   toDate.setDate(yearWeekCalendar);
   yearWeekCalendar.add(Calendar.DAY_OF_MONTH, -7);
   refreshReviewTable();
 }
Example #3
0
 {
   addItem("Custom");
   int currentYear = yearWeekCalendar.get(Calendar.YEAR);
   for (int year = currentYear - 5; year <= currentYear + 5; year++) addItem(year);
   addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent ae) {
           if (yearCB.getSelectedIndex() == 0) return;
           yearWeekCalendar.set(Calendar.YEAR, (Integer) yearCB.getSelectedItem());
           updateYearWeekDates();
         }
       });
 }
Example #4
0
  // Generates a unique filename based on the current date and time.
  private String getUniqueFileName() {

    GregorianCalendar now = new GregorianCalendar();
    String fileName =
        ""
            + now.get(Calendar.YEAR)
            + now.get(Calendar.MONTH)
            + now.get(Calendar.DATE)
            + now.get(Calendar.HOUR_OF_DAY)
            + now.get(Calendar.MINUTE)
            + now.get(Calendar.SECOND)
            + now.get(Calendar.MILLISECOND);

    return fileName + ".jpg";
  }
Example #5
0
  private void writeRecord(DataOutput dataOutput, Object[] objectArray) throws IOException {

    dataOutput.write((byte) ' ');
    for (int j = 0; j < this.header.fieldArray.length; j++) {
      /* iterate throught fields */

      switch (this.header.fieldArray[j].getDataType()) {
        case 'C':
          if (objectArray[j] != null) {

            String str_value = objectArray[j].toString();
            dataOutput.write(
                Utils.textPadding(
                    str_value, characterSetName, this.header.fieldArray[j].getFieldLength()));
          } else {

            dataOutput.write(
                Utils.textPadding(
                    "", this.characterSetName, this.header.fieldArray[j].getFieldLength()));
          }

          break;

        case 'D':
          if (objectArray[j] != null) {

            GregorianCalendar calendar = new GregorianCalendar();
            calendar.setTime((Date) objectArray[j]);
            dataOutput.write(String.valueOf(calendar.get(Calendar.YEAR)).getBytes());
            dataOutput.write(
                Utils.textPadding(
                    String.valueOf(calendar.get(Calendar.MONTH) + 1),
                    this.characterSetName,
                    2,
                    Utils.ALIGN_RIGHT,
                    (byte) '0'));
            dataOutput.write(
                Utils.textPadding(
                    String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)),
                    this.characterSetName,
                    2,
                    Utils.ALIGN_RIGHT,
                    (byte) '0'));
          } else {

            dataOutput.write("        ".getBytes());
          }

          break;

        case 'F':
          if (objectArray[j] != null) {

            dataOutput.write(
                Utils.doubleFormating(
                    (Double) objectArray[j],
                    this.characterSetName,
                    this.header.fieldArray[j].getFieldLength(),
                    this.header.fieldArray[j].getDecimalCount()));
          } else {

            dataOutput.write(
                Utils.textPadding(
                    " ",
                    this.characterSetName,
                    this.header.fieldArray[j].getFieldLength(),
                    Utils.ALIGN_RIGHT));
          }

          break;

        case 'N':
          if (objectArray[j] != null) {

            dataOutput.write(
                Utils.doubleFormating(
                    (Double) objectArray[j],
                    this.characterSetName,
                    this.header.fieldArray[j].getFieldLength(),
                    this.header.fieldArray[j].getDecimalCount()));
          } else {

            dataOutput.write(
                Utils.textPadding(
                    " ",
                    this.characterSetName,
                    this.header.fieldArray[j].getFieldLength(),
                    Utils.ALIGN_RIGHT));
          }

          break;
        case 'L':
          if (objectArray[j] != null) {

            if ((Boolean) objectArray[j] == Boolean.TRUE) {

              dataOutput.write((byte) 'T');
            } else {

              dataOutput.write((byte) 'F');
            }
          } else {

            dataOutput.write((byte) '?');
          }

          break;

        case 'M':
          break;

        default:
          throw new DBFException("Unknown field type " + this.header.fieldArray[j].getDataType());
      }
    } /* iterating through the fields */
  }