/** * @param cellIndex column or row index, depending on isRow parameter; must be in the range 0..grid.get{Row|Column}Count()-1 * @param isRow if true, row inserted, otherwise column * @param isBefore if true, row/column will be inserted before row/column with given index, otherwise after */ public static void insertRowOrColumn(final RadContainer grid, final int cellIndex, final boolean isRow, final boolean isBefore) { check(grid, isRow, cellIndex); final RadAbstractGridLayoutManager oldLayout = grid.getGridLayoutManager(); int beforeIndex = cellIndex; if (!isBefore) { // beforeIndex can actually be equal to get{Row|Column}Count an case we add row after the last row/column beforeIndex++; } final LayoutManager newLayout = oldLayout.copyLayout(grid.getLayout(), isRow ? 1 : 0, isRow ? 0 : 1); GridConstraints[] oldConstraints = copyConstraints(grid); for (int i=grid.getComponentCount() - 1; i >= 0; i--){ final GridConstraints constraints = grid.getComponent(i).getConstraints(); adjustConstraintsOnInsert(constraints, isRow, beforeIndex, 1); } grid.setLayout(newLayout); fireAllConstraintsChanged(grid, oldConstraints); }
@Override public void processDrop(final GuiEditor editor, final RadComponent[] components, final GridConstraints[] constraintsToAdjust, final ComponentDragObject dragObject) { RadAbstractGridLayoutManager gridLayout = myContainer.getGridLayoutManager(); if (myContainer.getGridRowCount() == 0) { gridLayout.insertGridCells(myContainer, 0, true, true, true); } if (myContainer.getGridColumnCount() == 0) { gridLayout.insertGridCells(myContainer, 0, false, true, true); } dropIntoGrid(myContainer, components, myRow, myColumn, dragObject); FormLayout formLayout = (FormLayout) myContainer.getDelegee().getLayout(); if (myXPart == 0) { formLayout.setColumnSpec(1, new ColumnSpec("d")); } else if (myXPart == 2) { gridLayout.insertGridCells(myContainer, 0, false, true, true); } if (myYPart == 0) { formLayout.setRowSpec(1, new RowSpec("d")); } else if (myYPart == 2) { gridLayout.insertGridCells(myContainer, 0, true, true, true); } }
@Override public void processDrop(final GuiEditor editor, final RadComponent[] components, final GridConstraints[] constraintsToAdjust, final ComponentDragObject dragObject) { RadAbstractGridLayoutManager gridLayout = myContainer.getGridLayoutManager(); if (myContainer.getGridRowCount() == 0) { gridLayout.insertGridCells(myContainer, 0, true, true, true); } if (myContainer.getGridColumnCount() == 0) { gridLayout.insertGridCells(myContainer, 0, false, true, true); } dropIntoGrid(myContainer, components, myRow, myColumn, dragObject); FormLayout formLayout = (FormLayout) myContainer.getDelegee().getLayout(); if (myXPart == 0) { formLayout.setColumnSpec(1, ColumnSpec.decode("d")); } else if (myXPart == 2) { gridLayout.insertGridCells(myContainer, 0, false, true, true); } if (myYPart == 0) { formLayout.setRowSpec(1, RowSpec.decode("d")); } else if (myYPart == 2) { gridLayout.insertGridCells(myContainer, 0, true, true, true); } }
/** * @param cellIndex column or row index, depending on isRow parameter; must be in the range 0..grid.get{Row|Column}Count()-1 * @param isRow if true, row is deleted, otherwise column */ public static void deleteCell(final RadContainer grid, final int cellIndex, final boolean isRow) { check(grid, isRow, cellIndex); if (canDeleteCell(grid, cellIndex, isRow) == CellStatus.Required) { throw new IllegalArgumentException("cell cannot be deleted"); } final RadAbstractGridLayoutManager oldLayout = grid.getGridLayoutManager(); final LayoutManager newLayout = oldLayout.copyLayout(grid.getLayout(), isRow ? -1 : 0, isRow ? 0 : -1); GridConstraints[] oldConstraints = copyConstraints(grid); for (int i=grid.getComponentCount() - 1; i >= 0; i--){ final GridConstraints constraints = grid.getComponent(i).getConstraints(); if (constraints.getCell(isRow) > cellIndex) { // component starts after the cell being deleted - move it addToCell(constraints, isRow, -1); } else if (isCellInsideComponent(constraints, isRow, cellIndex)) { // component belongs to the cell being deleted - decrement component's span addToSpan(constraints, isRow, -1); } } grid.setLayout(newLayout); fireAllConstraintsChanged(grid, oldConstraints); }
private static void deleteEmptyGridCells(final RadContainer parent, final GridConstraints delConstraints, final boolean isRow) { final RadAbstractGridLayoutManager layoutManager = parent.getGridLayoutManager(); for (int cell = delConstraints.getCell(isRow) + delConstraints.getSpan(isRow) - 1; cell >= delConstraints.getCell(isRow); cell--) { if (cell < parent.getGridCellCount(isRow) && GridChangeUtil.canDeleteCell(parent, cell, isRow) == GridChangeUtil.CellStatus.Empty && !layoutManager.isGapCell(parent, isRow, cell)) { layoutManager.deleteGridCells(parent, cell, isRow); } } }
@Override public void processDrop(final GuiEditor editor, final RadComponent[] components, final GridConstraints[] constraintsToAdjust, final ComponentDragObject dragObject) { RadAbstractGridLayoutManager gridLayout = myContainer.getGridLayoutManager(); if (myContainer.getGridRowCount() == 0 && myContainer.getGridColumnCount() == 0) { gridLayout.insertGridCells(myContainer, 0, false, true, true); gridLayout.insertGridCells(myContainer, 0, true, true, true); } super.processDrop(editor, components, constraintsToAdjust, dragObject); Palette palette = Palette.getInstance(editor.getProject()); ComponentItem hSpacerItem = palette.getItem(HSpacer.class.getName()); ComponentItem vSpacerItem = palette.getItem(VSpacer.class.getName()); InsertComponentProcessor icp = new InsertComponentProcessor(editor); if (myXPart == 0) { insertSpacer(icp, hSpacerItem, GridInsertMode.ColumnAfter); } if (myXPart == 2) { insertSpacer(icp, hSpacerItem, GridInsertMode.ColumnBefore); } if (myYPart == 0) { insertSpacer(icp, vSpacerItem, GridInsertMode.RowAfter); } if (myYPart == 2) { insertSpacer(icp, vSpacerItem, GridInsertMode.RowBefore); } }
public GridInsertLocation normalize() { final RadAbstractGridLayoutManager gridManager = myContainer.getGridLayoutManager(); if (myMode == GridInsertMode.RowBefore && myRow > 0) { myMode = GridInsertMode.RowAfter; myRow--; } else if (myMode == GridInsertMode.ColumnBefore && myColumn > 0) { myMode = GridInsertMode.ColumnAfter; myColumn--; } if (myMode == GridInsertMode.RowAfter && gridManager.isGapCell(myContainer, true, myRow)) { myRow--; } else if (myMode == GridInsertMode.RowBefore && gridManager.isGapCell(myContainer, true, myRow)) { myRow++; } else if (myMode == GridInsertMode.ColumnAfter && gridManager.isGapCell(myContainer, false, myColumn)) { myColumn--; } else if (myMode == GridInsertMode.ColumnBefore && gridManager.isGapCell(myContainer, false, myColumn)) { myColumn++; } return this; }
private boolean isInsertInsideComponent(final int size) { int endColumn = getInsertCell(); if (isInsertAfter()) endColumn++; int row = getOppositeCell(); for(int r=row; r<row+size; r++) { for(int col = 0; col<endColumn; col++) { RadComponent component; if (isColumnInsert()) { component = RadAbstractGridLayoutManager.getComponentAtGrid(getContainer(), r, col); } else { component = RadAbstractGridLayoutManager.getComponentAtGrid(getContainer(), col, r); } if (component != null) { GridConstraints constraints = component.getConstraints(); final boolean isRow = !isColumnInsert(); if (constraints.getCell(isRow) + constraints.getSpan(isRow) > endColumn && constraints.getSpan(isRow) > 1) { return true; } } } } return false; }
private static void deleteEmptyGridCells(final RadContainer parent, final GridConstraints delConstraints, final boolean isRow) { final RadAbstractGridLayoutManager layoutManager = parent.getGridLayoutManager(); for(int cell = delConstraints.getCell(isRow) + delConstraints.getSpan(isRow) - 1; cell >= delConstraints.getCell(isRow); cell--) { if(cell < parent.getGridCellCount(isRow) && GridChangeUtil.canDeleteCell(parent, cell, isRow) == GridChangeUtil.CellStatus.Empty && !layoutManager.isGapCell(parent, isRow, cell)) { layoutManager.deleteGridCells(parent, cell, isRow); } } }
public GridSpanInsertProcessor(RadContainer container, int insertRow, int insertColumn, GridInsertMode mode, ComponentDragObject dragObject) { myContainer = container; myLayoutManager = container.getGridLayoutManager(); myRow = insertRow; myColumn = insertColumn; int[] vGridLines = myLayoutManager.getVerticalGridLines(container); int[] hGridLines = myLayoutManager.getHorizontalGridLines(container); RadComponent component = RadAbstractGridLayoutManager.getComponentAtGrid(container, insertRow, insertColumn); if (component != null) { int lastColIndex = insertColumn + dragObject.getColSpan(0); if (lastColIndex > vGridLines.length - 1) { lastColIndex = insertColumn + 1; } int lastRowIndex = insertRow + dragObject.getRowSpan(0); if (lastRowIndex > hGridLines.length - 1) { lastRowIndex = insertRow + 1; } Rectangle bounds = component.getBounds(); bounds.translate(-vGridLines[insertColumn], -hGridLines[insertRow]); int spaceToRight = vGridLines[lastColIndex] - vGridLines[insertColumn] - (bounds.x + bounds.width); int spaceBelow = hGridLines[lastRowIndex] - hGridLines[insertRow] - (bounds.y + bounds.height); if (mode == GridInsertMode.RowBefore && bounds.y > GridInsertLocation.INSERT_RECT_MIN_SIZE) { myMode = GridInsertMode.RowBefore; myInsertCellComponent = component; } else if (mode == GridInsertMode.RowAfter && spaceBelow > GridInsertLocation.INSERT_RECT_MIN_SIZE) { myMode = GridInsertMode.RowAfter; } else if (mode == GridInsertMode.ColumnBefore && bounds.x > GridInsertLocation.INSERT_RECT_MIN_SIZE) { myMode = GridInsertMode.ColumnBefore; myInsertCellComponent = component; } else if (mode == GridInsertMode.ColumnAfter && spaceToRight > GridInsertLocation.INSERT_RECT_MIN_SIZE) { myMode = GridInsertMode.ColumnAfter; } } }
public static Rectangle getInsertFeedbackPosition(final GridInsertMode mode, final RadContainer container, final Rectangle cellRect, final Rectangle feedbackRect) { final RadAbstractGridLayoutManager manager = container.getGridLayoutManager(); int[] vGridLines = manager.getVerticalGridLines(container); int[] hGridLines = manager.getHorizontalGridLines(container); Rectangle rc = feedbackRect; int w=4; switch (mode) { case ColumnBefore: rc = new Rectangle(vGridLines [cellRect.x] - w, feedbackRect.y - INSERT_ARROW_SIZE, 2 * w, feedbackRect.height + 2 * INSERT_ARROW_SIZE); if (cellRect.x > 0 && manager.isGapCell(container, false, cellRect.x-1)) { rc.translate(-(vGridLines [cellRect.x] - vGridLines [cellRect.x-1]) / 2, 0); } break; case ColumnAfter: rc = new Rectangle(vGridLines [cellRect.x + cellRect.width+1] - w, feedbackRect.y - INSERT_ARROW_SIZE, 2 * w, feedbackRect.height + 2 * INSERT_ARROW_SIZE); if (cellRect.x < manager.getGridColumnCount(container)-1 && manager.isGapCell(container, false, cellRect.x+1)) { rc.translate((vGridLines [cellRect.x+2] - vGridLines [cellRect.x+1]) / 2, 0); } break; case RowBefore: rc = new Rectangle(feedbackRect.x - INSERT_ARROW_SIZE, hGridLines [cellRect.y] - w, feedbackRect.width + 2 * INSERT_ARROW_SIZE, 2 * w); if (cellRect.y > 0 && manager.isGapCell(container, true, cellRect.y-1)) { rc.translate(0, -(hGridLines [cellRect.y] - hGridLines [cellRect.y-1]) / 2); } break; case RowAfter: rc = new Rectangle(feedbackRect.x - INSERT_ARROW_SIZE, hGridLines [cellRect.y+cellRect.height+1] - w, feedbackRect.width + 2 * INSERT_ARROW_SIZE, 2 * w); if (cellRect.y < manager.getGridRowCount(container)-1 && manager.isGapCell(container, true, cellRect.y+1)) { rc.translate(0, (hGridLines [cellRect.y+2] - hGridLines [cellRect.y+1]) / 2); } break; } return rc; }