public void showChannelSelector() {
   try {
     createSelector(channelSelector, Color.GREEN);
   } catch (Exception e) {
     LogUtil.logException("MultiSpectralDisplay.showChannelSelector", e);
   }
 }
Ejemplo n.º 2
0
  /**
   * From the "animationInfo" set of animation properties, set all these values into all the
   * Animation objects held as memeber data.
   *
   * @param transfer AnimationInfo to get properties from
   */
  public void setProperties(AnimationInfo transfer) {
    setBoxPanelVisible(transfer.getBoxesVisible());
    animationInfo.set(transfer);
    setSharing(animationInfo.shared);
    if (animationInfo.getAnimationGroup() != null) {
      setShareGroup(animationInfo.getAnimationGroup());
    }
    if (propertiesDialog != null) {
      propertiesDialog.setInfo(animationInfo);
    }

    try {
      if (anime != null) {
        anime.setAnimationInfo(animationInfo);
        DisplayMaster displayMaster = anime.getDisplayMaster();
        if (displayMaster != null) {
          displayMaster.dataChange();
        } else {
          if (getAnimationSetInfo().getActive()) {
            anime.setSet(getAnimationSetInfo().makeTimeSet(null));
          } else {
            anime.setSet(getAnimationSetInfo().getBaseTimes());
          }
        }
      }
    } catch (Exception exp) {
      LogUtil.logException("Error setting properties", exp);
    }
    updateRunButton();
    checkAutoUpdate();
  }
  // TODO: needs work
  public boolean setWaveNumber(final float val) {
    if (data == null) return false;

    if (waveNumber == val) return true;

    try {
      if (spectrum == null) {
        spectrum = data.getSpectrum(new int[] {1, 1});
      }

      Gridded1DSet domain = (Gridded1DSet) spectrum.getDomainSet();
      int[] idx = domain.valueToIndex(new float[][] {{val}});
      float[][] tmp = domain.indexToValue(idx);
      float channel = tmp[0][0];

      setSelectorValue(channelSelector, channel);

      imageExpired = true;
    } catch (Exception e) {
      LogUtil.logException("MultiSpectralDisplay.setDisplayedWaveNum", e);
      return false;
    }

    waveNumber = val;

    if (data.hasBandNames()) {
      String name = data.getBandNameFromWaveNumber(waveNumber);
      bandSelectComboBox.setSelectedItem(name);
    }

    return true;
  }
Ejemplo n.º 4
0
 /**
  * The user has clicked on the box. Pass this through to the animation
  *
  * @param stepsOk What time steps are ok
  */
 public void stepsOkChanged(boolean[] stepsOk) {
   try {
     anime.setStepsOk(stepsOk);
   } catch (Exception exp) {
     LogUtil.logException("Error setting steps ok", exp);
   }
 }
Ejemplo n.º 5
0
 /**
  * Apply the state to the display
  *
  * @return Was this successful
  */
 protected boolean doApply() {
   // myInfo.setOrientation(GuiUtils.getValueFromBox(orientationBox));
   String place = (String) placementBox.getSelectedItem();
   if (place != null) {
     myInfo.setPlacement(place);
   }
   myInfo.setLabelColor(colorSwatch.getSwatchColor());
   myInfo.setIsVisible(visibilityCbx.isSelected());
   myInfo.setUnitVisible(unitCbx.isSelected());
   myInfo.setLabelVisible(labelVisibilityCbx.isSelected());
   myInfo.setUseAlpha(alphaCbx.isSelected());
   myInfo.setLabelFont(fontSelector.getFont());
   try {
     if (displayControl != null) {
       if (displayControl.getColorUnit() != null) {
         // mjh inq 1925: use colorUnit instead of displayUnit
         // if available; this fixes unit label when using the
         // "color by another value" displays.
         myInfo.setUnit(displayControl.getColorUnit());
       } else {
         myInfo.setUnit(displayControl.getDisplayUnit());
       }
       displayControl.setColorScaleInfo(new ColorScaleInfo(getInfo()));
     }
     return true;
   } catch (Exception exc) {
     LogUtil.logException("Setting color scale info", exc);
     return false;
   }
 }
 public void hideChannelSelector() {
   try {
     DragLine selector = removeSelector(channelSelector);
     selector = null;
   } catch (Exception e) {
     LogUtil.logException("MultiSpectralDisplay.hideChannelSelector", e);
   }
 }
 public void annihilate() {
   try {
     display.removeReference(selector);
     display.removeReference(line);
   } catch (Exception e) {
     LogUtil.logException("DragLine.annihilate", e);
   }
 }
