Search in sources :

Example 96 with NlComponent

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

the class RelativeLayoutHandler method createResizeHandler.

@Override
@Nullable
public ResizeHandler createResizeHandler(@NotNull ViewEditor editor, @NotNull NlComponent component, @Nullable SegmentType horizontalEdgeType, @Nullable SegmentType verticalEdgeType) {
    NlComponent parent = component.getParent();
    if (parent == null) {
        return null;
    }
    final RelativeResizeHandler resizeHandler = new RelativeResizeHandler(editor, parent, component, horizontalEdgeType, verticalEdgeType);
    return new ResizeHandler(editor, this, component, horizontalEdgeType, verticalEdgeType) {

        @Nullable
        @Override
        public String update(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers, @NotNull @AndroidCoordinate Rectangle newBounds) {
            super.update(x, y, modifiers, newBounds);
            resizeHandler.updateResize(component, newBounds, modifiers);
            return null;
        }

        @Override
        public void commit(@AndroidCoordinate int px, @AndroidCoordinate int py, int modifiers, @NotNull @AndroidCoordinate Rectangle newBounds) {
            resizeHandler.removeCycles();
            resizeHandler.applyConstraints(component);
        }

        @Override
        public void paint(@NotNull NlGraphics graphics) {
            GuidelinePainter.paint(graphics, resizeHandler);
        }
    };
}
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 97 with NlComponent

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

the class GridInfo method initChildren.

private void initChildren() throws NoSuchFieldException, IllegalAccessException {
    children = new NlComponent[rowCount][columnCount];
    assert layout.children != null;
    for (NlComponent child : layout.children) {
        ChildInfo info = getInfo(child);
        int endRow = Math.min(info.getRow2(), rowCount);
        int endColumn = Math.min(info.getColumn2(), columnCount);
        for (int row = info.getRow1(); row < endRow; row++) {
            for (int column = info.getColumn1(); column < endColumn; column++) {
                children[row][column] = child;
            }
        }
    }
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 98 with NlComponent

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

the class GroupDragHandler method createOrderToItemMultimap.

@NotNull
private Multimap<Integer, NlComponent> createOrderToItemMultimap(@NotNull Iterable<NlComponent> group) {
    Object draggedItem = myItems.get(0);
    Multimap<Integer, NlComponent> orderToItemMultimap = ArrayListMultimap.create();
    for (NlComponent item : group) {
        if (item == draggedItem) {
            continue;
        }
        Integer order = getOrderInCategory(item);
        if (order != null) {
            orderToItemMultimap.put(order, item);
        }
    }
    return orderToItemMultimap;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 99 with NlComponent

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

the class DependencyGraph method dependsOn.

/**
   * Returns the set of views that depend on the given node in either the horizontal or
   * vertical direction
   *
   * @param nodes    the set of nodes that we want to compute the transitive dependencies
   *                 for
   * @param vertical if true, look for vertical edge dependencies, otherwise look for
   *                 horizontal edge dependencies
   * @return the set of nodes that directly or indirectly depend on the given nodes in
   * the given direction
   */
public Set<NlComponent> dependsOn(Collection<? extends NlComponent> nodes, boolean vertical) {
    List<ViewData> reachable = new ArrayList<ViewData>();
    // Traverse the graph of constraints and determine all nodes affected by
    // this node
    Set<ViewData> visiting = new HashSet<ViewData>();
    for (NlComponent node : nodes) {
        ViewData view = myNodeToView.get(node);
        if (view != null) {
            findBackwards(view, visiting, reachable, vertical, view);
        }
    }
    Set<NlComponent> dependents = new HashSet<NlComponent>(reachable.size());
    for (ViewData v : reachable) {
        dependents.add(v.node);
    }
    return dependents;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 100 with NlComponent

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

the class GroupDragHandler method drawActionBarGroupDropZoneLines.

private void drawActionBarGroupDropZoneLines(@NotNull NlGraphics graphics) {
    List<NlComponent> items = myActionBar.getItems();
    int midpointX = myActiveItem.getMidpointX();
    graphics.useStyle(NlDrawingStyle.DROP_ZONE);
    for (int i = 1, size = items.size(); i < size; i++) {
        NlComponent item = items.get(i);
        if (myActiveItem == items.get(i - 1)) {
            if (lastX < midpointX) {
                graphics.drawLeft(item);
            }
        } else if (myActiveItem == item) {
            if (lastX >= midpointX) {
                graphics.drawLeft(item);
            }
        } else {
            graphics.drawLeft(item);
        }
    }
}
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