Exemple #1
0
 /**
  * Check if the server is ok
  *
  * @return status code
  */
 protected int checkIfServerIsOk() {
   try {
     StringBuffer buff = getUrl(REQ_TEXT);
     appendKeyValue(buff, PROP_FILE, FILE_PUBLICSRV);
     URL url = new URL(buff.toString());
     URLConnection urlc = url.openConnection();
     InputStream is = urlc.getInputStream();
     is.close();
     return STATUS_OK;
   } catch (AddeURLException ae) {
     String aes = ae.toString();
     if (aes.indexOf("Invalid project number") >= 0) {
       LogUtil.userErrorMessage("Invalid project number");
       return STATUS_NEEDSLOGIN;
     }
     if (aes.indexOf("Invalid user id") >= 0) {
       LogUtil.userErrorMessage("Invalid user ID");
       return STATUS_NEEDSLOGIN;
     }
     if (aes.indexOf("Accounting data") >= 0) {
       return STATUS_NEEDSLOGIN;
     }
     if (aes.indexOf("cannot run server 'txtgserv") >= 0) {
       return STATUS_OK;
     }
     LogUtil.userErrorMessage("Error connecting to server. " + ae.getMessage());
     return STATUS_ERROR;
   } catch (Exception exc) {
     logException("Connecting to server:" + getServer(), exc);
     return STATUS_ERROR;
   }
 }
Exemple #2
0
 /**
  * Show a dialog containing a message.
  *
  * @param msg Message to display.
  * @param breakLines If {@code true}, long lines are split.
  */
 public static void userMessage(String msg, boolean breakLines) {
   msg = Msg.msg(msg);
   if (LogUtil.showGui()) {
     LogUtil.consoleMessage(msg);
     JComponent msgComponent = getMessageComponent(msg, breakLines);
     GuiUtils.addModalDialogComponent(msgComponent);
     JOptionPane.showMessageDialog(LogUtil.getCurrentWindow(), msgComponent);
     GuiUtils.removeModalDialogComponent(msgComponent);
   } else {
     System.err.println(msg);
   }
 }
 public void showChannelSelector() {
   try {
     createSelector(channelSelector, Color.GREEN);
   } catch (Exception e) {
     LogUtil.logException("MultiSpectralDisplay.showChannelSelector", e);
   }
 }
  // 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;
  }
Exemple #5
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();
  }
Exemple #6
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);
   }
 }
Exemple #7
0
  /**
   * Generate a user interface from the given xml document (derived from the given path). The xml
   * can be a thredds query capability, any verion of a thredds catalog or an IDV menus xml file.
   *
   * @param doc the xml document
   * @param xmlRoot The root of the xml document to create a display for.
   * @param path The url path we got the xml from.
   */
  protected void makeUi(Document doc, Element xmlRoot, String path) {
    this.document = doc;
    setHaveData(false);
    if (xmlRoot == null) {
      return;
    }
    setSelected(path);
    XmlHandler handler = null;
    String tagName = XmlUtil.getLocalName(xmlRoot);

    if (tagName.equals(WmsUtil.TAG_WMS1) || tagName.equals(WmsUtil.TAG_WMS2)) {
      handler = new WmsHandler(this, xmlRoot, path);
    } else if (tagName.equals(TAG_ERROR)) {
      final String error = XmlUtil.getAttribute(xmlRoot, "label", "Error");
      LogUtil.userErrorMessage("Error: " + error);
      return;
    } else if (tagName.equals(CatalogUtil.TAG_CATALOG)) {
      handler = new ThreddsHandler(this, xmlRoot, path);
    } else if (tagName.equals("menus")) {
      handler = new MenuHandler(this, xmlRoot, path);
    } else {
      throw new IllegalArgumentException(
          "Unknown xml:"
              + ((xmlContents.length() > 100) ? xmlContents.substring(0, 100) : xmlContents)
              + " ...");
    }

    JComponent contents = handler.getContents();
    contents.setPreferredSize(new Dimension(200, 250));
    addToContents(contents);
    addToHistory(handler);
    updateStatus();
  }
 /**
  * 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;
   }
 }
Exemple #9
0
 /**
  * Implementation of the getData method.
  *
  * @param category the data category
  * @param dataSelection the selection properties
  * @param requestProperties special request properties
  * @return the data based on the input parameters
  * @throws DataCancelException if the request was canceled
  * @throws RemoteException Java RMI problem
  * @throws VisADException problem creating the Data object
  */
 protected Data getData(
     DataCategory category, DataSelection dataSelection, Hashtable requestProperties)
     throws VisADException, RemoteException, DataCancelException {
   try {
     // This could be simple text
     if (!url.startsWith("http:")) {
       return new visad.Text(url);
     }
     return new visad.Text(IOUtil.readContents(url));
   } catch (java.io.FileNotFoundException fnfe) {
     LogUtil.printException(log_, "getData", fnfe);
   } catch (java.io.IOException ioe) {
     LogUtil.printException(log_, "getData", ioe);
   }
   return null;
 }
 /**
  * Save the list of ParamInfo-s into the given file
  *
  * @param infoList List of infos
  * @param filename The filename to write to
  */
 public void doSave(List infoList, String filename) {
   try {
     Element root = createDom(XmlUtil.makeDocument(), infoList);
     IOUtil.writeFile(filename, XmlUtil.toString(root));
   } catch (Exception exc) {
     LogUtil.printException(log_, "Error writing file", exc);
   }
 }
 public void annihilate() {
   try {
     display.removeReference(selector);
     display.removeReference(line);
   } catch (Exception e) {
     LogUtil.logException("DragLine.annihilate", e);
   }
 }
 public void hideChannelSelector() {
   try {
     DragLine selector = removeSelector(channelSelector);
     selector = null;
   } catch (Exception e) {
     LogUtil.logException("MultiSpectralDisplay.hideChannelSelector", e);
   }
 }
