Search in sources :

Example 51 with NlComponent

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

the class GroupDragHandlerTest method updateUsingOverflowGroupEmptyGroupInMiddle.

@Test
public void updateUsingOverflowGroupEmptyGroupInMiddle() {
    NlComponent menu = newMenu(366, 162, 392, 192);
    menu.addChild(newOverflowItem(366, 162, 392, 96));
    menu.addChild(newGroup(0, 0, -1, -1));
    menu.addChild(newOverflowItem(366, 258, 392, 96));
    GroupDragHandler handler = newGroupDragHandler(menu);
    int y = 90;
    y += 48;
    handler.update(0, y, 0);
    assertEquals(0, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(0, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(1, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(2, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(-1, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(-1, handler.getInsertIndex());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) Test(org.junit.Test)

Example 52 with NlComponent

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

the class GroupDragHandlerTest method updateUsingOverflowGroupEmptyGroupInFront.

@Test
public void updateUsingOverflowGroupEmptyGroupInFront() {
    NlComponent menu = newMenu(366, 162, 392, 192);
    menu.addChild(newGroup(0, 0, -1, -1));
    menu.addChild(newOverflowItem(366, 162, 392, 96));
    menu.addChild(newOverflowItem(366, 258, 392, 96));
    GroupDragHandler handler = newGroupDragHandler(menu);
    int y = 90;
    y += 48;
    handler.update(0, y, 0);
    assertEquals(0, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(1, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(2, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(2, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(-1, handler.getInsertIndex());
    y += 48;
    handler.update(0, y, 0);
    assertEquals(-1, handler.getInsertIndex());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) Test(org.junit.Test)

Example 53 with NlComponent

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

the class NlComponentTreeTest method testSelectionInTreeIsPropagatedToModel.

public void testSelectionInTreeIsPropagatedToModel() {
    assertNull(myTree.getSelectionPaths());
    assertFalse(myModel.getSelectionModel().getSelection().iterator().hasNext());
    NlComponent root = (NlComponent) myTree.getModel().getRoot();
    NlComponent node1 = root.getChild(1);
    NlComponent node2 = root.getChild(2);
    myTree.addSelectionPath(new TreePath(new Object[] { root, node1 }));
    myTree.addSelectionPath(new TreePath(new Object[] { root, node2 }));
    Iterator<NlComponent> selected = myModel.getSelectionModel().getSelection().iterator();
    assertEquals(node1, selected.next());
    assertEquals(node2, selected.next());
    assertFalse(selected.hasNext());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) TreePath(javax.swing.tree.TreePath)

Example 54 with NlComponent

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

the class ConstraintPainter method paintConstraint.

/**
   * Paints a given match as a constraint.
   *
   * @param graphics     the graphics context
   * @param state        the handler state
   * @param match        the match
   */
static void paintConstraint(NlGraphics graphics, GuidelineHandler state, Match match) {
    NlComponent node = match.edge.component;
    if (node == null) {
        return;
    }
    Insets padding = node.getPadding();
    Rectangle targetBounds = node == state.layout ? new Rectangle(node.x + padding.left, node.y + padding.top, Math.max(0, node.w - padding.left - padding.right), Math.max(0, node.h - padding.top - padding.bottom)) : new Rectangle(node.x, node.y, node.w, node.h);
    ConstraintType type = match.type;
    assert type != null;
    Rectangle sourceBounds = state.myBounds;
    paintConstraint(graphics, type, node, sourceBounds, node, targetBounds, null, /* allConstraints */
    true, /* highlightTargetEdge */
    state.myTextDirection);
}
Also used : Insets(com.android.tools.idea.uibuilder.model.Insets) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 55 with NlComponent

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

the class ConstraintPainter method paintSelectionFeedback.

/**
   * Paint selection feedback by painting constraints for the selected nodes
   *  @param graphics       the graphics context
   * @param parentNode     the parent relative layout
   * @param childNodes     the nodes whose constraints should be painted
   * @param showDependents whether incoming constraints should be shown as well
   */
public static void paintSelectionFeedback(NlGraphics graphics, NlComponent parentNode, List<NlComponent> childNodes, boolean showDependents, TextDirection textDirection) {
    DependencyGraph dependencyGraph = DependencyGraph.get(parentNode);
    Set<NlComponent> horizontalDeps = dependencyGraph.dependsOn(childNodes, false);
    Set<NlComponent> verticalDeps = dependencyGraph.dependsOn(childNodes, true);
    Set<NlComponent> deps = new HashSet<NlComponent>(horizontalDeps.size() + verticalDeps.size());
    deps.addAll(horizontalDeps);
    deps.addAll(verticalDeps);
    if (deps.size() > 0) {
        for (NlComponent node : deps) {
            // Don't highlight the selected nodes themselves
            if (childNodes.contains(node)) {
                continue;
            }
            Rectangle bounds = getBounds(node);
            graphics.useStyle(DEPENDENCY);
            graphics.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
        }
    }
    for (NlComponent childNode : childNodes) {
        DependencyGraph.ViewData view = dependencyGraph.getView(childNode);
        if (view == null) {
            continue;
        }
        // Paint all incoming constraints
        if (showDependents) {
            paintConstraints(graphics, view.dependedOnBy, textDirection);
        }
        // Paint all outgoing constraints
        paintConstraints(graphics, view.dependsOn, textDirection);
    }
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) HashSet(java.util.HashSet)

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