Пример #1
0
 /**
  * Get the the colorTable unit.
  *
  * @return Unit used for colorTableing values. May be <code>null</code>.
  */
 public Unit getColorTableUnit() {
   if ((colorTableUnit == null) && (colorTableUnitName != null)) {
     try {
       colorTableUnit = ucar.visad.Util.parseUnit(colorTableUnitName);
     } catch (Exception exc) {
     }
   }
   return colorTableUnit;
 }
Пример #2
0
 /**
  * Get the the scale unit.
  *
  * @return Unit used for scaleing values. May be <code>null</code>.
  */
 public Unit getScaleUnit() {
   if ((scaleUnit == null) && (scaleUnitName != null)) {
     try {
       scaleUnit = ucar.visad.Util.parseUnit(scaleUnitName);
     } catch (Exception exc) {
     }
   }
   return scaleUnit;
 }
Пример #3
0
 /**
  * Get the the display unit.
  *
  * @return Unit used for displaying values. May be <code>null</code>.
  */
 public Unit getDisplayUnit() {
   if ((displayUnit == null) && (displayUnitName != null)) {
     try {
       displayUnit = ucar.visad.Util.parseUnit(displayUnitName);
     } catch (Exception exc) {
     }
   }
   return displayUnit;
 }
Пример #4
0
  /**
   * Set the vertical range unit from the preference
   *
   * @param nd navigated display to set the unit on
   * @throws RemoteException problem with remote display
   * @throws VisADException problem with local display
   */
  protected void setVerticalRangeUnitPreference(NavigatedDisplay nd)
      throws VisADException, RemoteException {
    Unit u = null;

    try {
      u =
          ucar.visad.Util.parseUnit(
              getIdv().getObjectStore().get(IdvConstants.PREF_VERTICALUNIT, "m"));
    } catch (Exception exc) {
      u = null;
    }

    if (u != null) {
      double[] range = nd.getVerticalRange();
      Unit defaultUnit = nd.getVerticalRangeUnit();

      if (!u.equals(defaultUnit) && Unit.canConvert(u, defaultUnit)) {
        range = u.toThis(range, defaultUnit);
        nd.setVerticalRangeUnit(u);
        nd.setVerticalRange(range[0], range[1]);
      }
    }
  }
Пример #5
0
  /** Initialize the default vertical range */
  private void initVerticalRange() {
    String typeName = getTypeName().toLowerCase();
    String verticalRangeStr =
        getIdv().getProperty("idv.viewmanager." + typeName + ".verticalrange", (String) null);

    if (verticalRangeStr != null) {
      List toks = StringUtil.split(verticalRangeStr, ",", true, true);

      if (toks.size() >= 2) {
        tmpVerticalRange =
            new double[] {
              new Double(toks.get(0).toString()).doubleValue(),
              new Double(toks.get(1).toString()).doubleValue()
            };

        if (toks.size() == 3) {
          try {
            tmpVertRangeUnit = ucar.visad.Util.parseUnit(toks.get(2).toString());
          } catch (Exception exc) {
          }
        }
      }
    }
  }
Пример #6
0
 /**
  * Popup a unit selection gui. This will also save off persistently any new unit names typed in.
  *
  * @param unit The current unit
  * @param defaultUnit The default unit to return if the user chooses "Default"
  * @return The new unit or null on a cancel or an error
  */
 public Unit selectUnit(Unit unit, Unit defaultUnit) {
   JComboBox ufld = makeUnitBox(unit, defaultUnit);
   Component panel = GuiUtils.label(" New unit:  ", ufld);
   if (!GuiUtils.showOkCancelDialog(
       null, "Change unit", GuiUtils.inset(panel, 5), null, Misc.newList(ufld))) {
     return null;
   }
   Object selected = ufld.getSelectedItem();
   String unitName = TwoFacedObject.getIdString(selected);
   if (unitName == null) {
     return defaultUnit;
   }
   try {
     Unit newUnit = Util.parseUnit(unitName);
     if (!(selected instanceof TwoFacedObject)) {
       selected = new TwoFacedObject(selected.toString(), newUnit);
     }
     addToUnitList(selected);
     return newUnit;
   } catch (Exception exc) {
     LogUtil.userMessage("Error parsing unit:" + unitName + "\n" + exc);
   }
   return null;
 }
