Search in sources :

Example 6 with FieldConfigRange

use of com.sldeditor.ui.detail.config.FieldConfigRange in project sldeditor by robward-scisys.

the class FieldConfigRangeTest method testCreateCopy.

/**
 * Test method for {@link com.sldeditor.ui.detail.config.FieldConfigRange#createCopy(com.sldeditor.ui.detail.config.FieldConfigBase)}.
 */
@Test
public void testCreateCopy() {
    boolean valueOnly = true;
    class TestFieldConfigRange extends FieldConfigRange {

        public TestFieldConfigRange(FieldConfigCommonData commonData, Class<?> rangeClass) {
            super(commonData, rangeClass);
        }

        public FieldConfigPopulate callCreateCopy(FieldConfigBase fieldConfigBase) {
            return createCopy(fieldConfigBase);
        }
    }
    TestFieldConfigRange field = new TestFieldConfigRange(new FieldConfigCommonData(Double.class, FieldIdEnum.NAME, "label", valueOnly), org.jaitools.numeric.Range.class);
    FieldConfigRange copy = (FieldConfigRange) field.callCreateCopy(null);
    assertNull(copy);
    copy = (FieldConfigRange) field.callCreateCopy(field);
    assertEquals(field.getFieldId(), copy.getFieldId());
    assertTrue(field.getLabel().compareTo(copy.getLabel()) == 0);
    assertEquals(field.isValueOnly(), copy.isValueOnly());
}
Also used : FieldConfigRange(com.sldeditor.ui.detail.config.FieldConfigRange) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) Test(org.junit.Test)

Example 7 with FieldConfigRange

use of com.sldeditor.ui.detail.config.FieldConfigRange in project sldeditor by robward-scisys.

the class FieldConfigRangeTest method testRevertToDefaultValue.

/**
 * Test method for {@link com.sldeditor.ui.detail.config.FieldConfigRange#revertToDefaultValue()}. Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigRange#setDefaultValue(double)}.
 */
@SuppressWarnings("rawtypes")
@Test
public void testRevertToDefaultValue() {
    boolean valueOnly = true;
    FieldConfigRange field = new FieldConfigRange(new FieldConfigCommonData(Double.class, FieldIdEnum.NAME, "label", valueOnly), org.jaitools.numeric.Range.class);
    Range expectedDefaultValue = Range.create(0.0, true, 1.0, true);
    field.revertToDefaultValue();
    Range actualValue = field.getRange();
    assertTrue(Math.abs(actualValue.getMin().doubleValue() - expectedDefaultValue.getMin().doubleValue()) < 0.001);
    assertEquals(actualValue.isMinIncluded(), expectedDefaultValue.isMinIncluded());
    assertTrue(Math.abs(actualValue.getMax().doubleValue() - expectedDefaultValue.getMax().doubleValue()) < 0.001);
    assertEquals(actualValue.isMaxIncluded(), expectedDefaultValue.isMaxIncluded());
    field.createUI();
    field.createUI();
    expectedDefaultValue = Range.create(5.1, true, 7.5, false);
    field.setDefaultValue(expectedDefaultValue);
    field.revertToDefaultValue();
    actualValue = field.getRange();
    assertTrue(Math.abs(actualValue.getMin().doubleValue() - expectedDefaultValue.getMin().doubleValue()) < 0.001);
    assertEquals(actualValue.isMinIncluded(), expectedDefaultValue.isMinIncluded());
    assertTrue(Math.abs(actualValue.getMax().doubleValue() - expectedDefaultValue.getMax().doubleValue()) < 0.001);
    assertEquals(actualValue.isMaxIncluded(), expectedDefaultValue.isMaxIncluded());
    assertTrue(String.valueOf(expectedDefaultValue).compareTo(field.getStringValue()) == 0);
}
Also used : FieldConfigRange(com.sldeditor.ui.detail.config.FieldConfigRange) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) Range(org.jaitools.numeric.Range) FieldConfigRange(com.sldeditor.ui.detail.config.FieldConfigRange) Test(org.junit.Test)

Example 8 with FieldConfigRange

use of com.sldeditor.ui.detail.config.FieldConfigRange in project sldeditor by robward-scisys.

the class FieldConfigRangeTest method testSetConfig.

/**
 * Test method for {@link com.sldeditor.ui.detail.config.FieldConfigRange#testSetConfig(double, double, double, double)}.
 */
@SuppressWarnings("rawtypes")
@Test
public void testSetConfig() {
    boolean valueOnly = true;
    FieldConfigRange field = new FieldConfigRange(new FieldConfigCommonData(Double.class, FieldIdEnum.NAME, "label", valueOnly), org.jaitools.numeric.Range.class);
    field.createUI();
    double minValue = 10.0;
    double maxValue = 20.0;
    double stepSize = 1.0;
    int noOfDecimalPlaces = 2;
    field.createUI();
    field.setConfig(minValue, maxValue, stepSize, noOfDecimalPlaces);
    // Should be set to the minimum value
    Range expectedValue1 = Range.create(3.0, false, 11.0, false);
    field.populateField(expectedValue1);
    Range actualValue = field.getRange();
    assertTrue(Math.abs(actualValue.getMin().doubleValue() - minValue) < 0.001);
    assertEquals(actualValue.isMinIncluded(), expectedValue1.isMinIncluded());
    assertTrue(Math.abs(actualValue.getMax().doubleValue() - expectedValue1.getMax().doubleValue()) < 0.001);
    assertEquals(actualValue.isMaxIncluded(), expectedValue1.isMaxIncluded());
    Range expectedValue1a = Range.create(113.0, false, 121.0, false);
    field.populateField(expectedValue1a);
    actualValue = field.getRange();
    assertTrue(Math.abs(actualValue.getMin().doubleValue() - maxValue) < 0.001);
    assertTrue(Math.abs(actualValue.getMax().doubleValue() - maxValue) < 0.001);
    // Should be set to the maximum value
    Range expectedValue2 = Range.create(15.0, false, 31.0, false);
    field.populateField(expectedValue2);
    actualValue = field.getRange();
    assertTrue(Math.abs(actualValue.getMin().doubleValue() - expectedValue2.getMin().doubleValue()) < 0.001);
    assertEquals(actualValue.isMinIncluded(), expectedValue2.isMinIncluded());
    assertTrue(Math.abs(actualValue.getMax().doubleValue() - maxValue) < 0.001);
    assertEquals(actualValue.isMaxIncluded(), expectedValue2.isMaxIncluded());
    Range expectedValue2a = Range.create(-13.0, false, -11.0, false);
    field.populateField(expectedValue2a);
    actualValue = field.getRange();
    assertTrue(Math.abs(actualValue.getMin().doubleValue() - minValue) < 0.001);
    assertTrue(Math.abs(actualValue.getMax().doubleValue() - minValue) < 0.001);
}
Also used : FieldConfigRange(com.sldeditor.ui.detail.config.FieldConfigRange) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) Range(org.jaitools.numeric.Range) FieldConfigRange(com.sldeditor.ui.detail.config.FieldConfigRange) Test(org.junit.Test)

Aggregations

FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)8 FieldConfigRange (com.sldeditor.ui.detail.config.FieldConfigRange)8 Test (org.junit.Test)8 Range (org.jaitools.numeric.Range)4 UndoEvent (com.sldeditor.common.undo.UndoEvent)1 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)1 Expression (org.opengis.filter.expression.Expression)1