Пример #1
0
 /**
  * Check for equality
  *
  * @param object the object in question
  * @return true if they are equal
  */
 public boolean equals(Object object) {
   if (!object.getClass().equals(getClass())) {
     return false;
   }
   RaobDataSource that = (RaobDataSource) object;
   if (file != null) {
     return Misc.equals(this.file, that.file);
   }
   return Misc.equals(raobDataSet, that.raobDataSet);
 }
Пример #2
0
 /**
  * overwrite
  *
  * @param o object
  * @return equals
  */
 public boolean equals(Object o) {
   if (!super.equals(o)) {
     return false;
   }
   WmsDataSource that = (WmsDataSource) o;
   return Misc.equals(this.wmsSelections, that.wmsSelections);
 }
Пример #3
0
  /**
   * _more_
   *
   * @param stormTrack _more_
   * @param param _more_
   * @return _more_
   */
  protected LineState makeLine(StormTrack stormTrack, StormParam param) {
    List<Real> values = new ArrayList<Real>();
    List<DateTime> times = stormTrack.getTrackTimes();
    List<StormTrackPoint> trackPoints = stormTrack.getTrackPoints();
    double min = 0;
    double max = 0;
    Unit unit = null;
    for (int pointIdx = 0; pointIdx < times.size(); pointIdx++) {
      Real value = trackPoints.get(pointIdx).getAttribute(param);
      if (value == null) {
        continue;
      }
      if (unit == null) {
        unit = ((RealType) value.getType()).getDefaultUnit();
      }
      values.add(value);
      double dvalue = value.getValue();
      //            System.err.print(","+dvalue);
      if ((pointIdx == 0) || (dvalue > max)) {
        max = dvalue;
      }
      if ((pointIdx == 0) || (dvalue < min)) {
        min = dvalue;
      }
    }
    if (values.size() == 0) {
      return null;
    }
    //        System.err.println("");
    String paramLabel = param.toString();
    String label = stormTrack.getWay().toString(); // +":" + paramLabel;
    LineState lineState = new LineState();
    lineState.setRangeIncludesZero(true);
    if (stormTrack.getWay().isObservation()) {
      lineState.setWidth(2);
    } else {
      lineState.setWidth(1);
    }
    lineState.setRange(new Range(min, max));
    lineState.setChartName(paramLabel);
    lineState.setAxisLabel("[" + unit + "]");

    //        System.err.println (param + " " +  StormDataSource.TYPE_STORMCATEGORY);
    if (Misc.equals(param, StormDataSource.PARAM_STORMCATEGORY)) {
      //            lineState.setShape(LineState.LINETYPE_BAR);
      lineState.setLineType(LineState.LINETYPE_BAR);
      lineState.setLineType(LineState.LINETYPE_AREA);
    } else {
      lineState.setLineType(LineState.LINETYPE_SHAPES_AND_LINES);
      lineState.setShape(LineState.SHAPE_LARGEPOINT);
    }

    lineState.setColor(stormDisplayState.getWayDisplayState(stormTrack.getWay()).getColor());
    lineState.setName(label);
    lineState.setTrack(times, values);
    return lineState;
  }
Пример #4
0
  /**
   * Respond to <code>ControlEvent</code>s.
   *
   * @param e <code>ControlEvent</code> to respond to
   */
  protected void handleControlChanged(ControlEvent e) {
    checkHistoryMatrix();

    NavigatedDisplay navDisplay = getNavigatedDisplay();

    if ((lastVerticalRangeUnit != null) && (lastVerticalRange != null)) {
      if (!(Misc.equals(lastVerticalRangeUnit, navDisplay.getVerticalRangeUnit())
          && Arrays.equals(lastVerticalRange, navDisplay.getVerticalRange()))) {
        verticalRangeChanged();
      }
    }

    lastVerticalRangeUnit = navDisplay.getVerticalRangeUnit();
    lastVerticalRange = navDisplay.getVerticalRange();
    super.handleControlChanged(e);
  }
