Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
 /**
  * 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);
   }
 }
Exemplo n.º 3
0
 /**
  * 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);
   }
 }
Exemplo n.º 4
0
 /** 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);
   }
 }
Exemplo n.º 5
0
 /** 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);
   }
 }
Exemplo n.º 6
0
 /**
  * Get the color table, range, etc, from the given display control and save them as the param
  * defaults for its data choice
  *
  * @param displayControl the display control to get state from
  */
 public void saveDefaults(DisplayControlImpl displayControl) {
   try {
     List choices = displayControl.getMyDataChoices();
     if (choices.size() != 1) {
       return;
     }
     DataChoice dc = (DataChoice) choices.get(0);
     String name = dc.getName();
     String ctName =
         ((displayControl.getColorTable() != null)
             ? displayControl.getColorTable().getName()
             : null);
     ParamInfo newParamInfo =
         new ParamInfo(
             name,
             ctName,
             displayControl.getRange(),
             displayControl.getContourInfo(),
             displayControl.getDisplayUnit());
     ParamDefaultsTable firstTable = getFirstTable();
     if (!firstTable.editRow(newParamInfo, false)) {
       return;
     }
     ParamInfo origParamInfo = firstTable.findByName(dc.getName());
     if (origParamInfo == null) {
       firstTable.addBeginning(newParamInfo);
       firstTable.getSelectionModel().setSelectionInterval(0, 0);
     } else {
       origParamInfo.initWith(newParamInfo);
       firstTable.tableChanged();
       firstTable.selectParamInfo(origParamInfo);
     }
     saveData();
     show();
     GuiUtils.showComponentInTabs(firstTable);
   } catch (Exception exc) {
     LogUtil.printException(log_, "copying defaults", exc);
   }
 }
Exemplo n.º 7
0
 /**
  * Wrapper method, calling into idv
  *
  * @param msg The message
  * @param excp The exception
  */
 public static void logException(String msg, Throwable excp) {
   LogUtil.printException(log_, msg, excp);
 }
Exemplo n.º 8
0
  /**
   * Create the param infos from the given xml root
   *
   * @param root The xml root
   * @return List of param infos
   */
  private List createParamInfoList(Element root) {

    List infos = new ArrayList();

    if (!root.getTagName().equals(TAG_PARAMS)) {
      try {
        Object obj = getIdv().getEncoderForRead().toObject(root);
        if (obj instanceof List) {
          infos.addAll((List) obj);
        } else {
          System.err.println("Unknown object type: " + obj.getClass().getName());
        }
      } catch (Exception exc) {
        System.err.println("Error reading param defaults");
      }
      return infos;
    }

    List nodes = XmlUtil.findChildren(root, TAG_PARAM);

    for (int i = 0; i < nodes.size(); i++) {
      Element child = (Element) nodes.get(i);
      Range range = null;
      Unit displayUnit = null;
      ContourInfo contourInfo = null;

      String paramName = XmlUtil.getAttribute(child, ATTR_NAME);
      String colorTableName = XmlUtil.getAttribute(child, ATTR_COLORTABLE, (String) null);
      String range_min = XmlUtil.getAttribute(child, ATTR_RANGE_MIN, (String) null);
      String range_max = XmlUtil.getAttribute(child, ATTR_RANGE_MAX, (String) null);

      String unitName = XmlUtil.getAttribute(child, ATTR_UNIT, (String) null);

      String ci_interval = XmlUtil.getAttribute(child, ATTR_CI_INTERVAL, (String) null);
      String ci_base = XmlUtil.getAttribute(child, ATTR_CI_BASE, (String) null);
      String ci_min = XmlUtil.getAttribute(child, ATTR_CI_MIN, range_min);
      String ci_max = XmlUtil.getAttribute(child, ATTR_CI_MAX, range_max);
      boolean ci_dash = XmlUtil.getAttribute(child, ATTR_CI_DASH, DFLT_CI_DASH);
      boolean ci_label = XmlUtil.getAttribute(child, ATTR_CI_LABEL, DFLT_CI_LABEL);
      String ci_width = XmlUtil.getAttribute(child, ATTR_CI_WIDTH, String.valueOf(DFLT_CI_WIDTH));

      if (unitName != null) {
        try {
          displayUnit = ucar.visad.Util.parseUnit(unitName);
        } catch (Exception e) {
          LogUtil.printException(log_, "Creating unit: " + unitName, e);
        }
      }

      if ((ci_interval != null) || (ci_base != null)) {
        if (ci_interval == null) {
          ci_interval = "NaN";
        }

        if (ci_base == null) {
          ci_base = "NaN";
        }
        if (ci_min == null) {
          ci_min = "NaN";
        }
        if (ci_max == null) {
          ci_max = "NaN";
        }
        if (ci_width == null) {
          ci_width = "1";
        }
        contourInfo =
            new ContourInfo(
                ci_interval,
                Misc.parseDouble(ci_base),
                Misc.parseDouble(ci_min),
                Misc.parseDouble(ci_max),
                ci_label,
                ci_dash,
                ContourInfo.DEFAULT_FILL,
                Misc.parseDouble(ci_width));
      }

      if ((ci_dash != DFLT_CI_DASH) || (ci_label != DFLT_CI_LABEL)) {
        if (contourInfo == null) {
          contourInfo = new ContourInfo(Double.NaN, Double.NaN, Double.NaN, Double.NaN);
          contourInfo.setIsLabeled(ci_label);
          contourInfo.setDashOn(ci_dash);
        }
      }

      if ((range_min != null) && (range_max != null)) {
        range = new Range(Misc.parseDouble(range_min), Misc.parseDouble(range_max));
      }

      ParamInfo paramInfo =
          new ParamInfo(paramName, colorTableName, range, contourInfo, displayUnit);
      infos.add(paramInfo);
    }
    return infos;
  }