public void onClick(ClickEvent e) { GPoint point = table.getIndexFromPixel(e.getClientX(), e.getClientY()); if (editor.isEditing()) { String text = editor.getEditingValue(); if (text.startsWith("=")) { point = table.getIndexFromPixel(e.getClientX(), e.getClientY()); if (point != null) { int column = point.getX(); int row = point.getY(); GeoElement geo = RelativeCopy.getValue(app, column - 1, row - 1); } } selectedCellName = null; prefix0 = null; table.isDragging2 = false; table.repaint(); } /*? else if (app.getMode() != EuclidianConstants.MODE_SELECTION_LISTENER) { int row = point.y;//?//table.rowAtPoint(e.getPoint()); int col = point.x;//?//table.columnAtPoint(e.getPoint()); GeoElement geo = (GeoElement) model.getValueAt(row, col); // let euclidianView know about the click AbstractEvent event = geogebra.web.euclidian.event.MouseEvent .wrapEvent(e); app.getActiveEuclidianView().clickedGeo(geo, event); event.release(); }*/ }
public void onMouseUp(MouseUpEvent e) { GPoint p = table.getIndexFromPixel(e.getClientX(), e.getClientY()); if (p.getY() == 0 && p.getX() > 0) { if (table.isEditing()) editor.cancelCellEditing(); table.scc.onMouseUp(e); return; } else if (p.getX() == 0 && p.getY() > 0) { if (table.isEditing()) editor.cancelCellEditing(); table.srh.onMouseUp(e); return; } mouseIsDown = false; e.preventDefault(); boolean eConsumed = false; boolean rightClick = (e.getNativeButton() == NativeEvent.BUTTON_RIGHT); if (table.getTableMode() == MyTable.TABLE_MODE_AUTOFUNCTION) { table.stopAutoFunction(); return; } if (!rightClick) { if (editor.isEditing()) { String text = editor.getEditingValue(); if (text.startsWith("=")) { GPoint point = table.getIndexFromPixel(e.getClientX(), e.getClientY()); if (point != null) { int column = point.getX(); int row = point.getY(); if (column != editor.column || row != editor.row) { eConsumed = true; } } } selectedCellName = null; prefix0 = null; postfix0 = null; table.isDragging2 = false; table.repaint(); } if (table.isOverDot) { // prevent UI manager from changing selection when mouse // is in a neighbor cell but is still over the dot region eConsumed = true; } if (table.isDragingDot) { if (table.dragingToColumn == -1 || table.dragingToRow == -1) return; int x1 = -1; int y1 = -1; int x2 = -1; int y2 = -1; // -|1|- // 2|-|3 // -|4|- if (table.dragingToColumn < table.minSelectionColumn) { // 2 x1 = table.dragingToColumn; y1 = table.minSelectionRow; x2 = table.minSelectionColumn - 1; y2 = table.maxSelectionRow; } else if (table.dragingToRow > table.maxSelectionRow) { // 4 x1 = table.minSelectionColumn; y1 = table.maxSelectionRow + 1; x2 = table.maxSelectionColumn; y2 = table.dragingToRow; } else if (table.dragingToRow < table.minSelectionRow) { // 1 x1 = table.minSelectionColumn; y1 = table.dragingToRow; x2 = table.maxSelectionColumn; y2 = table.minSelectionRow - 1; } else if (table.dragingToColumn > table.maxSelectionColumn) { // 3 x1 = table.maxSelectionColumn + 1; y1 = table.minSelectionRow; x2 = table.dragingToColumn; y2 = table.maxSelectionRow; } // copy the cells boolean succ = relativeCopy.doDragCopy( table.minSelectionColumn - 1, table.minSelectionRow - 1, table.maxSelectionColumn - 1, table.maxSelectionRow - 1, x1 - 1, y1 - 1, x2 - 1, y2 - 1); if (succ) { app.storeUndoInfo(); } // extend the selection to include the drag copy selection table.setSelection( Math.min(x1, table.minSelectionColumn) - 1, Math.min(y1, table.minSelectionRow) - 1, Math.max(x2, table.maxSelectionColumn) - 1, Math.max(y2, table.maxSelectionRow) - 1); // reset flags and cursor table.isOverDot = false; table.isDragingDot = false; table.dragingToRow = -1; table.dragingToColumn = -1; // TODO//setTableCursor(); // prevent UI manager from changing selection eConsumed = true; table.repaint(); } } // Alt click: copy definition to input field if (!table.isEditing() && e.isAltKeyDown() && app.showAlgebraInput()) { 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); if (geo != null) { // F3 key: copy definition to input bar app.getGlobalKeyDispatcher().handleFunctionKeyForAlgebraInput(3, geo); return; } } // handle right click if (rightClick) { if (!((AppW) kernel.getApplication()).letShowPopupMenu()) return; // change selection if right click is outside current selection if (p.getY() < table.minSelectionRow || p.getY() > table.maxSelectionRow || p.getX() < table.minSelectionColumn || p.getX() > table.maxSelectionColumn) { // switch to cell selection mode if (table.getSelectionType() != MyTable.CELL_SELECT) { table.setSelectionType(MyTable.CELL_SELECT); } // now change the selection if (p.getX() > 0 && p.getY() > 0) table.changeSelection(p.getY() - 1, p.getX() - 1, false, false); } // create and show context menu /*TODO SpreadsheetContextMenu popupMenu = new SpreadsheetContextMenu( table, e.isShiftDown()); popupMenu.show(e.getComponent(), e.getX(), e.getY());*/ } 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(); } } }
public void onMouseDown(MouseDownEvent e) { GPoint p = table.getIndexFromPixel(e.getClientX(), e.getClientY()); if (p.getY() == 0 && p.getX() > 0) { if (table.isEditing()) editor.cancelCellEditing(); table.scc.onMouseDown(e); return; } else if (p.getX() == 0 && p.getY() > 0) { if (table.isEditing()) editor.cancelCellEditing(); table.srh.onMouseDown(e); return; } // if (!view.hasViewFocus()) // ((LayoutW) app.getGuiManager().getLayout()).getDockManager() // .setFocusedPanel(App.VIEW_SPREADSHEET); view.requestFocus(); mouseIsDown = true; e.preventDefault(); boolean eConsumed = false; boolean rightClick = (e.getNativeButton() == NativeEvent.BUTTON_RIGHT); // tell selection listener about click on GeoElement if (!rightClick && app.getMode() == EuclidianConstants.MODE_SELECTION_LISTENER) { 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); // double click or empty geo if (geo != null) { // tell selection listener about click app.geoElementSelected(geo, false); return; } } if (!rightClick) { // memory testing // Application.debug("", true, true, 0); if (table.getSelectionType() != MyTable.CELL_SELECT) { table.setSelectionType(MyTable.CELL_SELECT); } // force column selection if (view.isColumnSelect()) { GPoint point = table.getIndexFromPixel(e.getClientX(), e.getClientY()); if (point != null) { int column = point.getX(); table.setColumnSelectionInterval(column, column); } } /* * if (MyTable.this.getSelectionModel().getSelectionMode() != * ListSelectionModel.SINGLE_INTERVAL_SELECTION) { * setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); * setColumnSelectionAllowed(true); setRowSelectionAllowed(true); } */ GPoint point1 = table.getMaxSelectionPixel(); if (point1 == null) return; // Handle click in another cell while editing a cell: // if the edit string begins with "=" then the clicked cell name // is inserted into the edit text if (editor.isEditing()) { String text = editor.getEditingValue(); if (text.startsWith("=")) { GPoint point = table.getIndexFromPixel(e.getClientX(), e.getClientY()); if (point != null && (point.getX() != editor.column || point.getY() != editor.row)) { // in Web, it's necessary to distinguish the editor row and column // because the event is not catched and not taken by the textfield int column = point.getX(); int row = point.getY(); GeoElement geo = RelativeCopy.getValue(app, column - 1, row - 1); if (geo != null) { // get cell name String name = GeoElementSpreadsheet.getSpreadsheetCellName(column - 1, row - 1); if (geo.isGeoFunction()) name += "(x)"; selectedCellName = name; // get prefix/post substrings for current text caret // position int caretPos = editor.getCaretPosition(); prefix0 = text.substring(0, caretPos); postfix0 = text.substring(caretPos, text.length()); table.isDragging2 = true; table.minColumn2 = column; table.maxColumn2 = column; table.minRow2 = row; table.maxRow2 = row; // insert the geo label into the editor string editor.addLabel(name); eConsumed = true; table.repaint(); } eConsumed = true; } } else { // if text does not start with "=" then stop the editor // and allow it to create/redefine a geo here editor.setAllowProcessGeo(true); editor.stopCellEditing(); editor.setAllowProcessGeo(false); table.finishEditing(); // almost like MyCellEditorW.stopCellEditing(int,int) } } else if (table.isOverDot) { table.isDragingDot = true; eConsumed = true; } } 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.anchorSelectionRow + 1 || p.getX() != table.anchorSelectionColumn + 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, false); table.repaint(); } } }