use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class NlActionManager method addViewHandlerActions.
private void addViewHandlerActions(@NotNull DefaultActionGroup group, @NotNull NlComponent component, @NotNull List<NlComponent> selection) {
// Look up view handlers
int prevCount = group.getChildrenCount();
NlComponent parent = !component.isRoot() ? component.getParent() : null;
addViewActions(group, component, parent, selection, false);
if (group.getChildrenCount() > prevCount) {
group.addSeparator();
}
}
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, @Nullable ScreenView screenView, @Nullable NlComponent leafComponent) {
ActionManager actionManager = ActionManager.getInstance();
DefaultActionGroup group = createPopupMenu(actionManager, screenView, leafComponent);
ActionPopupMenu popupMenu = actionManager.createActionPopupMenu("LayoutEditor", group);
Component invoker = event.getSource() instanceof Component ? (Component) event.getSource() : mySurface;
popupMenu.getComponent().show(invoker, event.getX(), event.getY());
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class AbsoluteLayoutHandler method createDragHandler.
@Override
@Nullable
public DragHandler createDragHandler(@NotNull ViewEditor editor, @NotNull NlComponent layout, @NotNull List<NlComponent> components, @NotNull DragType type) {
return new DragHandler(editor, this, layout, components, type) {
@Override
public void paint(@NotNull NlGraphics graphics) {
int deltaX = lastX - startX;
int deltaY = lastY - startY;
for (NlComponent component : components) {
int x = component.x + deltaX;
int y = component.y + deltaY;
int w = component.w;
int h = component.h;
graphics.useStyle(NlDrawingStyle.DROP_PREVIEW);
graphics.drawRect(x, y, w, h);
}
}
@Override
public void commit(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers, @NotNull InsertType insertType) {
// TODO: Remove all existing layout parameters; if you're dragging from one layout type to another, you don't
// want stale layout parameters (e.g. layout_alignLeft from a previous RelativeLayout in a new GridLayout, and so on.)
int deltaX = x - startX;
int deltaY = y - startY;
for (NlComponent component : components) {
component.setAttribute(ANDROID_URI, ATTR_LAYOUT_X, editor.pxToDpWithUnits(component.x - layout.x + deltaX));
component.setAttribute(ANDROID_URI, ATTR_LAYOUT_Y, editor.pxToDpWithUnits(component.y - layout.y + deltaY));
}
insertComponents(-1, insertType);
}
};
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class ViewHandlerManager method findLayoutHandler.
/**
* Finds the nearest layout/view group handler for the given component.
*
* @param component the component to search from
* @param strict if true, only consider parents of the component, not the component itself
*/
@Nullable
public ViewGroupHandler findLayoutHandler(@NotNull NlComponent component, boolean strict) {
NlComponent curr = component;
if (strict) {
curr = curr.getParent();
}
while (curr != null) {
ViewHandler handler = getHandler(curr);
if (handler instanceof ViewGroupHandler) {
return (ViewGroupHandler) handler;
}
curr = curr.getParent();
}
return null;
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class ConstraintDragHandler method commit.
@Override
public void commit(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers, @NotNull InsertType insertType) {
if (myComponent != null) {
myComponent = components.get(0);
myComponent.x = x;
myComponent.y = y;
NlComponent root = myComponent.getRoot();
root.ensureNamespace(SdkConstants.SHERPA_PREFIX, SdkConstants.AUTO_URI);
ConstraintModel model = ConstraintModel.getConstraintModel(editor.getModel());
if (model != null) {
int ax = model.pxToDp(x - this.layout.x - this.layout.getPadding().left - myComponent.w / 2);
int ay = model.pxToDp(y - this.layout.y - this.layout.getPadding().top - myComponent.h / 2);
AttributesTransaction attributes = myComponent.startAttributeTransaction();
ConstraintUtilities.setEditorPosition(null, attributes, ax, ay);
attributes.commit();
}
if (myDragWidget != null) {
model.commitDragComponent(myComponent);
}
}
insertComponents(-1, insertType);
}
Aggregations