Search in sources :

Example 6 with RadComponent

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

Example 7 with RadComponent

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

Example 8 with RadComponent

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

Example 9 with RadComponent

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

the class FormInspectionUtil method getText.

@Nullable
public static String getText(@NotNull final Module module, final IComponent component) {
    IProperty textProperty = findProperty(component, SwingProperties.TEXT);
    if (textProperty != null) {
        Object propValue = textProperty.getPropertyValue(component);
        String value = null;
        if (propValue instanceof StringDescriptor) {
            StringDescriptor descriptor = (StringDescriptor) propValue;
            if (component instanceof RadComponent) {
                value = StringDescriptorManager.getInstance(module).resolve((RadComponent) component, descriptor);
            } else {
                value = StringDescriptorManager.getInstance(module).resolve(descriptor, null);
            }
        } else if (propValue instanceof String) {
            value = (String) propValue;
        }
        if (value != null) {
            return value;
        }
    }
    return null;
}
Also used : IProperty(com.intellij.uiDesigner.lw.IProperty) StringDescriptor(com.intellij.uiDesigner.lw.StringDescriptor) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with RadComponent

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

the class FormSpellCheckingInspection method checkStringDescriptor.

@Override
protected void checkStringDescriptor(Module module, final IComponent component, final IProperty prop, final StringDescriptor descriptor, final FormErrorCollector collector) {
    final String value = descriptor.getResolvedValue();
    if (value == null) {
        return;
    }
    final SpellCheckerManager manager = SpellCheckerManager.getInstance(module.getProject());
    PlainTextSplitter.getInstance().split(value, TextRange.allOf(value), textRange -> {
        final String word = textRange.substring(value);
        if (manager.hasProblem(word)) {
            final List<String> suggestions = manager.getSuggestions(word);
            if (!suggestions.isEmpty() && prop instanceof IntroStringProperty) {
                EditorQuickFixProvider changeToProvider = new EditorQuickFixProvider() {

                    @Override
                    public QuickFix createQuickFix(final GuiEditor editor, final RadComponent component1) {
                        return new PopupQuickFix<String>(editor, "Change to...", component1) {

                            @Override
                            public void run() {
                                ListPopup popup = JBPopupFactory.getInstance().createListPopup(getPopupStep());
                                popup.showUnderneathOf(component1.getDelegee());
                            }

                            @Override
                            public ListPopupStep<String> getPopupStep() {
                                return new BaseListPopupStep<String>("Select Replacement", suggestions) {

                                    @Override
                                    public PopupStep onChosen(String selectedValue, boolean finalChoice) {
                                        FormInspectionUtil.updateStringPropertyValue(editor, component1, (IntroStringProperty) prop, descriptor, selectedValue);
                                        return FINAL_CHOICE;
                                    }
                                };
                            }
                        };
                    }
                };
                EditorQuickFixProvider acceptProvider = new EditorQuickFixProvider() {

                    @Override
                    public QuickFix createQuickFix(final GuiEditor editor, RadComponent component1) {
                        return new QuickFix(editor, "Save '" + word + "' to dictionary", component1) {

                            @Override
                            public void run() {
                                manager.acceptWordAsCorrect(word, editor.getProject());
                            }
                        };
                    }
                };
                collector.addError(getID(), component, prop, "Typo in word '" + word + "'", changeToProvider, acceptProvider);
            } else {
                collector.addError(getID(), component, prop, "Typo in word '" + word + "'");
            }
        }
    });
}
Also used : QuickFix(com.intellij.uiDesigner.quickFixes.QuickFix) PopupQuickFix(com.intellij.uiDesigner.quickFixes.PopupQuickFix) PopupQuickFix(com.intellij.uiDesigner.quickFixes.PopupQuickFix) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) SpellCheckerManager(com.intellij.spellchecker.SpellCheckerManager) IntroStringProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) ListPopup(com.intellij.openapi.ui.popup.ListPopup) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor)

Aggregations

RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)86 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)22 RadRootContainer (com.intellij.uiDesigner.radComponents.RadRootContainer)18 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)15 ArrayList (java.util.ArrayList)12 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)8 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)8 IComponent (com.intellij.uiDesigner.lw.IComponent)7 IProperty (com.intellij.uiDesigner.lw.IProperty)6 ComponentItem (com.intellij.uiDesigner.palette.ComponentItem)5 RadButtonGroup (com.intellij.uiDesigner.radComponents.RadButtonGroup)5 ListPopup (com.intellij.openapi.ui.popup.ListPopup)4 ComponentTree (com.intellij.uiDesigner.componentTree.ComponentTree)4 IntrospectedProperty (com.intellij.uiDesigner.propertyInspector.IntrospectedProperty)4 IntroComponentProperty (com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty)4 QuickFix (com.intellij.uiDesigner.quickFixes.QuickFix)4 Nullable (org.jetbrains.annotations.Nullable)4 RelativePoint (com.intellij.ui.awt.RelativePoint)3 Palette (com.intellij.uiDesigner.palette.Palette)3 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3