Search in sources :

Example 21 with CountListener

use of com.android.tools.idea.ui.properties.CountListener in project android by JetBrains.

the class TextPropertyTest method textPropertyCanWrapLabel.

@Test
public void textPropertyCanWrapLabel() {
    JLabel label = new JLabel("New Label");
    TextProperty textProperty = new TextProperty(label);
    CountListener listener = new CountListener();
    textProperty.addListener(listener);
    assertThat(textProperty.get()).isEqualTo("New Label");
    assertThat(listener.getCount()).isEqualTo(0);
    label.setText("Label text updated directly");
    assertThat(textProperty.get()).isEqualTo("Label text updated directly");
    assertThat(listener.getCount()).isEqualTo(1);
    textProperty.set("Label text updated via property");
    assertThat(label.getText()).isEqualTo("Label text updated via property");
    assertThat(listener.getCount()).isEqualTo(2);
}
Also used : CountListener(com.android.tools.idea.ui.properties.CountListener) Test(org.junit.Test)

Example 22 with CountListener

use of com.android.tools.idea.ui.properties.CountListener in project android by JetBrains.

the class TextPropertyTest method textPropertyCanWrapButton.

@Test
public void textPropertyCanWrapButton() {
    JButton button = new JButton("New Button");
    TextProperty textProperty = new TextProperty(button);
    CountListener listener = new CountListener();
    textProperty.addListener(listener);
    assertThat(textProperty.get()).isEqualTo("New Button");
    assertThat(listener.getCount()).isEqualTo(0);
    button.setText("Button text updated directly");
    assertThat(textProperty.get()).isEqualTo("Button text updated directly");
    assertThat(listener.getCount()).isEqualTo(1);
    textProperty.set("Button text updated via property");
    assertThat(button.getText()).isEqualTo("Button text updated via property");
    assertThat(listener.getCount()).isEqualTo(2);
}
Also used : CountListener(com.android.tools.idea.ui.properties.CountListener) Test(org.junit.Test)

Example 23 with CountListener

use of com.android.tools.idea.ui.properties.CountListener in project android by JetBrains.

the class ColorPropertyTest method testColorProperty.

@Test
public void testColorProperty() throws Exception {
    ColorPanel colorPanel = new ColorPanel();
    ColorProperty color = new ColorProperty(colorPanel);
    CountListener listener = new CountListener();
    color.addListener(listener);
    assertThat(color.get().isPresent()).isFalse();
    assertThat(listener.getCount()).isEqualTo(0);
    colorPanel.setSelectedColor(Color.RED);
    assertThat(color.get().isPresent()).isTrue();
    assertThat(color.getValue()).isEqualTo(Color.RED);
    // ColorPanel only fires its listener when the button is clicked, not when color is set
    // programmatically. Otherwise, this should have been true:
    // assertThat(listener.getCount()).isEqualTo(1);
    color.setValue(Color.BLUE);
    assertThat(colorPanel.getSelectedColor()).isEqualTo(Color.BLUE);
    assertThat(listener.getCount()).isEqualTo(1);
    color.clear();
    assertThat(colorPanel.getSelectedColor()).isNull();
    assertThat(listener.getCount()).isEqualTo(2);
}
Also used : ColorPanel(com.intellij.ui.ColorPanel) CountListener(com.android.tools.idea.ui.properties.CountListener) Test(org.junit.Test)

Example 24 with CountListener

use of com.android.tools.idea.ui.properties.CountListener in project android by JetBrains.

the class ObservableListTest method listInvalidatedOnAddAllAtIndex.

@Test
public void listInvalidatedOnAddAllAtIndex() throws Exception {
    ObservableList<String> list = new ObservableList<>();
    CountListener listener = new CountListener();
    list.addListener(listener);
    list.add("A");
    list.add("D");
    assertThat(listener.getCount()).isEqualTo(2);
    list.addAll(1, ImmutableSet.of("B", "C"));
    assertThat(listener.getCount()).isEqualTo(3);
    assertThat(list).containsExactly("A", "B", "C", "D");
}
Also used : CountListener(com.android.tools.idea.ui.properties.CountListener) Test(org.junit.Test)

Example 25 with CountListener

use of com.android.tools.idea.ui.properties.CountListener in project android by JetBrains.

the class ObservableListTest method clearOnEmptyListDoesntFireInvalidation.

@Test
public void clearOnEmptyListDoesntFireInvalidation() throws Exception {
    ObservableList<String> list = new ObservableList<>();
    CountListener listener = new CountListener();
    list.addListener(listener);
    list.clear();
    assertThat(listener.getCount()).isEqualTo(0);
}
Also used : CountListener(com.android.tools.idea.ui.properties.CountListener) Test(org.junit.Test)

Aggregations

CountListener (com.android.tools.idea.ui.properties.CountListener)41 Test (org.junit.Test)41 LabelWithEditLink (com.android.tools.adtui.LabelWithEditLink)1 ColorPanel (com.intellij.ui.ColorPanel)1