Ejemplo n.º 8
0
 /**
  * Use the functionality within {@link java.awt.Desktop} to try opening the user's preferred web
  * browser.
  *
  * @param url URL to visit.
  * @return Either {@code true} if things look ok, {@code false} if there were problems.
  */
 private static boolean openNewStyle(final String url) {
   boolean retVal = false;
   if (Desktop.isDesktopSupported()) {
     Desktop desktop = Desktop.getDesktop();
     if (desktop.isSupported(Desktop.Action.BROWSE)) {
       try {
         desktop.browse(new URI(url));
         // well... the assumption is that there was not a problem
         retVal = true;
       } catch (URISyntaxException e) {
         LogUtil.logException("Bad syntax in URI: " + url, e);
       } catch (IOException e) {
         LogUtil.logException("Problem accessing URI: " + url, e);
       }
     }
   }
   return retVal;
 }
Ejemplo n.º 9
0
 /**
  * Set the LineWidth property.
  *
  * @param value The new value for LineWidth
  */
 public void setLineWidth(float value) {
   super.setLineWidth(value);
   try {
     if (maxDistanceBox != null) {
       maxDistanceBox.setLineWidth(value);
     }
   } catch (Exception exc) {
     LogUtil.logException("Setting color", exc);
   }
 }
Ejemplo n.º 10
0
 /** Write the image */
 public void doSaveImage() {
   String filename =
       FileManager.getWriteFile(FileManager.FILTER_IMAGEWRITE, FileManager.SUFFIX_JPG);
   if (filename != null) {
     try {
       ImageUtils.writeImageToFile(getContents(), filename);
     } catch (Exception exc) {
       LogUtil.logException("Error writing image", exc);
     }
   }
 }
Ejemplo n.º 11
0
  public void updateRange(Range range) {
    if (ctw != null) ctw.setRange(range);

    try {
      SelectRangeWidget srw = getSelectRangeWidget(range);
      if (srw != null) {
        srw.setRange(range);
      }
    } catch (Exception e) {
      LogUtil.logException("Error updating select range widget", e);
    }

    if (colorScales != null) {
      ColorScale scale = (ColorScale) colorScales.get(0);
      try {
        scale.setRangeForColor(range.getMin(), range.getMax());
      } catch (Exception exc) {
        LogUtil.logException("Error updating display ColorScale range", exc);
      }
    }
  }
 public DisplayableData getImageDisplay() {
   if (imageDisplay == null) {
     try {
       uniqueRangeType = RealType.getRealType(rangeType.getName() + "_" + cnt++);
       imageDisplay =
           new HydraRGBDisplayable("image", uniqueRangeType, null, true, displayControl);
     } catch (Exception e) {
       LogUtil.logException("MultiSpectralDisplay.getImageDisplay", e);
     }
   }
   return imageDisplay;
 }
Ejemplo n.º 13
0
 /**
  * autoupdate the set of synthetic times
  *
  * @param myTimestamp used to only have on thread active
  */
 private void updateAnimationSet(int myTimestamp) {
   try {
     while (true) {
       long seconds = (long) (animationInfo.getAnimationSetInfo().getPollMinutes() * 60);
       Misc.sleepSeconds(seconds);
       DisplayMaster displayMaster = getDisplayMaster();
       if ((displayMaster == null) || (anime == null) || (myTimestamp != timestamp)) {
         break;
       }
       displayMaster.dataChange();
     }
   } catch (Exception exc) {
     LogUtil.logException("Error updating animation set", exc);
   }
 }
Ejemplo n.º 14
0
 /**
  * Attempts to launch the browser pointed at by the {@literal "idv.browser.path"} IDV property, if
  * it has been set.
  *
  * @param url URL to open.
  * @return Either {@code true} if the command-line was executed, {@code false} if either the
  *     command-line wasn't launched or {@literal "idv.browser.path"} was not set.
  */
 private static boolean tryUserSpecifiedBrowser(final String url) {
   McIDASV mcv = McIDASV.getStaticMcv();
   boolean retVal = false;
   if (mcv != null) {
     String browserPath = mcv.getProperty("idv.browser.path", (String) null);
     if ((browserPath != null) && !browserPath.trim().isEmpty()) {
       try {
         Runtime.getRuntime().exec(browserPath + ' ' + url);
         retVal = true;
       } catch (Exception e) {
         LogUtil.logException("Executing browser: " + browserPath, e);
       }
     }
   }
   return retVal;
 }
