Ejemplo n.º 1
0
 /**
  * Find the ParamInfo from the name
  *
  * @param name name
  * @return param info
  */
 public ParamInfo findByName(String name) {
   name = name.trim();
   for (int i = 0; i < myParamInfos.size(); i++) {
     ParamInfo paramInfo = (ParamInfo) myParamInfos.get(i);
     if (paramInfo.getName().equals(name)) {
       return paramInfo;
     }
   }
   return null;
 }
Ejemplo n.º 2
0
 /**
  * Get the list of resources
  *
  * @return the list of resources
  */
 public List getResources() {
   List infos = new ArrayList();
   for (int i = 0; i < myTables.size(); i++) {
     ParamDefaultsTable paramDefaultsTable = (ParamDefaultsTable) myTables.get(i);
     for (ParamInfo paramInfo : (List<ParamInfo>) paramDefaultsTable.getParamInfoList()) {
       infos.add(
           new ResourceViewer.ResourceWrapper(
               paramInfo,
               paramInfo.toString(),
               paramDefaultsTable.label,
               paramDefaultsTable.isEditable));
     }
   }
   return infos;
 }
Ejemplo n.º 3
0
 public void setEditMode(boolean s) {
   if (!s) pane.setEditMode(s);
   else {
     int edits = ParamInfo.getEditItems();
     if ((edits & ParamInfo.TOOLPANELS) > 0) pane.setEditMode(true);
     else pane.setEditMode(false);
   }
 }
Ejemplo n.º 4
0
  public VTabbedToolPanel(SessionShare sshare, AppIF appIF) {
    // super( new BorderLayout() );
    this.sshare = sshare;
    this.appIF = appIF;
    this.tabbedToolPanel = new JPanel();
    this.pinPanel = this;
    this.selectedTabName = null;
    setPinObj(this.tabbedToolPanel);
    this.tabbedToolPanel.setLayout(new BorderLayout());
    this.tabbedPane = new JTabbedPane();
    panelName = "Tab Panel";
    setTitle(panelName);
    setName(panelName);

    tabbedPane.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            tabChanged();
            /**
             * ** the following was moved to tabChanged() if(tabbedPane.getTabCount() > 1 &&
             * Util.getRQPanel() != null) { int ind = tabbedPane.getSelectedIndex(); if(ind >= 0 &&
             * ind < tabbedPane.getTabCount())
             * Util.getRQPanel().updatePopup(tabbedPane.getTitleAt(ind)); } *********
             */
          }
        });

    // Add Mouse Listener for CSH
    MouseAdapter ml = new CSHMouseAdapter();
    tabbedPane.addMouseListener(ml);

    Object obj = sshare.userInfo().get("canvasnum");
    if (obj != null) {
      Dimension dim = (Dimension) obj;
      nviews = (dim.height) * (dim.width);
    } else nviews = 1;

    for (int i = 0; i < nviews; i++) tp_paneInfo[i] = new Hashtable();

    /*
    obj = sshare.userInfo().get("activeWin");
    if(obj != null) {
               vpId = ((Integer)obj).intValue();
    } else vpId = 0;
            */

    // System.out.println("VToolPanel nviews vpId "+nviews+" "+vpId);

    fillHashtable();
    Util.setVTabbedToolPanel(this);
    ParamInfo.addEditListener(this);
  }
Ejemplo n.º 5
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);
   }
 }
Ejemplo n.º 6
0
  /**
   * Create the param infos from the given xml root
   *
   * @param root The xml root
   * @param overwriteOk Ok to overwrite an existing one
   */
  private void loadParamDefaults(Element root, boolean overwriteOk) {
    List listOfInfos = createParamInfoList(root);
    for (int i = 0; i < listOfInfos.size(); i++) {
      ParamInfo newParamInfo = (ParamInfo) listOfInfos.get(i);
      String paramName = newParamInfo.getName();
      if (!overwriteOk && (paramToInfo.get(paramName) != null)) {
        continue;
      }

      ParamInfo oldParamInfo = (ParamInfo) paramToInfo.get(paramName);
      if (oldParamInfo == null) {
        paramToInfo.put(paramName, newParamInfo);
        paramInfos.add(newParamInfo);
      } else {
        if (!oldParamInfo.hasColorTableName()) {
          oldParamInfo.setColorTableName(newParamInfo.getColorTableName());
        }
        if (!oldParamInfo.hasRange()) {
          oldParamInfo.setRange(newParamInfo.getRange());
        }
      }
    }
  }
Ejemplo n.º 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;
    }
Ejemplo n.º 8
0
 /**
  * Returns a Unit based on the parameter name (e.g., rh, t, etc.)
  *
  * @param paramName Name to look for
  * @return The Unit found or null
  */
 public Unit getParamDisplayUnit(String paramName) {
   ParamInfo paramInfo = getParamInfo(paramName);
   return ((paramInfo != null) ? paramInfo.getDisplayUnit() : null);
 }
Ejemplo n.º 9
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);
 }
Ejemplo n.º 10
0
 /**
  * Returns a Range based on the parameter name (e.g., rh, t, etc.)
  *
  * @param paramName Name to look for
  * @return The {@link ucar.unidata.util.Range} found or null
  */
 public Range getParamRange(String paramName) {
   ParamInfo paramInfo = getParamInfo(paramName);
   return ((paramInfo != null) ? paramInfo.getRange() : null);
 }
Ejemplo n.º 11
0
 /**
  * Get the color table for a particular parameter from ParamInfo
  *
  * @param info parameter information
  * @return the associated color table.
  */
 private ColorTable getColorTable(ParamInfo info) {
   if (info.getColorTableName() != null) {
     return getIdv().getColorTableManager().getColorTable(info.getColorTableName());
   }
   return null;
 }
Ejemplo n.º 12
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;
 }