Example #1
0
  /** Open Editor textfield for geo. */
  public void startEditing(GeoElement geo, boolean shiftDown) {
    if (geo == null) return;

    // open Object Properties for eg GeoImages
    if (!geo.isAlgebraViewEditable()) {
      ArrayList<GeoElement> geos = new ArrayList<GeoElement>();
      geos.add(geo);
      app.getGuiManager().getDialogManager().showPropertiesDialog(geos);
      return;
    }

    if (!shiftDown || !geo.isPointOnPath() && !geo.isPointInRegion()) {
      if (!geo.isIndependent() || !attached) // needed for F2 when Algebra
      // View closed
      {
        if (geo.isRedefineable()) {
          app.getGuiManager().getDialogManager().showRedefineDialog(geo, true);
        }
        return;
      }

      if (!geo.isChangeable()) {
        if (geo.isFixed()) {
          // app.showMessage(app.getError("AssignmentToFixed"));
        } else if (geo.isRedefineable()) {
          app.getGuiManager().getDialogManager().showRedefineDialog(geo, true);
        }
        return;
      }
    }

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodeTable.get(geo);

    if (node != null) {
      cancelEditing();
      // select and show node
      TreePath tp = new TreePath(node.getPath());
      setSelectionPath(tp); // select
      expandPath(tp);
      makeVisible(tp);
      scrollPathToVisible(tp);
      startEditingAtPath(tp); // opend editing text field
    }
  }
Example #2
0
  /**
   * processes valid expression.
   *
   * @param ve
   * @param redefineIndependent == true: independent objects are redefined too
   * @throws MyError
   * @throws Exception
   * @return
   */
  public GeoElement[] processValidExpression(ValidExpression ve, boolean redefineIndependent)
      throws MyError, Exception {

    // check for existing labels
    String[] labels = ve.getLabels();
    GeoElement replaceable = null;
    if (labels != null && labels.length > 0) {
      boolean firstTime = true;
      for (int i = 0; i < labels.length; i++) {
        GeoElement geo = kernel.lookupLabel(labels[i]);
        if (geo != null) {
          if (geo.isFixed()) {
            String[] strs = {
              "IllegalAssignment", "AssignmentToFixed", ":\n", geo.getLongDescription()
            };
            throw new MyError(app, strs);
          } else {
            // replace (overwrite or redefine) geo
            if (firstTime) { // only one geo can be replaced
              replaceable = geo;
              firstTime = false;
            }
          }
        }
      }
    }

    GeoElement[] ret;
    boolean oldMacroMode = cons.isSuppressLabelsActive();
    if (replaceable != null) cons.setSuppressLabelCreation(true);

    // we have to make sure that the macro mode is
    // set back at the end
    try {
      ret = doProcessValidExpression(ve);

      if (ret == null) { // eg (1,2,3) running in 2D
        Application.debug("Unhandled ValidExpression : " + ve);
        throw new MyError(app, app.getError("InvalidInput") + ":\n" + ve);
      }
    } finally {
      cons.setSuppressLabelCreation(oldMacroMode);
    }

    //	try to replace replaceable geo by ret[0]
    if (replaceable != null && ret != null && ret.length > 0) {
      // a changeable replaceable is not redefined:
      // it gets the value of ret[0]
      // (note: texts are always redefined)
      if (!redefineIndependent && replaceable.isChangeable() && !(replaceable.isGeoText())) {
        try {
          replaceable.set(ret[0]);
          replaceable.updateRepaint();
          ret[0] = replaceable;
        } catch (Exception e) {
          String errStr =
              app.getError("IllegalAssignment")
                  + "\n"
                  + replaceable.getLongDescription()
                  + "     =     "
                  + ret[0].getLongDescription();
          throw new MyError(app, errStr);
        }
      }
      // redefine
      else {
        try {
          // SPECIAL CASE: set value
          // new and old object are both independent and have same type:
          // simply assign value and don't redefine
          if (replaceable.isIndependent()
              && ret[0].isIndependent()
              && replaceable.getGeoClassType() == ret[0].getGeoClassType()) {
            replaceable.set(ret[0]);
            replaceable.updateRepaint();
            ret[0] = replaceable;
          }

          // STANDARD CASE: REDFINED
          else {
            GeoElement newGeo = ret[0];
            cons.replace(replaceable, newGeo);

            // now all objects have changed
            // get the new object with same label as our result
            String newLabel = newGeo.isLabelSet() ? newGeo.getLabel() : replaceable.getLabel();
            ret[0] = kernel.lookupLabel(newLabel, false);
          }
        } catch (CircularDefinitionException e) {
          throw e;
        } catch (Exception e) {
          e.printStackTrace();
          throw new MyError(app, "ReplaceFailed");
        } catch (MyError e) {
          e.printStackTrace();
          throw new MyError(app, "ReplaceFailed");
        }
      }
    }

    return ret;
  }