Search in sources :

Example 1 with ResourceComponent

use of com.android.tools.idea.editors.theme.ui.ResourceComponent in project android by JetBrains.

the class ThemeEditorTableFixture method attributeNameAt.

@NotNull
public String attributeNameAt(@NotNull final TableCell cell) {
    return GuiQuery.getNonNull(() -> {
        Component renderer = rendererComponentAt(cell);
        checkState(renderer instanceof ResourceComponent, "not a %s: %s", ResourceComponent.class.getSimpleName(), renderer);
        return new ResourceComponentFixture(robot(), (ResourceComponent) renderer).getLabelText();
    });
}
Also used : ResourceComponent(com.android.tools.idea.editors.theme.ui.ResourceComponent) ResourceComponent(com.android.tools.idea.editors.theme.ui.ResourceComponent) Component(java.awt.Component) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ResourceComponent

use of com.android.tools.idea.editors.theme.ui.ResourceComponent in project android by JetBrains.

the class ThemeEditorTableTest method testStateListPicker.

/**
   * Test creating a new state list and setting it as a style attribute value with the state list picker.
   */
@Test
public void testStateListPicker() throws IOException {
    guiTest.importSimpleApplication();
    ThemeEditorFixture themeEditor = ThemeEditorGuiTestUtils.openThemeEditor(guiTest.ideFrame());
    ThemeEditorTableFixture themeEditorTable = themeEditor.getPropertiesTable();
    TableCell parentCell = row(0).column(0);
    JTableCellFixture parentCellFixture = themeEditorTable.cell(parentCell);
    // Selects AppCompat as parent
    Component parentEditor = parentCellFixture.editor();
    parentCellFixture.startEditing();
    JComboBoxFixture parentComboBox = new JComboBoxFixture(guiTest.robot(), guiTest.robot().finder().findByType((JComponent) parentEditor, JComboBox.class));
    parentComboBox.selectItem("Theme.AppCompat.NoActionBar");
    parentCellFixture.stopEditing();
    TableCell cell = row(8).column(0);
    FontFixture cellFont = themeEditorTable.fontAt(cell);
    cellFont.requireNotBold();
    assertEquals("android:textColorPrimary", themeEditorTable.attributeNameAt(cell));
    assertEquals("@android:color/primary_text_material_dark", themeEditorTable.valueAt(cell));
    JTableCellFixture stateListCell = themeEditorTable.cell(cell);
    ResourceComponentFixture resourceComponent = new ResourceComponentFixture(guiTest.robot(), (ResourceComponent) stateListCell.editor());
    stateListCell.startEditing();
    resourceComponent.getSwatchButton().click();
    final ChooseResourceDialogFixture dialog = ChooseResourceDialogFixture.find(guiTest.robot());
    StateListPickerFixture stateListPicker = dialog.getStateListPicker();
    List<StateListComponentFixture> states = stateListPicker.getStateComponents();
    assertThat(states).hasSize(2);
    final StateListComponentFixture state0 = states.get(0);
    assertEquals("Not enabled", state0.getStateName());
    assertEquals("@android:color/primary_text_default_material_dark", state0.getValue());
    assertTrue(state0.isAlphaVisible());
    assertEquals("@android:dimen/disabled_alpha_material_dark", state0.getAlphaValue());
    final StateListComponentFixture state1 = states.get(1);
    assertEquals("Default", state1.getStateName());
    assertEquals("@android:color/primary_text_default_material_dark", state1.getValue());
    assertFalse(state1.isAlphaVisible());
    state0.getValueComponent().getSwatchButton().click();
    ChooseResourceDialogFixture secondDialog = ChooseResourceDialogFixture.find(guiTest.robot(), new GenericTypeMatcher<JDialog>(JDialog.class) {

        @Override
        protected boolean isMatching(@NotNull JDialog component) {
            return !component.equals(dialog.target());
        }
    });
    secondDialog.getColorPicker().setColorWithIntegers(new Color(200, 0, 0, 200));
    secondDialog.clickOK();
    Wait.seconds(1).expecting("component update").until(() -> "@color/primary_text_default_material_dark".equals(state0.getValue()));
    state0.getAlphaComponent().getSwatchButton().click();
    secondDialog = ChooseResourceDialogFixture.find(guiTest.robot(), new GenericTypeMatcher<JDialog>(JDialog.class) {

        @Override
        protected boolean isMatching(@NotNull JDialog component) {
            return !component.equals(dialog.target());
        }
    });
    secondDialog.getResourceNameTable().cell("android:disabledAlpha").click();
    secondDialog.clickOK();
    Wait.seconds(1).expecting("component update").until(() -> "?android:attr/disabledAlpha".equals(state0.getAlphaValue()));
    state1.getValueComponent().getSwatchButton().click();
    secondDialog = ChooseResourceDialogFixture.find(guiTest.robot(), new GenericTypeMatcher<JDialog>(JDialog.class) {

        @Override
        protected boolean isMatching(@NotNull JDialog component) {
            return !component.equals(dialog.target());
        }
    });
    secondDialog.getColorPicker().setColorWithIntegers(new Color(0, 200, 0, 255));
    secondDialog.clickOK();
    Wait.seconds(1).expecting("component update").until(() -> "@color/primary_text_default_material_dark".equals(state1.getValue()));
    dialog.requireNoError();
    dialog.clickOK();
    stateListCell.stopEditing();
    cellFont = themeEditorTable.fontAt(cell);
    cellFont.requireBold();
    assertEquals("android:textColorPrimary", themeEditorTable.attributeNameAt(cell));
    assertEquals("@color/primary_text_material_dark", themeEditorTable.valueAt(cell));
}
Also used : GenericTypeMatcher(org.fest.swing.core.GenericTypeMatcher) NotNull(org.jetbrains.annotations.NotNull) TableCell(org.fest.swing.data.TableCell) ResourceComponent(com.android.tools.idea.editors.theme.ui.ResourceComponent) Test(org.junit.Test)

