Search in sources :

Example 1 with TextInspectorComponent

use of com.android.tools.idea.uibuilder.property.inspector.TextInspectorProvider.TextInspectorComponent in project android by JetBrains.

the class TextInspectorProviderTest method testInspectorComponent.

public void testInspectorComponent() {
    List<NlComponent> components = ImmutableList.of(myTextView);
    Map<String, NlProperty> properties = getPropertyMap(components);
    assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
    TextInspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
    List<NlComponentEditor> editors = inspector.getEditors();
    assertThat(editors.size()).isEqualTo(9);
    assertThat(inspector.getMaxNumberOfRows()).isEqualTo(12);
    InspectorPanel panel = mock(InspectorPanel.class);
    when(panel.addComponent(anyString(), anyString(), any())).thenAnswer(invocation -> new JLabel());
    inspector.attachToInspector(panel);
    verify(panel).addTitle(eq(TEXT_VIEW));
    for (NlComponentEditor editor : editors) {
        NlProperty property = editor.getProperty();
        assertThat(property).isNotNull();
        if (property.getName().equals(ATTR_TEXT_APPEARANCE)) {
            assertThat(editor).isInstanceOf(NlEnumEditor.class);
            NlEnumEditor enumEditor = (NlEnumEditor) editor;
            verify(panel).addExpandableComponent(eq(property.getName()), eq(property.getTooltipText()), eq(editor.getComponent()), eq(enumEditor.getKeySource()));
        } else {
            verify(panel).addComponent(eq(property.getName()), eq(property.getTooltipText()), eq(editor.getComponent()));
        }
    }
    propertyPanelHasAllComponents(panel, ATTR_TEXT_STYLE, properties, inspector.getTextStyleEditors());
    propertyPanelHasAllComponents(panel, ATTR_TEXT_ALIGNMENT, properties, inspector.getTextAlignmentEditors());
}
Also used : 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 2 with TextInspectorComponent

use of com.android.tools.idea.uibuilder.property.inspector.TextInspectorProvider.TextInspectorComponent 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)

Aggregations

NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)2 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)2 TextInspectorComponent (com.android.tools.idea.uibuilder.property.inspector.TextInspectorProvider.TextInspectorComponent)2 Matchers.anyString (org.mockito.Matchers.anyString)2 SdkConstants (com.android.SdkConstants)1 PreferenceUtils (com.android.tools.idea.uibuilder.model.PreferenceUtils)1 PropertyTestCase (com.android.tools.idea.uibuilder.property.PropertyTestCase)1 com.android.tools.idea.uibuilder.property.editors (com.android.tools.idea.uibuilder.property.editors)1 ImmutableList (com.google.common.collect.ImmutableList)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 java.awt (java.awt)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 javax.swing (javax.swing)1 NotNull (org.jetbrains.annotations.NotNull)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 Matchers.any (org.mockito.Matchers.any)1