Search in sources :

Example 66 with NlComponent

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

the class ActionBar method getBounds.

@Nullable
private static Rectangle getBounds(@NotNull List<NlComponent> items) {
    if (items.isEmpty()) {
        return null;
    }
    NlComponent firstItem = items.get(0);
    Rectangle bounds = new Rectangle(firstItem.x, firstItem.y, firstItem.w, firstItem.h);
    items.subList(1, items.size()).forEach(item -> bounds.add(new Rectangle(item.x, item.y, item.w, item.h)));
    return bounds;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) Nullable(org.jetbrains.annotations.Nullable)

Example 67 with NlComponent

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

the class GroupDragHandler method drawOverflowGroupDropZoneLines.

private void drawOverflowGroupDropZoneLines(@NotNull NlGraphics graphics) {
    List<NlComponent> overflowItems = myActionBar.getOverflowItems();
    int midpointY = myActiveItem.getMidpointY();
    graphics.useStyle(NlDrawingStyle.DROP_ZONE);
    for (int i = 1, size = overflowItems.size(); i < size; i++) {
        NlComponent item = overflowItems.get(i);
        if (myActiveItem == overflowItems.get(i - 1)) {
            if (lastY < midpointY) {
                graphics.drawTop(item);
            }
        } else if (myActiveItem == item) {
            if (lastY >= midpointY) {
                graphics.drawTop(item);
            }
        } else {
            graphics.drawTop(item);
        }
    }
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 68 with NlComponent

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

the class IdAnalyzer method reserveAllIdsWithTransitiveReferencesToSelectedIds.

// Avoid creating a circular list of references
private void reserveAllIdsWithTransitiveReferencesToSelectedIds(@NotNull NlComponent parent) {
    Multimap<String, String> referenceMap = HashMultimap.create();
    for (NlComponent component : parent.getChildren()) {
        String id = component.getId();
        if (!StringUtil.isEmpty(id)) {
            for (String attribute : myPropertyGroup.myAttributes) {
                String referenced = NlComponent.stripId(component.getAttribute(myPropertyGroup.myNamespace, attribute));
                if (referenced != null) {
                    referenceMap.put(referenced, id);
                }
            }
        }
    }
    Set<String> references = new HashSet<>(myReservedIds);
    while (!references.isEmpty()) {
        String reference = references.iterator().next();
        references.remove(reference);
        myReservedIds.add(reference);
        referenceMap.get(reference).stream().filter(id -> !myReservedIds.contains(id)).forEach(references::add);
    }
}
Also used : HashSet(java.util.HashSet) List(java.util.List) HashMultimap(com.google.common.collect.HashMultimap) ImmutableList(com.google.common.collect.ImmutableList) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) SdkConstants(com.android.SdkConstants) StringUtil(com.intellij.openapi.util.text.StringUtil) Set(java.util.Set) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) Multimap(com.google.common.collect.Multimap) NotNull(org.jetbrains.annotations.NotNull) Collectors(java.util.stream.Collectors) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) HashSet(java.util.HashSet)

Example 69 with NlComponent

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

the class SceneDragHandler method commit.

@Override
public void commit(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers, @NotNull InsertType insertType) {
    Scene scene = ((ViewEditorImpl) editor).getScreenView().getScene();
    if (myComponent != null) {
        NlComponent nlComponent = components.get(0);
        NlComponent root = nlComponent.getRoot();
        root.ensureNamespace(SdkConstants.SHERPA_PREFIX, SdkConstants.AUTO_URI);
        SceneComponent component = scene.getSceneComponent(myComponent);
        if (component != null) {
            ArrayList<Target> targets = component.getTargets();
            int dx = x - myComponent.w / 2;
            int dy = y - myComponent.h / 2;
            for (int i = 0; i < targets.size(); i++) {
                if (targets.get(i) instanceof DragDndTarget) {
                    DragDndTarget target = (DragDndTarget) targets.get(i);
                    target.mouseRelease(scene.pxToDp(dx), scene.pxToDp(dy), nlComponent);
                    break;
                }
            }
        }
    }
    insertComponents(-1, insertType);
    scene.setDnDComponent(null);
    scene.checkRequestLayoutStatus();
}
Also used : DragDndTarget(com.android.tools.idea.uibuilder.scene.target.DragDndTarget) Target(com.android.tools.idea.uibuilder.scene.target.Target) DragTarget(com.android.tools.idea.uibuilder.scene.target.DragTarget) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) DragDndTarget(com.android.tools.idea.uibuilder.scene.target.DragDndTarget)

Example 70 with NlComponent

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

the class IdInspectorProviderTest method mockComponentWithTag.

private static NlComponent mockComponentWithTag(@NotNull String tagName) {
    NlComponent component = mock(NlComponent.class);
    when(component.getTagName()).thenReturn(tagName);
    return component;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

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