Search in sources :

Example 6 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class NlActionManager method addViewHandlerActions.

private void addViewHandlerActions(@NotNull DefaultActionGroup group, @NotNull NlComponent component, @NotNull List<NlComponent> selection) {
    // Look up view handlers
    int prevCount = group.getChildrenCount();
    NlComponent parent = !component.isRoot() ? component.getParent() : null;
    addViewActions(group, component, parent, selection, false);
    if (group.getChildrenCount() > prevCount) {
        group.addSeparator();
    }
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 7 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class NlActionManager method showPopup.

public void showPopup(@NotNull MouseEvent event, @Nullable ScreenView screenView, @Nullable NlComponent leafComponent) {
    ActionManager actionManager = ActionManager.getInstance();
    DefaultActionGroup group = createPopupMenu(actionManager, screenView, leafComponent);
    ActionPopupMenu popupMenu = actionManager.createActionPopupMenu("LayoutEditor", group);
    Component invoker = event.getSource() instanceof Component ? (Component) event.getSource() : mySurface;
    popupMenu.getComponent().show(invoker, event.getX(), event.getY());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 8 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class AbsoluteLayoutHandler method createDragHandler.

@Override
@Nullable
public DragHandler createDragHandler(@NotNull ViewEditor editor, @NotNull NlComponent layout, @NotNull List<NlComponent> components, @NotNull DragType type) {
    return new DragHandler(editor, this, layout, components, type) {

        @Override
        public void paint(@NotNull NlGraphics graphics) {
            int deltaX = lastX - startX;
            int deltaY = lastY - startY;
            for (NlComponent component : components) {
                int x = component.x + deltaX;
                int y = component.y + deltaY;
                int w = component.w;
                int h = component.h;
                graphics.useStyle(NlDrawingStyle.DROP_PREVIEW);
                graphics.drawRect(x, y, w, h);
            }
        }

        @Override
        public void commit(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers, @NotNull InsertType insertType) {
            // TODO: Remove all existing layout parameters; if you're dragging from one layout type to another, you don't
            // want stale layout parameters (e.g. layout_alignLeft from a previous RelativeLayout in a new GridLayout, and so on.)
            int deltaX = x - startX;
            int deltaY = y - startY;
            for (NlComponent component : components) {
                component.setAttribute(ANDROID_URI, ATTR_LAYOUT_X, editor.pxToDpWithUnits(component.x - layout.x + deltaX));
                component.setAttribute(ANDROID_URI, ATTR_LAYOUT_Y, editor.pxToDpWithUnits(component.y - layout.y + deltaY));
            }
            insertComponents(-1, insertType);
        }
    };
}
Also used : AndroidCoordinate(com.android.tools.idea.uibuilder.model.AndroidCoordinate) NlGraphics(com.android.tools.idea.uibuilder.graphics.NlGraphics) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class ViewHandlerManager method findLayoutHandler.

/**
   * Finds the nearest layout/view group handler for the given component.
   *
   * @param component the component to search from
   * @param strict    if true, only consider parents of the component, not the component itself
   */
@Nullable
public ViewGroupHandler findLayoutHandler(@NotNull NlComponent component, boolean strict) {
    NlComponent curr = component;
    if (strict) {
        curr = curr.getParent();
    }
    while (curr != null) {
        ViewHandler handler = getHandler(curr);
        if (handler instanceof ViewGroupHandler) {
            return (ViewGroupHandler) handler;
        }
        curr = curr.getParent();
    }
    return null;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ViewHandler(com.android.tools.idea.uibuilder.api.ViewHandler) AdViewHandler(com.android.tools.idea.uibuilder.handlers.google.AdViewHandler) MapViewHandler(com.android.tools.idea.uibuilder.handlers.google.MapViewHandler) ViewGroupHandler(com.android.tools.idea.uibuilder.api.ViewGroupHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class ConstraintDragHandler method commit.

@Override
public void commit(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers, @NotNull InsertType insertType) {
    if (myComponent != null) {
        myComponent = components.get(0);
        myComponent.x = x;
        myComponent.y = y;
        NlComponent root = myComponent.getRoot();
        root.ensureNamespace(SdkConstants.SHERPA_PREFIX, SdkConstants.AUTO_URI);
        ConstraintModel model = ConstraintModel.getConstraintModel(editor.getModel());
        if (model != null) {
            int ax = model.pxToDp(x - this.layout.x - this.layout.getPadding().left - myComponent.w / 2);
            int ay = model.pxToDp(y - this.layout.y - this.layout.getPadding().top - myComponent.h / 2);
            AttributesTransaction attributes = myComponent.startAttributeTransaction();
            ConstraintUtilities.setEditorPosition(null, attributes, ax, ay);
            attributes.commit();
        }
        if (myDragWidget != null) {
            model.commitDragComponent(myComponent);
        }
    }
    insertComponents(-1, insertType);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction)

Aggregations

NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)184 NlModel (com.android.tools.idea.uibuilder.model.NlModel)34 NotNull (org.jetbrains.annotations.NotNull)34 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)18 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)17 Nullable (org.jetbrains.annotations.Nullable)14 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)11 ViewGroupHandler (com.android.tools.idea.uibuilder.api.ViewGroupHandler)9 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)9 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)8 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)7 XmlFile (com.intellij.psi.xml.XmlFile)7 XmlTag (com.intellij.psi.xml.XmlTag)7 ArrayList (java.util.ArrayList)7 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)6 NlGraphics (com.android.tools.idea.uibuilder.graphics.NlGraphics)6 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)6 Project (com.intellij.openapi.project.Project)6 List (java.util.List)6