Search in sources :

Example 91 with NlComponent

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

the class NlTreeDumper method describe.

private void describe(@NotNull StringBuilder sb, @NotNull NlComponent component, int depth) {
    for (int i = 0; i < depth; i++) {
        sb.append("    ");
    }
    sb.append(describe(component));
    sb.append('\n');
    for (NlComponent child : component.getChildren()) {
        describe(sb, child, depth + 1);
    }
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 92 with NlComponent

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

the class ModelBuilder method updateModel.

/** Update the given model to reflect the component hierarchy in the given builder */
public void updateModel(NlModel model, boolean preserveXmlTags) {
    assertThat(model).isNotNull();
    // temporary workaround: replacing contents not working
    name("linear2.xml");
    NlModel newModel = preserveXmlTags ? model : build();
    model.updateHierarchy(newModel.getFile().getRootTag(), buildViewInfos(newModel));
    for (NlComponent component : newModel.getComponents()) {
        checkStructure(component);
    }
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel) SyncNlModel(com.android.tools.idea.uibuilder.SyncNlModel)

Example 93 with NlComponent

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

the class MarqueeInteraction method update.

@Override
public void update(@SwingCoordinate int x, @SwingCoordinate int y, @InputEventMask int modifiers) {
    if (myOverlay == null) {
        return;
    }
    int xp = Math.min(x, myStartX);
    int yp = Math.min(y, myStartY);
    int w = Math.abs(x - myStartX);
    int h = Math.abs(y - myStartY);
    myOverlay.updateSize(xp, yp, w, h);
    // Convert to Android coordinates and compute selection overlaps
    int ax = Coordinates.getAndroidX(myScreenView, xp);
    int ay = Coordinates.getAndroidY(myScreenView, yp);
    int aw = Coordinates.getAndroidDimension(myScreenView, w);
    int ah = Coordinates.getAndroidDimension(myScreenView, h);
    Collection<NlComponent> within = myScreenView.getModel().findWithin(ax, ay, aw, ah);
    List<NlComponent> selection = Lists.newArrayList();
    if (!myInitialSelection.isEmpty()) {
        // Copy; we're not allowed to touch the passed in collection
        Set<NlComponent> result = new HashSet<NlComponent>(myInitialSelection);
        for (NlComponent component : selection) {
            if (myInitialSelection.contains(component)) {
                result.remove(component);
            } else {
                result.add(component);
            }
        }
        within = result;
    }
    myScreenView.getSelectionModel().setSelection(within);
    myScreenView.getSurface().repaint();
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 94 with NlComponent

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

the class GuidelinePainter method paint.

public static void paint(@NotNull NlGraphics g, GuidelineHandler myState) {
    g.useStyle(DRAGGED);
    for (NlComponent dragged : myState.myDraggedNodes) {
        if (dragged.w > 0 && dragged.h > 0) {
            g.fillRect(dragged.x, dragged.y, dragged.w, dragged.h);
        }
    }
    Set<NlComponent> horizontalDeps = myState.myHorizontalDeps;
    Set<NlComponent> verticalDeps = myState.myVerticalDeps;
    Set<NlComponent> deps = new HashSet<NlComponent>(horizontalDeps.size() + verticalDeps.size());
    deps.addAll(horizontalDeps);
    deps.addAll(verticalDeps);
    if (deps.size() > 0) {
        g.useStyle(DEPENDENCY);
        for (NlComponent n : deps) {
            // Don't highlight the selected nodes themselves
            if (myState.myDraggedNodes.contains(n)) {
                continue;
            }
            g.fillRect(n.x, n.y, n.w, n.h);
        }
    }
    // If the layout has padding applied, draw the padding bounds to make it obvious what the boundaries are
    if (!myState.layout.getPadding().isEmpty() || !myState.layout.getMargins().isEmpty()) {
        g.useStyle(NlDrawingStyle.PADDING_BOUNDS);
        NlComponent layout = myState.layout;
        Insets padding = layout.getPadding();
        g.drawRect(layout.x + padding.left, layout.y + padding.top, Math.max(0, layout.w - padding.left - padding.right), Math.max(0, layout.h - padding.top - padding.bottom));
    }
    if (myState.myBounds != null) {
        Rectangle bounds = myState.myBounds;
        if (myState instanceof RelativeDragHandler) {
            g.useStyle(DROP_PREVIEW);
        } else {
            // Resizing
            if (myState.haveSuggestions()) {
                g.useStyle(RESIZE_PREVIEW);
            } else {
                g.useStyle(RESIZE_FAIL);
            }
        }
        g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height);
    // Draw baseline preview too
    // TODO: Implement when we have drag information from palette drag previews
    //if (myFeedback.dragBaseline != -1) {
    //  int y = myState.myBounds.y + myFeedback.dragBaseline;
    //  g.drawLine(myState.myBounds.x, y, myState.myBounds.x + myState.myBounds.width, y);
    //}
    }
    showMatch(g, myState.getCurrentLeftMatch(), myState);
    showMatch(g, myState.getCurrentRightMatch(), myState);
    showMatch(g, myState.getCurrentTopMatch(), myState);
    showMatch(g, myState.getCurrentBottomMatch(), myState);
    if (myState.myHorizontalCycle != null) {
        paintCycle(myState, g, myState.myHorizontalCycle);
    }
    if (myState.myVerticalCycle != null) {
        paintCycle(myState, g, myState.myVerticalCycle);
    }
}
Also used : Insets(com.android.tools.idea.uibuilder.model.Insets) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) HashSet(java.util.HashSet)

Example 95 with NlComponent

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

the class RelativeLayoutHandler method paintConstraints.

@Override
public boolean paintConstraints(@NotNull ScreenView screenView, @NotNull Graphics2D graphics, @NotNull NlComponent component) {
    NlGraphics g = new NlGraphics(graphics, screenView);
    Iterable<NlComponent> iterable = component.getChildren();
    List<NlComponent> children = Lists.newArrayList(iterable);
    ConstraintPainter.paintSelectionFeedback(g, component, children, true, TextDirection.LEFT_TO_RIGHT);
    return false;
}
Also used : NlGraphics(com.android.tools.idea.uibuilder.graphics.NlGraphics) 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