Search in sources :

Example 6 with ComponentItem

use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.

the class InsertComponentProcessor method processKeyEvent.

protected void processKeyEvent(final KeyEvent e) {
    if (e.getID() == KeyEvent.KEY_PRESSED) {
        if (e.getKeyCode() == KeyEvent.VK_ENTER) {
            if (myLastLocation != null) {
                myEditor.getMainProcessor().stopCurrentProcessor();
                processComponentInsert(getComponentToInsert(), myLastLocation);
            }
        } else {
            ComponentItem componentToInsert = getComponentToInsert();
            if (componentToInsert == null) {
                cancelOperation();
            } else {
                myLastLocation = moveDropLocation(myEditor, myLastLocation, new ComponentItemDragObject(componentToInsert), e);
            }
        }
    }
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem)

Example 7 with ComponentItem

use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.

the class InsertComponentProcessor method setLastLocation.

public void setLastLocation(final ComponentDropLocation location) {
    final ComponentItem componentToInsert = getComponentToInsert();
    assert componentToInsert != null;
    ComponentItemDragObject dragObject = new ComponentItemDragObject(componentToInsert);
    if (location.canDrop(dragObject)) {
        myLastLocation = location;
    } else {
        ComponentDropLocation locationToRight = location.getAdjacentLocation(ComponentDropLocation.Direction.RIGHT);
        ComponentDropLocation locationToBottom = location.getAdjacentLocation(ComponentDropLocation.Direction.DOWN);
        if (locationToRight != null && locationToRight.canDrop(dragObject)) {
            myLastLocation = locationToRight;
        } else if (locationToBottom != null && locationToBottom.canDrop(dragObject)) {
            myLastLocation = locationToBottom;
        } else {
            myLastLocation = location;
        }
    }
    if (myLastLocation.canDrop(dragObject)) {
        myLastLocation.placeFeedback(myEditor.getActiveDecorationLayer(), dragObject);
    }
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem)

Example 8 with ComponentItem

use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.

the class FormEditingUtil method getDefaultConstraints.

public static GridConstraints getDefaultConstraints(final RadComponent component) {
    final Palette palette = Palette.getInstance(component.getProject());
    final ComponentItem item = palette.getItem(component.getComponentClassName());
    if (item != null) {
        return item.getDefaultConstraints();
    }
    return new GridConstraints();
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) Palette(com.intellij.uiDesigner.palette.Palette) GridConstraints(com.intellij.uiDesigner.core.GridConstraints)

Example 9 with ComponentItem

use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.

the class GridBuildUtil method convertToGridImpl.

