@Override
  protected final GeoElement[] perform(Command c) throws MyError {
    int n = c.getArgumentNumber();
    GeoElement arg2[];
    switch (n) {
      case 2:
        arg2 = resArgs(c);
        if (arg2[1].isGeoBoolean()) {

          GeoElement geo = arg2[0];

          try {
            geo.setShowObjectCondition((GeoBoolean) arg2[1]);
          } catch (CircularDefinitionException e) {
            e.printStackTrace();
            throw argErr(app, c.getName(), arg2[1]);
          }
          geo.updateRepaint();

          return new GeoElement[0];
        }
        throw argErr(app, c.getName(), arg2[1]);

      default:
        throw argNumErr(app, c.getName(), n);
    }
  }
예제 #2
0
  /** Just copying the selection as string text format, independently! */
  public String copyString(int column1, int row1, int column2, int row2) {
    StringBuilder cellBufferStrLoc = new StringBuilder();
    for (int row = row1; row <= row2; ++row) {
      for (int column = column1; column <= column2; ++column) {
        GeoElement value = RelativeCopy.getValue(app, column, row);
        if (value != null) {
          String valueString = value.toValueString(StringTemplate.maxPrecision);

          // for aesthetical copying, it is also good to remove
          // trailing zeroes (zero is nothing anyway):
          int indx = valueString.indexOf(app.getKernel().getLocalization().unicodeDecimalPoint);
          if (indx > -1) {
            int end = valueString.length() - 1;
            // only in this case, we should remove trailing zeroes!
            while (valueString.charAt(end) == '0') end--;
            if (end == indx) end--;
            valueString = valueString.substring(0, end + 1);
          }

          cellBufferStrLoc.append(valueString);
        }
        if (column != column2) {
          cellBufferStrLoc.append('\t');
        }
      }
      if (row != row2) {
        cellBufferStrLoc.append('\n');
      }
    }
    return new String(cellBufferStrLoc);
  }
  private void removePoint(GeoElement oldPoint) {

    // remove dependent algorithms (e.g. segments) from update sets of
    // objects further up (e.g. polygon) the tree
    ArrayList<AlgoElement> algoList = oldPoint.getAlgorithmList();
    for (int k = 0; k < algoList.size(); k++) {
      AlgoElement algo = algoList.get(k);
      for (int j = 0; j < input.length; j++) input[j].removeFromUpdateSets(algo);
    }

    // remove old point
    oldPoint.setParentAlgorithm(null);

    // remove dependent segment algorithm that are part of this polygon
    // to make sure we don't remove the polygon as well
    GeoPolygon poly = getPoly();
    for (int k = 0; k < algoList.size(); k++) {
      AlgoElement algo = algoList.get(k);
      // make sure we don't remove the polygon as well
      if (algo instanceof AlgoJoinPointsSegmentInterface
          && ((AlgoJoinPointsSegmentInterface) algo).getPoly() == poly) {
        continue;
      }
      algo.remove();
    }

    algoList.clear();
    // remove point
    oldPoint.doRemove();
  }
예제 #4
0
  /**
   * @param app application
   * @param view view
   * @param selectedGeos selected geos
   * @param geos geos
   * @param location place to show
   */
  public ContextMenuChooseGeoD(
      AppD app,
      EuclidianView view,
      ArrayList<GeoElement> selectedGeos,
      ArrayList<GeoElement> geos,
      Point location,
      GPoint invokerLocation) {

    super(app, selectedGeos, location);

    this.view = view;
    this.selectedGeos = selectedGeos;

    // return if just one geo, or if first geos more than one
    if (
    /* geos.size()<2 || */ selectedGeos.size() > 1) {
      justOneGeo = false;
      return;
    }

    justOneGeo = true;

    // section to choose a geo
    // addSeparator();
    createSelectAnotherMenu(view.getMode());

    this.loc = invokerLocation;
    this.geos = geos;

    GeoElement geoSelected = selectedGeos.get(0);

    // add geos
    geoAddedForSelectAnother = false;

    metas = new TreeSet<GeoElement>();

    for (GeoElement geo : geos) {
      if (geo != geoSelected) { // don't add selected geo
        addGeo(geo);
      }

      if (geo.getMetasLength() > 0) {
        for (GeoElement meta : ((FromMeta) geo).getMetas()) {
          if (!metas.contains(meta)) {
            addGeo(meta);
          }
        }
      }
    }

    if (geoAddedForSelectAnother) {
      addSelectAnotherMenu();
    }

    // TODO: clear selection is not working from here
    this.getWrappedPopup().getSelectionModel().clearSelection();
  }