Пример #5
0
 /** Reload the list of servers if they have changed */
 public void updateServerList() {
   boolean old = ignoreStateChangedEvents;
   ignoreStateChangedEvents = true;
   List newList = getIdv().getIdvChooserManager().getAddeServers(getGroupType());
   if (Misc.equals(newList, this.addeServers)) {
     ignoreStateChangedEvents = old;
     return;
   }
   this.addeServers = getIdv().getIdvChooserManager().getAddeServers(getGroupType());
   Object selected = serverSelector.getSelectedItem();
   GuiUtils.setListData(serverSelector, addeServers);
   if ((selected != null) && addeServers.contains(selected)) {
     serverSelector.setSelectedItem(selected);
   }
   setGroups();
   ignoreStateChangedEvents = old;
 }
Пример #6
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);
    }
  }
Пример #7
0
  /**
   * Actually get the data identified by the given DataChoce. The default is to call the
   * getDataInner that does not take the requestProperties. This allows other, non unidata.data
   * DataSource-s (that follow the old API) to work.
   *
   * @param dataChoice The data choice that identifies the requested data.
   * @param category The data category of the request.
   * @param dataSelection Identifies any subsetting of the data.
   * @param requestProperties Hashtable that holds any detailed request properties.
   * @return The visad.Data object
   * @throws RemoteException Java RMI problem
   * @throws VisADException VisAD problem
   */
  protected Data getDataInner(
      DataChoice dataChoice,
      DataCategory category,
      DataSelection dataSelection,
      Hashtable requestProperties)
      throws VisADException, RemoteException {

    loadId = JobManager.getManager().stopAndRestart(loadId, "WMSControl");
    Object myLoadId = loadId;

    if (requestProperties == null) {
      requestProperties = new Hashtable();
    }
    WmsSelection wmsInfo = (WmsSelection) dataChoice.getId();

    // Look if there was a layer that overrides the one in the data choice
    Object tfoLayer = requestProperties.get(PROP_LAYER);
    if ((tfoLayer != null) && (tfoLayer instanceof TwoFacedObject)) {
      String layer = ((TwoFacedObject) tfoLayer).getId().toString();
      for (int i = 0; i < wmsSelections.size(); i++) {
        WmsSelection tmpSelection = (WmsSelection) wmsSelections.get(i);
        if (Misc.equals(tmpSelection.getLayer(), layer)) {
          wmsInfo = tmpSelection;
          break;
        }
      }
    }

    GeoLocationInfo boundsToUse = (GeoLocationInfo) requestProperties.get(PROP_BOUNDS);

    Image image = null;
    FieldImpl xyData = null;
    byte[] imageContent = null;

    //        System.err.println(wmsInfo.getImageFile());
    if (wmsInfo.getImageFile() != null) {
      try {
        boundsToUse = new GeoLocationInfo(90, -180, -90, 180);
        InputStream is = IOUtil.getInputStream(wmsInfo.getImageFile());
        imageContent = IOUtil.readBytes(is, myLoadId);
        image = Toolkit.getDefaultToolkit().createImage(imageContent);
        //                javax.swing.JLabel l = new javax.swing.JLabel(new
        // javax.swing.ImageIcon(image));
        //                l.setBackground(Color.red);
        //                ucar.unidata.util.GuiUtils.showOkCancelDialog(null,null, l,null);
        xyData = ucar.visad.Util.makeField(image, 0, false, true);
      } catch (Exception iexc) {
        logException("There was an error accessing the image:\n" + wmsInfo.getImageFile(), iexc);
        return null;
      }
    } else {
      String writeFile = (String) requestProperties.get(PROP_WRITEFILE);

      int imageWidth = Misc.getProperty(requestProperties, PROP_IMAGEWIDTH, 800);
      int imageHeight = Misc.getProperty(requestProperties, PROP_IMAGEHEIGHT, -1);
      double resolution = Misc.getProperty(requestProperties, PROP_RESOLUTION, (float) 1.0);

      if (wmsInfo.getLegendIcon() != null) {
        requestProperties.put(PROP_ICONPATH, wmsInfo.getLegendIcon());
      }
      if (!wmsInfo.getAllowSubsets() || (boundsToUse == null)) {
        boundsToUse = wmsInfo.getBounds();
      } else {
        boundsToUse.rectify(wmsInfo.getBounds(), 0.0);
        boundsToUse.snapToGrid();
        boundsToUse.rectify(wmsInfo.getBounds(), 0.0);
      }

      double widthDegrees = boundsToUse.getMaxLon() - boundsToUse.getMinLon();
      double heightDegrees = boundsToUse.getMaxLat() - boundsToUse.getMinLat();

      if ((widthDegrees == 0) || (heightDegrees == 0)) {
        return null;
      }

      if (wmsInfo.getFixedWidth() > -1) {
        imageWidth = wmsInfo.getFixedWidth();
      }
      if (wmsInfo.getFixedHeight() > -1) {
        imageHeight = wmsInfo.getFixedHeight();
      } else {
        if (imageHeight < 0) {
          imageHeight =
              Math.abs((int) (imageWidth * boundsToUse.getDegreesY() / boundsToUse.getDegreesX()));
        }
      }
      imageWidth = Math.min(Math.max(imageWidth, 50), 2056);
      imageHeight = Math.min(Math.max(imageHeight, 50), 2056);

      if (maintainRatio) {
        imageHeight = (int) (imageWidth * (heightDegrees / widthDegrees));
      }

      double diff = Math.abs(boundsToUse.getMinLon() - boundsToUse.getMaxLon());
      String url =
          wmsInfo.assembleRequest(
              boundsToUse, (int) (imageWidth / resolution), (int) (imageHeight / resolution));

      String cacheGroup = "WMS";
      synchronized (cachedUrls) {
        if (writeFile == null) {
          for (int i = 0; i < cachedUrls.size(); i++) {
            if (url.equals(cachedUrls.get(i))) {
              image = (Image) cachedData.get(i);
              break;
            }
          }
        }
      }

      try {
        if (image == null) {
          if (Misc.equals(url, lastUrl) && (lastImageContent != null)) {
            imageContent = lastImageContent;
          } else {
          }

          if (imageContent == null) {
            long t1 = System.currentTimeMillis();
            //                    System.err.println("getting image:" + url);
            LogUtil.message("Reading WMS image: " + wmsInfo);
            // System.err.println ("url:" + url);

            InputStream is = IOUtil.getInputStream(url);
            long t2 = System.currentTimeMillis();
            imageContent = IOUtil.readBytes(is, myLoadId);
            long t3 = System.currentTimeMillis();
            LogUtil.message("");
            //                    System.err.println("Done");
          }
          // If it is null then there is another thread that is doing
          // a subsequent read
          lastImageContent = null;
          if (imageContent == null) {
            return null;
          }
          Trace.call2("Getting image");
          Trace.call1("Making image");
          image = Toolkit.getDefaultToolkit().createImage(imageContent);
          // Wait on the image
          image = ucar.unidata.ui.ImageUtils.waitOnImage(image);
          if (image == null) {
            throw new IllegalStateException();
          }

          Trace.call2("Making image");
          lastImageContent = imageContent;
          lastUrl = url;
          updateDetailsText();
          if (!JobManager.getManager().canContinue(myLoadId)) {
            Trace.call2("WMSControl.loadImage");
            return null;
          }
          synchronized (cachedUrls) {
            if (cachedUrls.size() > 5) {
              cachedUrls.remove(cachedUrls.size() - 1);
              cachedData.remove(cachedData.size() - 1);
            }
            // For now don't cache
            //      cachedUrls.add(0, url);
            //                    cachedData.add(0, image);
          }
        }
        ImageHelper ih = new ImageHelper();
        int width = image.getWidth(ih);
        if (ih.badImage) {
          throw new IllegalStateException();
        }
        long tt1 = System.currentTimeMillis();

        xyData = ucar.visad.Util.makeField(image, 0, false, true);
        long tt2 = System.currentTimeMillis();
        //      System.err.println("time to make field:" + (tt2-tt1));
      } catch (Exception iexc) {
        if (imageContent != null) {
          String msg = new String(imageContent);
          //  System.err.println ("msg:" + msg);
          /* Check to see if this is of the form:

          <?xml version='1.0' encoding="UTF-8" standalone="no" ?>
          <!DOCTYPE ServiceExceptionReport SYSTEM "http://www.digitalearth.gov/wmt/xml/exception_1_1_0.dtd ">
          <ServiceExceptionReport version="1.1.0">
           <ServiceException>
             Service denied due to system overload. Please try again later.
           </ServiceException>
          </ServiceExceptionReport>

          */
          if (msg.indexOf("<ServiceExceptionReport") >= 0) {
            try {
              StringBuffer errors = new StringBuffer();
              errors.append("\n");
              Element root = XmlUtil.getRoot(msg);
              List children = XmlUtil.findChildren(root, "ServiceException");
              for (int i = 0; i < children.size(); i++) {

                Element node = (Element) children.get(i);
                String code = XmlUtil.getAttribute(node, "code", (String) null);
                String body = XmlUtil.getChildText(node);
                if (code != null) {
                  errors.append(code + "\n");
                }
                errors.append(body.trim() + "\n");
              }
              LogUtil.userErrorMessage(
                  "Error accessing image with the url:\n" + url + "\nError:\n" + errors);
            } catch (Exception exc) {
              LogUtil.userErrorMessage(
                  "Error accessing image with the url:\n"
                      + url
                      + "\nError:\n"
                      + StringUtil.stripTags(msg));
            }
            return null;
          }

          msg = StringUtil.replace(msg, "\n", " ").toLowerCase();
          if (StringUtil.stringMatch(msg, "service\\s*exception")) {
            if (StringUtil.stringMatch(msg, "cannot\\s*be\\s*less\\s*than")) {
              return null;
            }
          }
          if (msg.indexOf("error") >= 0) {
            LogUtil.userErrorMessage(
                "There was an error accessing the image with the url:\n"
                    + url
                    + "\nError:\n"
                    + new String(imageContent));
            return null;
          }
        }
        logException("There was an error accessing the image with the url:\n" + url, iexc);
        return null;
      }

      if (writeFile != null) {
        try {
          ImageXmlDataSource.writeToFile(writeFile, boundsToUse, imageContent, wmsInfo.getFormat());
        } catch (Exception exc) {
          throw new IllegalArgumentException(
              "Error writing image xml file:" + writeFile + " " + exc);
        }
      }
    }

    Linear2DSet domain = (Linear2DSet) xyData.getDomainSet();
    Linear2DSet imageDomain =
        new Linear2DSet(
            RealTupleType.SpatialEarth2DTuple,
            boundsToUse.getMinLon(),
            boundsToUse.getMaxLon(),
            domain.getX().getLength(),
            boundsToUse.getMaxLat(),
            boundsToUse.getMinLat(),
            domain.getY().getLength());

    // System.err.println("image domain:" + imageDomain);

    /*
    new Linear2DSet(RealTupleType.SpatialEarth2DTuple,
                        boundsToUse.getMinLon(), boundsToUse.getMaxLon(),
                        domain.getX().getLength(),
                        boundsToUse.getMinLat() +diff, boundsToUse.getMinLat(),
                        domain.getY().getLength());*/

    FieldImpl field = GridUtil.setSpatialDomain(xyData, imageDomain, true);

    return field;
  }