Search in sources :

Example 1 with ScreenView

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);
        }
    };
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) Mockup(com.android.tools.idea.uibuilder.mockup.Mockup) WidgetCreator(com.android.tools.idea.uibuilder.mockup.editor.creators.WidgetCreator) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ScreenView

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;
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration)

Example 3 with 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;
            }
        }
    }
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Editor(com.intellij.openapi.editor.Editor)

Example 4 with ScreenView

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);
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 5 with ScreenView

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

ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)42 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)16 NlModel (com.android.tools.idea.uibuilder.model.NlModel)6 SelectionModel (com.android.tools.idea.uibuilder.model.SelectionModel)6 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)6 Nullable (org.jetbrains.annotations.Nullable)5 NotNull (org.jetbrains.annotations.NotNull)4 Configuration (com.android.tools.idea.configurations.Configuration)3 LintAnnotationsModel (com.android.tools.idea.uibuilder.lint.LintAnnotationsModel)2 Presentation (com.intellij.openapi.actionSystem.Presentation)2 BufferedImage (java.awt.image.BufferedImage)2 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)1 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)1 GradleDependencyManager (com.android.tools.idea.gradle.dependencies.GradleDependencyManager)1 RenderResult (com.android.tools.idea.rendering.RenderResult)1 InsertType (com.android.tools.idea.uibuilder.api.InsertType)1 ViewEditor (com.android.tools.idea.uibuilder.api.ViewEditor)1 ViewHandler (com.android.tools.idea.uibuilder.api.ViewHandler)1 ViewEditorImpl (com.android.tools.idea.uibuilder.handlers.ViewEditorImpl)1 LintNotificationPanel (com.android.tools.idea.uibuilder.lint.LintNotificationPanel)1