Пример #1
0
  private void updateBounds(MyPoint p) {

    if (bounds == null) {
      bounds = AwtFactory.prototype.newRectangle();
      bounds.setBounds((int) p.getX(), (int) p.getY(), 0, 0);
    }

    if (Math.abs(p.getX()) > largestCoord) largestCoord = Math.abs(p.getX());
    if (Math.abs(p.getY()) > largestCoord) largestCoord = Math.abs(p.getY());

    bounds.add(p.getX(), p.getY());
  }
Пример #2
0
  private void addClippedLine(
      MyPoint prevP, MyPoint curP, geogebra.common.awt.GRectangle viewRect) {
    // check if both points on screen
    if (viewRect.contains(prevP) && viewRect.contains(curP)) {
      // draw line to point
      addToGeneralPath(curP, true);
      return;
    }

    // at least one point is not on screen: clip line at screen
    geogebra.common.awt.GPoint2D[] clippedPoints =
        ClipLine.getClipped(
            prevP.getX(),
            prevP.getY(),
            curP.getX(),
            curP.getY(),
            -10,
            view.getWidth() + 10,
            -10,
            view.getHeight() + 10);

    if (clippedPoints != null) {
      // we have two intersection points with the screen
      // get closest clip point to prevP
      int first = 0;
      int second = 1;
      if (clippedPoints[first].distance(prevP.getX(), prevP.getY())
          > clippedPoints[second].distance(prevP.getX(), prevP.getY())) {
        first = 1;
        second = 0;
      }

      // draw line to first clip point
      addToGeneralPath(clippedPoints[first], true);
      // draw line between clip points: this ensures high quality
      // rendering
      // which Java2D doesn't deliver with the regular float GeneralPath
      // and huge coords
      addToGeneralPath(clippedPoints[second], true);

      // draw line to end point if not already there
      addToGeneralPath(getPointCloseToScreen(curP.getX(), curP.getY()), true);
    } else {
      // line is off screen
      // draw line to off screen end point
      addToGeneralPath(getPointCloseToScreen(curP.getX(), curP.getY()), true);
    }
  }
  public void onMouseMove(MouseMoveEvent e) {

    GPoint p = table.getIndexFromPixel(e.getClientX(), e.getClientY());
    if (p.getY() == 0 && p.getX() > 0) {
      table.scc.onMouseMove(e);
      return;
    } else if (p.getX() == 0 && p.getY() > 0) {
      table.srh.onMouseMove(e);
      return;
    }

    e.preventDefault();
    boolean eConsumed = false;

    // TODO: move the content of the mouseMoved method here

    // DRAG

    if (mouseIsDown) {

      if (table.getTableMode() == MyTable.TABLE_MODE_AUTOFUNCTION
          || table.getTableMode() == MyTable.TABLE_MODE_DROP) {
        // System.out.println("drop is dragging ");
        return;
      }

      // handle editing mode drag
      if (editor.isEditing()) {
        GPoint point = table.getIndexFromPixel(e.getClientX(), e.getClientY());
        if (point != null && selectedCellName != null) {
          int column2 = point.getX() - 1;
          int row2 = point.getY() - 1;

          MatchResult matcher = GeoElementSpreadsheet.spreadsheetPattern.exec(selectedCellName);
          int column1 = GeoElementSpreadsheet.getSpreadsheetColumn(matcher);
          int row1 = GeoElementSpreadsheet.getSpreadsheetRow(matcher);

          if (column1 > column2) {
            int temp = column1;
            column1 = column2;
            column2 = temp;
          }
          if (row1 > row2) {
            int temp = row1;
            row1 = row2;
            row2 = temp;
          }
          String name1 = GeoElementSpreadsheet.getSpreadsheetCellName(column1, row1);
          String name2 = GeoElementSpreadsheet.getSpreadsheetCellName(column2, row2);
          if (!name1.equals(name2)) {
            name1 += ":" + name2;
          }

          name1 = prefix0 + name1 + postfix0;
          editor.setLabel(name1);
          table.minColumn2 = column1;
          table.maxColumn2 = column2;
          table.minRow2 = row1;
          table.maxRow2 = row2;
          table.repaint();
        }
        return;
      }

      // handle dot drag
      if (table.isDragingDot) {

        eConsumed = true;
        int mouseX = e.getClientX();
        int mouseY = e.getClientY();
        GPoint mouseCell = table.getIndexFromPixel(mouseX, mouseY);

        // save the selected cell position so it can be re-selected if
        // needed
        CellRange oldSelection = table.getSelectedCellRanges().get(0);

        if (mouseCell == null) { // user has dragged outside the table, to
          // left or above
          table.dragingToRow = -1;
          table.dragingToColumn = -1;
        } else {
          table.dragingToRow = mouseCell.getY();
          table.dragingToColumn = mouseCell.getX();
          GRectangle selRect = table.getSelectionRect(true);

          // increase size if we're at the bottom of the spreadsheet
          if (table.dragingToRow + 1 == table.getRowCount()
              && table.dragingToRow < Kernel.MAX_SPREADSHEET_ROWS) {
            model.setRowCount(table.getRowCount() + 1);
          }

          // increase size if we go beyond the right edge
          if (table.dragingToColumn + 1 == table.getColumnCount()
              && table.dragingToColumn < Kernel.MAX_SPREADSHEET_COLUMNS) {
            model.setColumnCount(table.getColumnCount() + 1);
            view.columnHeaderRevalidate();
            // Java's addColumn method will clear selection, so
            // re-select our cell
            table.setSelection(oldSelection);
          }

          // scroll to show "highest" selected cell
          // TODO//table.scrollRectToVisible(table.getCellRect(mouseCell.y, mouseCell.x, true));

          if (!selRect.contains(e.getClientX(), e.getClientY())) {

            int rowOffset = 0, colOffset = 0;

            // get row distance
            if (table.minSelectionRow > 0 && table.dragingToRow < table.minSelectionRow) {
              rowOffset = mouseY - (int) selRect.getY();
              if (-rowOffset
                  < 0.5
                      * table
                          .getCellRect(table.minSelectionRow - 1, table.minSelectionColumn, true)
                          .getHeight()) rowOffset = 0;
            } else if (table.maxSelectionRow < Kernel.MAX_SPREADSHEET_ROWS
                && table.dragingToRow > table.maxSelectionRow) {
              rowOffset = mouseY - ((int) selRect.getY() + (int) selRect.getHeight());
              if (rowOffset
                  < 0.5
                      * table
                          .getCellRect(table.maxSelectionRow + 1, table.maxSelectionColumn, true)
                          .getHeight()) rowOffset = 0;
            }

            // get column distance
            if (table.minSelectionColumn > 0 && table.dragingToColumn < table.minSelectionColumn) {
              colOffset = mouseX - (int) selRect.getX();
              if (-colOffset
                  < 0.5
                      * table
                          .getCellRect(table.minSelectionRow, table.minSelectionColumn - 1, true)
                          .getWidth()) colOffset = 0;
            } else if (table.maxSelectionColumn < Kernel.MAX_SPREADSHEET_COLUMNS
                && table.dragingToColumn > table.maxSelectionColumn) {
              colOffset = mouseX - ((int) selRect.getX() + (int) selRect.getWidth());
              if (colOffset
                  < 0.5
                      * table
                          .getCellRect(table.maxSelectionRow, table.maxSelectionColumn + 1, true)
                          .getWidth()) colOffset = 0;
            }

            if (rowOffset == 0 && colOffset == 0) {
              table.dragingToColumn = -1;
              table.dragingToRow = -1;
            } else if (Math.abs(rowOffset) > Math.abs(colOffset)) {
              table.dragingToRow = mouseCell.y;
              table.dragingToColumn =
                  (colOffset > 0) ? table.maxSelectionColumn : table.minSelectionColumn;
            } else {
              table.dragingToColumn = mouseCell.x;
              table.dragingToRow = (rowOffset > 0) ? table.maxSelectionRow : table.minSelectionRow;
            }
            table.repaint();
          }

          // handle ctrl-select dragging of cell blocks
          else {
            /*TODO if (e.isControlDown()) {
            	table.handleControlDragSelect(e);
            }*/
          }
        }
      }

      if (eConsumed) return;

      // MyTable's default listeners follow, they should be simulated in Web e.g. here

      // change selection if right click is outside current selection
      if (p.getY() != table.leadSelectionRow + 1 || p.getX() != table.leadSelectionColumn + 1) {
        // switch to cell selection mode

        if (p.getY() > 0 && p.getX() > 0) {

          if (table.getSelectionType() != MyTable.CELL_SELECT) {
            table.setSelectionType(MyTable.CELL_SELECT);
          }

          // now change the selection
          table.changeSelection(p.getY() - 1, p.getX() - 1, false, true);
          table.repaint();
        }
      }
    } else {
      // MOVE, NO DRAG

      if (table.isEditing()) return;

      // get GeoElement at mouse location
      int row = p.getY(); // ?//table.rowAtPoint(e.getPoint());
      int col = p.getX(); // ?//table.columnAtPoint(e.getPoint());
      GeoElement geo = (GeoElement) model.getValueAt(row - 1, col - 1);

      // set tooltip with geo's description
      if (geo != null & view.getAllowToolTips()) {
        app.setTooltipFlag();
        // TODO//table.setToolTipText(geo.getLongDescriptionHTML(true, true));
        app.clearTooltipFlag();
      } else {
        // TODO//table.setToolTipText(null);
      }

      // check if over the dragging dot and update accordingly
      GPoint maxPoint = table.getMaxSelectionPixel();
      GPoint minPoint = table.getMinSelectionPixel();

      if (maxPoint != null) {
        int dotX = maxPoint.getX();
        int dotY = maxPoint.getY();
        int s = MyTableW.DOT_SIZE + 2;
        GRectangle2DW dotRect = new GRectangle2DW(dotX - s / 2, dotY - s / 2, s, s);
        boolean overDot = dotRect.contains(e.getClientX(), e.getClientY());
        if (table.isOverDot != overDot) {
          table.isOverDot = overDot;
          // TODO//setTableCursor();
          table.repaint();
        }
      }

      // check if over the DnD region and update accordingly
      GPoint testPoint = table.getMinSelectionPixel();
      if (testPoint != null) {
        int minX = minPoint.getX();
        int minY = minPoint.getY();
        int maxX = maxPoint.getX();
        int w = maxX - minX;
        GRectangle2DW dndRect = new GRectangle2DW(minX, minY - 2, w, 4);
        boolean overDnD = dndRect.contains(e.getClientX(), e.getClientY());
        if (table.isOverDnDRegion != overDnD) {
          table.isOverDnDRegion = overDnD;
          // TODO//setTableCursor();
        }
      }
    }
  }
Пример #4
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);
  }