示例#1
0
  /**
   * Set the sounding in the table
   *
   * @param sounding the sounding
   * @throws RemoteException Java RMI problem
   * @throws VisADException problem dissecting data
   */
  private void setupTable(Field sounding) throws VisADException, RemoteException {

    Set domain = sounding.getDomainSet();
    CoordinateSystem cs = domain.getCoordinateSystem();

    numDomainCols = domain.getDimension();
    if (cs != null) {
      numDomainCols++;
    }
    RealType[] rangeComps = ((FunctionType) sounding.getType()).getRealComponents();
    numRangeCols = rangeComps.length;
    columnNames = new String[numDomainCols + numRangeCols];

    SetType t = (SetType) domain.getType();
    Unit[] units = domain.getSetUnits();
    RealTupleType rtt = t.getDomain();
    RealType[] comps = rtt.getRealComponents();
    columnNames[0] = makeColumnName(comps[0], units[0]);
    if ((cs != null)) {
      RealTupleType refType = cs.getReference();
      RealType[] refComps = refType.getRealComponents();
      Unit[] refUnits = cs.getReferenceUnits();
      columnNames[1] = makeColumnName(refComps[0], refUnits[0]);
    }

    // set for default
    for (int i = 0; i < rangeComps.length; i++) {
      columnNames[numDomainCols + i] =
          makeColumnName(rangeComps[i], rangeComps[i].getDefaultUnit());
    }
    // wind
    if (rangeComps.length > 2) {
      csUnits = new Unit[] {rangeComps[2].getDefaultUnit(), rangeComps[3].getDefaultUnit()};
      haveUV =
          (Unit.canConvert(csUnits[0], CommonUnit.meterPerSecond)
              && Unit.canConvert(csUnits[1], CommonUnit.meterPerSecond));
      if (haveUV) {
        windTransform =
            new InverseCoordinateSystem(
                new RealTupleType(Speed.getRealType(), Direction.getRealType()),
                new PolarHorizontalWind.PolarCoordinateSystem(
                    new RealTupleType(rangeComps[2], rangeComps[3]),
                    CommonUnit.meterPerSecond,
                    CommonUnit.degree));
      } else {
        windTransform = new PolarHorizontalWind.PolarCoordinateSystem(csUnits[0], csUnits[1]);
      }
    }
    if (model == null) {
      model = new SoundingTableModel();
      sorter = new TableSorter(model);
      JTableHeader header = getTableHeader();
      header.setToolTipText("Click to sort");
      sorter.setTableHeader(getTableHeader());
      setModel(sorter);
      setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
      setPreferredScrollableViewportSize(new Dimension(400, 200));
      getTableHeader().setReorderingAllowed(false);
    }
  }
示例#2
0
  /**
   * Set the sounding in the table
   *
   * @param sounding the sounding
   * @throws RemoteException Java RMI problem
   * @throws VisADException problem dissecting data
   */
  private void setSounding(Field sounding) throws VisADException, RemoteException {
    domainData = null;

    // domain values
    Set domain = sounding.getDomainSet();
    CoordinateSystem cs = domain.getCoordinateSystem();

    float[][] domSamples = domain.getSamples(false);
    if ((cs != null)) {
      float[][] domFloats = Set.copyFloats(domSamples);
      // Must convert from the default coordinate domain system to
      // the domain coordinate system of the sounding.
      String fromUnit = sounding.getDomainUnits()[0].toString();
      String toUnit = cs.getCoordinateSystemUnits()[0].toString();
      if (!fromUnit.equals(toUnit) && SimpleUnit.isCompatible(fromUnit, toUnit)) {
        float conversionFactor = (float) SimpleUnit.getConversionFactor(fromUnit, toUnit);
        for (int i = 0; i < domFloats.length; i++) {
          for (int j = 0; j < domFloats[i].length; j++) {
            domFloats[i][j] = domFloats[i][j] * conversionFactor;
          }
        }
      }
      float[][] refData = cs.toReference(domFloats);
      domainData = new float[][] {domSamples[0], refData[0]};
    }
    // range values
    RealType[] rangeComps = ((FunctionType) sounding.getType()).getRealComponents();
    rangeData = sounding.getFloats(false);

    // wind
    if (rangeComps.length > 2) {
      transformWinds = (showUAndV && !haveUV) || (!showUAndV && haveUV);
      if (!transformWinds) {
        for (int i = 2; i < 4; i++) {
          columnNames[numDomainCols + i] =
              makeColumnName(rangeComps[i], rangeComps[i].getDefaultUnit());
        }
      } else {
        RealTupleType refType = windTransform.getReference();
        Unit[] refUnits = windTransform.getReferenceUnits();
        for (int i = 0; i < 2; i++) {
          columnNames[numDomainCols + i + 2] =
              makeColumnName((RealType) refType.getComponent(i), refUnits[i]);
        }
        float[][] newVals =
            windTransform.toReference(Set.copyFloats(new float[][] {rangeData[2], rangeData[3]}));
        rangeData[2] = newVals[0];
        rangeData[3] = newVals[1];
      }
    }
    sorter.setTableModel(model);
  }