private static void convertToGridImpl(final GuiEditor editor, final int gridType) {
    final boolean createNewContainer;
    final RadContainer parent;
    final RadComponent[] componentsToConvert;
    {
        final ArrayList<RadComponent> selection = FormEditingUtil.getSelectedComponents(editor);
        if (selection.size() == 0) {
            // root container selected
            final RadRootContainer rootContainer = editor.getRootContainer();
            if (rootContainer.getComponentCount() < 2) {
                // nothing to convert
                return;
            }
            componentsToConvert = new RadComponent[rootContainer.getComponentCount()];
            for (int i = 0; i < componentsToConvert.length; i++) {
                componentsToConvert[i] = rootContainer.getComponent(i);
            }
            parent = rootContainer;
            createNewContainer = true;
        } else if (selection.size() == 1 && selection.get(0) instanceof RadContainer) {
            parent = (RadContainer) selection.get(0);
            componentsToConvert = new RadComponent[parent.getComponentCount()];
            for (int i = 0; i < componentsToConvert.length; i++) {
                componentsToConvert[i] = parent.getComponent(i);
            }
            createNewContainer = false;
        } else {
            componentsToConvert = selection.toArray(new RadComponent[selection.size()]);
            parent = selection.get(0).getParent();
            createNewContainer = true;
        }
    }
    if (!parent.isXY()) {
        // only components in XY can be layed out in grid
        return;
    }
    for (int i = 1; i < componentsToConvert.length; i++) {
        final RadComponent component = componentsToConvert[i];
        if (component.getParent() != parent) {
            return;
        }
    }
    final GridLayoutManager gridLayoutManager;
    if (componentsToConvert.length == 0) {
        // we convert empty XY panel to grid
        gridLayoutManager = new GridLayoutManager(1, 1);
    } else {
        if (gridType == VERTICAL_GRID) {
            gridLayoutManager = createOneDimensionGrid(componentsToConvert, true);
        } else if (gridType == HORIZONTAL_GRID) {
            gridLayoutManager = createOneDimensionGrid(componentsToConvert, false);
        } else if (gridType == GRID) {
            gridLayoutManager = createTwoDimensionGrid(componentsToConvert);
        } else {
            throw new IllegalArgumentException("invalid grid type: " + gridType);
        }
    }
    for (final RadComponent component : componentsToConvert) {
        if (component instanceof RadContainer) {
            final LayoutManager layout = ((RadContainer) component).getLayout();
            if (layout instanceof XYLayoutManager) {
                ((XYLayoutManager) layout).setPreferredSize(component.getSize());
            }
        }
    }
    if (createNewContainer) {
        // we should create a new panel
        final Module module = editor.getModule();
        final ComponentItem panelItem = Palette.getInstance(editor.getProject()).getPanelItem();
        final RadContainer newContainer = new RadContainer(editor, FormEditingUtil.generateId(editor.getRootContainer()));
        newContainer.setLayout(gridLayoutManager);
        newContainer.init(editor, panelItem);
        for (RadComponent componentToConvert : componentsToConvert) {
            newContainer.addComponent(componentToConvert);
        }
        final Point topLeftPoint = getTopLeftPoint(componentsToConvert);
        newContainer.setLocation(topLeftPoint);
        final Point bottomRightPoint = getBottomRightPoint(componentsToConvert);
        final Dimension size = new Dimension(bottomRightPoint.x - topLeftPoint.x, bottomRightPoint.y - topLeftPoint.y);
        Util.adjustSize(newContainer.getDelegee(), newContainer.getConstraints(), size);
        newContainer.getDelegee().setSize(size);
        parent.addComponent(newContainer);
        FormEditingUtil.clearSelection(editor.getRootContainer());
        newContainer.setSelected(true);
        // restore binding of main component
        {
            final String mainComponentBinding = editor.getRootContainer().getMainComponentBinding();
            if (mainComponentBinding != null && parent instanceof RadRootContainer) {
                newContainer.setBinding(mainComponentBinding);
                editor.getRootContainer().setMainComponentBinding(null);
            }
        }
    } else {
        // convert entire 'parent' to grid
        parent.setLayout(gridLayoutManager);
        FormEditingUtil.clearSelection(editor.getRootContainer());
        parent.setSelected(true);
    }
    editor.refreshAndSave(true);
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) ArrayList(java.util.ArrayList) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) XYLayoutManager(com.intellij.uiDesigner.shared.XYLayoutManager) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) XYLayoutManager(com.intellij.uiDesigner.shared.XYLayoutManager) Module(com.intellij.openapi.module.Module)

Example 10 with ComponentItem

use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.

the class CreateComponentAction method actionPerformed.

protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
    Processor<ComponentItem> processor = selectedValue -> {
        if (selectedValue != null) {
            myLastCreatedComponent = selectedValue;
            editor.getMainProcessor().startInsertProcessor(selectedValue, getCreateLocation(editor, selection));
        }
        return true;
    };
    PaletteListPopupStep step = new PaletteListPopupStep(editor, myLastCreatedComponent, processor, UIDesignerBundle.message("create.component.title"));
    final ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(step);
    if (selection.size() > 0) {
        FormEditingUtil.showPopupUnderComponent(listPopup, selection.get(0));
    } else {
        listPopup.showInCenterOf(editor.getRootContainer().getDelegee());
    }
}
Also used : UIDesignerBundle(com.intellij.uiDesigner.UIDesignerBundle) com.intellij.uiDesigner.designSurface(com.intellij.uiDesigner.designSurface) ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil) java.awt(java.awt) ListPopup(com.intellij.openapi.ui.popup.ListPopup) List(java.util.List) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) Processor(com.intellij.util.Processor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer) ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) ListPopup(com.intellij.openapi.ui.popup.ListPopup)

Aggregations

ComponentItem (com.intellij.uiDesigner.palette.ComponentItem)16 Palette (com.intellij.uiDesigner.palette.Palette)5 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)4 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)4 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)3 ArrayList (java.util.ArrayList)3 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)2 ListPopup (com.intellij.openapi.ui.popup.ListPopup)2 UIDesignerBundle (com.intellij.uiDesigner.UIDesignerBundle)2 GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)2 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)2 IComponent (com.intellij.uiDesigner.lw.IComponent)2 IProperty (com.intellij.uiDesigner.lw.IProperty)2 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)2 RadRootContainer (com.intellij.uiDesigner.radComponents.RadRootContainer)2 XYLayoutManager (com.intellij.uiDesigner.shared.XYLayoutManager)2 Processor (com.intellij.util.Processor)2 List (java.util.List)2 CommandProcessor (com.intellij.openapi.command.CommandProcessor)1