use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.
the class ExtractWidgetTool method createAnActionButton.
@NotNull
private AnAction createAnActionButton(@NotNull final CreatorAction creatorAction, boolean viewGroupOnly) {
return new AnAction(creatorAction.myTitle, creatorAction.myTitle, creatorAction.myIcon) {
@Override
public void update(AnActionEvent e) {
Mockup mockup = myMockupEditor.getMockup();
if (viewGroupOnly && (mockup == null || !canAddChild(creatorAction, mockup.getComponent()))) {
e.getPresentation().setEnabledAndVisible(false);
} else {
e.getPresentation().setEnabledAndVisible(true);
}
}
@Override
public void actionPerformed(AnActionEvent e) {
Mockup mockup = myMockupEditor.getMockup();
ScreenView currentScreenView = mySurface.getCurrentScreenView();
if (mockup == null) {
myMockupEditor.showError("Cannot create a widget from an empty mockup");
LOGGER.warn("MockupEditor has no associated mockup");
return;
}
if (currentScreenView == null) {
myMockupEditor.showError("The designer is not ready to create a new widget");
LOGGER.warn("The DesignSurface does not have a current screen view");
return;
}
WidgetCreator creator = WidgetCreatorFactory.create(creatorAction.myAndroidClassName, mockup, currentScreenView.getModel(), currentScreenView, mySelection);
executeCreator(creator);
}
};
}
use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.
the class LayoutTestUtilities method createScreen.
public static ScreenView createScreen(DesignSurface surface, NlModel model, SelectionModel selectionModel, double scale, @SwingCoordinate int x, @SwingCoordinate int y, Density density) {
Configuration configuration = mock(Configuration.class);
when(configuration.getDensity()).thenReturn(density);
when(configuration.getFile()).thenReturn(model.getFile().getVirtualFile());
when(configuration.getFullConfig()).thenReturn(new FolderConfiguration());
ScreenView screenView = mock(ScreenView.class);
when(screenView.getConfiguration()).thenReturn(configuration);
when(screenView.getModel()).thenReturn(model);
when(screenView.getScale()).thenReturn(scale);
when(screenView.getSelectionModel()).thenReturn(selectionModel);
when(screenView.getSize()).thenReturn(new Dimension());
when(screenView.getSurface()).thenReturn(surface);
when(screenView.getX()).thenReturn(x);
when(screenView.getY()).thenReturn(y);
when(surface.getScreenView(anyInt(), anyInt())).thenReturn(screenView);
return screenView;
}
use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.
the class NlPreviewForm method selectComponent.
private void selectComponent(@Nullable NlComponent component) {
ScreenView screenView = mySurface.getCurrentScreenView();
if (screenView == null) {
return;
}
if (myEditor != null && component != null && component.getTag().isValid() && myUseInteractiveSelector && !myIgnoreListener) {
int offset = component.getTag().getTextOffset();
if (offset != -1) {
Editor editor = myEditor.getEditor();
myIgnoreListener = true;
try {
screenView.getSelectionModel().setSelection(Collections.singletonList(component));
editor.getCaretModel().moveToOffset(offset);
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
} finally {
myIgnoreListener = false;
}
}
}
}
use of com.android.tools.idea.uibuilder.surface.ScreenView 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);
}
use of com.android.tools.idea.uibuilder.surface.ScreenView 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