Search in sources :

Example 1 with NlComponent

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

the class NlComponentUtils method getMap.

private static HashMap<String, NlComponent> getMap(NlComponent nlComponent) {
    List<NlComponent> list = nlComponent.getModel().getComponents();
    HashMap<String, NlComponent> map = new HashMap<String, NlComponent>();
    for (NlComponent component : list) {
        String id = component.getAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_ID);
        if (id != null) {
            map.put(id, component);
        }
    }
    return map;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) HashMap(java.util.HashMap)

Example 2 with NlComponent

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

the class NlComponentUtils method getTopMostInChain.

public static NlComponent getTopMostInChain(NlComponent component) {
    HashMap<String, NlComponent> map = getMap(component);
    NlComponent current = component;
    NlComponent leftComponent;
    do {
        leftComponent = current;
        current = getDir(map, leftComponent, TOP);
        if (current == null) {
            return leftComponent;
        }
    } while (getDir(map, current, BOTTOM) == leftComponent);
    return leftComponent;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 3 with NlComponent

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

the class ConstraintLayoutHandler method willDelete.

/**
   * Update the given component if one of its constraint points to one of the component deleted
   *
   * @param component the component we want to check
   * @param deleted the list of components that are deleted
   */
private void willDelete(NlComponent component, @NotNull List<NlComponent> deleted) {
    final int count = deleted.size();
    for (int i = 0; i < count; i++) {
        NlComponent deletedComponent = deleted.get(i);
        String id = deletedComponent.getId();
        ConstraintComponentUtilities.updateOnDelete(component, id);
    }
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 4 with NlComponent

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

the class ConstraintLayoutHandler method deleteChildren.

/**
   * Called when one or more children are about to be deleted by the user.
   *
   * @param parent  the parent of the deleted children (which still contains
   *                the children since this method is called before the deletion
   *                is performed)
   * @param deleted a nonempty list of children about to be deleted
   * @return true if the children have been fully deleted by this participant; false if normal deletion should resume. Note that even though
   * an implementation may return false from this method, that does not mean it did not perform any work. For example, a RelativeLayout
   * handler could remove constraints pointing to now deleted components, but leave the overall deletion of the elements to the core
   * designer.
   */
@Override
public boolean deleteChildren(@NotNull NlComponent parent, @NotNull List<NlComponent> deleted) {
    final int count = parent.getChildCount();
    for (int i = 0; i < count; i++) {
        NlComponent component = parent.getChild(i);
        if (deleted.contains(component)) {
            continue;
        }
        willDelete(component, deleted);
    }
    return false;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 5 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) {
    NlComponent component = null;
    int x = event.getX();
    int y = event.getY();
    ScreenView screenView = mySurface.getScreenView(x, y);
    if (screenView == null) {
        screenView = mySurface.getCurrentScreenView();
    }
    if (screenView != null) {
        component = Coordinates.findComponent(screenView, x, y);
    }
    showPopup(event, screenView, component);
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) 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