Search in sources :

Example 1 with InsertionPoint

use of com.android.tools.idea.uibuilder.structure.NlComponentTree.InsertionPoint in project android by JetBrains.

the class NlDropListener method findInsertionPoint.

@Nullable
private Pair<TreePath, InsertionPoint> findInsertionPoint(@NotNull NlDropEvent event) {
    myDragReceiver = null;
    myNextDragSibling = null;
    TreePath path = myTree.getClosestPathForLocation(event.getLocation().x, event.getLocation().y);
    if (path == null) {
        return null;
    }
    ScreenView screenView = myTree.getScreenView();
    if (screenView == null) {
        return null;
    }
    NlModel model = screenView.getModel();
    NlComponent component = (NlComponent) path.getLastPathComponent();
    if (component == null) {
        return null;
    }
    Rectangle bounds = myTree.getPathBounds(path);
    if (bounds == null) {
        return null;
    }
    InsertionPoint insertionPoint = findTreeStateInsertionPoint(event.getLocation().y, bounds);
    if (shouldInsert(component, insertionPoint)) {
        if (!canAddComponent(model, component)) {
            return null;
        }
        myDragReceiver = component;
        myNextDragSibling = component.getChild(0);
    } else {
        NlComponent parent = component.getParent();
        if (parent == null) {
            return null;
        } else {
            if (parent.getViewHandler() == null || !model.canAddComponents(myDragged, parent, component)) {
                return null;
            }
            insertionPoint = event.getLocation().y > bounds.getCenterY() ? INSERT_AFTER : INSERT_BEFORE;
            myDragReceiver = parent;
            if (insertionPoint == INSERT_BEFORE) {
                myNextDragSibling = component;
            } else {
                myNextDragSibling = component.getNextSibling();
            }
        }
    }
    return Pair.of(path, insertionPoint);
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) TreePath(javax.swing.tree.TreePath) InsertionPoint(com.android.tools.idea.uibuilder.structure.NlComponentTree.InsertionPoint) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

InsertionPoint (com.android.tools.idea.uibuilder.structure.NlComponentTree.InsertionPoint)1 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)1 TreePath (javax.swing.tree.TreePath)1 Nullable (org.jetbrains.annotations.Nullable)1