public static int width(IGridRegion i1) { return i1.getRight() - i1.getLeft() + 1; }
public int getWidth() { return region.getRight() - region.getLeft() + 1; }
@Override public int getWidth() { IGridRegion region = getRegion(); return region == null ? 1 : region.getRight() - region.getLeft() + 1; }
/** * @param region Region to register in the pool */ public void add(IGridRegion region) { for (int row = region.getTop(); row <= region.getBottom(); row++) { Map<DisjointInterval, IGridRegion> regionsMap = pool.get(row); if (regionsMap == null) { regionsMap = new TreeMap<DisjointInterval, IGridRegion>(); pool.put(row, regionsMap); } regionsMap.put(new DisjointInterval(region.getLeft(), region.getRight()), region); } }
public int getWidth() { if (region == null){ return delegate.getWidth(); } return region.getRight() - region.getLeft() + 1; }
public static boolean intersects(IGridRegion i1, IGridRegion i2) { int left = Math.max(i1.getLeft(), i2.getLeft()); int right = Math.min(i1.getRight(), i2.getRight()); if (right < left) { return false; } int top = Math.max(i1.getTop(), i2.getTop()); int bottom = Math.min(i1.getBottom(), i2.getBottom()); return top <= bottom; }
public void remove(IGridRegion region) { if (region != null) { for (int row = region.getTop(); row <= region.getBottom(); row++) { Map<DisjointInterval, IGridRegion> regionsMap = pool.get(row); regionsMap.remove(new DisjointInterval(region.getLeft(), region.getRight())); if (regionsMap.isEmpty()) { pool.remove(row); } } } }
/** * Finds common {@link IGridRegion} for incoming regions. * * @param i1 first grid region * @param i2 second grid region * @return intersection of incoming grid regions. <code>null</code> if there is no intersection. */ public static IGridRegion intersect(IGridRegion i1, IGridRegion i2) { int left = Math.max(i1.getLeft(), i2.getLeft()); int right = Math.min(i1.getRight(), i2.getRight()); int top = Math.max(i1.getTop(), i2.getTop()); int bottom = Math.min(i1.getBottom(), i2.getBottom()); return top <= bottom && left <= right ? new GridRegion(top, left, bottom, right) : null; }
public void resizeRegion(boolean isInsert, boolean isColumns, int rowsOrColumns, IGridRegion r) { int inc = isInsert ? rowsOrColumns : -rowsOrColumns; if (isColumns) { ((GridRegion) r).setRight(r.getRight() + inc); } else { ((GridRegion) r).setBottom(r.getBottom() + inc); } }
public GridRegion(IGridRegion g) { top = g.getTop(); left = g.getLeft(); bottom = g.getBottom(); right = g.getRight(); }
public static boolean isValidRegion(IGridRegion region, SpreadsheetConstants spreadsheetConstants) { int rowIndex = region.getBottom(); int columnIndex = region.getRight(); return rowIndex >= 0 && rowIndex <= spreadsheetConstants.getMaxRowIndex() && columnIndex >= 0 && columnIndex <= spreadsheetConstants.getMaxColumnIndex(); } }
public static IUndoableGridTableAction removeColumns(int nCols, int startColumn, IGridRegion region, IGrid grid, MetaInfoWriter metaInfoWriter) { int firstToMove = region.getLeft() + startColumn + nCols; int w = IGridRegion.Tool.width(region); int h = IGridRegion.Tool.height(region); ArrayList<IUndoableGridTableAction> actions = new ArrayList<>(h * (w - startColumn)); // resize merged regions -> shift cells by column -> clear cells actions.addAll(resizeMergedRegions(grid, startColumn, nCols, REMOVE, COLUMNS, region, metaInfoWriter)); actions.addAll(shiftColumns(firstToMove, nCols, REMOVE, region, grid, metaInfoWriter)); actions.addAll(clearCells(region.getRight() + 1 - nCols, nCols, region.getTop(), h, grid, metaInfoWriter)); return new UndoableCompositeAction(actions); }
/** * Gets the URI to the table by table region. Just calls * {@link XlsSheetGridModel#getRangeUri(int, int, int, int)}. * * @param region Table region. * @return URI to the table in the sheet. (e.g. * <code>file:D:\work\Workspace\org.openl.tablets.tutorial4\rules * \main&wbName=Tutorial_4.xls&wsName=Vehicle-Scoring&range=B3:D12</code>) */ public String getRangeUri(IGridRegion region) { return getRangeUri(region.getLeft(), region.getTop(), region.getRight(), region.getBottom()); }
private Object findFirstValueInRegion(IGridRegion reg) { for (int row = reg.getTop(); row <= reg.getBottom(); row++) { for (int column = reg.getLeft(); column <= reg.getRight(); column++) { Object cellValue = getCell(column, row).getObjectValue(); if (cellValue != null) { return cellValue; } } } return null; }
public MetaInfoWriterImpl(MetaInfoReader delegate, IGridTable gridTable) { // Copy all meta info for a given table from delegate. IGridRegion region = GridTableUtils.getOriginalTable(gridTable).getRegion(); int top = region.getTop(); int left = region.getLeft(); int bottom = region.getBottom(); int right = region.getRight(); for (int row = top; row <= bottom; row++) { for (int col = left; col <= right; col++) { CellKey key = CellKey.CellKeyFactory.getCellKey(col, row); metaInfoMap.put(key, delegate.getMetaInfo(row, col)); } } }
public int getWidth(ICell cell) { IGridRegion gr; if ((gr = cell.getRegion()) == null) { return grid.getColumnWidth(cell.getColumn()); } int w = 0; gr = IGridRegion.Tool.intersect(gr, reg); if (gr != null) { for (int c = gr.getLeft(); c <= gr.getRight(); c++) { w += grid.getColumnWidth(c); } } return w; }
public void moveRegion(boolean isInsert, boolean isColumns, int rowsOrColumns, IGridRegion r) { int inc = isInsert ? rowsOrColumns : -rowsOrColumns; if (isColumns) { ((GridRegion) r).setLeft(r.getLeft() + inc); ((GridRegion) r).setRight(r.getRight() + inc); } else { ((GridRegion) r).setTop(r.getTop() + inc); ((GridRegion) r).setBottom(r.getBottom() + inc); } } }
public static boolean canInsertRows(IGridTable table, int nRows) { IGridRegion region = getOriginalRegion(table); GridRegion newRegion = new GridRegion(region.getBottom() + 1, region.getLeft() - 1, region.getBottom() + 1 + nRows, region.getRight() + 1); IGridTable[] allGridTables = table.getGrid().getTables(); for (IGridTable allGridTable : allGridTables) { if (!table.getUri().equals(allGridTable.getUri()) && IGridRegion.Tool.intersects(newRegion, allGridTable.getRegion())) { return false; } } return true; }
public int addMergedRegion(IGridRegion reg) { Object topLeftCellValue = findFirstValueInRegion(reg); for (int row = reg.getTop(); row <= reg.getBottom(); row++) { for (int column = reg.getLeft(); column <= reg.getRight(); column++) { if (column != reg.getLeft() || row != reg.getTop()) clearCellValue(column, row); } } setCellValue(reg.getLeft(), reg.getTop(), topLeftCellValue); getMergedRegionsPool().add(reg); return getSheet() .addMergedRegion(new CellRangeAddress(reg.getTop(), reg.getBottom(), reg.getLeft(), reg.getRight())); }
/** * Usually there is a parameter duplication: the same column and row exist in cell object. * But sometimes cell is null, so we will have just the coordinates of the cell. */ public XlsCell(int column, int row, XlsSheetGridModel gridModel) { this.column = column; this.row = row; this.region = gridModel.getRegionContaining(column, row); this.cellLoader = gridModel.getSheetSource().getSheetLoader().getCellLoader(column, row); if (region != null && region.getLeft() == column && region.getTop() == row) { this.width = region.getRight() - region.getLeft() + 1; this.height = region.getBottom() - region.getTop() + 1; } this.gridModel = gridModel; }