Пример #7
0
    /**
     * Edit row
     *
     * @param paramInfo param info
     * @param removeOnCancel Should remove param info if user presses cancel_
     * @return ok
     */
    public boolean editRow(ParamInfo paramInfo, boolean removeOnCancel) {

      List comps = new ArrayList();
      ParamField nameFld = new ParamField(null, true);
      nameFld.setText(paramInfo.getName());
      JPanel topPanel = GuiUtils.hbox(GuiUtils.lLabel("Parameter:  "), nameFld);
      topPanel = GuiUtils.inset(topPanel, 5);

      comps.add(GuiUtils.inset(new JLabel("Defined"), new Insets(5, 0, 0, 0)));
      comps.add(GuiUtils.filler());
      comps.add(GuiUtils.filler());

      final JLabel ctPreviewLbl = new JLabel("");
      final JLabel ctLbl = new JLabel("");
      if (paramInfo.hasColorTableName()) {
        ctLbl.setText(paramInfo.getColorTableName());
        ColorTable ct =
            getIdv().getColorTableManager().getColorTable(paramInfo.getColorTableName());
        if (ct != null) {
          ctPreviewLbl.setIcon(ColorTableCanvas.getIcon(ct));
        } else {
          ctPreviewLbl.setIcon(null);
        }
      }
      String cbxLabel = "";
      final ArrayList menus = new ArrayList();
      getIdv()
          .getColorTableManager()
          .makeColorTableMenu(
              new ObjectListener(null) {
                public void actionPerformed(ActionEvent ae, Object data) {
                  ctLbl.setText(data.toString());
                  ColorTable ct = getIdv().getColorTableManager().getColorTable(ctLbl.getText());
                  if (ct != null) {
                    ctPreviewLbl.setIcon(ColorTableCanvas.getIcon(ct));
                  } else {
                    ctPreviewLbl.setIcon(null);
                  }
                }
              },
              menus);

      JCheckBox ctUseCbx = new JCheckBox(cbxLabel, paramInfo.hasColorTableName());
      final JButton ctPopup = new JButton("Change");
      ctPopup.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
              GuiUtils.showPopupMenu(menus, ctPopup);
            }
          });
      addEditComponents(
          comps,
          "Color Table:",
          ctUseCbx,
          GuiUtils.hbox(ctPopup, GuiUtils.vbox(ctLbl, ctPreviewLbl), 5));

      JCheckBox rangeUseCbx = new JCheckBox(cbxLabel, paramInfo.hasRange());
      JTextField minFld = new JTextField("" + paramInfo.getMin(), 4);
      JTextField maxFld = new JTextField("" + paramInfo.getMax(), 4);
      JPanel rangePanel = GuiUtils.hbox(minFld, maxFld, 5);
      addEditComponents(comps, "Range:", rangeUseCbx, rangePanel);

      JCheckBox unitUseCbx = new JCheckBox(cbxLabel, paramInfo.hasDisplayUnit());
      String unitLabel = "";
      Unit unit = null;
      if (paramInfo.hasDisplayUnit()) {
        unit = paramInfo.getDisplayUnit();
      }

      JComboBox unitFld = getIdv().getDisplayConventions().makeUnitBox(unit, null);
      //            JTextField unitFld = new JTextField(unitLabel, 15);
      addEditComponents(comps, "Unit:", unitUseCbx, unitFld);

      ContourInfo ci = paramInfo.getContourInfo();
      JCheckBox contourUseCbx = new JCheckBox(cbxLabel, ci != null);
      if (ci == null) {
        ci = new ContourInfo();
      }
      ContourInfoDialog contDialog =
          new ContourInfoDialog("Edit Contour Defaults", false, null, false);
      contDialog.setState(ci);
      addEditComponents(comps, "Contour:", contourUseCbx, contDialog.getContents());

      GuiUtils.tmpInsets = new Insets(5, 5, 5, 5);
      JComponent contents = GuiUtils.doLayout(comps, 3, GuiUtils.WT_NNY, GuiUtils.WT_N);

      contents = GuiUtils.topCenter(topPanel, contents);
      contents = GuiUtils.inset(contents, 5);
      while (true) {
        if (!GuiUtils.showOkCancelDialog(null, "Parameter Defaults", contents, null)) {
          if (removeOnCancel) {
            myParamInfos.remove(paramInfo);
            tableChanged();
          }
          return false;
        }
        String what = "";
        try {
          if (contourUseCbx.isSelected()) {
            what = "setting contour defaults";
            contDialog.doApply();
            ci.set(contDialog.getInfo());
            paramInfo.setContourInfo(ci);
          } else {
            paramInfo.clearContourInfo();
          }
          if (unitUseCbx.isSelected()) {
            what = "setting display unit";
            Object selected = unitFld.getSelectedItem();
            String unitName = TwoFacedObject.getIdString(selected);
            if ((unitName == null) || unitName.trim().equals("")) {
              paramInfo.setDisplayUnit(null);
            } else {
              paramInfo.setDisplayUnit(ucar.visad.Util.parseUnit(unitName));
            }
          } else {
            paramInfo.setDisplayUnit(null);
          }

          if (ctUseCbx.isSelected()) {
            paramInfo.setColorTableName(ctLbl.getText());
          } else {
            paramInfo.clearColorTableName();
          }

          if (rangeUseCbx.isSelected()) {
            what = "setting range";
            paramInfo.setRange(
                new Range(Misc.parseNumber(minFld.getText()), Misc.parseNumber(maxFld.getText())));
          } else {
            paramInfo.clearRange();
          }

          paramInfo.setName(nameFld.getText().trim());
          break;
        } catch (Exception exc) {
          errorMsg("An error occurred " + what + "\n " + exc.getMessage());
          //              exc.printStackTrace();
        }
      }
      repaint();
      saveData();
      return true;
    }
