Ejemplo n.º 1
0
  private void addNewGeoToConstruction() {

    if (objectType == TYPE_LISTOFPOINTS || objectType == TYPE_POLYLINE) {
      app.getKernel().getConstruction().addToConstructionList(newGeo.getParentAlgorithm(), true);
    }

    newGeo.setEuclidianVisible(true);
    if (!newGeo.isGeoText()) newGeo.setAuxiliaryObject(false);

    if (objectType == TYPE_LISTOFPOINTS) {
      GeoList gl = (GeoList) newGeo;
      for (int i = 0; i < gl.size(); i++) {
        gl.get(i).setEuclidianVisible(true);
        gl.get(i).setAuxiliaryObject(false);
      }
    }

    if (objectType == TYPE_POLYLINE) {
      GeoPoint[] pts = ((AlgoPolyLine) newGeo.getParentAlgorithm()).getPoints();
      for (int i = 0; i < pts.length; i++) {
        pts[i].setEuclidianVisible(true);
        pts[i].setAuxiliaryObject(false);
      }
    }

    newGeo.update();
    app.storeUndoInfo();
  }
Ejemplo n.º 2
0
  public final void perform(Command c) throws MyError {
    int n = c.getArgumentNumber();
    GeoElement[] arg;

    switch (n) {
      case 1:
        arg = resArgs(c);
        if (arg[0].isNumberValue()) {
          GeoNumeric layerGeo = (GeoNumeric) arg[0];
          int layer = (int) layerGeo.getDouble();

          Iterator<GeoElement> it = kernelA.getConstruction().getGeoSetLabelOrder().iterator();
          while (it.hasNext()) {
            GeoElement geo = it.next();
            if (geo.getLayer() == layer) {
              geo.setEuclidianVisible(true);
              geo.updateRepaint();
            }
          }

          return;

        } else throw argErr(app, c.getName(), null);

      default:
        throw argNumErr(app, c.getName(), n);
    }
  }
Ejemplo n.º 3
0
  private static GeoElement updateOldValue(
      Kernel kernel, GeoElement oldValue, String name, String text) throws Exception {
    String text0 = text;
    if (text.charAt(0) == '=') {
      text = text.substring(1);
    }
    GeoElement newValue = null;
    try {
      // always redefine objects in spreadsheet, don't store undo info
      // here
      newValue =
          kernel
              .getAlgebraProcessor()
              .changeGeoElementNoExceptionHandling(oldValue, text, true, false);

      // newValue.setConstructionDefaults();
      newValue.setAllVisualProperties(oldValue, true);
      if (oldValue.isAuxiliaryObject()) {
        newValue.setAuxiliaryObject(true);
      }

      // Application.debug("GeoClassType = " +
      // newValue.getGeoClassType()+" " + newValue.getGeoClassType());
      if (newValue.getGeoClassType() == oldValue.getGeoClassType()) {
        // newValue.setVisualStyle(oldValue);
      } else {
        kernel.getApplication().refreshViews();
      }
    } catch (CircularDefinitionException cde) {
      kernel.getApplication().showError("CircularDefinition");
      return null;
    } catch (Throwable e) {
      // if exception is thrown treat the input as text and try to update
      // the cell as a GeoText
      {
        // reset the text string if old value is GeoText
        if (oldValue.isGeoText()) {
          ((GeoText) oldValue).setTextString(text0);
          oldValue.updateCascade();
        }

        // if not currently a GeoText and no children, redefine the cell
        // as new GeoText
        else if (!oldValue.hasChildren()) {
          oldValue.remove();

          // add input as text
          try {
            newValue = prepareNewValue(kernel, name, "\"" + text0 + "\"");
          } catch (Throwable t) {
            newValue = prepareNewValue(kernel, name, "");
          }
          newValue.setEuclidianVisible(false);
          newValue.update();
        }

        // otherwise throw an exception and let the cell revert to the
        // old value
        else {
          throw new Exception(e);
        }
      }
    }
    return newValue;
  }
