Exemplo n.º 1
0
 /**
  * Returns array of GeoElements that depend on given GeoElement geo
  *
  * @param geo
  * @return
  */
 public static GeoElement[] getDependentObjects(GeoElement geo) {
   if (geo.isIndependent()) {
     return new GeoElement[0];
   }
   TreeSet<GeoElement> geoTree = geo.getAllPredecessors();
   return geoTree.toArray(new GeoElement[0]);
 }
Exemplo n.º 2
0
  public JPanel update(Object[] geos) {
    this.geos = geos;
    if (!checkGeos(geos)) return null;

    tfAnimStep.removeActionListener(this);

    // check if properties have same values
    GeoElement temp, geo0 = (GeoElement) geos[0];
    boolean equalStep = true;
    boolean onlyAngles = true;

    for (int i = 0; i < geos.length; i++) {
      temp = (GeoElement) geos[i];
      // same object visible value
      if (!Kernel.isEqual(geo0.getAnimationStep(), temp.getAnimationStep())) equalStep = false;
      if (!(temp.isGeoAngle())) onlyAngles = false;
    }

    // set trace visible checkbox
    // int oldDigits = kernel.getMaximumFractionDigits();
    // kernel.setMaximumFractionDigits(PropertiesDialog.TEXT_FIELD_FRACTION_DIGITS);
    StringTemplate highPrecision =
        StringTemplate.printDecimals(
            StringType.GEOGEBRA, PropertiesDialog.TEXT_FIELD_FRACTION_DIGITS, false);

    if (equalStep) {
      GeoElement stepGeo = geo0.getAnimationStepObject();
      if (onlyAngles && (stepGeo == null || (!stepGeo.isLabelSet() && stepGeo.isIndependent())))
        tfAnimStep.setText(kernel.formatAngle(geo0.getAnimationStep(), highPrecision).toString());
      else tfAnimStep.setText(stepGeo.getLabel(highPrecision));
    } else tfAnimStep.setText("");

    tfAnimStep.addActionListener(this);
    return this;
  }
Exemplo n.º 3
0
  private boolean checkGeos(Object[] geos) {
    boolean geosOK = true;
    for (int i = 0; i < geos.length; i++) {
      GeoElement geo = (GeoElement) geos[i];
      if (!geo.isChangeable()
          || geo.isGeoText()
          || geo.isGeoImage()
          || geo.isGeoList()
          || geo.isGeoBoolean()
          || geo.isGeoButton()
          || (!partOfSliderPanel && geo.isGeoNumeric() && geo.isIndependent()) // slider			
      ) {
        geosOK = false;
        break;
      }
    }

    return geosOK;
  }
Exemplo n.º 4
0
  // for AlgoElement
  @Override
  protected void setInputOutput() {
    // it is inefficient to have Q and P as input
    // let's take all independent parents of Q
    // and the path as input
    TreeSet<GeoElement> inSet = new TreeSet<GeoElement>();
    inSet.add((GeoElement) path.toGeoElement());

    // we need all independent parents of Q PLUS
    // all parents of Q that are points on a path
    Iterator<GeoElement> it = Qin.iterator();
    while (it.hasNext()) {
      GeoElement geo = it.next();
      if (geo.isIndependent() || geo.isPointOnPath()) {
        inSet.add(geo);
      }
    }
    // remove P from input set!
    inSet.remove(movingPoint);

    efficientInput = new GeoElement[inSet.size()];
    it = inSet.iterator();
    int i = 0;
    while (it.hasNext()) {
      efficientInput[i] = (GeoElement) it.next();
      i++;
    }

    // the standardInput array should be used for
    // the dependency graph
    standardInput = new GeoElement[2];
    standardInput[0] = locusPoint;
    standardInput[1] = movingPoint;

    setOutputLength(1);
    setOutput(0, locus);

    // handle dependencies
    setEfficientDependencies(standardInput, efficientInput);
  }
