Search in sources :

Example 31 with ScreenView

use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.

the class MockupEditor method setToolContext.

@Override
public void setToolContext(@Nullable DesignSurface newDesignSurface) {
    if (mySurface != null) {
        mySurface.removeListener(myDesignSurfaceListener);
        mySurface = null;
        myExtractWidgetTool.setDesignSurface(null);
    }
    ScreenView screenView = newDesignSurface != null ? newDesignSurface.getCurrentScreenView() : null;
    if (screenView != null) {
        mySurface = newDesignSurface;
        mySurface.addListener(myDesignSurfaceListener);
        setModel(screenView.getModel());
        myExtractWidgetTool.setDesignSurface(mySurface);
    }
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView)

Example 32 with ScreenView

use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.

the class MockupTest method testGetBounds_nullPosition.

public void testGetBounds_nullPosition() {
    final NlModel model = createModel1Mockup(MOCKUP_PSD, null, null);
    final NlComponent component = model.getComponents().get(0);
    final Mockup mockup = Mockup.create(component);
    assertNotNull(mockup);
    DesignSurface mockSurface = mock(DesignSurface.class);
    when(mockSurface.getScale()).thenReturn(1.0);
    final ScreenView screenView = new ScreenView(mockSurface, ScreenView.ScreenViewType.BLUEPRINT, model);
    final Rectangle destinationRectangle = mockup.getScreenBounds(screenView);
    assertEquals(new Rectangle(0, 0, component.w, component.h), destinationRectangle);
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 33 with ScreenView

use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.

the class MockupTest method testGetBounds_Normal_Position.

public void testGetBounds_Normal_Position() {
    final NlModel model = createModel1Mockup(MOCKUP_PSD, "0 0 -1 -1 10 10 120 50");
    DesignSurface mockSurface = mock(DesignSurface.class);
    when(mockSurface.getScale()).thenReturn(1.0);
    Configuration configuration = mock(Configuration.class);
    when(configuration.getDensity()).thenReturn(Density.DPI_280);
    ScreenView screenView = mock(ScreenView.class);
    when(screenView.getX()).thenReturn(0);
    when(screenView.getY()).thenReturn(0);
    when(screenView.getSize()).thenReturn(new Dimension(1000, 2000));
    when(screenView.getSize(anyObject())).thenReturn(new Dimension(1000, 2000));
    when(screenView.getScale()).thenReturn(2.);
    when(screenView.getConfiguration()).thenReturn(configuration);
    final Mockup mockup = Mockup.create(model.getComponents().get(0));
    assertNotNull(mockup);
    assertEquals(new Rectangle(10, 10, 120, 50), mockup.getBounds());
    final Rectangle swingBounds = mockup.getScreenBounds(screenView);
    assertEquals(Coordinates.getSwingXDip(screenView, 10), swingBounds.x, 2.);
    assertEquals(Coordinates.getSwingXDip(screenView, 10), swingBounds.y, 2.);
    assertEquals(Coordinates.getSwingDimensionDip(screenView, 110), swingBounds.width, 2.);
    assertEquals(Coordinates.getSwingDimensionDip(screenView, 40), swingBounds.height, 2.);
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) Configuration(com.android.tools.idea.configurations.Configuration) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 34 with ScreenView

use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.

the class GenerateLayoutTestSkeletonAction method getModel.

@Nullable
private static NlModel getModel(@Nullable Project project) {
    if (project == null) {
        return null;
    }
    DesignSurface surface = getSurface(project);
    if (surface == null) {
        return null;
    }
    ScreenView screenView = surface.getCurrentScreenView();
    if (screenView == null) {
        return null;
    }
    return screenView.getModel();
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) Nullable(org.jetbrains.annotations.Nullable)

Example 35 with ScreenView

use of com.android.tools.idea.uibuilder.surface.ScreenView in project android by JetBrains.

the class GotoComponentAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    ScreenView screenView = mySurface.getCurrentScreenView();
    if (screenView != null) {
        SelectionModel selectionModel = screenView.getSelectionModel();
        NlComponent primary = selectionModel.getPrimary();
        if (primary != null) {
            XmlTag tag = primary.getTag();
            if (tag.isValid()) {
                screenView.getSurface().deactivate();
                PsiNavigateUtil.navigate(tag);
            }
        }
    }
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) SelectionModel(com.android.tools.idea.uibuilder.model.SelectionModel) XmlTag(com.intellij.psi.xml.XmlTag)

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