Пример #1
0
  // TODO: moveInwardsBy() not implemented
  public void moveInwardsBy(float offset) {
    int type = this.getType();
    if (type == TYPE_SLOPED)
      // return;
      throw new RuntimeException("Cannot move a sloped egde inwards: " + this);

    float xOffset = 0;
    float yOffset = 0;

    ShapePoint middle = getMiddle();
    GeneralPath path = owner.makeIntoPath();
    if (type == TYPE_HORIZONTAL) {
      xOffset = 0;
      ShapePoint up = new ShapePoint(middle.x, middle.y - 0.05f);
      ShapePoint down = new ShapePoint(middle.x, middle.y + 0.05f);
      if (path.contains(up)) yOffset = -offset;
      else if (path.contains(down)) yOffset = offset;
    } else if (type == TYPE_VERTICAL) {
      yOffset = 0;
      ShapePoint left = new ShapePoint(middle.x - 0.05f, middle.y);
      ShapePoint right = new ShapePoint(middle.x + 0.05f, middle.y);
      if (path.contains(left)) xOffset = -offset;
      else if (path.contains(right)) xOffset = offset;
    }
    if (DEBUG) System.out.println("Moved edge " + this + " by " + xOffset + ", " + yOffset);
    translate(xOffset, yOffset);
  }
Пример #2
0
  public void editingStopped(ChangeEvent e) {

    System.out.println("_p = " + _p + " Name: " + oldpValue); // new undoredo

    if (_valueType.equals(TYPE_PRIMITIVE)) {
      try {
        String type = _p.getType();
        // The array of parameter of the constructor, here is the class
        // is String
        Class[] para = new Class[1];
        para[0] = Class.forName("java.lang.String");
        // get the constructor of the class "type"
        Constructor c = Class.forName(type).getConstructor(para);
        // get the argument of the constructor
        Object[] argu = new Object[1];
        argu[0] = _tField.getText();
        // use the constructor to new an instance
        Object o = c.newInstance(argu);

        // store the old value
        undoCommand = new UndoCommand(_p, oldpValue, o); // new
        // UndoCommand
        undoList.add(undoCommand); // new
        oldpValue = o; // new

        _p.setValue(o);

        DiagramShape.getDiagram().repaint(); // new

      } catch (Exception ex) {
        System.out.println("CEditor 1 -- " + ex);
      }
    } else if (_valueType.equals(TYPE_TRANSFORM)) {
    } else if (_valueType.equals(TYPE_DISTRIBUTION)) {

    } else if (_valueType.equals(TYPE_OBJECT_CREATOR)) {

    } else if (_valueType.equals(TYPE_ANIMATION)) {

    } else if (_valueType.equals(TYPE_SPLITTERMODEL)) {

    } else if (_valueType.equals(TYPE_MERGERMODEL)) {

    } else {
      String className = (_p.getValue().getClass().getName());
      String originalItem = className.substring((className.lastIndexOf(".") + 1));

      boolean found = false;
      String type = _p.getType();
      String fullClassName = null; // This is the String of full class
      // name e.g. distribution.Uniformation
      String selectedItem = ((String) _tComboBox.getSelectedItem());
      String[] typeAry = _pReader.getType(type);

      for (int j = 0; j < typeAry.length && !found; j++) {
        StringTokenizer st = new StringTokenizer(typeAry[j], ".");
        int count = st.countTokens();

        while (count != 1) {
          st.nextToken();
          count--;
        }

        String s = st.nextToken(); // System.out.println("Next token"+st.nextToken());

        if (selectedItem.equals(s)) {
          fullClassName = typeAry[j];
          found = true;
        }
      }
      if (found) {

        try {
          Object o, o2; // new
          o2 = _p.getValue(); // new

          _p.setValue(_editorComponent.getObject());

          if ((_p.getValue() == null)
              || (_p.getValue().getClass() != Class.forName(fullClassName))) {
            o = Class.forName(fullClassName).newInstance(); // This
            // is
            // the
            // object
            // created
          } else {
            o = _p.getValue();
          }

          PropertiesTableReader pReader = new PropertiesTableReader();

          if (pReader.hasProperties(fullClassName)) {
            PropertiesInputForm inputForm = new PropertiesInputForm(pReader);
            inputForm.dataInput(this, _p, o, fullClassName);
            inputForm.display();
          }
          System.out.println("o2: " + o2.toString());
          System.out.println("o: " + o);

          if (o2 != o) { // new
            // new undocommand(_p, o2);
            _p.setValue(o);
          }

          //					_p.setValue(o);
        } catch (Exception ex) {
          System.out.println("CEditor 2 -- " + ex);
        }
      }
    }
  }