Search in sources :

Example 26 with RadContainer

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

the class FormEditingUtil method selectSingleComponent.

public static void selectSingleComponent(final GuiEditor editor, final RadComponent component) {
    final RadContainer root = (RadContainer) getRoot(component);
    if (root == null)
        return;
    ComponentTreeBuilder builder = DesignerToolWindowManager.getInstance(editor).getComponentTreeBuilder();
    // the component tree will be instantiated after the event has been processed completely
    if (builder != null) {
        builder.beginUpdateSelection();
    }
    try {
        clearSelection(root);
        selectComponent(editor, component);
        editor.setSelectionAnchor(component);
        editor.scrollComponentInView(component);
    } finally {
        if (builder != null) {
            builder.endUpdateSelection();
        }
    }
}
Also used : RadContainer(com.intellij.uiDesigner.radComponents.RadContainer) ComponentTreeBuilder(com.intellij.uiDesigner.componentTree.ComponentTreeBuilder)

Example 27 with RadContainer

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

the class FormEditingUtil method deleteComponents.

public static void deleteComponents(final Collection<? extends RadComponent> selection, boolean deleteEmptyCells) {
    if (selection.size() == 0) {
        return;
    }
    final RadRootContainer rootContainer = (RadRootContainer) getRoot(selection.iterator().next());
    final Set<String> deletedComponentIds = new HashSet<>();
    for (final RadComponent component : selection) {
        boolean wasSelected = component.isSelected();
        final RadContainer parent = component.getParent();
        boolean wasPackedHorz = false;
        boolean wasPackedVert = false;
        if (parent.getParent() != null && parent.getParent().isXY()) {
            final Dimension minSize = parent.getMinimumSize();
            wasPackedHorz = parent.getWidth() == minSize.width;
            wasPackedVert = parent.getHeight() == minSize.height;
        }
        iterate(component, new ComponentVisitor() {

            public boolean visit(final IComponent c) {
                RadComponent rc = (RadComponent) c;
                BindingProperty.checkRemoveUnusedField(rootContainer, rc.getBinding(), null);
                deletedComponentIds.add(rc.getId());
                return true;
            }
        });
        GridConstraints delConstraints = parent.getLayoutManager().isGrid() ? component.getConstraints() : null;
        int index = parent.indexOfComponent(component);
        parent.removeComponent(component);
        if (wasSelected) {
            if (parent.getComponentCount() > index) {
                parent.getComponent(index).setSelected(true);
            } else if (index > 0 && parent.getComponentCount() == index) {
                parent.getComponent(index - 1).setSelected(true);
            } else {
                parent.setSelected(true);
            }
        }
        if (delConstraints != null && deleteEmptyCells) {
            deleteEmptyGridCells(parent, delConstraints);
        }
        if (wasPackedHorz || wasPackedVert) {
            final Dimension minSize = parent.getMinimumSize();
            Dimension newSize = new Dimension(parent.getWidth(), parent.getHeight());
            if (wasPackedHorz) {
                newSize.width = minSize.width;
            }
            if (wasPackedVert) {
                newSize.height = minSize.height;
            }
            parent.setSize(newSize);
        }
    }
    iterate(rootContainer, new ComponentVisitor() {

        public boolean visit(final IComponent component) {
            RadComponent rc = (RadComponent) component;
            for (IProperty p : component.getModifiedProperties()) {
                if (p instanceof IntroComponentProperty) {
                    IntroComponentProperty icp = (IntroComponentProperty) p;
                    final String value = icp.getValue(rc);
                    if (deletedComponentIds.contains(value)) {
                        try {
                            icp.resetValue(rc);
                        } catch (Exception e) {
                        // ignore
                        }
                    }
                }
            }
            return true;
        }
    });
}
Also used : RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RelativePoint(com.intellij.ui.awt.RelativePoint) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) IncorrectOperationException(com.intellij.util.IncorrectOperationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IntroComponentProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer) HashSet(com.intellij.util.containers.HashSet)

Example 28 with RadContainer

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

the class GridChangeUtilTest method testMoveDisjointRowsDown.

public void testMoveDisjointRowsDown() throws Exception {
    final RadContainer grid = SampleGrid.create();
    GridChangeUtil.moveCells(grid, true, new int[] { 0, 2 }, 5);
    assertEquals(3, grid.getComponent(0).getConstraints().getRow());
    assertEquals(4, grid.getComponent(2).getConstraints().getRow());
    assertEquals(1, grid.getComponent(3).getConstraints().getRow());
}
Also used : RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 29 with RadContainer

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

the class GridChangeUtilTest method testMoveAdjacentRowsUp.

public void testMoveAdjacentRowsUp() throws Exception {
    final RadContainer grid = SampleGrid.create();
    GridChangeUtil.moveCells(grid, true, new int[] { 4, 5 }, 3);
    assertEquals(5, grid.getComponent(3).getConstraints().getRow());
    assertEquals(3, grid.getComponent(4).getConstraints().getRow());
    assertEquals(4, grid.getComponent(5).getConstraints().getRow());
}
Also used : RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 30 with RadContainer

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

the class GridChangeUtilTest method test_insert_first.

@SuppressWarnings({ "PointlessArithmeticExpression" })
public void test_insert_first() throws Exception {
    final RadContainer grid = SampleGrid.create();
    GridChangeUtil.insertRowOrColumn(grid, 0, false, true);
    assertGridDimensions(grid, SampleGrid.ORIGINAL_ROWS, SampleGrid.ORIGINAL_COLUMNS + 1);
    // all must be shifted one cell right
    assertComponentCellAndSpan(grid, 0, SampleGrid.C0 + 1, SampleGrid.S0);
    assertComponentCellAndSpan(grid, 1, SampleGrid.C1 + 1, SampleGrid.S1);
    assertComponentCellAndSpan(grid, 2, SampleGrid.C2 + 1, SampleGrid.S2);
    assertComponentCellAndSpan(grid, 3, SampleGrid.C3 + 1, SampleGrid.S3);
    assertComponentCellAndSpan(grid, 4, SampleGrid.C4 + 1, SampleGrid.S4);
    assertComponentCellAndSpan(grid, 5, SampleGrid.C5 + 1, SampleGrid.S5);
}
Also used : RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Aggregations

RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)51 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)20 RadRootContainer (com.intellij.uiDesigner.radComponents.RadRootContainer)6 ArrayList (java.util.ArrayList)6 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)5 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)3 IComponent (com.intellij.uiDesigner.lw.IComponent)3 ComponentTreeBuilder (com.intellij.uiDesigner.componentTree.ComponentTreeBuilder)2 GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)2 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)2 IProperty (com.intellij.uiDesigner.lw.IProperty)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 LayoutManager (java.awt.LayoutManager)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Ref (com.intellij.openapi.util.Ref)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 SelectionState (com.intellij.uiDesigner.SelectionState)1 ComponentPtr (com.intellij.uiDesigner.componentTree.ComponentPtr)1 ComponentTree (com.intellij.uiDesigner.componentTree.ComponentTree)1