Exemplo n.º 5
0
  public static GeoElement doCopyNoStoringUndoInfo0(
      Kernel kernel, App app, GeoElement value, GeoElement oldValue, int dx, int dy)
      throws Exception {
    if (value == null) {
      if (oldValue != null) {
        MatchResult matcher =
            GeoElementSpreadsheet.spreadsheetPatternPart.exec(
                oldValue.getLabel(StringTemplate.defaultTemplate));
        int column = GeoElementSpreadsheet.getSpreadsheetColumn(matcher);
        int row = GeoElementSpreadsheet.getSpreadsheetRow(matcher);

        prepareAddingValueToTableNoStoringUndoInfo(kernel, app, null, oldValue, column, row);
      }
      return null;
    }
    String text = null;

    // make sure a/0.001 doesn't become a/0

    StringTemplate highPrecision = StringTemplate.maxPrecision;
    if (value.isPointOnPath() || value.isPointInRegion()) {
      text = value.getCommandDescription(highPrecision);
    } else if (value.isChangeable()) {
      text = value.toValueString(highPrecision);
    } else {
      text = value.getCommandDescription(highPrecision);
    }

    // handle GeoText source value
    if (value.isGeoText() && !((GeoText) value).isTextCommand()) {
      // enclose text in quotes if we are copying an independent GeoText,
      // e.g. "2+3"
      if (value.isIndependent()) {
        text = "\"" + text + "\"";
      } else {

        // check if 'text' parses to a GeoText
        GeoText testGeoText = kernel.getAlgebraProcessor().evaluateToText(text, false, false);

        // if it doesn't then force it to by adding +"" on the end
        if (testGeoText == null) {
          text = text + "+\"\"";
        }
      }
    }

    // for E1 = Polynomial[D1] we need value.getCommandDescription();
    // even though it's a GeoFunction
    if (value.isGeoFunction() && text.equals("")) {
      // we need the definition without A1(x)= on the front
      text = ((GeoFunction) value).toSymbolicString(highPrecision);
    }

    boolean freeImage = false;

    if (value.isGeoImage()) {
      GeoImage image = (GeoImage) value;
      if (image.getParentAlgorithm() == null) {
        freeImage = true;
      }
    }

    // Application.debug("before:"+text);
    text = updateCellReferences(value, text, dx, dy);
    // Application.debug("after:"+text);

    // condition to show object
    GeoBoolean bool = value.getShowObjectCondition();
    String boolText = null, oldBoolText = null;
    if (bool != null) {
      if (bool.isChangeable()) {
        oldBoolText = bool.toValueString(highPrecision);
      } else {
        oldBoolText = bool.getCommandDescription(highPrecision);
      }
    }

    if (oldBoolText != null) {
      boolText = updateCellReferences(bool, oldBoolText, dx, dy);
    }

    String startPoints[] = null;
    if (value instanceof Locateable) {
      Locateable loc = (Locateable) value;

      GeoPointND[] pts = loc.getStartPoints();

      startPoints = new String[pts.length];

      for (int i = 0; i < pts.length; i++) {
        startPoints[i] = ((GeoElement) pts[i]).getLabel(highPrecision);
        startPoints[i] = updateCellReferences((GeoElement) pts[i], startPoints[i], dx, dy);
      }
    }

    // dynamic color function
    GeoList dynamicColorList = value.getColorFunction();
    String colorText = null, oldColorText = null;
    if (dynamicColorList != null) {
      if (dynamicColorList.isChangeable()) {
        oldColorText = dynamicColorList.toValueString(highPrecision);
      } else {
        oldColorText = dynamicColorList.getCommandDescription(highPrecision);
      }
    }

    if (oldColorText != null) {
      colorText = updateCellReferences(dynamicColorList, oldColorText, dx, dy);
    }

    // allow pasting blank strings
    if (text.equals("")) {
      text = "\"\"";
    }

    // make sure that non-GeoText elements are copied when the
    // equalsRequired option is set
    if (!value.isGeoText() && app.getSettings().getSpreadsheet().equalsRequired()) {
      text = "=" + text;
    }

    // Application.debug("add text = " + text + ", name = " + (char)('A' +
    // column + dx) + (row + dy + 1));

    // create the new cell geo
    MatchResult matcher =
        GeoElementSpreadsheet.spreadsheetPatternPart.exec(
            value.getLabel(StringTemplate.defaultTemplate));
    int column0 = GeoElementSpreadsheet.getSpreadsheetColumn(matcher);
    int row0 = GeoElementSpreadsheet.getSpreadsheetRow(matcher);
    GeoElement value2;
    if (freeImage || value.isGeoButton()) {
      value2 = value.copy();
      if (oldValue != null) {
        oldValue.remove();
      }
      // value2.setLabel(table.getModel().getColumnName(column0 + dx)
      //		+ (row0 + dy + 1));
      value2.setLabel(GeoElementSpreadsheet.getSpreadsheetCellName(column0 + dx, row0 + dy + 1));
      value2.updateRepaint();
    } else {
      value2 =
          prepareAddingValueToTableNoStoringUndoInfo(
              kernel, app, text, oldValue, column0 + dx, row0 + dy);
    }
    value2.setAllVisualProperties(value, false);

    value2.setAuxiliaryObject(true);

    // attempt to set updated condition to show object (if it's changed)
    if ((boolText != null)) {
      // removed as doesn't work for eg "random()<0.5" #388
      // && !boolText.equals(oldBoolText)) {
      try {
        // Application.debug("new condition to show object: "+boolText);
        GeoBoolean newConditionToShowObject =
            kernel.getAlgebraProcessor().evaluateToBoolean(boolText);
        value2.setShowObjectCondition(newConditionToShowObject);
        value2.update(); // needed to hide/show object as appropriate
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }
    }

    // attempt to set updated dynamic color function (if it's changed)
    if ((colorText != null)) {
      // removed as doesn't work for eg "random()" #388
      // && !colorText.equals(oldColorText)) {
      try {
        // Application.debug("new color function: "+colorText);
        GeoList newColorFunction = kernel.getAlgebraProcessor().evaluateToList(colorText);
        value2.setColorFunction(newColorFunction);
        // value2.update();
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }
    }

    if (startPoints != null) {
      for (int i = 0; i < startPoints.length; i++) {
        ((Locateable) value2)
            .setStartPoint(
                kernel.getAlgebraProcessor().evaluateToPoint(startPoints[i], false, true), i);
      }

      value2.update();
    }

    // Application.debug((row + dy) + "," + column);
    // Application.debug("isGeoFunction()=" + value2.isGeoFunction());
    // Application.debug("row0 ="+row0+" dy="+dy+" column0= "+column0+" dx="+dx);

    return value2;
  }
