Beispiel #1
0
 /**
  * Create xml dom from the given list of {@link ucar.unidata.idv.ui.ParamInfo}-s
  *
  * @param doc The document to write to
  * @param paramInfos List of param infos
  * @return Root xml element
  */
 private Element createDom(Document doc, List paramInfos) {
   Element root = doc.createElement(TAG_PARAMS);
   for (int i = 0; i < paramInfos.size(); i++) {
     ParamInfo paramInfo = (ParamInfo) paramInfos.get(i);
     if (paramInfo.getName().trim().length() == 0) {
       continue;
     }
     Element node = doc.createElement(TAG_PARAM);
     node.setAttribute(ATTR_NAME, paramInfo.getName());
     if (paramInfo.hasColorTableName()) {
       node.setAttribute(ATTR_COLORTABLE, paramInfo.getColorTableName());
     }
     if (paramInfo.hasRange()) {
       node.setAttribute(ATTR_RANGE_MIN, "" + paramInfo.getRange().getMin());
       node.setAttribute(ATTR_RANGE_MAX, "" + paramInfo.getRange().getMax());
     }
     if (paramInfo.hasDisplayUnit()) {
       node.setAttribute(ATTR_UNIT, "" + paramInfo.getDisplayUnit());
     }
     if (paramInfo.hasContourInfo()) {
       ContourInfo ci = paramInfo.getContourInfo();
       node.setAttribute(ATTR_CI_INTERVAL, "" + ci.getIntervalString(true));
       node.setAttribute(ATTR_CI_BASE, "" + ci.getBase());
       node.setAttribute(ATTR_CI_MIN, "" + ci.getMin());
       node.setAttribute(ATTR_CI_MAX, "" + ci.getMax());
       if (ci.getDashOn() != DFLT_CI_DASH) {
         node.setAttribute(ATTR_CI_DASH, "" + ci.getDashOn());
       }
       if (ci.getIsLabeled() != DFLT_CI_LABEL) {
         node.setAttribute(ATTR_CI_LABEL, "" + ci.getIsLabeled());
       }
       node.setAttribute(ATTR_CI_WIDTH, "" + ci.getLineWidth());
     }
     root.appendChild(node);
   }
   return root;
 }
Beispiel #2
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;
    }
Beispiel #3
0
 /**
  * Returns a ContourInfo based on the parameter name (e.g., rh, t, etc.)
  *
  * @param paramName Name to look for
  * @return The {@link ucar.unidata.util.ContourInfo} found or null
  */
 public ContourInfo getParamContourInfo(String paramName) {
   ParamInfo paramInfo = getParamInfo(paramName);
   return ((paramInfo != null) ? paramInfo.getContourInfo() : null);
 }