int w = right - left + 1;
int h = bottom - top + 1;
//check merge range;
JSONObject json = new JSONObject();
json.put("type", "jump");
json.put("left", left);
json.put("top", top);
json.put("width", w);
json.put("height", h);
SpreadsheetCtrl.Header header = SpreadsheetCtrl.Header.NONE;
if (!_hidecolhead && !_hiderowhead) {
header = SpreadsheetCtrl.Header.BOTH;
} else if (!_hidecolhead) {
header = SpreadsheetCtrl.Header.COLUMN;
} else if (!_hiderowhead) {
header = SpreadsheetCtrl.Header.ROW;
}
int preloadColSize = _spreadsheet.getPreloadColumnSize();
int preloadRowSize = _spreadsheet.getPreloadRowSize();
int re = top + h;
int ce = left + w;
int rangeLeft = left;
int rangeRight = right;
int rangeTop = top;
int rangeBtm = bottom;
if (preloadColSize > 0 && preloadRowSize > 0) {
//extends both
preloadColSize = preloadColSize / 2;
preloadRowSize = preloadRowSize / 2;
int newLeft = Math.max(rangeLeft - preloadColSize, 0);
int newTop = Math.max(rangeTop - preloadRowSize, 0);
int newRight = Math.min(rangeRight + preloadColSize, _spreadsheet.getMaxcolumns() - 1);
int newBtm = Math.min(rangeBtm + preloadRowSize, _spreadsheet.getMaxrows() - 1);
rangeTop = _mergeMatrix.getTopConnectedRow(newTop, newLeft, newRight);
rangeBtm = _mergeMatrix.getBottomConnectedRow(newBtm, newLeft, newRight);
rangeRight = _mergeMatrix.getRightConnectedColumn(newRight, newTop, newBtm);
rangeLeft = _mergeMatrix.getLeftConnectedColumn(newLeft, newTop, newBtm);
} else if (preloadColSize > 0) {
//extends range left and right
int preloadSize = preloadColSize / 2;
int newLeft = Math.max(rangeLeft - preloadSize, 0);
int newRight = Math.min(rangeRight + preloadSize, _spreadsheet.getMaxcolumns() - 1);
rangeLeft = _mergeMatrix.getLeftConnectedColumn(newLeft, rangeTop, rangeBtm);
rangeRight = _mergeMatrix.getRightConnectedColumn(newRight, rangeTop, rangeBtm);
} else if (preloadRowSize > 0) {
int preloadSize = preloadRowSize / 2;
int newTop = Math.max(rangeTop - preloadSize, 0);
int newBtm = Math.min(rangeBtm + preloadSize, _spreadsheet.getMaxrows() - 1);
rangeTop = _mergeMatrix.getTopConnectedRow(newTop, rangeLeft, rangeRight);
rangeBtm = _mergeMatrix.getBottomConnectedRow(newBtm, rangeLeft, rangeRight);
}
final SpreadsheetCtrl spreadsheetCtrl = ((SpreadsheetCtrl) _spreadsheet.getExtraCtrl());
JSONObject mainBlock = spreadsheetCtrl.getRangeAttrs(sheet,
header, SpreadsheetCtrl.CellAttribute.ALL, rangeLeft, rangeTop, rangeRight, rangeBtm);
mainBlock.put("dir", "jump");
json.put("data", mainBlock);
_lastleft = left;
_lastright = right;
_lasttop = top;
_lastbottom = bottom;
_loadedLeft = rangeLeft;
_loadedRight = rangeRight;
_loadedTop = rangeTop;
_loadedRight = rangeBtm;
// prepare top frozen cell
int fzr = _spreadsheet.getRowfreeze();
if (fzr > -1) {
mainBlock.put("topFrozen", spreadsheetCtrl.getRangeAttrs(sheet,
header, SpreadsheetCtrl.CellAttribute.ALL, rangeLeft, 0, rangeRight, fzr));
}
//prepare left frozen cell
int fzc = _spreadsheet.getColumnfreeze();
if (fzc > -1) {
mainBlock.put("leftFrozen", spreadsheetCtrl.getRangeAttrs(sheet,
header, SpreadsheetCtrl.CellAttribute.ALL, 0, rangeTop, fzc, rangeBtm));
}
return json.toString();
}