예제 #5
0
  public void update(GeoElement geo) {
    if (geo.isEmptySpreadsheetCell() && geo.isDefined()) {
      geo.setEmptySpreadsheetCell(false);
    }
    updateWithoutTrace(geo);

    // trace value
    if (!isIniting && geo.getSpreadsheetTrace()) {
      app.getTraceManager().traceToSpreadsheet(geo);
    }
  }
예제 #6
0
 private void applyUseAsText(ArrayList<GeoElement> geos) {
   // btnUseAsText
   for (int i = 0; i < geos.size(); i++) {
     GeoElement geo = geos.get(i);
     if (geo instanceof GeoCasCell) {
       ((GeoCasCell) geo).setUseAsText(btnUseAsText.isSelected());
       geo.updateRepaint();
       needUndo = true;
     }
   }
 }
 @Override
 public void mousePressed(MouseEvent e) {
   if (e.getSource() != table) return;
   int row = table.rowAtPoint(e.getPoint());
   if (row >= 0) { // init drag
     GeoElement geo = ((ConstructionTableData) data).getGeoElement(row);
     dragIndex = geo.getConstructionIndex();
     minIndex = geo.getMinConstructionIndex();
     maxIndex = geo.getMaxConstructionIndex();
   }
 }
예제 #8
0
  private void applyTextColor(ArrayList<GeoElement> geos) {

    Color color = org.geogebra.desktop.awt.GColorD.getAwtColor(btnTextColor.getSelectedColor());
    for (int i = 0; i < geos.size(); i++) {
      GeoElement geo = geos.get(i);
      if (geo instanceof GeoCasCell) {
        ((GeoCasCell) geo).setFontColor(new org.geogebra.desktop.awt.GColorD(color));
        geo.updateRepaint();
        needUndo = true;
      }
    }
  }
예제 #9
0
  @Override
  public final void compute() {
    int size = geoList.size();
    if (!geoList.isDefined() || size <= 1) {
      g.setUndefined();
      return;
    }

    double sigmax = 0;
    double sigmay = 0;
    double sigmaxx = 0;
    // double sigmayy=0; not needed
    double sigmaxy = 0;

    for (int i = 0; i < size; i++) {
      GeoElement geo = geoList.get(i);
      if (geo.isGeoPoint()) {
        double x;
        double y;
        if (geo.isGeoElement3D()) {
          Coords coords = ((GeoPointND) geo).getInhomCoordsInD3();
          if (!Kernel.isZero(coords.getZ())) {
            g.setUndefined();
            return;
          }
          x = coords.getX();
          y = coords.getY();
        } else {
          double xy[] = new double[2];
          ((GeoPoint) geo).getInhomCoords(xy);
          x = xy[0];
          y = xy[1];
        }

        sigmax += x;
        sigmay += y;
        sigmaxx += x * x;
        sigmaxy += x * y;
        // sigmayy+=y*y; not needed
      } else {
        g.setUndefined();
        return;
      }
    }
    // y on x regression line
    // (y - sigmay / n) = (Sxx / Sxy)*(x - sigmax / n)
    // rearranged to eliminate all divisions
    g.x = size * sigmax * sigmay - size * size * sigmaxy;
    g.y = size * size * sigmaxx - size * sigmax * sigmax;
    g.z = size * sigmax * sigmaxy - size * sigmaxx * sigmay; // (g.x)x +
    // (g.y)y +
    // g.z = 0
  }
 /** Calls doRemove() for all output objects of this algorithm except for keepGeo. */
 @Override
 public void removeOutputExcept(GeoElement keepGeo) {
   for (int i = 0; i < super.getOutputLength(); i++) {
     GeoElement geo = super.getOutput(i);
     if (geo != keepGeo) {
       if (geo.isGeoPoint()) {
         removePoint(geo);
       } else {
         geo.doRemove();
       }
     }
   }
 }
예제 #11
0
 @Override
 public List<String> getChoiches(Localization loc) {
   TreeSet<GeoElement> points = app.getKernel().getPointSet();
   choices.clear();
   choices.add("");
   Iterator<GeoElement> it = points.iterator();
   int count = 0;
   while (it.hasNext() || ++count > MAX_CHOICES) {
     GeoElement p = it.next();
     choices.add(p.getLabel(StringTemplate.editTemplate));
   }
   return choices;
 }
