Пример #1
0
  public Flexible copyToGroup(String group) {

    String newName;
    if (group.equals(nullString)) newName = Group.substractObjectName(getName());
    else newName = group + Constants.GROUP_SEPARATOR + Group.substractObjectName(getName());

    // object with new name already exists, add suffix ///!!!
    while (Group.getRoot().findObject(newName, true) != null)
      newName = StringUtils.incrementName(newName, Constants.COPY_SUFFIX);

    Box grBox =
        new Box(
            newName,
            null,
            startVertex.getX(),
            startVertex.getY(),
            endVertex.getX(),
            endVertex.getY());
    grBox.setColor(getColor());
    Group.getRoot().addSubObject(newName, grBox, true);

    // ViewState view = ViewState.getInstance();
    // grBox.move(20 - view.getRx(), 20 - view.getRy());

    unconditionalValidation();
    return grBox;
  }
Пример #2
0
  public boolean rename(String newName) {
    String newObjName = Group.substractObjectName(newName);
    String oldObjName = Group.substractObjectName(getName());

    if (!oldObjName.equals(newObjName)) {
      getParent().removeObject(oldObjName);
      String fullName = StringUtils.replaceEnding(getName(), oldObjName, newObjName);
      name = fullName;
      getParent().addSubObject(newObjName, this);
    }

    // move if needed
    moveToGroup(Group.substractParentName(newName));

    return true;
  }
Пример #3
0
  public void destroy() {
    super.destroy();
    if (getParent() != null) getParent().removeObject(Group.substractObjectName(name));

    if (!startVertex.isDestroyed()) startVertex.destroy();

    if (!endVertex.isDestroyed()) endVertex.destroy();
  }
Пример #4
0
  public boolean moveToGroup(String group) {
    String currentParent = Group.substractParentName(getName());
    if (group.equals(currentParent)) return false;

    // String oldName = getName();
    String newName;
    if (group.equals(nullString)) newName = Group.substractObjectName(getName());
    else newName = group + Constants.GROUP_SEPARATOR + Group.substractObjectName(getName());

    // object with new name already exists, add suffix // !!!
    Object obj;
    boolean renameNeeded = false;
    while ((obj = Group.getRoot().findObject(newName, true)) != null) {
      if (obj == this) // it's me :) already moved, fix data
      {
        name = newName;
        return true;
      } else {
        renameNeeded = true;
        newName = StringUtils.incrementName(newName, Constants.MOVE_SUFFIX);
      }
    }

    if (renameNeeded) return rename(newName);

    getParent().removeObject(Group.substractObjectName(getName()));
    setParent(null);
    Group.getRoot().addSubObject(newName, this, true);

    name = newName;
    unconditionalValidation();

    return true;
  }
Пример #5
0
  public Box(String parName, Group parentGroup, int posX, int posY, int posX2, int posY2) {
    super(parentGroup);

    startVertex = new Vertex(this, posX, posY);
    endVertex = new Vertex(this, posX2, posY2);

    revalidatePosition();

    // for move rectangle
    setWidth(Constants.CONNECTOR_WIDTH);
    setHeight(Constants.CONNECTOR_HEIGHT);

    setColor(currentColor);
    dashed = currentIsDashed;

    if (parName == null) {
      hashId = getAvailableHashId();

      if (parentGroup.getAbsoluteName().length() > 0)
        name = parentGroup.getAbsoluteName() + Constants.GROUP_SEPARATOR + hashId;
      else name = hashId;
    } else name = parName;
  }