Search in sources :

Example 41 with NlComponent

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

the class GridDragHandlerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    GridLayout viewObject = new GridLayout();
    viewObject.setVerticalAxis(new Axis(new int[] { 0, 1024 }));
    viewObject.setHorizontalAxis(new Axis(new int[] { 0, 248, 248, 248, 248, 248, 248, 248, 248, 520, 768 }));
    viewObject.setRowCount(1);
    viewObject.setColumnCount(10);
    // @formatter:off
    ComponentDescriptor button1 = component(SdkConstants.BUTTON).withBounds(0, 160, 248, 96).withAttribute("android:layout_row", "0").withAttribute("android:layout_column", "0").layoutParamsObject(new LayoutParams(new Spec(new Interval(0, 1)), new Spec(new Interval(0, 1))));
    ComponentDescriptor button2 = component(SdkConstants.BUTTON).withBounds(520, 160, 248, 96).withAttribute("android:layout_row", "0").withAttribute("android:layout_column", "9").layoutParamsObject(new LayoutParams(new Spec(new Interval(0, 1)), new Spec(new Interval(9, 10))));
    ComponentDescriptor layout = component(SdkConstants.GRID_LAYOUT).withBounds(0, 160, 768, 1024).viewObject(viewObject).children(button1, button2);
    NlModel model = model("grid_layout.xml", layout).build();
    // @formatter:on
    ViewEditor editor = Mockito.mock(ViewEditor.class);
    Mockito.when(editor.getModel()).thenReturn(model);
    List<NlComponent> components = Collections.emptyList();
    handler = new GridDragHandler(editor, new ViewGroupHandler(), model.getComponents().get(0), components, DragType.CREATE);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ComponentDescriptor(com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor) ViewEditor(com.android.tools.idea.uibuilder.api.ViewEditor) NlModel(com.android.tools.idea.uibuilder.model.NlModel) ViewGroupHandler(com.android.tools.idea.uibuilder.api.ViewGroupHandler)

Example 42 with NlComponent

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

the class MockupTest method testSetAlphaString.

public void testSetAlphaString() {
    NlModel model = createModel1Mockup(MOCKUP_PSD, DEFAULT_TEST_POSITION);
    final NlComponent component = model.getComponents().get(0);
    final Mockup mockup = Mockup.create(component);
    assertNotNull(mockup);
    assertEquals(Mockup.DEFAULT_OPACITY, mockup.getAlpha());
    mockup.setAlpha("0.9");
    assertEquals(0.9f, mockup.getAlpha());
    mockup.setAlpha("2.9");
    assertEquals(Mockup.DEFAULT_OPACITY_IF_ERROR, mockup.getAlpha());
    mockup.setAlpha("-2.9");
    assertEquals(Mockup.DEFAULT_OPACITY_IF_ERROR, mockup.getAlpha());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 43 with NlComponent

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

the class MockupTest method testCreateMockupLayerEmptyStringPosition.

public void testCreateMockupLayerEmptyStringPosition() {
    final NlModel model = createModel1Mockup(MOCKUP_PSD, "");
    NlComponent component = model.getComponents().get(0).getRoot();
    final Mockup mockup = Mockup.create(component);
    assertNotNull("Model creation", mockup);
    assertEquals(new Rectangle(0, 0, -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 44 with NlComponent

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

use of com.android.tools.idea.uibuilder.model.NlComponent 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)

Aggregations

NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)184 NlModel (com.android.tools.idea.uibuilder.model.NlModel)34 NotNull (org.jetbrains.annotations.NotNull)34 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)18 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)17 Nullable (org.jetbrains.annotations.Nullable)14 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)11 ViewGroupHandler (com.android.tools.idea.uibuilder.api.ViewGroupHandler)9 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)9 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)8 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)7 XmlFile (com.intellij.psi.xml.XmlFile)7 XmlTag (com.intellij.psi.xml.XmlTag)7 ArrayList (java.util.ArrayList)7 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)6 NlGraphics (com.android.tools.idea.uibuilder.graphics.NlGraphics)6 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)6 Project (com.intellij.openapi.project.Project)6 List (java.util.List)6