예제 #12
0
  /** @param cell initialize table with cell information */
  protected void initData(GeoCasCell cell) {
    HashSet<GeoElement> vars = new HashSet<GeoElement>();
    if (cell.getInputVE().getVariables() != null) {
      for (GeoElement var : cell.getInputVE().getVariables()) {
        addVariables(var, vars);
      }
    }

    // get the substitution list from cell
    ArrayList<Vector<String>> substList = cell.getSubstList();

    Vector<String> row;
    data = new Vector<Vector<String>>(vars.size() + 1);
    Iterator<GeoElement> iter = vars.iterator();
    while (iter.hasNext()) {
      row = new Vector<String>(2);
      GeoElement var = iter.next();
      String nextVar = var.getLabel(StringTemplate.defaultTemplate);
      int i = 0;
      for (i = 0; i < data.size(); i++) {
        if (data.get(i).firstElement().compareTo(nextVar) >= 0) {
          break;
        }
      }
      if (i == data.size() || !data.get(i).firstElement().equals(nextVar)) {
        row.add(nextVar);
        boolean added = false;
        if (substList != null && !substList.isEmpty()) {
          // search for nextVar in subst list
          for (int k = 0; k < substList.size(); k++) {
            // case we found it
            if (substList.get(k).get(0).equals(nextVar)) {
              // add to substitution data
              row.add(substList.get(k).get(1));
              added = true;
              break;
            }
          }
        }
        // case we didn't found
        if (!added) {
          row.add("");
        }
        data.insertElementAt(row, i);
      }
    }
    row = new Vector<String>(2);
    row.add("");
    row.add("");
    data.add(row);
  }
예제 #13
0
  @Override
  public boolean doHighlighting() {

    // if the polygon depends on a polyhedron, look at the meta'
    // highlighting

    if (getGeoElement().getMetasLength() > 0) {
      for (GeoElement meta : ((FromMeta) getGeoElement()).getMetas()) {
        if (meta != null && meta.doHighlighting()) return true;
      }
    }

    return super.doHighlighting();
  }
예제 #14
0
  /**
   * @param mouseLoc mouse location
   * @return first hitted label geo
   */
  public GeoElement getLabelHit(GPoint mouseLoc) {
    for (Drawable3DList list : lists) {
      for (Drawable3D d : list) {
        if (d.isVisible()) {
          GeoElement geo = d.getGeoElement();
          if (!geo.isGeoText() && geo.isPickable() && d.label.hit(mouseLoc)) {
            return geo;
          }
        }
      }
    }

    return null;
  }
  public AlgoQuadricLimitedPointPointRadius(
      Construction c,
      String[] labels,
      GeoPointND origin,
      GeoPointND secondPoint,
      NumberValue r,
      int type) {
    super(c);

    this.origin = origin;
    this.secondPoint = secondPoint;
    this.radius = r;

    quadric = new GeoQuadric3DLimited(c); // ,origin,secondPoint);
    quadric.setType(type);

    input = new GeoElement[] {(GeoElement) origin, (GeoElement) secondPoint, (GeoElement) r};

    ((GeoElement) origin).addAlgorithm(this);
    ((GeoElement) secondPoint).addAlgorithm(this);
    ((GeoElement) r).addAlgorithm(this);

    // parent of output
    quadric.setParentAlgorithm(this);
    cons.addToAlgorithmList(this);

    setQuadric();

    algoSide = new AlgoQuadricSide(cons, quadric, true, null);
    cons.removeFromConstructionList(algoSide);
    side = (GeoQuadric3DPart) algoSide.getQuadric();
    side.setParentAlgorithm(this);
    quadric.setSide(side);

    algoEnds = createEnds();
    bottom.setParentAlgorithm(this);
    top.setParentAlgorithm(this);
    quadric.setBottomTop(bottom, top);

    // output = new GeoElement[] {quadric,bottom,top,side};
    setOutput();

    quadric.initLabelsIncludingBottom(labels);
    quadric.updatePartsVisualStyle();

    // force update for side
    update();
  }