Ejemplo n.º 4
0
  private void createNewGeo() {

    boolean nullGeo = newGeo == null;

    if (!nullGeo) {
      if (objectType == TYPE_LISTOFPOINTS) {
        GeoList gl = (GeoList) newGeo;
        for (int i = 0; i < gl.size(); i++) gl.get(i).remove();
      }

      if (objectType == TYPE_POLYLINE) {
        GeoPoint[] pts = ((AlgoPolyLine) newGeo.getParentAlgorithm()).getPoints();
        for (int i = 0; i < pts.length; i++) pts[i].remove();
      }
      newGeo.remove();
    }

    int column1 = table.selectedCellRanges.get(0).getMinColumn();
    int column2 = table.selectedCellRanges.get(0).getMaxColumn();
    int row1 = table.selectedCellRanges.get(0).getMinRow();
    int row2 = table.selectedCellRanges.get(0).getMaxRow();

    boolean copyByValue = btnValue.isSelected();
    boolean scanByColumn = cbScanOrder.getSelectedIndex() == 1;
    boolean leftToRight = cbLeftRightOrder.getSelectedIndex() == 0;
    boolean transpose = ckTranspose.isSelected();
    boolean doCreateFreePoints = true;
    boolean doStoreUndo = true;
    boolean isSorted = false;

    try {
      switch (objectType) {
        case TYPE_LIST:
          newGeo = cp.createList(selectedCellRanges, scanByColumn, copyByValue);
          break;

        case TYPE_LISTOFPOINTS:
          newGeo =
              cp.createPointGeoList(
                  selectedCellRanges,
                  copyByValue,
                  leftToRight,
                  isSorted,
                  doStoreUndo,
                  doCreateFreePoints);
          newGeo.setLabel(null);
          for (int i = 0; i < ((GeoList) newGeo).size(); i++) {
            ((GeoList) newGeo).get(i).setAuxiliaryObject(true);
            ((GeoList) newGeo).get(i).setEuclidianVisible(false);
          }
          newGeo.updateRepaint();
          break;

        case TYPE_MATRIX:
          newGeo = cp.createMatrix(column1, column2, row1, row2, copyByValue, transpose);
          break;

        case TYPE_TABLETEXT:
          newGeo = cp.createTableText(column1, column2, row1, row2, copyByValue, transpose);
          break;

        case TYPE_POLYLINE:
          newGeo = cp.createPolyLine(selectedCellRanges, copyByValue, leftToRight);
          newGeo.setLabel(null);
          GeoPoint[] pts = ((AlgoPolyLine) newGeo.getParentAlgorithm()).getPoints();
          for (int i = 0; i < pts.length; i++) {
            pts[i].setAuxiliaryObject(true);
            pts[i].setEuclidianVisible(false);
          }
          newGeo.updateRepaint();
          break;
      }

      ImageIcon latexIcon = new ImageIcon();
      // String latexStr = newGeo.getLaTeXAlgebraDescription(true);

      String latexStr = newGeo.getFormulaString(StringTemplate.latexTemplate, true);

      // System.out.println(latexStr);

      Font latexFont =
          new Font(
              app.getPlainFont().getName(),
              app.getPlainFont().getStyle(),
              app.getPlainFont().getSize() - 1);

      if (latexStr != null && newGeo.isLaTeXDrawableGeo()) {
        app.getDrawEquation()
            .drawLatexImageIcon(app, latexIcon, latexStr, latexFont, false, Color.black, null);
        lblPreview.setText(" ");
      } else {
        lblPreview.setText(newGeo.getAlgebraDescriptionTextOrHTMLDefault());
      }
      lblPreview.setIcon(latexIcon);

      if (!nullGeo) {
        newGeo.setLabel(fldName.getText());
        newGeo.setAuxiliaryObject(true);
        newGeo.setEuclidianVisible(false);
      }

      updateGUI();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 5
0
 /**
  * Set the visibility of the Geo
  *
  * @param b true to make the Geo visible
  */
 public static void setEuclidianVisible(GeoElement geo, boolean b) {
   geo.setEuclidianVisible(b);
 }
Ejemplo n.º 6
0
  /*
   * MouseListener implementation for popup menus
   */
  public void mouseClicked(java.awt.event.MouseEvent 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() || AppD.isRightClick(e)) {
      return;
    }

    // get GeoElement at mouse location
    TreePath tp = tree.getPathForLocation(e.getX(), e.getY());
    GeoElement geo = AlgebraTree.getGeoElementForPath(tp);

    ArrayList<GeoElement> groupedGeos = null;

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

    } else { // try group action
      groupedGeos = groupAction(e, tp, false);
    }

    // check double click
    if (checkDoubleClick(geo, e)) return;

    EuclidianViewInterfaceCommon ev = app.getActiveEuclidianView();
    int mode = ev.getMode();
    if (!skipSelection && isSelectionModeForClick(mode)) {
      // update selection
      if (geo == null) {
        if (!AppD.isControlDown(e) && !e.isShiftDown()) app.clearSelectedGeos();

        if (groupedGeos != null) app.addSelectedGeos(groupedGeos, true);

      } else {
        // handle selecting geo
        if (AppD.isControlDown(e)) {
          app.toggleSelectedGeo(geo);
          if (app.getSelectedGeos().contains(geo)) lastSelectedGeo = geo;
        } else if (e.isShiftDown() && lastSelectedGeo != null) {
          ArrayList<GeoElement> geos = tree.getGeosBetween(lastSelectedGeo, geo);
          if (geos != null) {
            app.clearSelectedGeos(false); // repaint will be done next step
            app.addSelectedGeos(geos, true);
          }

        } else {
          app.clearSelectedGeos(false); // repaint will be done next step
          app.addSelectedGeo(geo);
          lastSelectedGeo = geo;
        }
      }
    } else if (mode != EuclidianConstants.MODE_SELECTION_LISTENER) {
      euclidianViewClick(ev, geo, e);
    } 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);
  }
Ejemplo 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);
  }