示例#1
0
 /**
  * set the property
  *
  * @param tfo value_
  */
 public void setWidthFromComboBox(TwoFacedObject tfo) {
   double value = ((Double) tfo.getId()).doubleValue();
   if (value == 0.0) {
     return;
   }
   binWidthField.setTime(value);
   widthCbx.setSelectedIndex(0);
 }
示例#2
0
  /** _more_ */
  private void getSelectedTimes() {
    if (isHourly()) {
      Object[] selects = chartTimeBox.getSelectedValues();
      if (forecastHours == null) {
        forecastHours = new ArrayList();
      }
      for (int i = 0; i < selects.length; i++) {
        Object select = selects[i];
        TwoFacedObject tfo = (TwoFacedObject) select;
        Integer hour = (Integer) tfo.getId();
        forecastHours.add(hour);
      }

    } else {
      forecastTimes = (List<DateTime>) Misc.toList(chartTimeBox.getSelectedValues());
    }
  }
示例#3
0
    /**
     * Make the gui for the field selector
     *
     * @return gui for field selector
     */
    protected JComponent doMakeContents() {
      GuiUtils.tmpInsets = GuiUtils.INSETS_5;
      comp = GuiUtils.doLayout(comps, 2, GuiUtils.WT_N, GuiUtils.WT_N);
      if (dataSelection != null) {
        Object prop;
        prop = dataSelection.getProperty(PROP_GRID_X);
        if (prop != null) {
          gridXFld.setText("" + prop);
          // If we have a data selection property then turn of cbx
          useDefaultCbx.setSelected(false);
        }
        prop = dataSelection.getProperty(PROP_GRID_Y);
        if (prop != null) {
          gridYFld.setText("" + prop);
        }

        prop = dataSelection.getProperty(PROP_GRID_UNIT);
        if (prop != null) {
          gridUnitCmbx.setSelectedItem(TwoFacedObject.findId(prop, tfos));
        }
        prop = dataSelection.getProperty(PROP_GRID_NUMPASSES);
        if (prop != null) {
          numGridPassesFld.setText("" + prop);
        }
        prop = dataSelection.getProperty(PROP_GRID_GAIN);
        if (prop != null) {
          gainComp.setValue(((Number) prop).floatValue());
        }
        prop = dataSelection.getProperty(PROP_GRID_SEARCH_RADIUS);
        if (prop != null) {
          searchComp.setValue(((Number) prop).floatValue());
        }
      }

      checkEnable();
      return GuiUtils.topCenter(GuiUtils.right(useDefaultCbx), GuiUtils.topLeft(comp));
    }
示例#4
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;
 }
示例#5
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;
    }
示例#6
0
  /** _more_ */
  protected void updateChart() {

    try {
      if (!madeChart) {
        createChart();
      }
      ignoreChartTimeChanges = true;

      if (isHourly()) {
        List<Integer> fHours = findForecastHours();
        List<TwoFacedObject> tfos = new ArrayList<TwoFacedObject>();
        for (Integer i : fHours) {
          tfos.add(new TwoFacedObject(i + "H", i));
        }

        Object[] selected = chartTimeBox.getSelectedValues();
        chartTimeBox.setListData(new Vector(tfos));
        GuiUtils.setSelectedItems(chartTimeBox, Misc.toList(selected));

        if ((selected == null) && (tfos.size() > 0)) {
          TwoFacedObject selected0 = tfos.get(0);
          forecastHours.add((Integer) selected0.getId());
        }

        // chartTimeBox.setSelectedItem(selected);
      } else {
        List<DateTime> fTimes = findForecastTimes();

        Object[] selected = chartTimeBox.getSelectedValues();

        chartTimeBox.setListData(new Vector(fTimes));
        GuiUtils.setSelectedItems(chartTimeBox, Misc.toList(selected));

        if ((selected == null) && (fTimes.size() > 0)) {
          DateTime dt0 = fTimes.get(0);
          forecastTimes.add(dt0);
        }

        // chartTimeBox.setSelectedItem(forecastTime);
      }
      ignoreChartTimeChanges = false;
      getSelectedTimes();
      chartTimeBox.repaint();
      Hashtable<Way, List> wayToTracks = new Hashtable<Way, List>();
      for (Way way : chartWays) {
        wayToTracks.put(way, new ArrayList<Way>());
      }

      List<StormTrack> tracksToUse = new ArrayList<StormTrack>();
      for (StormTrack track : stormDisplayState.getTrackCollection().getTracks()) {
        List trackList = wayToTracks.get(track.getWay());
        if (trackList == null) {
          continue;
        }
        if (track.getWay().isObservation()) {
          tracksToUse.add(track);
        } else {
          trackList.add(track);
        }
      }

      StormTrack obsTrack = stormDisplayState.getTrackCollection().getObsTrack();

      if (isHourly()) {
        for (Way way : chartWays) {
          List<StormTrack> tracksFromWay = wayToTracks.get(way);

          for (Integer fHour : forecastHours) {
            List<StormTrackPoint> points = new ArrayList<StormTrackPoint>();
            for (StormTrack track : tracksFromWay) {
              StormTrackPoint stp = track.findPointWithForecastHour(fHour.intValue());
              if (stp != null) {
                // TODO: What time do we use???
                points.add(stp);
              }
            }
            if (points.size() > 0) {
              points = (List<StormTrackPoint>) Misc.sort(points);
              tracksToUse.add(new StormTrack(stormDisplayState.getStormInfo(), way, points, null));
            }
          }
        }

      } else {
        for (Way way : chartWays) {
          List<StormTrack> tracksFromWay = wayToTracks.get(way);
          for (StormTrack track : tracksFromWay) {
            for (DateTime fTime : forecastTimes) {
              if (Misc.equals(fTime, track.getStartTime())) {
                tracksToUse.add(track);
              }
            }
          }
        }
      }

      List<LineState> lines = new ArrayList<LineState>();

      for (StormParam param : chartParams) {
        Hashtable seenWays = new Hashtable();
        List<LineState> linesForParam = new ArrayList<LineState>();
        for (StormTrack track : tracksToUse) {
          LineState lineState = null;
          if (chartDifference && param.getCanDoDifference()) {
            if (track.getWay().isObservation()) {
              continue;
            }
            track = StormDataSource.difference(obsTrack, track, param);
            if (track != null) {
              lineState = makeLine(track, param);
            }
          } else {
            lineState = makeLine(track, param);
          }
          if (lineState == null) {
            continue;
          }
          // Only add it if there are values
          if (lineState.getRange().getMin() == lineState.getRange().getMin()) {
            if (seenWays.get(track.getWay()) != null) {
              lineState.setVisibleInLegend(false);
            } else {
              seenWays.put(track.getWay(), "");
            }

            linesForParam.add(lineState);
          }
        }
        double max = Double.NEGATIVE_INFINITY;
        double min = Double.POSITIVE_INFINITY;
        ;
        for (LineState lineState : linesForParam) {
          Range r = lineState.getRange();
          min = Math.min(min, r.getMin());
          max = Math.max(max, r.getMax());
        }
        //                System.err.println(param + " min/max:" + min + "/" + max);
        boolean first = true;
        for (LineState lineState : linesForParam) {
          lineState.setAxisVisible(first);
          first = false;
          lineState.setRange(new Range(min, max));
        }
        lines.addAll(linesForParam);
      }
      getChart().setTracks(lines);
    } catch (Exception exc) {
      stormDisplayState.getStormTrackControl().logException("Updating chart", exc);
    }
  }
