Search in sources :

Example 16 with NlModel

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

the class MockupTest method testGetBounds_0000_Position.

public void testGetBounds_0000_Position() {
    final NlModel model = createModel1Mockup(MOCKUP_PSD, "0 0 0 0", 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 componentSwingCoordinates = new Rectangle(0, 0, Coordinates.getSwingDimension(screenView, 1000), // See createModel for the 1000 value
    Coordinates.getSwingDimension(screenView, 1000));
    final Rectangle destinationRectangle = mockup.getScreenBounds(screenView);
    assertEquals(componentSwingCoordinates, 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 17 with NlModel

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

the class MockupTest method testCreateMockupModelFromCorrectFullString.

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

Example 18 with NlModel

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

the class MockupTest method testCreateMockupModelFromIncorrectPositionString.

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

Example 19 with NlModel

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

the class MockupTest method testCreateMockup.

public void testCreateMockup() {
    final NlModel model = createModel1Mockup(MOCKUP_PSD, DEFAULT_TEST_POSITION, "0.4");
    NlComponent component = model.getComponents().get(0).getRoot();
    final Mockup mockup = Mockup.create(component);
    assertNotNull("Model creation", mockup);
    assertEquals(new Rectangle(20, 20, 60, 60), mockup.getBounds());
    assertEquals(new Rectangle(10, 10, 60, 60), mockup.getCropping());
    assertEquals(0.4f, mockup.getAlpha());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 20 with NlModel

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

the class MockupTestCase method createModel0Mockup.

protected NlModel createModel0Mockup() {
    ModelBuilder builder = model("relative.xml", component(RELATIVE_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight());
    final NlModel model = builder.build();
    assertEquals(1, model.getComponents().size());
    return model;
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

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