Search in sources :

Example 41 with RadContainer

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

the class IntrospectedProperty method appliesTo.

@Override
public boolean appliesTo(final RadComponent component) {
    @NonNls String name = getName();
    //noinspection SimplifiableIfStatement
    if (name.equals(SwingProperties.PREFERRED_SIZE) || name.equals(SwingProperties.MINIMUM_SIZE) || name.equals(SwingProperties.MAXIMUM_SIZE)) {
        // our own properties must be used instead
        final RadContainer parent = component.getParent();
        return parent != null && !(parent.getLayoutManager() instanceof RadGridLayoutManager);
    }
    // check if property is available in the JDK used by the module containing the component
    final PsiManager psiManager = PsiManager.getInstance(component.getProject());
    final GlobalSearchScope scope = component.getModule().getModuleWithDependenciesAndLibrariesScope(true);
    PsiClass componentClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(component.getComponentClassName(), scope);
    if (componentClass == null)
        return true;
    final PsiMethod[] psiMethods = componentClass.findMethodsByName(myReadMethod.getName(), true);
    for (PsiMethod method : psiMethods) {
        if (!method.hasModifierProperty(PsiModifier.STATIC) && method.getParameterList().getParametersCount() == 0) {
            return true;
        }
    }
    return false;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) RadGridLayoutManager(com.intellij.uiDesigner.radComponents.RadGridLayoutManager) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 42 with RadContainer

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

the class ComponentEditor method collectFilteredComponents.

protected RadComponent[] collectFilteredComponents(final RadComponent component) {
    final ArrayList<RadComponent> result = new ArrayList<>();
    result.add(null);
    RadContainer container = component.getParent();
    while (container.getParent() != null) {
        container = container.getParent();
    }
    FormEditingUtil.iterate(container, new FormEditingUtil.ComponentVisitor() {

        public boolean visit(final IComponent component) {
            RadComponent radComponent = (RadComponent) component;
            final JComponent delegee = radComponent.getDelegee();
            if (!myPropertyType.isInstance(delegee)) {
                return true;
            }
            if (myFilter == null || myFilter.value(radComponent)) {
                result.add(radComponent);
            }
            return true;
        }
    });
    return result.toArray(new RadComponent[result.size()]);
}
Also used : IComponent(com.intellij.uiDesigner.lw.IComponent) ArrayList(java.util.ArrayList) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 43 with RadContainer

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

the class LayoutManagerProperty method getValue.

public String getValue(RadContainer component) {
    RadContainer container = component;
    while (container != null) {
        final RadLayoutManager layoutManager = container.getLayoutManager();
        if (layoutManager != null) {
            return layoutManager.getName();
        }
        container = container.getParent();
    }
    return UIFormXmlConstants.LAYOUT_INTELLIJ;
}
Also used : RadLayoutManager(com.intellij.uiDesigner.radComponents.RadLayoutManager) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 44 with RadContainer

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

the class DesignDropTargetListener method processDragEnter.

private void processDragEnter(final DraggedComponentList draggedComponentList, final Point location, final int dropAction) {
    final List<RadComponent> dragComponents = draggedComponentList.getComponents();
    Rectangle allBounds = null;
    if (!draggedComponentList.hasDragDelta() || !myUseDragDelta) {
        final RadContainer[] originalParents = draggedComponentList.getOriginalParents();
        final Rectangle[] originalBounds = draggedComponentList.getOriginalBounds();
        for (int i = 0; i < originalParents.length; i++) {
            Rectangle rc = SwingUtilities.convertRectangle(originalParents[i].getDelegee(), originalBounds[i], myEditor.getDragLayer());
            if (allBounds == null) {
                allBounds = rc;
            } else {
                allBounds = allBounds.union(rc);
            }
        }
    }
    // Place selected components to the drag layer.
    myDraggedComponentsCopy = CutCopyPasteSupport.copyComponents(myEditor, dragComponents);
    for (int i = 0; i < dragComponents.size(); i++) {
        myDraggedComponentsCopy.get(i).setSelected(true);
        final JComponent delegee = myDraggedComponentsCopy.get(i).getDelegee();
        final Point point = SwingUtilities.convertPoint(draggedComponentList.getOriginalParents()[i].getDelegee(), delegee.getLocation(), myEditor.getDragLayer());
        if (draggedComponentList.hasDragDelta() && myUseDragDelta) {
            delegee.setLocation((int) point.getX() + draggedComponentList.getDragDeltaX(), (int) point.getY() + draggedComponentList.getDragDeltaY());
        } else {
            assert allBounds != null;
            delegee.setLocation((int) (point.getX() - allBounds.getX() + location.getX()), (int) (point.getY() - allBounds.getY() + location.getY()));
        }
    //myEditor.getDragLayer().add(delegee);
    }
    for (final RadComponent c : dragComponents) {
        if (dropAction != DnDConstants.ACTION_COPY) {
            c.setDragBorder(true);
        }
        c.setSelected(false);
    }
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 45 with RadContainer

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

the class MorphAction method morphComponent.

private static boolean morphComponent(final GuiEditor editor, final RadComponent oldComponent, ComponentItem targetItem) {
    targetItem = InsertComponentProcessor.replaceAnyComponentItem(editor, targetItem, "Morph to Non-Palette Component");
    if (targetItem == null) {
        return false;
    }
    final RadComponent newComponent = InsertComponentProcessor.createInsertedComponent(editor, targetItem);
    if (newComponent == null)
        return false;
    newComponent.setBinding(oldComponent.getBinding());
    newComponent.setCustomLayoutConstraints(oldComponent.getCustomLayoutConstraints());
    newComponent.getConstraints().restore(oldComponent.getConstraints());
    updateBoundFieldType(editor, oldComponent, targetItem);
    final IProperty[] oldProperties = oldComponent.getModifiedProperties();
    final Palette palette = Palette.getInstance(editor.getProject());
    for (IProperty prop : oldProperties) {
        IntrospectedProperty newProp = palette.getIntrospectedProperty(newComponent, prop.getName());
        if (newProp == null || !prop.getClass().equals(newProp.getClass()))
            continue;
        Object oldValue = prop.getPropertyValue(oldComponent);
        try {
            //noinspection unchecked
            newProp.setValue(newComponent, oldValue);
        } catch (Exception e) {
        // ignore
        }
    }
    retargetComponentProperties(editor, oldComponent, newComponent);
    final RadContainer parent = oldComponent.getParent();
    int index = parent.indexOfComponent(oldComponent);
    parent.removeComponent(oldComponent);
    parent.addComponent(newComponent, index);
    newComponent.setSelected(true);
    if (oldComponent.isDefaultBinding()) {
        final String text = FormInspectionUtil.getText(newComponent.getModule(), newComponent);
        if (text != null) {
            String binding = BindingProperty.suggestBindingFromText(newComponent, text);
            if (binding != null) {
                new BindingProperty(newComponent.getProject()).setValueEx(newComponent, binding);
            }
        }
        newComponent.setDefaultBinding(true);
    }
    return true;
}
Also used : Palette(com.intellij.uiDesigner.palette.Palette) IProperty(com.intellij.uiDesigner.lw.IProperty) IntrospectedProperty(com.intellij.uiDesigner.propertyInspector.IntrospectedProperty) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) BindingProperty(com.intellij.uiDesigner.propertyInspector.properties.BindingProperty) IncorrectOperationException(com.intellij.util.IncorrectOperationException) 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