示例#7
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;
    }
  }
示例#8
0
 /**
  * get grid unit
  *
  * @return grid unit
  */
 public String getGridUnit() {
   return (String) TwoFacedObject.getIdString(gridUnitCmbx.getSelectedItem());
 }
示例#9
0
 /**
  * ctor
  *
  * @param pointDataSource the associated data source
  */
 public GridParameters(PointDataSource pointDataSource) {
   super("Grid Parameters");
   this.pointDataSource = pointDataSource;
   gridXFld = new JTextField("" + pointDataSource.gridX, 4);
   gridXFld.setToolTipText("X spacing in spacing units");
   gridYFld = new JTextField("" + pointDataSource.gridY, 4);
   gridYFld.setToolTipText("Y spacing in spacing units");
   gridUnitCmbx = new JComboBox();
   gridUnitCmbx.setToolTipText("Set grid spacing option");
   tfos = TwoFacedObject.createList(SPACING_IDS, SPACING_NAMES);
   GuiUtils.setListData(gridUnitCmbx, tfos);
   gridUnitCmbx.setSelectedItem(TwoFacedObject.findId(pointDataSource.gridUnit, tfos));
   gridUnitCmbx.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent ae) {
           TwoFacedObject tfo = (TwoFacedObject) ((JComboBox) ae.getSource()).getSelectedItem();
           if (tfo != null) {
             useCompute = tfo.getId().equals(SPACING_IDS[0]);
             enableAutoComps(!useCompute);
           }
         }
       });
   gainComp =
       new ValueSliderComponent(
           pointDataSource,
           0,
           1,
           "gridGain",
           "Gain",
           10,
           false,
           "Factor by which scaleLength is reduced for the second pass");
   searchComp =
       new ValueSliderComponent(
           pointDataSource,
           0,
           20,
           "gridSearchRadius",
           "Search Radius",
           1,
           false,
           "Search radius in grid units for weighting");
   numGridPassesFld = new JTextField("" + pointDataSource.numGridPasses, 4);
   numGridPassesFld.setToolTipText("Set the number of passes for the Barnes analysis");
   comps.add(GuiUtils.rLabel("Spacing:"));
   comps.add(GuiUtils.left(gridUnitCmbx));
   comps.add(GuiUtils.rLabel("Grid Size:"));
   sizeComp =
       GuiUtils.left(GuiUtils.hbox(new JLabel("X: "), gridXFld, new JLabel("  Y: "), gridYFld));
   comps.add(sizeComp);
   comps.add(GuiUtils.rLabel("Passes:"));
   comps.add(GuiUtils.left(numGridPassesFld));
   comps.add(GuiUtils.rLabel("Search Radius:"));
   comps.add(GuiUtils.left(searchComp.getContents(false)));
   comps.add(GuiUtils.rLabel("Gain:"));
   comps.add(GuiUtils.left(gainComp.getContents(false)));
   enableAutoComps(!useCompute);
   useDefaultCbx.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent ae) {
           checkEnable();
         }
       });
 }