Exemple #13
0
  /** Handle unknown data set error */
  protected void handleUnknownDataSetError() {
    // Don't do this for now
    //        List groups =  readGroups();
    List groups = null;
    if (groups == null) {
      LogUtil.userErrorMessage("Dataset not found on server: " + getServer());

    } else {
      LogUtil.userErrorMessage(
          "Dataset not found on server: "
              + getServer()
              + "\nPossible data sets:\n"
              + "   "
              + StringUtil.join("\n   ", groups));
    }
    setState(STATE_UNCONNECTED);
  }
Exemple #14
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;
 }
 /** Export allthe param infos to the plugin manager */
 public void exportToPlugin() {
   ParamDefaultsTable table = getCurrentTable();
   List list = table.getParamInfoList();
   if (list.size() == 0) {
     LogUtil.userMessage("No rows selected");
     return;
   }
   getIdv().getPluginManager().addObject(list);
 }
Exemple #16
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);
   }
 }
Exemple #17
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);
    }
  }
Exemple #18
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);
     }
   }
 }
 /**
  * Load in all of the {@link ucar.unidata.idv.ui.ParamInfo}-s pointed to by the given resource
  * collection
  *
  * @param resources The resources (e.g., the paramdefaults.xml)
  */
 private void init(XmlResourceCollection resources) {
   try {
     for (int i = 0; i < resources.size(); i++) {
       Element root = resources.getRoot(i, false);
       if (root != null) {
         loadParamDefaults(root, false);
       }
     }
   } catch (Exception exc) {
     LogUtil.printException(log_, "Loading  parameter to color table properties ", exc);
   }
 }
Exemple #20
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;
 }
Exemple #22
0
 /**
  * Apply properties
  *
  * @return Was successful
  */
 protected boolean applyProperties() {
   if (!super.applyProperties()) {
     return false;
   }
   try {
     bins = new Integer(binFld.getText().trim()).intValue();
   } catch (NumberFormatException nfe) {
     LogUtil.userErrorMessage("Bad value for bins: " + binFld.getText());
     return false;
   }
   //        stacked = stackedCbx.isSelected();
   return true;
 }
 /** Write out the user's editable param infos */
 private void saveData() {
   Document usersDoc = XmlUtil.makeDocument();
   Element usersRoot = createDom(usersDoc, getFirstTable().getParamInfoList());
   try {
     resources.setWritableDocument(usersDoc, usersRoot);
     resources.writeWritable();
     // Reinitialize the static state
     paramInfos = new ArrayList();
     paramToInfo = new Hashtable();
     init(resources);
   } catch (Exception exc) {
     LogUtil.printException(log_, "writing aliases xml", exc);
   }
 }
Exemple #24
0
 /**
  * _more_
  *
  * @return _more_
  */
 private boolean windowOk() {
   getContents();
   if (contents == null) {
     return false;
   }
   if (shouldMakeDialog()) {
     if (dialog == null) {
       dialog = new JDialog((Frame) null, getWindowTitle(), false);
       LogUtil.registerWindow(dialog);
       GuiUtils.packDialog(dialog, contents);
       dialog.setLocation(100, 100);
       window = dialog;
     }
   } else {
     if (frame == null) {
       frame = new JFrame(getWindowTitle());
       if (menuBar != null) {
         GuiUtils.decorateFrame(frame, menuBar);
       }
       LogUtil.registerWindow(frame);
       frame.getContentPane().add(contents);
       frame.pack();
       Msg.translateTree(frame);
       frame.setLocation(100, 100);
       window = frame;
     }
   }
   if (window != null) {
     window.addWindowListener(
         new WindowAdapter() {
           public void windowClosing(WindowEvent e) {
             windowIsClosing();
           }
         });
   }
   return window != null;
 }