Ejemplo n.º 15
0
  /**
   * Create the charts
   *
   * @throws RemoteException On badness
   * @throws VisADException On badness
   */
  public void loadData() throws VisADException, RemoteException {
    createChart();
    List dataChoiceWrappers = getDataChoiceWrappers();
    try {
      for (int dataSetIdx = 0; dataSetIdx < plot.getDatasetCount(); dataSetIdx++) {
        MyHistogramDataset dataset = (MyHistogramDataset) plot.getDataset(dataSetIdx);
        dataset.removeAllSeries();
      }

      //            dataset.removeAllSeries();
      Hashtable props = new Hashtable();
      props.put(TrackDataSource.PROP_TRACKTYPE, TrackDataSource.ID_TIMETRACE);

      for (int paramIdx = 0; paramIdx < dataChoiceWrappers.size(); paramIdx++) {
        DataChoiceWrapper wrapper = (DataChoiceWrapper) dataChoiceWrappers.get(paramIdx);

        DataChoice dataChoice = wrapper.getDataChoice();
        FlatField data = getFlatField((FieldImpl) dataChoice.getData(null, props));
        Unit unit = ucar.visad.Util.getDefaultRangeUnits((FlatField) data)[0];
        double[][] samples = data.getValues(false);
        double[] actualValues = filterData(samples[0], getTimeValues(samples, data))[0];
        NumberAxis domainAxis = new NumberAxis(wrapper.getLabel(unit));

        XYItemRenderer renderer;
        if (stacked) {
          renderer = new StackedXYBarRenderer();
        } else {
          renderer = new XYBarRenderer();
        }
        plot.setRenderer(paramIdx, renderer);
        Color c = wrapper.getColor(paramIdx);
        domainAxis.setLabelPaint(c);
        renderer.setSeriesPaint(0, c);

        MyHistogramDataset dataset = new MyHistogramDataset();
        dataset.setType(HistogramType.FREQUENCY);
        dataset.addSeries(dataChoice.getName() + " [" + unit + "]", actualValues, bins);
        plot.setDomainAxis(paramIdx, domainAxis, false);
        plot.mapDatasetToDomainAxis(paramIdx, paramIdx);
        plot.setDataset(paramIdx, dataset);
      }

    } catch (Exception exc) {
      LogUtil.logException("Error creating data set", exc);
      return;
    }
  }
Ejemplo n.º 16
0
  /**
   * Show the given error to the user. If it was an Adde exception that was a bad server error then
   * print out a nice message.
   *
   * @param excp The exception
   */
  protected void handleConnectionError(Exception excp) {
    String message = excp.getMessage();
    if (excp instanceof AddeURLException) {
      handleUnknownDataSetError();

    } else if (message.toLowerCase().indexOf("unknownhostexception") >= 0) {
      LogUtil.userErrorMessage("Could not access server: " + getServer());
    } else if (message.toLowerCase().indexOf("server unable to resolve this dataset") >= 0) {
      handleUnknownDataSetError();
    } else if ((message.toLowerCase().indexOf("no images satisfy") >= 0)
        || (message.toLowerCase().indexOf("error generating list of files") >= 0)) {
      LogUtil.userErrorMessage("No data available for the selection");
      return;
    } else {
      LogUtil.logException("Error connecting to: " + getServer(), excp);
    }
    if (!(getState() == STATE_CONNECTED)) {
      setState(STATE_UNCONNECTED);
    }
  }
 public FlatField getImageDataFrom(final float channel) {
   FlatField imageData = null;
   try {
     MultiDimensionSubset select = null;
     Hashtable table = dataChoice.getProperties();
     Enumeration keys = table.keys();
     while (keys.hasMoreElements()) {
       Object key = keys.nextElement();
       if (key instanceof MultiDimensionSubset) {
         select = (MultiDimensionSubset) table.get(key);
       }
     }
     HashMap subset = select.getSubset();
     imageData = data.getImage(channel, subset);
     uniqueRangeType = RealType.getRealType(rangeType.getName() + "_" + cnt++);
     imageData = changeRangeType(imageData, uniqueRangeType);
   } catch (Exception e) {
     LogUtil.logException("MultiSpectralDisplay.getImageDataFrom", e);
   }
   return imageData;
 }
Ejemplo n.º 18
0
  /** Export a list of user selected projections */
  public void doExport() {
    List projections = getProjections();

    Vector<String> projectionNames = new Vector<>(projections.size());
    for (int i = 0; i < projections.size(); i++) {
      ProjectionImpl projection = (ProjectionImpl) projections.get(i);
      projectionNames.add(projection.getName());
    }

    JList<String> jlist = new JList<>(projectionNames);
    JPanel contents =
        GuiUtils.topCenter(
            GuiUtils.cLabel("Please select the projections you want to export"),
            GuiUtils.makeScrollPane(jlist, 200, 400));

    if (!GuiUtils.showOkCancelDialog(null, "Export Projections", contents, null)) {
      return;
    }

    int[] indices = jlist.getSelectedIndices();
    if ((indices == null) || (indices.length == 0)) {
      return;
    }
    List<ProjectionImpl> selected = new ArrayList<>(indices.length);
    for (int i = 0; i < indices.length; i++) {
      selected.add((ProjectionImpl) projections.get(indices[i]));
    }
    String xml = (new XmlEncoder()).toXml(selected);
    String filename = FileManager.getWriteFile(FileManager.FILTER_XML, FileManager.SUFFIX_XML);
    if (filename == null) {
      return;
    }
    try {
      IOUtil.writeFile(filename, xml);
    } catch (Exception exc) {
      LogUtil.logException("Writing projection file: " + filename, exc);
    }
  }
