Esempio n. 1
0
  void populateStartDate() throws SQLException, Exception {
    startDateS.removeActionListener(this);
    startDateS.removeAllItems();
    dateRange.clear();
    if (sourceTable.sourceListModel.isSelectionEmpty() == false
        && sourceTable.getValueAt(sourceTable.getSelectedRow(), 0).toString() != null) {
      Statement MySQL_Statement = dbConn.createStatement();
      String getMinMaxSQL =
          "SELECT UNIX_TIMESTAMP(DATE_ADD(DATE(MIN(date_time)),INTERVAL 1 DAY)) AS min_date,UNIX_TIMESTAMP(DATE(MAX(date_time))) AS max_date FROM data_sa WHERE site_id = "
              + siteTable.getValueAt(siteTable.getSelectedRow(), 0)
              + " AND source_id = "
              + sourceTable.getValueAt(sourceTable.getSelectedRow(), 0);
      ResultSet minMaxResults = MySQL_Statement.executeQuery(getMinMaxSQL);
      if (minMaxResults.next()) {
        Calendar minCal = Calendar.getInstance();
        minCal.setTimeZone(TimeZone.getTimeZone("GMT+10"));
        minCal.setTimeInMillis(minMaxResults.getLong("min_date") * 1000);
        long maxCal = minMaxResults.getLong("max_date") * 1000;

        while (minCal.getTimeInMillis() <= maxCal) {
          dateRange.add(minCal.getTimeInMillis());
          startDateS.addItem(dateFormatter.format(minCal.getTimeInMillis()));
          minCal.add(Calendar.DATE, 1);
        }
        startDateS.setEnabled(true);
        populateEndDate();
      } else {
        throw new Exception("ERR:NoData");
      }
    } else { // This should never be able to happen
      throw new Exception("NoSource");
    }
    startDateS.addActionListener(this);
  }
Esempio n. 2
0
  @Override
  public void valueChanged(ListSelectionEvent lSE) {
    if (lSE.getSource().equals(siteTable.siteListModel) && lSE.getValueIsAdjusting() == false) {
      sourceTable.updateList(dbConn, siteTable.siteList.get(siteTable.getSelectedRow()));

      if (sourceTable.sourceListModel.isSelectionEmpty()) {
        plotButton.setEnabled(false);
        startDateS.removeAllItems();
        endDateS.removeAllItems();
      }
    } else if (lSE.getSource().equals(sourceTable.sourceListModel)
        && lSE.getValueIsAdjusting() == false) {

      if (sourceTable.sourceListModel.isSelectionEmpty() == false) {
        try {
          populateStartDate();
          if (startDateS.getItemCount() > 0 && endDateS.getItemCount() > 0) {
            plotButton.setEnabled(true);
          }
        } catch (SQLException e) {
          plotButton.setEnabled(false);
          startDateS.removeAllItems();
          endDateS.removeAllItems();
          startDateS.addItem("ERR:NoData");
          endDateS.addItem("ERR:NoData");
          e.printStackTrace();
        } catch (Exception e) {
          plotButton.setEnabled(false);
          startDateS.removeAllItems();
          endDateS.removeAllItems();
          startDateS.addItem(e.getMessage());
          endDateS.addItem(e.getMessage());
        }
      } else {
        plotButton.setEnabled(false);
        startDateS.removeAllItems();
        endDateS.removeAllItems();
      }
    }
  }
Esempio n. 3
0
  public void actionPerformed(ActionEvent aE) {
    if (aE.getSource() == plotButton) {
      if (sourceTable.sourceListModel.isSelectionEmpty() == false
          && sourceTable.getValueAt(sourceTable.getSelectedRow(), 0) != null) {
        // Build dates
        final GregorianCalendar startDate = new GregorianCalendar();
        final GregorianCalendar endDate = new GregorianCalendar();
        startDate.setTimeZone(TimeZone.getTimeZone("GMT+10"));
        endDate.setTimeZone(TimeZone.getTimeZone("GMT+10"));
        try {
          Calendar now = GregorianCalendar.getInstance();
          now.setTimeZone(TimeZone.getTimeZone("GMT+10"));
          now.set(Calendar.HOUR_OF_DAY, 0);
          now.set(Calendar.MINUTE, 0);
          now.set(Calendar.SECOND, 0);
          now.set(Calendar.MILLISECOND, 0);
          if (week.isSelected()) {
            startDate.setTimeInMillis(now.getTimeInMillis() - ((long) 7 * 24 * 60 * 60 * 1000));
            endDate.setTimeInMillis(now.getTimeInMillis());
          } else if (month.isSelected()) {
            startDate.setTimeInMillis(now.getTimeInMillis() - ((long) 28 * 24 * 60 * 60 * 1000));
            endDate.setTimeInMillis(now.getTimeInMillis());
          } else if (thisMonth.isSelected()) {
            Calendar monthStart = new GregorianCalendar();
            monthStart.setTimeZone(TimeZone.getTimeZone("GMT+10"));
            monthStart.setTimeInMillis(now.getTimeInMillis());
            if (monthStart.get(Calendar.DAY_OF_MONTH) == 1) {
              monthStart.set(Calendar.MONTH, monthStart.get(Calendar.MONTH) - 1);
            }
            monthStart.set(Calendar.DAY_OF_MONTH, 1);
            startDate.setTimeInMillis(monthStart.getTimeInMillis());
            endDate.setTimeInMillis(now.getTimeInMillis());
          } else {
            startDate.setTime(dateParser.parse(startDateS.getSelectedItem().toString() + " 00:00"));
            endDate.setTime(dateParser.parse(endDateS.getSelectedItem().toString() + " 00:00"));
            endDate.add(Calendar.DATE, 1); // for "inclusive"
          }
          // SimpleDateFormat sqlDateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
          // sqlDateFormatter.setTimeZone(TimeZone.getTimeZone("GMT+10"));
          // System.out.println(sqlDateFormatter.format(startDate.getTimeInMillis())+"
          // "+sqlDateFormatter.format(endDate.getTimeInMillis()));

          if (startDate.before(endDate)) {
            loadingLayerUI.start();

            final Thread fetchMissingData =
                new Thread( // Thread to fetch missing Data in
                    new Runnable() {
                      public void run() {
                        missingPlotter.setData(
                            dbConn,
                            siteTable.getValueAt(siteTable.getSelectedRow(), 0).toString(),
                            getSelectedSources(sourceTable.getSelectedRows()),
                            startDate.getTimeInMillis(),
                            endDate.getTimeInMillis(),
                            1440);
                      }
                    });

            fetchMissingData.start(); // Fetch Missing Data

            new Thread(
                    new Runnable() { // new Thread to wait for missing data to complete and then
                                     // ungrey window
                      public void run() {
                        try {
                          fetchMissingData.join();
                        } catch (InterruptedException e) {
                          e.printStackTrace();
                        }
                        loadingLayerUI.stop();
                      }
                    })
                .start();

          } else {
            JOptionPane.showMessageDialog(null, "Error: Start date must be before End Date.");
          }
        } catch (ParseException e) {
          e.printStackTrace();
          JOptionPane.showMessageDialog(
              null, "Error: could not build valid dates from the selection made.");
        }
      } else {
        JOptionPane.showMessageDialog(
            null,
            "Error Code 002\r\nPlease select a file to Analyse.",
            "Error",
            JOptionPane.ERROR_MESSAGE);
      }
    }
  }