Пример #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;
  }
Пример #9
0
  /**
   * Return the list of {@link ucar.unidata.util.TwoFacedObject}s that make up the list of units.
   *
   * @return List of unit holding objects.
   */
  public List getDefaultUnitList() {
    synchronized (UNIT_MUTEX) {
      // TODO:
      if (unitList != null) {
        return unitList;
      }
      // First  check if we have one saved as a preference
      unitList = (List) getStore().get(PREF_UNITLIST);
      if (unitList == null) {
        unitList = new ArrayList();
        unitList.add(new TwoFacedObject("Default", null));
      }
      HashSet<String> seenName = new HashSet<String>();
      List tmp = new ArrayList();
      for (Object o : unitList) {
        String s = o.toString().toLowerCase();
        if (seenName.contains(s)) {
          continue;
        }
        if (tmp.contains(o)) {
          continue;
        }
        tmp.add(o);
        seenName.add(s);
      }
      unitList = tmp;

      String[] names = {
        // Temperature
        "Celsius",
        "Fahrenheit",
        "Kelvin",
        // Pressure
        "millibar",
        "hectoPascal",
        // Distance
        "m",
        "km",
        "miles",
        "feet",
        "inches",
        "cm",
        "mm",
        // speed
        "m/s",
        "mi/hr",
        "knot",
        "km/hr"
      };
      for (int i = 0; i < names.length; i++) {
        try {
          TwoFacedObject tfo = new TwoFacedObject(names[i], Util.parseUnit(names[i]));
          if (!unitList.contains(tfo) && !seenName.contains(tfo.toString().toLowerCase())) {
            unitList.add(tfo);
          }

        } catch (Exception exc) {
        }
      }

      return unitList;
    }
  }