List of usage examples for javax.swing CellEditor cancelCellEditing
public void cancelCellEditing();
From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java
/** * Performs a clipboard function of pasting * * @param startRow - Where pasting is to start. If from selected row, supply -1 as a parameter * @param startCol - Where pasting is to start. If from selected column, supply -1 as a parameter * @param storeInHistory - variable to determine whether or not to store the paste action in the history *///from w w w .j a v a 2s . c o m public void paste(int startRow, int startCol, boolean storeInHistory) { CellEditor editor = spreadsheet.getTable().getCellEditor(); if (editor != null) { editor.cancelCellEditing(); } startRow = (startRow == -1) ? spreadsheet.getTable().getSelectedRow() : startRow; startCol = (startCol == -1) ? spreadsheet.getTable().getSelectedColumn() : startCol; //checks if anything is selected if (startRow != -1) { try { String trstring = (String) (spreadsheet.system.getContents(this) .getTransferData(DataFlavor.stringFlavor)); SpreadsheetCellPoint size = SpreadsheetModel.getSize(trstring, '\t'); int rowSpaceToFill = (size.getRow()); int endRow = Math.min(spreadsheet.getTable().getRowCount() - 1, (startRow + size.getRow()) - 1); int endCol = Math.min(spreadsheet.getTable().getColumnCount() - 1, (startCol + size.getCol()) - 1); int colSpaceToFill = (endCol - startCol) + 1; int[] colRange = new int[colSpaceToFill]; int[] rowRange = new int[rowSpaceToFill]; if (colSpaceToFill > 0) { colRange = new int[colSpaceToFill]; int startVal = 0; for (int val = startCol; val <= endCol; val++) { colRange[startVal] = val; startVal++; } } if (rowSpaceToFill > 0) { rowRange = new int[rowSpaceToFill]; int startVal = 0; for (int val = startRow; val <= endRow; val++) { rowRange[startVal] = val; startVal++; } } if (colRange.length == 0) { colRange = new int[1]; colRange[0] = startCol; } if (rowRange.length == 0) { rowRange = new int[1]; rowRange[0] = startRow; } SpreadsheetCellRange affectedRange = new SpreadsheetCellRange(rowRange, Utils.convertSelectedColumnsToModelIndices(spreadsheet.getTable(), colRange)); // add to history if (storeInHistory) { spreadsheet.spreadsheetHistory.add(affectedRange); } spreadsheet.spreadsheetModel.extendedFromString(trstring, '\t', affectedRange); spreadsheet.spreadsheetModel.extendedSetSelection(affectedRange); spreadsheet.getTable().repaint(); spreadsheet.notifyObservers(SpreadsheetEvent.PASTE); } catch (Exception e) { e.printStackTrace(); } } }
From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java
/** * Performs a clipboard function of cut/copy * * @param isCut true for cut, false for copy * @param toUse - the SpreadsheetCellRange representing the values to be pasted into the spreadsheet *///w w w . j a va 2s . c o m public void doCopy(boolean isCut, SpreadsheetCellRange toUse) { CellEditor editor = spreadsheet.getTable().getCellEditor(); if (editor != null) { editor.cancelCellEditing(); } boolean modifiedCellRange = false; if (spreadsheet.getTable().getSelectedRowCount() != 0 || toUse != null) { if (toUse == null) { toUse = new SpreadsheetCellRange(spreadsheet.getTable().getSelectedRows(), Utils.convertSelectedColumnsToModelIndices(spreadsheet.getTable(), spreadsheet.getTable().getSelectedColumns())); modifiedCellRange = true; } if (isCut && modifiedCellRange) { spreadsheet.spreadsheetHistory.add(toUse); } String str = spreadsheet.spreadsheetModel.extendedToString(toUse, '\t'); StringSelection stsel = new StringSelection(str); spreadsheet.system.setContents(stsel, stsel); if (isCut) { spreadsheet.spreadsheetModel.clearRange(toUse); } spreadsheet.notifyObservers(SpreadsheetEvent.COPY); } else { System.out.println("no rows are selected so no copying has taken place."); } }
From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java
/** * Fill a range of cells with a given value (or formula) * * @param range The range to fill//ww w . j a va2 s . c om * @param value The value to fill. Should begin with '=' for a formula. */ public void fill(SpreadsheetCellRange range, String value) { CellEditor editor = spreadsheet.getTable().getCellEditor(); if (editor != null) { editor.cancelCellEditing(); } spreadsheet.spreadsheetHistory.add(range); spreadsheet.spreadsheetModel.fillRange(range, value); spreadsheet.spreadsheetModel.fireTableDataChanged(); }