Ejemplo n.º 19
0
  /**
   * Make a dataset with the file
   *
   * @return dataset
   */
  private RaobDataSet doMakeRaobDataSet() {
    SoundingAdapter adapter = null;
    try {
      adapter = new NetcdfSoundingAdapter(file);
    } catch (Exception ill) {
    }

    if (adapter == null) {
      try {
        adapter = new CMASoundingAdapter(file);
      } catch (Exception exc) {
        LogUtil.logException("Reading sounding:" + file, exc);
        return null;
      }
    }

    if (adapter == null) {
      throw new IllegalArgumentException("Could not open sounding file:" + file);
    }

    SoundingOb[] obs = adapter.getSoundingObs();
    return new RaobDataSet(adapter, Misc.toList(obs));
  }
  // TODO: generalize this so that you can grab the image data for any
  // channel
  public FlatField getImageData() {
    try {
      if ((imageExpired) || (image == null)) {
        imageExpired = false;

        MultiDimensionSubset select = null;
        Hashtable table = dataChoice.getProperties();
        Enumeration keys = table.keys();
        while (keys.hasMoreElements()) {
          Object key = keys.nextElement();
          if (key instanceof MultiDimensionSubset) {
            select = (MultiDimensionSubset) table.get(key);
          }
        }
        HashMap subset = select.getSubset();
        image = data.getImage(waveNumber, subset);
        image = changeRangeType(image, uniqueRangeType);
      }
    } catch (Exception e) {
      LogUtil.logException("MultiSpectralDisplay.getImageData", e);
    }

    return image;
  }
  private void init() throws VisADException, RemoteException {

    HydraDataSource source = (HydraDataSource) dataChoice.getDataSource();

    // TODO revisit this, may want to move method up to base class HydraDataSource
    if (source instanceof SuomiNPPDataSource) {
      data = ((SuomiNPPDataSource) source).getMultiSpectralData(dataChoice);
    }

    if (source instanceof MultiSpectralDataSource) {
      data = ((MultiSpectralDataSource) source).getMultiSpectralData(dataChoice);
    }

    waveNumber = data.init_wavenumber;

    try {
      spectrum = data.getSpectrum(new int[] {1, 1});
    } catch (Exception e) {
      LogUtil.logException("MultiSpectralDisplay.init", e);
    }

    domainSet = (Gridded1DSet) spectrum.getDomainSet();
    initialRangeX = getXRange(domainSet);
    initialRangeY = data.getDataRange();

    domainType = getDomainType(spectrum);
    rangeType = getRangeType(spectrum);

    master = new XYDisplay(DISP_NAME, domainType, rangeType);

    setDisplayMasterAttributes(master);

    // set up the x- and y-axis
    xmap = new ScalarMap(domainType, Display.XAxis);
    ymap = new ScalarMap(rangeType, Display.YAxis);

    xmap.setRange(initialRangeX[0], initialRangeX[1]);
    ymap.setRange(initialRangeY[0], initialRangeY[1]);

    display = master.getDisplay();
    display.addMap(xmap);
    display.addMap(ymap);
    display.addDisplayListener(this);

    new RubberBandBox(this, xmap, ymap);

    if (displayControl == null) { // - add in a ref for the default spectrum, ie no DisplayControl
      DataReferenceImpl spectrumRef = new DataReferenceImpl(hashCode() + "_spectrumRef");
      spectrumRef.setData(spectrum);
      addRef(spectrumRef, Color.WHITE);
    }

    if (data.hasBandNames()) {
      bandSelectComboBox = new JComboBox(data.getBandNames().toArray());
      bandSelectComboBox.setSelectedItem(data.init_bandName);
      bandSelectComboBox.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              String bandName = (String) bandSelectComboBox.getSelectedItem();
              if (bandName == null) return;

              HashMap<String, Float> bandMap = data.getBandNameMap();
              if (bandMap == null) return;

              if (!bandMap.containsKey(bandName)) return;

              setWaveNumber(bandMap.get(bandName));
            }
          });
    }
  }