예제 #16
0
  public void copy(int column1, int row1, int column2, int row2, boolean skipGeoCopy, boolean nat) {
    sourceColumn1 = column1;
    sourceRow1 = row1;

    // copy tab-delimited geo values into the external buffer
    if (cellBufferStr == null) {
      cellBufferStr = new StringBuilder();
    } else {
      cellBufferStr.setLength(0);
    }
    for (int row = row1; row <= row2; ++row) {
      for (int column = column1; column <= column2; ++column) {
        GeoElement value = RelativeCopy.getValue(app, column, row);
        if (value != null) {
          cellBufferStr.append(value.toValueString(StringTemplate.maxPrecision));
        }
        if (column != column2) {
          cellBufferStr.append('\t');
        }
      }
      if (row != row2) {
        cellBufferStr.append('\n');
      }
    }

    // store the tab-delimited values in the clipboard
    /*Toolkit toolkit = Toolkit.getDefaultToolkit();
    Clipboard clipboard = toolkit.getSystemClipboard();
    StringSelection stringSelection = new StringSelection(cellBufferStr);
    clipboard.setContents(stringSelection, null);*/

    // a clipboard inside this application is better than nothing
    // staticClipboardString = new String(cellBufferStr);
    if (nat) {
      // if called from native event, setting clipboard contents
      // is not crucial, and redundant/harmful in IE...
      setInternalClipboardContents(new String(cellBufferStr));
    } else {
      setClipboardContents(new String(cellBufferStr), getFocusCallback());
    }

    // store copies of the actual geos in the internal buffer
    if (skipGeoCopy) {
      cellBufferGeo = null;
    } else {
      cellBufferGeo = RelativeCopy.getValues(app, column1, row1, column2, row2);
    }
  }
예제 #17
0
  public Widget getTableCellEditorWidget(
      MyTableW table0, Object value0, boolean isSelected, int row0, int column0) {

    table = table0;

    if (value0 instanceof String) { // clicked to type
      value = null;
    } else {
      value = (GeoElement) value0;
    }

    column = column0;
    row = row0;
    String text = "";

    if (value != null) {
      text = getEditorInitString(value);
      int index = text.indexOf("=");
      if ((!value.isGeoText())) {
        if (index == -1) {
          text = "=" + text;
        }
      }
    }

    autoCompleteTextField.setText(text);
    autoCompleteTextField.setFont(app.getFontCanDisplay(text));
    autoCompleteTextField.requestFocus();

    editing = true;

    return autoCompleteTextField;
  }
예제 #18
0
  /**
   * Creates new random element algo
   *
   * @param cons
   * @param label
   * @param geoList
   */
  public AlgoRandomElement(Construction cons, String label, GeoList geoList) {
    super(cons);
    this.geoList = geoList;

    // init return element as copy of first list element
    if (geoList.size() > 0) {
      element = geoList.get(0).copyInternal(cons);
    } else if (geoList.getTypeStringForXML() != null) {
      // if the list was non-empty at some point before saving, get the
      // same type of geo
      // saved in XML from 4.1.131.0
      element = kernel.createGeoElement(cons, geoList.getTypeStringForXML());
    }

    // desperate case: empty list
    else {
      // saved in XML from 4.0.18.0
      element = cons.getOutputGeo();
    }

    setInputOutput();
    compute();
    element.setLabel(label);
    cons.addRandomGeo(element);
  }
예제 #19
0
  private void applyFontStyle(ArrayList<GeoElement> geos) {

    int fontStyle = 0;
    if (btnBold.isSelected()) fontStyle += 1;
    if (btnItalic.isSelected()) fontStyle += 2;
    for (int i = 0; i < geos.size(); i++) {
      GeoElement geo = geos.get(i);
      Log.debug(((GeoCasCell) geo).getGeoText());
      if (geo instanceof GeoCasCell
          && ((GeoCasCell) geo).getGeoText().getFontStyle() != fontStyle) {
        ((GeoCasCell) geo).getGeoText().setFontStyle(fontStyle);
        geo.updateRepaint();
        needUndo = true;
      }
    }
  }
예제 #20
0
 public void remove(GeoElement geo) {
   GPoint location = geo.getSpreadsheetCoords();
   if (location != null) {
     doRemove(geo, location.y, location.x);
     cellRangeManager.updateCellRangeAlgos(geo, location, true);
   }
 }
예제 #21
0
  private void updateWithoutTrace(GeoElement geo) {
    GPoint location = geo.getSpreadsheetCoords();

    if (location != null
        && location.x < app.getMaxSpreadsheetColumnsVisible()
        && location.y < app.getMaxSpreadsheetRowsVisible()) {

      highestUsedColumn = Math.max(highestUsedColumn, location.x);
      highestUsedRow = Math.max(highestUsedRow, location.y);

      if (location.y >= getRowCount()) {
        setRowCount(location.y + 1);
      }

      if (location.x >= getColumnCount()) {
        // table.setMyColumnCount(location.x + 1);
        // JViewport cH = spreadsheet.getColumnHeader();

        // bugfix: double-click to load ggb file gives cH = null
        // if (cH != null) cH.revalidate();
      }
      setValueAt(geo, location.y, location.x);

      /*
       * DONE ELSEWHERE // add tracing geos to the trace collection if
       * (!isIniting && geo.getSpreadsheetTrace()) {
       * app.getTraceManager().addSpreadsheetTraceGeo(geo); }
       */
    }
  }
