예제 #1
0
  public void testVariableGe() {
    HashMap<String, CvValue> v = createCvMap();
    CvValue cv = new CvValue("81", p);
    cv.setValue(3);
    v.put("81", cv);
    // create a variable pointed at CV 81, check name
    VariableValue variable =
        makeVar(
            "label check",
            "comment",
            "",
            false,
            false,
            false,
            false,
            "81",
            "XXVVVVVV",
            0,
            255,
            v,
            null,
            "item check");

    // test "ge"
    ArithmeticQualifier aq = new TestArithmeticQualifier(variable, 10, "ge");
    Assert.assertEquals(false, aq.currentDesiredState());
    cv.setValue(10);
    Assert.assertEquals(true, aq.currentDesiredState());
    cv.setValue(20);
    Assert.assertEquals(true, aq.currentDesiredState());
    cv.setValue(5);
    Assert.assertEquals(false, aq.currentDesiredState());
  }
예제 #2
0
  public void actionPerformed(ActionEvent e) {
    // see if this is from _value itself, or from an alternate rep.
    // if from an alternate rep, it will contain the value to select
    if (log.isDebugEnabled()) {
      log.debug(label() + " start action event: " + e);
    }
    if (!(e.getActionCommand().equals(""))) {
      // is from alternate rep
      _value.setSelectedItem(e.getActionCommand());
      if (log.isDebugEnabled()) {
        log.debug(label() + " action event was from alternate rep");
      }
      // match and select in tree
      for (int i = 0; i < _valueArray.length; i++) {
        if (e.getActionCommand().toString().equals(_itemArray[i])) {
          // now select in the tree
          TreePath path = _pathArray[i];
          for (JTree tree : trees) {
            tree.setSelectionPath(path);
            // ensure selection is in visible portion of JScrollPane
            tree.scrollPathToVisible(path);
          }
          break; // first one is enough
        }
      }
    }

    int oldVal = getIntValue();

    // called for new values - set the CV as needed
    CvValue cv = _cvMap.get(getCvNum());
    // compute new cv value by combining old and request
    int oldCv = cv.getValue();
    int newVal = getIntValue();
    int newCv = newValue(oldCv, newVal, getMask());
    if (newCv != oldCv) {
      cv.setValue(newCv); // to prevent CV going EDITED during loading of decoder file

      // notify  (this used to be before setting the values)
      if (log.isDebugEnabled()) {
        log.debug(label() + " about to firePropertyChange");
      }
      prop.firePropertyChange("Value", null, Integer.valueOf(oldVal));
      if (log.isDebugEnabled()) {
        log.debug(label() + " returned to from firePropertyChange");
      }
    }
    if (log.isDebugEnabled()) {
      log.debug(
          label()
              + " end action event saw oldCv="
              + oldCv
              + " newVal="
              + newVal
              + " newCv="
              + newCv);
    }
  }
 // abstract members invoked by tests in parent VariableValueTest class
 VariableValue makeVar(
     String label,
     String comment,
     String cvName,
     boolean readOnly,
     boolean infoOnly,
     boolean writeOnly,
     boolean opsOnly,
     String cvNum,
     String mask,
     int minVal,
     int maxVal,
     HashMap<String, CvValue> v,
     JLabel status,
     String item) {
   // make sure next CV exists
   CvValue cvNext = new CvValue(cvNum + 1, p);
   cvNext.setValue(0);
   v.put(cvNum + 1, cvNext);
   return new CompositeVariableValue(
       label, comment, "", readOnly, infoOnly, writeOnly, opsOnly, cvNum, mask, minVal, maxVal, v,
       status, item);
 }
