예제 #1
0
  /**
   * for AlgebraView changes in the tree selection and redefine dialog
   *
   * @return changed geo
   */
  public GeoElement changeGeoElementNoExceptionHandling(
      GeoElement geo, ValidExpression newValue, boolean redefineIndependent, boolean storeUndoInfo)
      throws Exception {
    String oldLabel, newLabel;
    GeoElement[] result;

    try {
      oldLabel = geo.getLabel();
      newLabel = newValue.getLabel();

      if (newLabel == null) {
        newLabel = oldLabel;
        newValue.setLabel(newLabel);
      }

      // make sure that points stay points and vectors stay vectors
      if (newValue instanceof ExpressionNode) {
        ExpressionNode n = (ExpressionNode) newValue;
        if (geo.isGeoPoint()) n.setForcePoint();
        else if (geo.isGeoVector()) n.setForceVector();
        else if (geo.isGeoFunction()) n.setForceFunction();
      }

      if (newLabel.equals(oldLabel)) {
        // try to overwrite
        result = processValidExpression(newValue, redefineIndependent);
        if (result != null && storeUndoInfo) app.storeUndoInfo();
        return result[0];
      } else if (cons.isFreeLabel(newLabel)) {
        newValue.setLabel(oldLabel);
        // rename to oldLabel to enable overwriting
        result = processValidExpression(newValue, redefineIndependent);
        result[0].setLabel(newLabel); // now we rename
        if (storeUndoInfo) app.storeUndoInfo();
        return result[0];
      } else {
        String str[] = {"NameUsed", newLabel};
        throw new MyError(app, str);
      }
    } catch (CircularDefinitionException e) {
      Application.debug("CircularDefinition");
      throw e;
    } catch (Exception e) {
      e.printStackTrace();
      throw new Exception(app.getError("InvalidInput") + ":\n" + newValue);
    } catch (MyError e) {
      e.printStackTrace();
      throw new Exception(e.getLocalizedMessage());
    } catch (Error e) {
      e.printStackTrace();
      throw new Exception(app.getError("InvalidInput") + ":\n" + newValue);
    }
  }