Search in sources :

Example 1 with RadAbstractGridLayoutManager

use of com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager in project intellij-community by JetBrains.

the class GridInsertLocation method normalize.

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;
}
Also used : RadAbstractGridLayoutManager(com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager)

Example 2 with RadAbstractGridLayoutManager

use of com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager 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());
}
Also used : RadAbstractGridLayoutManager(com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent)

Example 3 with RadAbstractGridLayoutManager

use of com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager in project intellij-community by JetBrains.

the class GridInsertLocation method getInsertFeedbackPosition.

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;
}
Also used : RadAbstractGridLayoutManager(com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager)

Example 4 with RadAbstractGridLayoutManager

use of com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager in project intellij-community by JetBrains.

the class FirstComponentInsertLocation method processDrop.

@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);
    }
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) VSpacer(com.intellij.uiDesigner.VSpacer) Palette(com.intellij.uiDesigner.palette.Palette) RadAbstractGridLayoutManager(com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager) HSpacer(com.intellij.uiDesigner.HSpacer)

Example 5 with RadAbstractGridLayoutManager

use of com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager in project intellij-community by JetBrains.

the class FormFirstComponentInsertLocation method processDrop.

@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);
    }
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) RadAbstractGridLayoutManager(com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager) ColumnSpec(com.jgoodies.forms.layout.ColumnSpec) RowSpec(com.jgoodies.forms.layout.RowSpec)

Aggregations

RadAbstractGridLayoutManager (com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager)8 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)2 HSpacer (com.intellij.uiDesigner.HSpacer)1 VSpacer (com.intellij.uiDesigner.VSpacer)1 ComponentItem (com.intellij.uiDesigner.palette.ComponentItem)1 Palette (com.intellij.uiDesigner.palette.Palette)1 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)1 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)1 ColumnSpec (com.jgoodies.forms.layout.ColumnSpec)1 FormLayout (com.jgoodies.forms.layout.FormLayout)1 RowSpec (com.jgoodies.forms.layout.RowSpec)1