Пример #1
0
 /**
  * Set up the default screen control for this field.
  *
  * @param itsLocation Location of this component on screen (ie., GridBagConstraint).
  * @param targetScreen Where to place this component (ie., Parent screen or GridBagLayout).
  * @param converter The converter to set the screenfield to.
  * @param iDisplayFieldDesc Display the label? (optional).
  * @param properties Extra properties
  * @return Return the component or ScreenField that is created for this field.
  */
 public ScreenComponent setupDefaultView(
     ScreenLoc itsLocation,
     ComponentParent targetScreen,
     Convert converter,
     int iDisplayFieldDesc,
     Map<String, Object> properties) {
   converter = new FieldLengthConverter((Converter) converter, 25);
   if (m_recSpecialFunction == null) {
     m_recSpecialFunction = new SpecialFunction(this.getRecord().findRecordOwner());
     if (m_recSpecialFunction.getRecordOwner() != null)
       m_recSpecialFunction.getRecordOwner().removeRecord(m_recSpecialFunction);
   }
   FieldConverter convert =
       new QueryConverter((Converter) converter, m_recSpecialFunction, SpecialFunction.NAME, true);
   return createScreenComponent(
       ScreenModel.COMBO_BOX, itsLocation, targetScreen, convert, iDisplayFieldDesc, properties);
 }
Пример #2
0
  /**
   * Parse a double value
   *
   * @param d double to parse
   * @param n number of significant figures
   * @param p precision of the number
   * @param f format of the number scientific, algebraic etc. return <i>true</i> if the parse was
   *     successful
   */
  public boolean parseDouble(double d, int n, int p, int f) {
    double x = d;
    int left = n - p;
    double right = 0;
    int power;
    int exponent;
    int i;
    StringBuffer s = new StringBuffer(n + 4);

    if (left < 0) {
      System.out.println("TextLine.parseDouble: Precision > significant figures!");
      return false;
    }

    if (d < 0.0) {
      x = -d;
      s.append("-");
    }

    // System.out.println("parseDouble: value = "+x);

    if (d == 0.0) exponent = 0;
    else exponent = (int) (Math.floor(SpecialFunction.log10(x)));

    // System.out.println("parseDouble: exponent = "+exponent);

    power = exponent - (left - 1);

    // System.out.println("parseDouble: power = "+power);

    if (power < 0) {
      for (i = power; i < 0; i++) {
        x *= 10.0;
      }
    } else {
      for (i = 0; i < power; i++) {
        x /= 10.0;
      }
    }

    // System.out.println("parseDouble: adjusted value = "+x);

    left = (int) x;
    s.append(left);

    // System.out.println("parseDouble: left = "+left);

    if (p > 0) {
      s.append('.');
      right = x - left;
      for (i = 0; i < p; i++) {
        right *= 10;
        if (i == p - 1) right += 0.5;
        s.append((int) (right));
        right -= (int) right;
      }
    }

    // System.out.println("parseDouble: right = "+right);

    if (power != 0) {
      if (f == SCIENTIFIC) {
        s.append('E');
        if (power < 0) s.append('-');
        else s.append('+');
        power = Math.abs(power);
        if (power > 9) {
          s.append(power);
        } else {
          s.append('0');
          s.append(power);
        }
      } else {
        s.append("x10{^");
        s.append(power);
        s.append("}");
      }
    }

    setText(s.toString());

    return true;
  }