private void populateUnitCombo() {

    if (comboWidthUnits.getItemCount() != 0) {
      return; // this collection is inmutable, only populates the first
      // time
    }

    final Unit<?> defaultUnit = Preferences.bufferUnits();
    final Set<Unit<?>> commonLengthUnits = UnitList.getCommonLengthUnits();

    SortedMap<String, Unit<?>> units = new TreeMap<String, Unit<?>>();
    for (Unit<?> unit : commonLengthUnits) {
      units.put(UnitList.getUnitName(unit), unit);
    }

    bufferUnits = new ArrayList<Unit<?>>(units.values());

    int index = 0;
    Set<Entry<String, Unit<?>>> unitset = units.entrySet();
    for (Entry<String, Unit<?>> entry : unitset) {

      String unitName = entry.getKey();
      comboWidthUnits.add(unitName, index);
      if (defaultUnit.equals(units.get(unitName))) {
        comboWidthUnits.select(index);
      }
      index++;
    }
  }
Пример #2
0
  public FXMesureAreaHandler() {
    super();
    uiArea.setMaxHeight(Double.MAX_VALUE);
    uiUnit.setItems(FXCollections.observableArrayList(Unit.valueOf("km2"), SI.SQUARE_METRE));
    uiUnit.getSelectionModel().selectFirst();

    pane.setAlignment(Pos.CENTER);
    pane.setBackground(
        new Background(new BackgroundFill(Color.WHITE, new CornerRadii(10), Insets.EMPTY)));
    pane.setPadding(new Insets(10, 10, 10, 10));
    deco.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
    deco.getColumnConstraints()
        .add(
            new ColumnConstraints(
                0, HBox.USE_COMPUTED_SIZE, Double.MAX_VALUE, Priority.ALWAYS, HPos.CENTER, true));
    deco.getColumnConstraints()
        .add(
            new ColumnConstraints(
                0, HBox.USE_COMPUTED_SIZE, Double.MAX_VALUE, Priority.NEVER, HPos.CENTER, true));
    deco.getColumnConstraints()
        .add(
            new ColumnConstraints(
                0, HBox.USE_COMPUTED_SIZE, Double.MAX_VALUE, Priority.ALWAYS, HPos.CENTER, true));

    uiUnit
        .valueProperty()
        .addListener(
            (ObservableValue<? extends Unit> observable, Unit oldValue, Unit newValue) -> {
              updateGeometry();
            });

    deco.add(pane, 1, 0);
  }
  /**
   * Convert the value from a source unit to a target unit Note: if the value is an age, the method
   * adjusts the value to return the right age
   *
   * @param activeInstrumentRunService
   * @param targetInstrumentRunValue
   * @param sourceInstrumentRunValue
   */
  @SuppressWarnings("unchecked")
  public void convert(
      ActiveInstrumentRunService activeInstrumentRunService,
      InstrumentRunValue targetInstrumentRunValue,
      InstrumentRunValue sourceInstrumentRunValue) {

    InstrumentParameter sourceParameter =
        activeInstrumentRunService
            .getInstrumentType()
            .getInstrumentParameter(sourceInstrumentRunValue.getInstrumentParameter());
    InstrumentParameter targetParameter =
        activeInstrumentRunService
            .getInstrumentType()
            .getInstrumentParameter(targetInstrumentRunValue.getInstrumentParameter());

    log.debug(
        "Converting parameters from source {} to target {}", sourceParameter, targetParameter);

    Unit sourceUnit = Unit.valueOf(sourceParameter.getMeasurementUnit());
    Unit targetUnit = Unit.valueOf(targetParameter.getMeasurementUnit());

    log.debug(
        "Converting units from source {} to target {}",
        sourceUnit.toString(),
        targetUnit.toString());

    double sourceValue;
    // Extract the source value and convert it to a double
    try {
      sourceValue =
          Double.parseDouble(
              sourceInstrumentRunValue.getData(sourceParameter.getDataType()).getValueAsString());
    } catch (NumberFormatException e) {
      Data sourceData = sourceInstrumentRunValue.getData(sourceParameter.getDataType());
      log.error(
          "Error converting between measurement units. Original value {} of type {} cannot be converted to a double, which is required to convert between measurement units.",
          sourceData.getValueAsString(),
          sourceData.getType());
      throw e;
    }

    double newValue = sourceUnit.getConverterTo(targetUnit).convert(sourceValue);

    switch (activeInstrumentRunService
        .getInstrumentType()
        .getInstrumentParameter(targetInstrumentRunValue.getInstrumentParameter())
        .getDataType()) {
      case DECIMAL:
        targetInstrumentRunValue.setData(DataBuilder.buildDecimal(newValue));
        break;

      case INTEGER:
        if (targetUnit.toString().equalsIgnoreCase("year")) newValue = Math.floor(newValue);
        targetInstrumentRunValue.setData(DataBuilder.buildInteger(Math.round(newValue)));
        break;
    }
  }
Пример #4
0
 static {
   productMap = new HashMap<String, HDF4ProductFieldType.Product>();
   // TODO add more products
   productMap.put(
       "mcsst", new HDF4ProductFieldType.Product("mcsst", SI.CELSIUS, "sea surface temperature"));
   productMap.put(
       "sst", new HDF4ProductFieldType.Product("sst", SI.CELSIUS, "sea surface temperature"));
   productMap.put("sst4", new HDF4ProductFieldType.Product("sst4", SI.CELSIUS, "temperature"));
   productMap.put("lowcloud", new HDF4ProductFieldType.Product("lowcloud", Unit.ONE, "lowcloud"));
   productMap.put(
       "K_490", new HDF4ProductFieldType.Product("K_490", Unit.valueOf("m^-1"), "k_490"));
 }