Exemplo n.º 6
0
 /**
  * tells whether a GeoElement is dependent on others or not
  *
  * @param geo the GeoElement
  * @return true if the GeoElement is free (does not depend on others)
  */
 public static boolean isFree(GeoElement geo) {
   return geo.isIndependent();
 }
Exemplo n.º 7
0
  public void mouseClicked(AbstractEvent e) {
    // right click is consumed in mousePressed, but in GeoGebra 3D,
    // where heavyweight popup menus are enabled this doesn't work
    // so make sure that this is no right click as well (ticket #302)
    if (
    /*e.isConsumed() FIXME||*/ e.isRightClick()) {
      return;
    }

    // get GeoElement at mouse location
    Object tp = view.getPathForLocation(e.getX(), e.getY());
    GeoElement geo = view.getGeoElementForPath(tp);

    // check if we clicked on the 16x16 show/hide icon
    if (geo != null) {
      GRectangle rect = (GRectangle) view.getPathBounds(tp);
      boolean iconClicked =
          rect != null && e.getX() - rect.getX() < 16; // distance from left border			
      if (iconClicked) {
        // icon clicked: toggle show/hide
        geo.setEuclidianVisible(!geo.isSetEuclidianVisible());
        geo.updateVisualStyle();
        app.storeUndoInfo();
        kernel.notifyRepaint();
        return;
      }
    }

    // check double click
    int clicks = e.getClickCount();
    // EuclidianView ev = app.getEuclidianView();
    EuclidianViewInterfaceCommon ev = app.getActiveEuclidianView();
    if (clicks == 2) {
      app.clearSelectedGeos();
      ev.resetMode();
      if (geo != null && !e.isControlDown()) {
        view.startEditing(geo, e.isShiftDown());
      }
      return;
    }

    int mode = ev.getMode();
    if (!skipSelection
        && (mode == EuclidianConstants.MODE_MOVE
            || mode == EuclidianConstants.MODE_RECORD_TO_SPREADSHEET)) {
      // update selection
      if (geo == null) {
        app.clearSelectedGeos();
      } else {
        // handle selecting geo
        if (e.isControlDown()) {
          app.toggleSelectedGeo(geo);
          if (app.getSelectedGeos().contains(geo)) lastSelectedGeo = geo;
        } else if (e.isShiftDown() && lastSelectedGeo != null) {
          boolean nowSelecting = true;
          boolean selecting = false;
          boolean aux = geo.isAuxiliaryObject();
          boolean ind = geo.isIndependent();
          boolean aux2 = lastSelectedGeo.isAuxiliaryObject();
          boolean ind2 = lastSelectedGeo.isIndependent();

          if ((aux == aux2 && aux) || (aux == aux2 && ind == ind2)) {

            Iterator<GeoElement> it = kernel.getConstruction().getGeoSetLabelOrder().iterator();

            boolean direction =
                geo.getLabel(StringTemplate.defaultTemplate)
                        .compareTo(lastSelectedGeo.getLabel(StringTemplate.defaultTemplate))
                    < 0;

            while (it.hasNext()) {
              GeoElement geo2 = it.next();
              if ((geo2.isAuxiliaryObject() == aux && aux)
                  || (geo2.isAuxiliaryObject() == aux && geo2.isIndependent() == ind)) {

                if (direction && geo2.equals(lastSelectedGeo)) selecting = !selecting;
                if (!direction && geo2.equals(geo)) selecting = !selecting;

                if (selecting) {
                  app.toggleSelectedGeo(geo2);
                  nowSelecting = app.getSelectedGeos().contains(geo2);
                }

                if (!direction && geo2.equals(lastSelectedGeo)) selecting = !selecting;
                if (direction && geo2.equals(geo)) selecting = !selecting;
              }
            }
          }

          if (nowSelecting) {
            app.addSelectedGeo(geo);
            lastSelectedGeo = geo;
          } else {
            app.removeSelectedGeo(lastSelectedGeo);
            lastSelectedGeo = null;
          }

        } else {
          app.clearSelectedGeos(false); // repaint will be done next step
          app.addSelectedGeo(geo);
          lastSelectedGeo = geo;
        }
      }
    } else if (mode != EuclidianConstants.MODE_SELECTION_LISTENER) {
      // let euclidianView know about the click
      AbstractEvent event = e;
      ev.clickedGeo(geo, event);
      event.release();
    } else
      // tell selection listener about click
      app.geoElementSelected(geo, false);

    // Alt click: copy definition to input field
    if (geo != null && e.isAltDown() && app.showAlgebraInput()) {
      // F3 key: copy definition to input bar
      app.getGlobalKeyDispatcher().handleFunctionKeyForAlgebraInput(3, geo);
    }

    ev.mouseMovedOver(null);
  }