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);
}
Aggregations