Пример #5
0
  /**
   * @param bufferWidth
   * @param bufferUnits
   * @param geometryUnits
   * @return the converted distance <code>bufferWidth</code> from <code>targetUnits</code> to <code>
   *     sourceUnits</code>
   */
  private double getBufferWidth(double bufferWidth, Unit sourceUnits, Unit targetUnits) {
    assert sourceUnits != null;
    assert targetUnits != null;

    double convertedWidth;
    if (GeoToolsUtils.PIXEL_UNITS.equals(targetUnits)) {

      IViewportModel viewportModel = this.sourceLayer.getMap().getViewportModel();
      Coordinate origin = viewportModel.pixelToWorld(0, 0);
      int fixedBufferWidth = (int) Math.round(bufferWidth);
      Coordinate originPlusWidth = viewportModel.pixelToWorld(fixedBufferWidth, fixedBufferWidth);
      convertedWidth = Math.abs(originPlusWidth.x - origin.x);
    } else {
      UnitConverter converter = targetUnits.getConverterTo(sourceUnits);
      convertedWidth = converter.convert(bufferWidth);
    }
    return convertedWidth;
  }
Пример #6
0
 @Override
 public Measure<String, Q> to(Unit<Q> unit) {
   if ((unit == this.unit) || (unit.equals(this.unit))) return this;
   return new KnittingMeasure<Q>(stringValue(unit), unit);
 }
Пример #7
0
 @Override
 public double doubleValue(Unit<Q> unit) {
   if ((unit == this.unit) || (unit.equals(this.unit))) return stringToDouble(this.value);
   return this.unit.getConverterTo(unit).convert(stringToDouble(this.value));
 }
  /**
   * Creates the needed JEVis structure
   *
   * @param buildingId building node id, where the structure has to be created
   *     <p>TODO Enable mysql server TODO Add units
   */
  public void createStructure(long buildingId) {

    ObjectAndBoolean dsd =
        createObjectCheckNameExistance(
            buildingId, "Data Source Directory", "Data Source Directory");

    ObjectAndBoolean mysqlServer =
        createObjectCheckNameExistance(
            dsd.getJEVisObject().getID(), "MySQL Server", "MySQL Server");

    if (mysqlServer.isNew) {
      long id = mysqlServer.getJEVisObject().getID();
      writeToJEVis(id, "Schema", _schema);
      writeToJEVis(id, "User", _dbUser);
      writeToJEVis(id, "Port", _port);
      writeToJEVis(id, "Host", _host);
      writeToJEVis(id, "Password", _dbPW);
      writeToJEVis(id, "Enabled", true);
    }

    ObjectAndBoolean dataDirectory =
        createObjectCheckNameExistance(buildingId, "Data Directory", "Data Directory");

    for (Sensor sensor : _result) {
      ObjectAndBoolean sqlChannelDir =
          createObjectCheckNameExistance(
              mysqlServer.getJEVisObject().getID(),
              "SQL Channel Directory",
              sensor.getName() + "_" + sensor.getSymbol());
      ObjectAndBoolean channel =
          createObjectCheckNameExistance(
              sqlChannelDir.getJEVisObject().getID(), "SQL Channel", "SQL Channel");
      if (channel.isNew) {
        long id = channel.getJEVisObject().getID();

        writeToJEVis(id, "Column Timestamp", "time");
        writeToJEVis(id, "Column Value", "value");
        writeToJEVis(id, "Table", sensor.getTable());
        writeToJEVis(id, "Timestamp Format", "yyyy-MM-dd HH:mm:ss.s");
      }

      ObjectAndBoolean sqlDPD =
          createObjectCheckNameExistance(
              channel.getJEVisObject().getID(), "SQL Data Point Directory", "DPD");
      ObjectAndBoolean sqlDP =
          createObjectCheckNameExistance(sqlDPD.getJEVisObject().getID(), "SQL Data Point", "DP");
      ObjectAndBoolean device =
          createObjectCheckNameExistance(
              dataDirectory.getJEVisObject().getID(), "Device", sensor.getName());
      if (device.isNew) {
        long id = device.getJEVisObject().getID();
        writeToJEVis(id, "MAC", sensor.getName());
      }
      ObjectAndBoolean data =
          createObjectCheckNameExistance(
              device.getJEVisObject().getID(), "Data", sensor.getSymbol());

      try {
        JEVisAttribute attributeValue = data.getJEVisObject().getAttribute("Value");
        attributeValue.setDisplayUnit(
            new JEVisUnitImp(Unit.valueOf(sensor.getUnit()), "", JEVisUnit.Prefix.NONE));
        attributeValue.setInputUnit(
            new JEVisUnitImp(Unit.valueOf(sensor.getUnit()), "", JEVisUnit.Prefix.NONE));
        attributeValue.commit();
      } catch (JEVisException ex) {
        Logger.getLogger(WiotechStructureCreator.class.getName()).log(Level.SEVERE, null, ex);
      }

      if (data.isNew) {
        writeToJEVis(
            sqlDP.getJEVisObject().getID(), "Target", data.getJEVisObject().getID().toString());
      }
    }
  }