Search in sources :

Example 76 with NlComponent

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

the class TextInspectorProviderTest method testTextAppearanceResetsOtherStyles.

public void testTextAppearanceResetsOtherStyles() {
    List<NlComponent> components = ImmutableList.of(myTextView);
    Map<String, NlProperty> properties = getPropertyMap(components);
    properties.get(ATTR_FONT_FAMILY).setValue("serif");
    properties.get(ATTR_TYPEFACE).setValue("sans");
    properties.get(ATTR_TEXT_SIZE).setValue("24sp");
    properties.get(ATTR_LINE_SPACING_EXTRA).setValue("24sp");
    properties.get(ATTR_TEXT_COLOR).setValue("@android:color/holo_blue_dark");
    properties.get(ATTR_TEXT_STYLE).setValue("bold|italic");
    properties.get(ATTR_TEXT_ALL_CAPS).setValue("true");
    properties.get(ATTR_TEXT_ALIGNMENT).setValue("textStart");
    assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
    TextInspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
    inspector.refresh();
    Optional<NlComponentEditor> textAppearanceEditor = inspector.getEditors().stream().filter(editor -> editor.getProperty() != null && editor.getProperty().getName().equals(ATTR_TEXT_APPEARANCE)).findFirst();
    assertThat(textAppearanceEditor.isPresent()).isTrue();
    assert textAppearanceEditor.isPresent();
    assertThat(textAppearanceEditor.get()).isInstanceOf(NlBaseComponentEditor.class);
    NlBaseComponentEditor editor = (NlBaseComponentEditor) textAppearanceEditor.get();
    editor.stopEditing("Material.Display1");
    assertThat(properties.get(ATTR_TEXT_APPEARANCE).getValue()).isEqualTo("Material.Display1");
    assertThat(properties.get(ATTR_FONT_FAMILY).getValue()).isNull();
    assertThat(properties.get(ATTR_TYPEFACE).getValue()).isNull();
    assertThat(properties.get(ATTR_TEXT_SIZE).getValue()).isNull();
    assertThat(properties.get(ATTR_LINE_SPACING_EXTRA).getValue()).isNull();
    assertThat(properties.get(ATTR_TEXT_COLOR).getValue()).isNull();
    assertThat(properties.get(ATTR_TEXT_STYLE).getValue()).isNull();
    assertThat(properties.get(ATTR_TEXT_ALL_CAPS).getValue()).isNull();
    assertThat(properties.get(ATTR_TEXT_ALIGNMENT).getValue()).isNull();
}
Also used : SdkConstants(com.android.SdkConstants) HashMap(java.util.HashMap) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) Matchers.anyString(org.mockito.Matchers.anyString) java.awt(java.awt) Matchers.any(org.mockito.Matchers.any) PropertyTestCase(com.android.tools.idea.uibuilder.property.PropertyTestCase) Mockito(org.mockito.Mockito) List(java.util.List) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) com.android.tools.idea.uibuilder.property.editors(com.android.tools.idea.uibuilder.property.editors) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) Optional(java.util.Optional) TextInspectorComponent(com.android.tools.idea.uibuilder.property.inspector.TextInspectorProvider.TextInspectorComponent) PreferenceUtils(com.android.tools.idea.uibuilder.model.PreferenceUtils) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) TextInspectorComponent(com.android.tools.idea.uibuilder.property.inspector.TextInspectorProvider.TextInspectorComponent) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) Matchers.anyString(org.mockito.Matchers.anyString)

Example 77 with NlComponent

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

the class PropertyTestCase method clearSnapshots.

protected static void clearSnapshots(@NotNull List<NlComponent> components) {
    for (NlComponent component : components) {
        component.setSnapshot(null);
        clearSnapshots(component.getChildren());
    }
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 78 with NlComponent

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

the class IdAnalyzerTest method testButton1And2.

public void testButton1And2() {
    ModelBuilder modelBuilder = createRelativeLayout();
    NlModel model = modelBuilder.build();
    NlComponent button1 = findById(model, "button1");
    NlComponent button2 = findById(model, "button2");
    NlProperty accessibility = new NlPropertyItem(ImmutableList.of(button1, button2), ANDROID_URI, new AttributeDefinition(ATTR_ACCESSIBILITY_TRAVERSAL_BEFORE));
    IdAnalyzer analyzer = new IdAnalyzer(accessibility);
    List<String> ids = analyzer.findIds();
    assertEquals(ImmutableList.of("button3", "button4", "button5", "group1", "radio_button1", "radio_button2", "radio_button3", "text_view1"), ids);
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) NlModel(com.android.tools.idea.uibuilder.model.NlModel) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NlPropertyItem(com.android.tools.idea.uibuilder.property.NlPropertyItem)

Example 79 with NlComponent

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

the class IdAnalyzerTest method testRadioGroup.

public void testRadioGroup() {
    ModelBuilder modelBuilder = createRelativeLayout();
    NlModel model = modelBuilder.build();
    NlComponent group = findById(model, "group1");
    NlProperty property = new NlPropertyItem(ImmutableList.of(group), ANDROID_URI, new AttributeDefinition(ATTR_CHECKED_BUTTON));
    IdAnalyzer analyzer = new IdAnalyzer(property);
    List<String> ids = analyzer.findIds();
    assertEquals(ImmutableList.of("radio_button1", "radio_button2", "radio_button3"), ids);
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) NlModel(com.android.tools.idea.uibuilder.model.NlModel) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NlPropertyItem(com.android.tools.idea.uibuilder.property.NlPropertyItem)

Example 80 with NlComponent

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

the class IdInspectorProviderTest method testInspectorComponent.

public void testInspectorComponent() {
    List<NlComponent> components = ImmutableList.of(myTextView);
    Map<String, NlProperty> properties = getPropertyMap(components);
    assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
    IdInspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
    List<NlComponentEditor> editors = inspector.getEditors();
    assertThat(editors.size()).isEqualTo(3);
    assertThat(inspector.getMaxNumberOfRows()).isEqualTo(4);
    InspectorPanel panel = mock(InspectorPanel.class);
    when(panel.addComponent(anyString(), anyString(), any())).thenAnswer(invocation -> new JLabel());
    inspector.attachToInspector(panel);
    for (NlComponentEditor editor : editors) {
        NlProperty property = editor.getProperty();
        assertThat(property).isNotNull();
        String propertyName = property.getName();
        if (propertyName.equals(ATTR_ID)) {
            propertyName = "ID";
        }
        verify(panel).addComponent(eq(propertyName), eq(null), eq(editor.getComponent()));
    }
    verify(panel, never()).addPanel(inspector.getConstraintPanel());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) Matchers.anyString(org.mockito.Matchers.anyString) IdInspectorComponent(com.android.tools.idea.uibuilder.property.inspector.IdInspectorProvider.IdInspectorComponent) NlComponentEditor(com.android.tools.idea.uibuilder.property.editors.NlComponentEditor)

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