Search in sources :

Example 61 with NlModel

use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.

the class MockupTest method testCreateMockup_createWithoutAttribute.

public void testCreateMockup_createWithoutAttribute() {
    final NlModel model = createModel0Mockup();
    final NlComponent component = model.getComponents().get(0);
    assertNotNull(Mockup.create(component, true));
    assertNull(Mockup.create(component, false));
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 62 with NlModel

use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.

the class MockupTestCase method createModel1Mockup.

protected NlModel createModel1Mockup(@NotNull String mockupFile, @Nullable String mockupPosition, @Nullable String opacity) {
    final ComponentDescriptor root = component(RELATIVE_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().withAttribute(TOOLS_URI, ATTR_MOCKUP, mockupFile);
    if (mockupPosition != null) {
        root.withAttribute(TOOLS_URI, ATTR_MOCKUP_CROP, mockupPosition);
    }
    if (opacity != null) {
        root.withAttribute(TOOLS_URI, ATTR_MOCKUP_OPACITY, opacity);
    }
    ModelBuilder builder = model("relative.xml", root);
    final NlModel model = builder.build();
    assertEquals(1, model.getComponents().size());
    return model;
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) ComponentDescriptor(com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 63 with NlModel

use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.

the class MockupTest method testCreateMockupModelFromCorrectXYString.

public void testCreateMockupModelFromCorrectXYString() {
    final NlModel model = createModel1Mockup(MOCKUP_PSD, "0 0 -1 -1 1 2");
    NlComponent component = model.getComponents().get(0);
    //mockProject, "", "1 2");
    final Mockup mockup = Mockup.create(component);
    assertNotNull(mockup);
    assertEquals(new Rectangle(1, 2, -1, -1), mockup.getBounds());
    assertEquals(new Rectangle(0, 0, -1, -1), mockup.getCropping());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 64 with NlModel

use of com.android.tools.idea.uibuilder.model.NlModel 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 65 with NlModel

use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.

the class NlComponentTreeTest method createModel.

@NotNull
private NlModel createModel() {
    ModelBuilder builder = model("relative.xml", component(RELATIVE_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().children(component(LINEAR_LAYOUT).withBounds(0, 0, 200, 200).wrapContentWidth().wrapContentHeight().children(component(BUTTON).withBounds(0, 0, 100, 100).id("@+id/myButton").width("100dp").height("100dp")), component(TEXT_VIEW).withBounds(0, 200, 100, 100).id("@+id/myText").width("100dp").height("100dp"), component(ABSOLUTE_LAYOUT).withBounds(0, 300, 400, 500).width("400dp").height("500dp")));
    final NlModel model = builder.build();
    assertEquals(1, model.getComponents().size());
    assertEquals("NlComponent{tag=<RelativeLayout>, bounds=[0,0:1000x1000}\n" + "    NlComponent{tag=<LinearLayout>, bounds=[0,0:200x200}\n" + "        NlComponent{tag=<Button>, bounds=[0,0:100x100}\n" + "    NlComponent{tag=<TextView>, bounds=[0,200:100x100}\n" + "    NlComponent{tag=<AbsoluteLayout>, bounds=[0,300:400x500}", NlTreeDumper.dumpTree(model.getComponents()));
    return model;
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NlModel (com.android.tools.idea.uibuilder.model.NlModel)71 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)33 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)19 NotNull (org.jetbrains.annotations.NotNull)18 XmlFile (com.intellij.psi.xml.XmlFile)14 Project (com.intellij.openapi.project.Project)12 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)11 Result (com.intellij.openapi.application.Result)11 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)11 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)6 ComponentDescriptor (com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor)5 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)5 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)5 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)5 Configuration (com.android.tools.idea.configurations.Configuration)4 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 SelectionModel (com.android.tools.idea.uibuilder.model.SelectionModel)2 XmlTag (com.intellij.psi.xml.XmlTag)2 BufferedImage (java.awt.image.BufferedImage)2