Exemple #25
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);
   }
 }
Exemple #26
0
  /**
   * apply the properties
   *
   * @return success
   */
  public boolean applyProperties() {
    if (!super.applyProperties()) {
      return false;
    }
    boolean changed = false;
    String what = "";
    try {
      what = "Bad bin value";
      changed |= (binRoundToField.getTime() != binRoundTo) || (binWidth != binWidthField.getTime());
      binRoundTo = binRoundToField.getTime();
      binWidth = binWidthField.getTime();

      what = "Bad grid points X value";
      changed |= (gridX != gridProperties.getGridX());
      what = "Bad grid points Y value";
      changed |= (gridY != gridProperties.getGridY());
      what = "Bad grid passes value";
      changed |= (numGridPasses != gridProperties.getNumGridPasses());
      what = "Bad grid unit value";
      changed |= (!gridUnit.equals(gridProperties.getGridUnit()));
      what = "Bad grid search value";
      changed |= (gridSearchRadius != gridProperties.getGridSearchRadius());
      what = "Bad grid gain value";
      changed |= (gridGain != gridProperties.getGridGain());
    } catch (NumberFormatException nfe) {
      LogUtil.userErrorMessage(what);
      return false;
    }

    gridX = gridProperties.getGridX();
    gridY = gridProperties.getGridY();
    gridUnit = gridProperties.getGridUnit();
    numGridPasses = gridProperties.getNumGridPasses();
    gridGain = gridProperties.getGridGain();
    gridSearchRadius = gridProperties.getGridSearchRadius();
    if (makeGridFields != makeGridFieldsCbx.isSelected()) {
      makeGridFields = makeGridFieldsCbx.isSelected();
      dataChoices = null;
      getDataChoices();
      getDataContext().dataSourceChanged(this);
    }

    if (changed) {
      flushCache();
    }

    return true;
  }
Exemple #27
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;
 }
Exemple #28
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;
    }
  }
Exemple #29
0
  /**
   * A utility method that will wait until all displays are finished being created. This looks at
   * the DisplayControls, data sources, global wait cursor count, the visad thread pool and looks at
   * any active java3d threads
   *
   * @param uiManager The ui manager. We use this to access the wait cursor count
   * @param timeToWait (milliseconds) elapsed time to wait for nothing to be active
   */
  public static void waitUntilDisplaysAreDone(IdvUIManager uiManager, long timeToWait) {
    Trace.call1("Waiting on displays");
    int successiveTimesWithNoActive = 0;
    int sleepTime = 10;
    long firstTime = System.currentTimeMillis();
    int cnt = 0;
    while (true) {
      boolean cursorCount = (uiManager.getWaitCursorCount() > 0);
      boolean actionCount = ActionImpl.getTaskCount() > 0;
      boolean dataActive = DataSourceImpl.getOutstandingGetDataCalls() > 0;
      boolean anyJ3dActive = anyJava3dThreadsActive();
      boolean allDisplaysInitialized = uiManager.getIdv().getAllDisplaysIntialized();

      //            System.err.println ("\tAll displays init:" + allDisplaysInitialized +" cursor
      // cnt:" + uiManager.getWaitCursorCount() + " action cnt:" +actionCount + " data active: " +
      // dataActive);
      //            if ((cnt++) % 30 == 0) {
      //                System.err.println ("\tcnt:" + uiManager.getWaitCursorCount() + " "
      // +actionCount + " " + dataActive);
      //            }
      boolean anyActive =
          actionCount || cursorCount || dataActive || !allDisplaysInitialized || anyJ3dActive;
      if (dataActive) {
        firstTime = System.currentTimeMillis();
      }

      if (anyActive) {
        successiveTimesWithNoActive = 0;
      } else {
        successiveTimesWithNoActive++;
      }
      if ((timeToWait == 0) && !anyActive) {
        break;
      }
      if (successiveTimesWithNoActive * sleepTime > timeToWait) {
        break;
      }
      Misc.sleep(sleepTime);
      // At most wait 120 seconds
      if (System.currentTimeMillis() - firstTime > 120000) {
        System.err.println("Error waiting for to be done:" + LogUtil.getStackDump(false));
        return;
      }
    }
    Trace.call2("Waiting on displays");
  }
 /** Import an xml param defaults file */
 public void doImport() {
   try {
     String filename = FileManager.getReadFile(FileManager.FILTER_XML);
     if (filename == null) {
       return;
     }
     Element root = XmlUtil.getRoot(IOUtil.readContents(filename));
     if (root == null) {
       return;
     }
     List infos = createParamInfoList(root);
     ParamDefaultsTable table = getCurrentTable();
     table.getParamInfoList().addAll(infos);
     table.tableChanged();
     saveData();
   } catch (Exception exc) {
     LogUtil.printException(log_, "Error importing file", exc);
   }
 }