Search in sources :

Example 16 with CountListener

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

the class ObservableListTest method setAllWithEmptyCollectionCanClearTheCurrentList.

@Test
public void setAllWithEmptyCollectionCanClearTheCurrentList() throws Exception {
    ObservableList<Integer> numericList = new ObservableList<>();
    numericList.add(1);
    numericList.add(2);
    numericList.add(3);
    CountListener listener = new CountListener();
    numericList.addListener(listener);
    numericList.setAll(ImmutableSet.<Integer>of());
    assertThat(numericList).isEmpty();
    assertThat(listener.getCount()).isEqualTo(1);
}
Also used : CountListener(com.android.tools.idea.ui.properties.CountListener) Test(org.junit.Test)

Example 17 with CountListener

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

the class TextPropertyTest method textPropertyCanWrapTextField.

@Test
public void textPropertyCanWrapTextField() {
    JTextField field = new JTextField("New Field");
    TextProperty textProperty = new TextProperty(field);
    CountListener listener = new CountListener();
    textProperty.addListener(listener);
    assertThat(textProperty.get()).isEqualTo("New Field");
    assertThat(listener.getCount()).isEqualTo(0);
    field.setText("Field text updated directly");
    assertThat(textProperty.get()).isEqualTo("Field text updated directly");
    // +2 here: TextField fires two events when setText is called directly (remove and insert)
    assertThat(listener.getCount()).isEqualTo(2);
    textProperty.set("Field text updated via property");
    assertThat(field.getText()).isEqualTo("Field text updated via property");
    // Only +1 here: Property.set hides extra validation calls
    assertThat(listener.getCount()).isEqualTo(3);
}
Also used : CountListener(com.android.tools.idea.ui.properties.CountListener) Test(org.junit.Test)

Example 18 with CountListener

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

the class SelectedItemPropertyTest method testSelectedItemProperty.

@Test
public void testSelectedItemProperty() {
    TestString a = new TestString("A");
    TestString b = new TestString("B");
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    model.addElement(a);
    model.addElement(b);
    JComboBox comboBox = new JComboBox(model);
    SelectedItemProperty<TestString> selectedItemProperty = new SelectedItemProperty<>(comboBox);
    CountListener listener = new CountListener();
    selectedItemProperty.addListener(listener);
    assertThat(selectedItemProperty.getValue()).isEqualTo(a);
    assertThat(listener.getCount()).isEqualTo(0);
    selectedItemProperty.setValue(b);
    assertThat(comboBox.getSelectedItem()).isEqualTo(b);
    assertThat(listener.getCount()).isEqualTo(1);
    comboBox.setSelectedIndex(0);
    assertThat(comboBox.getSelectedItem()).isEqualTo(a);
    assertThat(listener.getCount()).isEqualTo(2);
    comboBox.setSelectedItem(null);
    assertThat(selectedItemProperty.get().isPresent()).isEqualTo(false);
    assertThat(listener.getCount()).isEqualTo(3);
}
Also used : CountListener(com.android.tools.idea.ui.properties.CountListener) Test(org.junit.Test)

Example 19 with CountListener

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

the class SelectedPropertyTest method testSelectedProperty.

@Test
public void testSelectedProperty() {
    JCheckBox checkbox = new JCheckBox();
    checkbox.setSelected(true);
    SelectedProperty selectedProperty = new SelectedProperty(checkbox);
    CountListener listener = new CountListener();
    selectedProperty.addListener(listener);
    assertThat(selectedProperty.get()).isTrue();
    assertThat(listener.getCount()).isEqualTo(0);
    checkbox.setSelected(false);
    assertThat(selectedProperty.get()).isFalse();
    assertThat(listener.getCount()).isEqualTo(1);
    selectedProperty.set(true);
    assertThat(checkbox.isSelected()).isTrue();
    assertThat(listener.getCount()).isEqualTo(2);
}
Also used : CountListener(com.android.tools.idea.ui.properties.CountListener) Test(org.junit.Test)

Example 20 with CountListener

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

the class SliderValuePropertyTest method testSliderValueProperty.

@Test
public void testSliderValueProperty() throws Exception {
    JSlider slider = new JSlider(0, 100, 50);
    SliderValueProperty sliderValue = new SliderValueProperty(slider);
    CountListener listener = new CountListener();
    sliderValue.addListener(listener);
    assertThat(sliderValue.get()).isEqualTo(50);
    assertThat(listener.getCount()).isEqualTo(0);
    slider.setValue(90);
    assertThat(sliderValue.get()).isEqualTo(90);
    assertThat(listener.getCount()).isEqualTo(1);
    sliderValue.set(10);
    assertThat(slider.getValue()).isEqualTo(10);
    assertThat(listener.getCount()).isEqualTo(2);
}
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