Example 3 with ResourceComponent

use of com.android.tools.idea.editors.theme.ui.ResourceComponent in project android by JetBrains.

the class ThemeEditorComponent method updateUiParameters.

private void updateUiParameters() {
    //noinspection ConstantConditions
    if (myAttributesTable == null) {
        return;
    }
    Font regularFont = UIUtil.getLabelFont();
    int regularFontSize = getFontMetrics(regularFont).getHeight();
    Font headerFont = regularFont.deriveFont(regularFontSize * ThemeEditorConstants.ATTRIBUTES_HEADER_FONT_SCALE);
    int headerFontSize = getFontMetrics(headerFont).getHeight();
    // We calculate the size of the resource cell (drawable and color cells) by creating a ResourceComponent that
    // we use to measure the preferred size.
    ResourceComponent sampleComponent = new ResourceComponent(myProject, false);
    int bigCellSize = sampleComponent.getPreferredSize().height;
    myAttributesTable.setClassHeights(ImmutableMap.of(Object.class, regularFontSize + REGULAR_CELL_PADDING, Color.class, bigCellSize, DrawableDomElement.class, bigCellSize, TableLabel.class, headerFontSize + LARGE_CELL_PADDING, AttributesTableModel.ParentAttribute.class, bigCellSize));
}
Also used : ResourceComponent(com.android.tools.idea.editors.theme.ui.ResourceComponent) TableLabel(com.android.tools.idea.editors.theme.attributes.TableLabel) DrawableDomElement(org.jetbrains.android.dom.drawable.DrawableDomElement)

Aggregations

ResourceComponent (com.android.tools.idea.editors.theme.ui.ResourceComponent)3 NotNull (org.jetbrains.annotations.NotNull)2 TableLabel (com.android.tools.idea.editors.theme.attributes.TableLabel)1 Component (java.awt.Component)1 GenericTypeMatcher (org.fest.swing.core.GenericTypeMatcher)1 TableCell (org.fest.swing.data.TableCell)1 DrawableDomElement (org.jetbrains.android.dom.drawable.DrawableDomElement)1 Test (org.junit.Test)1