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); } }
/** 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); }
/** * 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; }