/** Initializes contained components. */
  private void initComponents() {
    final SimpleDateFormat format = new SimpleDateFormat("mm:ss");
    final Calendar c = Calendar.getInstance();
    final JLabel counter = new JLabel();

    counter.setForeground(Color.red);
    counter.setFont(counter.getFont().deriveFont((float) (counter.getFont().getSize() + 5)));

    setLayout(new GridBagLayout());
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

    GridBagConstraints constraints = new GridBagConstraints();

    JLabel messageLabel =
        new JLabel(
            GuiActivator.getResources().getI18NString("service.gui.security.SECURITY_ALERT"));

    messageLabel.setForeground(Color.WHITE);

    constraints.anchor = GridBagConstraints.CENTER;
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 0;
    constraints.gridy = 0;
    add(messageLabel, constraints);

    constraints.anchor = GridBagConstraints.CENTER;
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 0;
    constraints.gridy = 1;
    add(counter, constraints);

    ZrtpControl zrtpControl = null;
    if (securityControl instanceof ZrtpControl) zrtpControl = (ZrtpControl) securityControl;

    long initialSeconds = 0;

    if (zrtpControl != null) initialSeconds = zrtpControl.getTimeoutValue();

    c.setTimeInMillis(initialSeconds);

    counter.setText(format.format(c.getTime()));

    if (initialSeconds > 0)
      timer.schedule(
          new TimerTask() {
            @Override
            public void run() {
              if (c.getTimeInMillis() - 1000 > 0) {
                c.add(Calendar.SECOND, -1);
                counter.setText(format.format(c.getTime()));
              }
            }
          },
          1000,
          1000);
  }
  /**
   * isValidDate tests a string to see whether it is a valid date.
   *
   * @param date
   * @return true if valid date, false if not valid
   */
  public static boolean isValidDate(String date) {

    SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy");
    Date testDate = null;

    try {
      testDate = sdf.parse(date);
    } catch (ParseException e) {
      return false;
    }

    if (!sdf.format(testDate).equals(date)) {
      return false;
    }

    return true;
  }
 public void setFecha(String val) {
   try {
     fecha.setDate(sdf.parse(val));
   } catch (Exception e) {
     omoikane.sistema.Dialogos.lanzarDialogoError(
         null,
         "Error en el registro: Fecha inválida",
         omoikane.sistema.Herramientas.getStackTraceString(e));
   }
 }
示例#4
0
  /*==========================================================
   * public methods
   *==========================================================*/
  public Vector parse(Object entry) throws ParseException {
    String logEntry = (String) entry;
    // parsing the log Entry and return segments
    // Debug.println("LogDataModel: DefaultLogParser: parse() -" +logEntry);
    int x = logEntry.indexOf("[");
    if (x == -1) throw new ParseException(logEntry, 0);
    String temp = logEntry.substring(x + 1);
    x = temp.indexOf("]");
    if (x == -1) throw new ParseException(logEntry, 0);

    String dateStr = temp.substring(0, x);
    // Debug.println("LogDataModel: DefaultLogParser: parse() -"+dateStr+" "+temp);
    SimpleDateFormat format = new SimpleDateFormat(DATE_PATTERN);
    Date date = format.parse(dateStr);
    String dateColumn = DateFormat.getDateInstance().format(date);
    String timeColumn = DateFormat.getTimeInstance().format(date);

    // Debug.println("LogDataModel: DefaultLogParser: parse() -"+dateColumn+" "+timeColumn);
    temp = temp.substring(x + 2);
    x = temp.indexOf("]");
    if (x == -1) throw new ParseException(logEntry, 0);
    String source = temp.substring(1, x);
    temp = temp.substring(x + 2);
    x = temp.indexOf("]");
    if (x == -1) throw new ParseException(logEntry, 0);
    String level = temp.substring(1, x);
    temp = temp.substring(x + 2);
    Vector row = new Vector();
    row.addElement(getSourceString(source));
    row.addElement(getLevelString(level));
    row.addElement(dateColumn);
    row.addElement(timeColumn);
    JLabel detail = new JLabel(temp);
    detail.setToolTipText(temp);
    row.addElement(detail);
    return row;
  }
 public String getFecha() {
   return (String) sdf.format(this.fecha.getDate());
 }
 // method to display current Person object in the ArrayList
 // uses global index ??
 private void displayRecord() {
   p = (Person) persons.get(index);
   n.setText(p.name);
   d.setText(f.format(p.date));
 }
示例#7
0
 private String formatDate(Date myDate) {
   String strFormat = "yyyy-MM-dd HH:mm:ss";
   SimpleDateFormat formatter = new SimpleDateFormat(strFormat);
   String strDate = formatter.format(myDate);
   return strDate;
 }