예제 #4
0
  void updatedTextField() {
    if (log.isDebugEnabled()) {
      log.debug(
          "CV " + getCvName() + "," + getSecondCvNum() + " enter updatedTextField in SplitVal");
    }
    // called for new values - set the CV as needed
    CvValue cv1 = _cvMap.get(getCvName());
    CvValue cv2 = _cvMap.get(mSecondCVname);

    int newEntry; // entered value
    try {
      newEntry = Integer.valueOf(_value.getText()).intValue();
    } catch (java.lang.NumberFormatException ex) {
      newEntry = 0;
    }

    // calculate resulting number
    int newVal = (newEntry - mOffset) / mFactor;

    // combine with existing values via mask
    if (log.isDebugEnabled()) {
      log.debug(
          "CV "
              + getCvName()
              + ","
              + getSecondCvNum()
              + " lo cv was "
              + cv1.getValue()
              + " mask="
              + lowerbitmask
              + " offset="
              + lowerbitoffset);
    }
    int newCv1 = ((newVal << lowerbitoffset) & lowerbitmask) | (~lowerbitmask & cv1.getValue());

    if (log.isDebugEnabled()) {
      log.debug(
          "CV "
              + getCvName()
              + ","
              + getSecondCvNum()
              + " hi cv was "
              + cv2.getValue()
              + " mask="
              + upperbitmask
              + " offset="
              + upperbitoffset);
    }
    int newCv2 =
        (((newVal << upperbitoffset) >> 8) & upperbitmask) | (~upperbitmask & cv2.getValue());
    if (log.isDebugEnabled()) {
      log.debug(
          "CV "
              + getCvName()
              + ","
              + getSecondCvNum()
              + " new value "
              + newVal
              + " gives first="
              + newCv1
              + " second="
              + newCv2);
    }

    // cv updates here trigger updated property changes, which means
    // we're going to get notified sooner or later.
    cv1.setValue(newCv1);
    cv2.setValue(newCv2);
    if (log.isDebugEnabled()) {
      log.debug("CV " + getCvName() + "," + getSecondCvNum() + " exit updatedTextField");
    }
  }
  // create and load the an object to test
  protected CompositeVariableValue createTestVar() {

    ProgDebugger p = new ProgDebugger();

    // create 3 CVs
    HashMap<String, CvValue> v = createCvMap();
    cv17 = new CvValue("17", p);
    cv18 = new CvValue("18", p);
    cv19 = new CvValue("19", p);
    cv17.setValue(2);
    cv18.setValue(3);
    cv18.setValue(4);
    v.put("17", cv17);
    v.put("18", cv18);
    v.put("19", cv19);

    // create variables for each CV
    var17 =
        new DecVariableValue(
            "label17",
            "comment17",
            "",
            false,
            false,
            false,
            false,
            "17",
            "VVVVVVVV",
            0,
            255,
            v,
            null,
            null);
    var18 =
        new DecVariableValue(
            "label18",
            "comment18",
            "",
            false,
            false,
            false,
            false,
            "18",
            "VVVVVVVV",
            0,
            255,
            v,
            null,
            null);
    var19 =
        new DecVariableValue(
            "label19",
            "comment19",
            "",
            false,
            false,
            false,
            false,
            "19",
            "VVVVVVVV",
            0,
            255,
            v,
            null,
            null);

    // create composite variable
    CompositeVariableValue testVar =
        new CompositeVariableValue(
            "testVariable",
            "commentTest",
            "",
            false,
            false,
            false,
            false,
            "17",
            "VVVVVVVV",
            0,
            2,
            v,
            null,
            null);

    // two choices
    testVar.addChoice("first");
    testVar.addSetting("first", "label17", var17, "11");
    testVar.addSetting("first", "label18", var18, "12");
    testVar.addSetting("first", "label19", var19, "13");

    testVar.addChoice("second");
    testVar.addSetting("second", "label17", var17, "21");
    testVar.addSetting("second", "label18", var18, "22");
    testVar.addSetting("second", "label19", var19, "23");

    testVar.addChoice("third");
    testVar.addSetting("third", "label17", var17, "123");
    testVar.addSetting("third", "label18", var18, "123");
    testVar.addSetting("third", "label19", var19, "123");

    testVar.lastItem();

    return testVar;
  }