Пример #1
0
 /**
  * _more_
  *
  * @return _more_
  */
 private List<DateTime> findForecastTimes() {
   List<DateTime> forecastTimes = new ArrayList<DateTime>();
   Hashtable seenForecastTime = new Hashtable();
   for (StormTrack track : stormDisplayState.getTrackCollection().getTracks()) {
     if (track.getWay().isObservation()) {
       continue;
     }
     if (!chartWays.contains(track.getWay())) {
       continue;
     }
     DateTime dttm = track.getStartTime();
     if (seenForecastTime.get(dttm) == null) {
       seenForecastTime.put(dttm, dttm);
       forecastTimes.add(dttm);
     }
   }
   return (List<DateTime>) Misc.sort(forecastTimes);
 }
Пример #2
0
  /** _more_ */
  protected void updateChart() {

    try {
      if (!madeChart) {
        createChart();
      }
      ignoreChartTimeChanges = true;

      if (isHourly()) {
        List<Integer> fHours = findForecastHours();
        List<TwoFacedObject> tfos = new ArrayList<TwoFacedObject>();
        for (Integer i : fHours) {
          tfos.add(new TwoFacedObject(i + "H", i));
        }

        Object[] selected = chartTimeBox.getSelectedValues();
        chartTimeBox.setListData(new Vector(tfos));
        GuiUtils.setSelectedItems(chartTimeBox, Misc.toList(selected));

        if ((selected == null) && (tfos.size() > 0)) {
          TwoFacedObject selected0 = tfos.get(0);
          forecastHours.add((Integer) selected0.getId());
        }

        // chartTimeBox.setSelectedItem(selected);
      } else {
        List<DateTime> fTimes = findForecastTimes();

        Object[] selected = chartTimeBox.getSelectedValues();

        chartTimeBox.setListData(new Vector(fTimes));
        GuiUtils.setSelectedItems(chartTimeBox, Misc.toList(selected));

        if ((selected == null) && (fTimes.size() > 0)) {
          DateTime dt0 = fTimes.get(0);
          forecastTimes.add(dt0);
        }

        // chartTimeBox.setSelectedItem(forecastTime);
      }
      ignoreChartTimeChanges = false;
      getSelectedTimes();
      chartTimeBox.repaint();
      Hashtable<Way, List> wayToTracks = new Hashtable<Way, List>();
      for (Way way : chartWays) {
        wayToTracks.put(way, new ArrayList<Way>());
      }

      List<StormTrack> tracksToUse = new ArrayList<StormTrack>();
      for (StormTrack track : stormDisplayState.getTrackCollection().getTracks()) {
        List trackList = wayToTracks.get(track.getWay());
        if (trackList == null) {
          continue;
        }
        if (track.getWay().isObservation()) {
          tracksToUse.add(track);
        } else {
          trackList.add(track);
        }
      }

      StormTrack obsTrack = stormDisplayState.getTrackCollection().getObsTrack();

      if (isHourly()) {
        for (Way way : chartWays) {
          List<StormTrack> tracksFromWay = wayToTracks.get(way);

          for (Integer fHour : forecastHours) {
            List<StormTrackPoint> points = new ArrayList<StormTrackPoint>();
            for (StormTrack track : tracksFromWay) {
              StormTrackPoint stp = track.findPointWithForecastHour(fHour.intValue());
              if (stp != null) {
                // TODO: What time do we use???
                points.add(stp);
              }
            }
            if (points.size() > 0) {
              points = (List<StormTrackPoint>) Misc.sort(points);
              tracksToUse.add(new StormTrack(stormDisplayState.getStormInfo(), way, points, null));
            }
          }
        }

      } else {
        for (Way way : chartWays) {
          List<StormTrack> tracksFromWay = wayToTracks.get(way);
          for (StormTrack track : tracksFromWay) {
            for (DateTime fTime : forecastTimes) {
              if (Misc.equals(fTime, track.getStartTime())) {
                tracksToUse.add(track);
              }
            }
          }
        }
      }

      List<LineState> lines = new ArrayList<LineState>();

      for (StormParam param : chartParams) {
        Hashtable seenWays = new Hashtable();
        List<LineState> linesForParam = new ArrayList<LineState>();
        for (StormTrack track : tracksToUse) {
          LineState lineState = null;
          if (chartDifference && param.getCanDoDifference()) {
            if (track.getWay().isObservation()) {
              continue;
            }
            track = StormDataSource.difference(obsTrack, track, param);
            if (track != null) {
              lineState = makeLine(track, param);
            }
          } else {
            lineState = makeLine(track, param);
          }
          if (lineState == null) {
            continue;
          }
          // Only add it if there are values
          if (lineState.getRange().getMin() == lineState.getRange().getMin()) {
            if (seenWays.get(track.getWay()) != null) {
              lineState.setVisibleInLegend(false);
            } else {
              seenWays.put(track.getWay(), "");
            }

            linesForParam.add(lineState);
          }
        }
        double max = Double.NEGATIVE_INFINITY;
        double min = Double.POSITIVE_INFINITY;
        ;
        for (LineState lineState : linesForParam) {
          Range r = lineState.getRange();
          min = Math.min(min, r.getMin());
          max = Math.max(max, r.getMax());
        }
        //                System.err.println(param + " min/max:" + min + "/" + max);
        boolean first = true;
        for (LineState lineState : linesForParam) {
          lineState.setAxisVisible(first);
          first = false;
          lineState.setRange(new Range(min, max));
        }
        lines.addAll(linesForParam);
      }
      getChart().setTracks(lines);
    } catch (Exception exc) {
      stormDisplayState.getStormTrackControl().logException("Updating chart", exc);
    }
  }