示例#8
0
  public void update(MultihopMsg msg) {
    String info;
    SurgeMsg SMsg = new SurgeMsg(msg.dataGet(), msg.offset_data(0));
    if (SMsg.get_type() == 0) {

      if (SMsg.get_parentaddr() == MainFrame.BEACON_BASE_ADDRESS) {
        isDirectChild = true;
      } else {
        isDirectChild = false;
      }

      // Update message count and rate
      // Only update if this message is coming to the root from
      // a direct child
      int saddr = msg.get_sourceaddr();
      NodeInfo ni = (NodeInfo) SensorAnalyzer.proprietaryNodeInfo.get(new Integer(saddr));
      if (ni != null) {
        if (ni.isDirectChild) {
          msgCount++;
          int new_seq_no = (int) SMsg.get_seq_no() & 0x7fffff;
          if (stats_start_sequence_number == 0) stats_start_sequence_number = new_seq_no;
          if (seq_no == 0) seq_no = new_seq_no - 1;
          int diff = new_seq_no - seq_no;
          if (diff > 1000) diff = 1;
          active = true;
          long curtime = System.currentTimeMillis();
          packetTimes[packetTimesPointer++] = curtime - lastTime;
          packetTimesPointer %= SensorAnalyzer.HISTORY_LENGTH;
          packetSkips[packetSkipsPointer++] = diff;
          packetSkipsPointer %= SensorAnalyzer.HISTORY_LENGTH;
          msgRate = calcMsgRate(0);
          msgYield = calcMsgYield(0);

          SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");

          String log = "";
          log += nodeNumber + "#";
          log += msgCount + "#";
          log += formatter.format(new Date()) + "#";
          log += curtime + "#";
          log += (curtime - lastTime) + "#";
          log += SMsg.get_parentaddr() + "#";

          parent_count[SMsg.get_parentaddr()]++;
          log += msgRate + "#";
          seq_no = new_seq_no;
          batt = (int) SMsg.get_seq_no() >> 23 & 0x1ff;

          log += seq_no + "#";
          log += hopcount + "#";

          level_sum += hopcount;
          log += SMsg.get_reading() + "#";
          log += batt + "#";
          for (int i = 0; i < 5; i++) {
            log += neighbors[i].id + "#";
            log += neighbors[i].hopcount + "#";
            log += neighbors[i].link_quality / 255.0 + "#";
          }
          log += SMsg.get_temp() + "#";
          log += SMsg.get_light() + "#";
          log += SMsg.get_accelx() + "#";
          log += SMsg.get_accely() + "#";
          log += SMsg.get_magx() + "#";
          log += SMsg.get_magy() + "#";
          System.out.println(log);

          double batt_val = (double) batt;
          batt_val = 1.25 * 1023.0 / batt_val;
          batt_val *= 256.0 / 4.0;
          // System.out.println(batt_val);
          // Store the sensor readings.
          yield_series.insertNewReading(total_yield++, new Integer((int) (yield() * 256.0)));
          time_series.insertNewReading(seq_no, new Long(curtime));
          batt_series.insertNewReading(seq_no, new Integer((int) batt_val));
          temp_series.insertNewReading(seq_no, new Integer(SMsg.get_temp()));
          light_series.insertNewReading(seq_no, new Integer(SMsg.get_light()));
          accelx_series.insertNewReading(seq_no, new Integer(SMsg.get_accelx()));
          accely_series.insertNewReading(seq_no, new Integer(SMsg.get_accely()));
          magx_series.insertNewReading(seq_no, new Integer(SMsg.get_magx()));
          magy_series.insertNewReading(seq_no, new Integer(SMsg.get_magy()));

          link_quality = neighbors[0].link_quality / 255;

          // update the edge quality as well...
          MainClass.locationAnalyzer.setQualityForEdge(
              nodeNumber.intValue(), SMsg.get_parentaddr(), (int) (link_quality * 255.0));

          lastTime = curtime;
        }
      }

      if (self_calc != false) info = msgCount + " msgs ";
      else info = "";

      this.value = SMsg.get_reading();
      if (panel != null) {
        panel.YieldLabel.setText(String.valueOf(percent_yield()) + " %");
        panel.SensorLabel.setText(String.valueOf(value));
        panel.ParentLabel.setText(String.valueOf(SMsg.get_parentaddr()));
        panel.SequenceLabel.setText(String.valueOf(seq_no));
        panel.CountLabel.setText(String.valueOf(msgCount));
        panel.DepthLabel.setText(String.valueOf(hopcount));
        panel.repaint();
      }

      this.infoString = info;
    }
  }