예제 #22
0
  private void applyTextSize(ArrayList<GeoElement> geos) {

    double fontSize =
        GeoText.getRelativeFontSize(
            btnTextSize.getSelectedIndex()); // transform indices to the range -4, .. ,
    // 4

    for (int i = 0; i < geos.size(); i++) {
      GeoElement geo = geos.get(i);
      if (geo instanceof GeoCasCell
          && ((GeoCasCell) geo).getGeoText().getFontSizeMultiplier() != fontSize) {
        ((GeoCasCell) geo).setFontSizeMultiplier(fontSize);
        geo.updateRepaint();
        needUndo = true;
      }
    }
  }
    @Override
    public Component getTableCellEditorComponent(
        JTable table1, Object value, boolean isSelected, int rowIndex, int columnIndex) {

      geo = ((ConstructionTableData) data).getGeoElement(rowIndex);
      String val = geo.getCaptionDescription(StringTemplate.defaultTemplate);
      inputPanel = new InputPanelD("", (AppD) app, 20, false);
      inputPanel.setText(val);
      inputPanel.setEnabled(true);
      inputPanel.setVisible(true);
      return inputPanel;
    }
  @Override
  protected String getDescription(GeoElement geo) {

    String text = null;
    if (geo.isIndependent() && geo.getDefinition() == null) {
      text = getAlgebraDescriptionTextOrHTML(geo);
    } else {
      switch (kernel.getAlgebraStyle()) {
        case Kernel.ALGEBRA_STYLE_VALUE:
          text = getAlgebraDescriptionTextOrHTML(geo);
          break;

        case Kernel.ALGEBRA_STYLE_DESCRIPTION:
          IndexHTMLBuilder builder = new IndexHTMLBuilder(true);
          geo.addLabelTextOrHTML(
              geo.getDefinitionDescription(StringTemplate.defaultTemplate), builder);
          text = builder.toString();
          break;

        case Kernel.ALGEBRA_STYLE_DEFINITION:
          builder = new IndexHTMLBuilder(true);
          geo.addLabelTextOrHTML(geo.getDefinition(StringTemplate.defaultTemplate), builder);
          text = builder.toString();
          break;
      }
    }

    return text;
  }
예제 #25
0
  /**
   * Attempts to create or redefine the cell geo using the current editing string
   *
   * @return
   */
  private boolean processGeo() {

    try {

      if (allowProcessGeo) {
        String text = autoCompleteTextField.getText(); // ?// (String)
        // delegate.getCellEditorValue();
        // get GeoElement of current cell
        value = kernel.lookupLabel(GeoElementSpreadsheet.getSpreadsheetCellName(column, row));

        if (text.equals("")) {
          if (value != null) {
            value.removeOrSetUndefinedIfHasFixedDescendent();
            value = null;
          }

        } else {
          GeoElement newVal =
              RelativeCopy.prepareAddingValueToTableNoStoringUndoInfo(
                  kernel, app, text, value, column, row, false);
          if (newVal == null) {
            return false;
          }
          value = newVal;
        }

        if (value != null) app.storeUndoInfo();
      }

    } catch (Exception ex) {
      // show GeoGebra error dialog
      // kernel.getApplication().showError(ex.getMessage());
      ex.printStackTrace();
      // TODO super.stopCellEditing();
      editing = false;
      return false;
    }
    return true;
  }
예제 #26
0
  @Override
  public final void compute() {
    if (!geoList.isDefined() || geoList.size() == 0) {
      element.setUndefined();
      return;
    }

    GeoElement randElement =
        geoList.get((int) Math.floor((cons.getApplication().getRandomNumber() * geoList.size())));

    // check type:
    if (randElement.getGeoClassType() == element.getGeoClassType()) {
      element.set(randElement);
    } else {
      element.setUndefined();
    }
  }
예제 #27
0
 protected GeoElement copyInternal(Construction cons, GeoElement geo) {
   return geo.copyInternal(cons);
 }
예제 #28
0
 protected GeoElement copy(GeoElement geo) {
   return geo.copy();
 }
예제 #29
0
 protected GeoElement getResultTemplate(GeoElement geo) {
   if (geo instanceof GeoPoly || geo.isLimitedPath()) return copyInternal(cons, geo);
   if (geo.isGeoList()) return new GeoList(cons);
   return copy(geo);
 }
예제 #30
0
 public void geoToPlotPanel(GeoElement listGeo) {
   listGeo.addView(plotPanel.getViewID());
   plotPanel.add(listGeo);
   listGeo.removeView(App.VIEW_EUCLIDIAN);
   app.getEuclidianView1().remove(listGeo);
 }