use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class GridDropLocation method canDrop.
public boolean canDrop(final ComponentDragObject dragObject) {
// If target point doesn't belong to any cell and column then do not allow drop.
if (myRow == -1 || myColumn == -1) {
LOG.debug("RadContainer.canDrop=false because no cell at mouse position");
return false;
}
// allow drop any (NxM) component to cell (1x1)
int colSpan = 1;
int rowSpan = 1;
for (int i = 0; i < dragObject.getComponentCount(); i++) {
int relativeCol = dragObject.getRelativeCol(i);
int relativeRow = dragObject.getRelativeRow(i);
LOG.debug("checking component: relativeRow" + relativeRow + ", relativeCol" + relativeCol + ", colSpan=" + colSpan + ", rowSpan=" + rowSpan);
if (myRow + relativeRow < 0 || myColumn + relativeCol < 0 || myRow + relativeRow + rowSpan > myContainer.getGridRowCount() || myColumn + relativeCol + colSpan > myContainer.getGridColumnCount()) {
LOG.debug("RadContainer.canDrop=false because range is outside grid: row=" + (myRow + relativeRow) + ", col=" + (myColumn + relativeCol) + ", colSpan=" + colSpan + ", rowSpan=" + rowSpan);
return false;
}
final RadComponent componentInRect = findOverlappingComponent(myRow + relativeRow, myColumn + relativeCol, rowSpan, colSpan);
if (componentInRect != null) {
LOG.debug("GridDropLocation.canDrop=false because found component " + componentInRect.getId() + " in rect (row=" + (myRow + relativeRow) + ", col=" + (myColumn + relativeCol) + ", rowSpan=" + rowSpan + ", colSpan=" + colSpan + ")");
return false;
}
}
LOG.debug("canDrop=true");
return true;
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class GridDropLocation method dropIntoGrid.
protected static void dropIntoGrid(final RadContainer container, final RadComponent[] components, int row, int column, final ComponentDragObject dragObject) {
assert components.length > 0;
for (int i = 0; i < components.length; i++) {
RadComponent c = components[i];
if (c instanceof RadContainer) {
final LayoutManager layout = ((RadContainer) c).getLayout();
if (layout instanceof XYLayoutManager) {
((XYLayoutManager) layout).setPreferredSize(c.getSize());
}
}
int relativeCol = dragObject.getRelativeCol(i);
int relativeRow = dragObject.getRelativeRow(i);
LOG.debug("dropIntoGrid: relativeRow=" + relativeRow + ", relativeCol=" + relativeCol);
int colSpan = dragObject.getColSpan(i);
int rowSpan = dragObject.getRowSpan(i);
assert row + relativeRow >= 0;
assert column + relativeCol >= 0;
if (rowSpan > 1 || colSpan > 1) {
if ((row + relativeRow + rowSpan > container.getGridRowCount() && rowSpan > 1) || (column + relativeCol + colSpan > container.getGridColumnCount() && colSpan > 1) || container.findComponentInRect(row + relativeRow, column + relativeCol, rowSpan, colSpan) != null) {
rowSpan = 1;
colSpan = 1;
}
}
if (!container.getGridLayoutManager().isGridDefinedByComponents()) {
assert relativeRow + rowSpan <= container.getGridRowCount();
assert relativeCol + colSpan <= container.getGridColumnCount();
}
RadComponent old = container.findComponentInRect(row + relativeRow, column + relativeCol, rowSpan, colSpan);
if (old != null) {
LOG.error("Drop rectangle not empty: (" + (row + relativeRow) + ", " + (column + relativeCol) + ", " + rowSpan + ", " + colSpan + "), component ID=" + old.getId());
}
final GridConstraints constraints = c.getConstraints();
constraints.setRow(row + relativeRow);
constraints.setColumn(column + relativeCol);
constraints.setRowSpan(rowSpan);
constraints.setColSpan(colSpan);
LOG.info("GridDropLocation.dropIntoGrid() constraints=" + constraints);
container.addComponent(c);
// Fill DropInfo
c.revalidate();
}
container.revalidate();
LOG.info("GridDropLocation.dropIntoGrid() done");
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class GridInsertLocation method isInsertInsideComponent.
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;
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class GridInsertLocation method placeFeedback.
@Override
public void placeFeedback(FeedbackLayer feedbackLayer, ComponentDragObject dragObject) {
final int insertCol = getColumn();
final int insertRow = getRow();
Rectangle feedbackRect = getGridFeedbackRect(dragObject, isColumnInsert(), isRowInsert(), false);
if (feedbackRect == null) {
feedbackLayer.removeFeedback();
return;
}
Rectangle cellRect = getGridFeedbackCellRect(dragObject, isColumnInsert(), isRowInsert(), false);
assert cellRect != null;
final RadAbstractGridLayoutManager layoutManager = getContainer().getGridLayoutManager();
int[] vGridLines = layoutManager.getVerticalGridLines(getContainer());
int[] hGridLines = layoutManager.getHorizontalGridLines(getContainer());
FeedbackPainter painter = (myMode == GridInsertMode.ColumnBefore || myMode == GridInsertMode.ColumnAfter) ? VertInsertFeedbackPainter.INSTANCE : HorzInsertFeedbackPainter.INSTANCE;
Rectangle rc;
Rectangle rcFeedback = null;
if (dragObject.getComponentCount() == 1) {
int lastColIndex = insertCol + dragObject.getColSpan(0);
if (lastColIndex > vGridLines.length - 1) {
lastColIndex = insertCol + 1;
}
int lastRowIndex = insertRow + dragObject.getRowSpan(0);
if (lastRowIndex > hGridLines.length - 1) {
lastRowIndex = insertRow + 1;
}
int cellWidth = vGridLines[lastColIndex] - vGridLines[insertCol];
int cellHeight = hGridLines[lastRowIndex] - hGridLines[insertRow];
RadComponent component = layoutManager.getComponentAtGrid(getContainer(), insertRow, insertCol);
if (component != null && mySpanInsertMode) {
Rectangle bounds = component.getBounds();
bounds.translate(-vGridLines[insertCol], -hGridLines[insertRow]);
int spaceToRight = vGridLines[lastColIndex] - vGridLines[insertCol] - (bounds.x + bounds.width);
int spaceBelow = hGridLines[lastRowIndex] - hGridLines[insertRow] - (bounds.y + bounds.height);
if (myMode == GridInsertMode.RowBefore && bounds.y > INSERT_RECT_MIN_SIZE) {
rcFeedback = new Rectangle(0, 0, cellWidth, bounds.y);
} else if (myMode == GridInsertMode.RowAfter && spaceBelow > INSERT_RECT_MIN_SIZE) {
rcFeedback = new Rectangle(0, bounds.y + bounds.height, cellWidth, spaceBelow);
} else if (myMode == GridInsertMode.ColumnBefore && bounds.x > INSERT_RECT_MIN_SIZE) {
rcFeedback = new Rectangle(0, 0, bounds.x, cellHeight);
} else if (myMode == GridInsertMode.ColumnAfter && spaceToRight > INSERT_RECT_MIN_SIZE) {
rcFeedback = new Rectangle(bounds.x + bounds.width, 0, spaceToRight, cellHeight);
}
if (rcFeedback != null) {
boolean spanInsertMode = false;
if (isRowInsert()) {
int columns = layoutManager.getGridColumnCount(getContainer());
for (int i = 0; i < columns; i++) {
if (i != insertCol && RadAbstractGridLayoutManager.getComponentAtGrid(getContainer(), insertRow, i) != null) {
spanInsertMode = true;
break;
}
}
} else {
int rows = layoutManager.getGridRowCount(getContainer());
for (int i = 0; i < rows; i++) {
if (i != insertRow && RadAbstractGridLayoutManager.getComponentAtGrid(getContainer(), i, insertCol) != null) {
spanInsertMode = true;
break;
}
}
}
if (!spanInsertMode) {
rcFeedback = null;
}
}
if (rcFeedback != null) {
rcFeedback.translate(vGridLines[insertCol], hGridLines[insertRow]);
}
}
if (rcFeedback == null) {
if (insertCol == layoutManager.getGridColumnCount(getContainer()) - 1 && myMode == GridInsertMode.ColumnAfter) {
final Dimension initialSize = dragObject.getInitialSize(getContainer());
int feedbackX = vGridLines[vGridLines.length - 1] + layoutManager.getGapCellSize(myContainer, false);
int remainingSize = getContainer().getDelegee().getWidth() - feedbackX;
if (!dragObject.isHGrow() && remainingSize > initialSize.width) {
if (dragObject.isVGrow() || initialSize.height > cellHeight) {
rcFeedback = new Rectangle(feedbackX, hGridLines[insertRow], initialSize.width, cellHeight);
} else {
rcFeedback = new Rectangle(feedbackX, hGridLines[insertRow] + (cellHeight - initialSize.height) / 2, initialSize.width, initialSize.height);
}
} else if (remainingSize >= 4) {
rcFeedback = new Rectangle(feedbackX, hGridLines[insertRow], remainingSize, cellHeight);
}
} else if (insertRow == layoutManager.getGridRowCount(getContainer()) - 1 && myMode == GridInsertMode.RowAfter) {
final Dimension initialSize = dragObject.getInitialSize(getContainer());
int feedbackY = hGridLines[hGridLines.length - 1] + layoutManager.getGapCellSize(myContainer, true);
int remainingSize = getContainer().getDelegee().getHeight() - feedbackY;
if (!dragObject.isVGrow() && remainingSize > initialSize.height) {
rcFeedback = new Rectangle(vGridLines[insertCol], feedbackY, cellWidth, initialSize.height);
} else if (remainingSize >= 4) {
rcFeedback = new Rectangle(vGridLines[insertCol], feedbackY, cellWidth, remainingSize);
}
}
}
}
if (rcFeedback != null) {
feedbackLayer.putFeedback(getContainer().getDelegee(), rcFeedback, getInsertFeedbackTooltip());
return;
}
rc = getInsertFeedbackPosition(myMode, getContainer(), cellRect, feedbackRect);
feedbackLayer.putFeedback(getContainer().getDelegee(), rc, painter, getInsertFeedbackTooltip());
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class GridInsertProcessor method getDropTargetContainer.
public static RadContainer getDropTargetContainer(final RadRootContainer rootContainer, final Point aPoint) {
int EPSILON = 4;
RadContainer container = FormEditingUtil.getRadContainerAt(rootContainer, aPoint.x, aPoint.y, EPSILON);
// to facilitate initial component adding, increase stickiness if there is one container at top level
if (container instanceof RadRootContainer && rootContainer.getComponentCount() == 1) {
final RadComponent singleComponent = rootContainer.getComponents()[0];
if (singleComponent instanceof RadContainer) {
Rectangle rc = singleComponent.getDelegee().getBounds();
rc.grow(EPSILON * 2, EPSILON * 2);
if (rc.contains(aPoint)) {
container = (RadContainer) singleComponent;
EPSILON *= 2;
}
}
}
return container;
}
Aggregations