Search in sources :

Example 6 with Range

use of org.jaitools.numeric.Range in project sldeditor by robward-scisys.

the class FieldConfigRange method redoAction.

/**
 * Redo action.
 *
 * @param undoRedoObject the undo/redo object
 */
@SuppressWarnings("rawtypes")
@Override
public void redoAction(UndoInterface undoRedoObject) {
    if ((startRange.spinner != null) && (undoRedoObject != null)) {
        if (undoRedoObject.getNewValue() instanceof Range) {
            Range newValue = (Range) undoRedoObject.getNewValue();
            internalSetValue(newValue);
        }
    }
}
Also used : Range(org.jaitools.numeric.Range)

Example 7 with Range

use of org.jaitools.numeric.Range in project sldeditor by robward-scisys.

the class FieldConfigRange method populateExpression.

/**
 * Populate expression.
 *
 * @param objValue the obj value
 */
@SuppressWarnings("rawtypes")
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.detail.config.FieldConfigBase#populateExpression(java.lang.Object)
     */
@Override
public void populateExpression(Object objValue) {
    Range newValue = defaultValue;
    if (objValue instanceof Range) {
        newValue = (Range) objValue;
    } else if (objValue instanceof it.geosolutions.jaiext.range.Range) {
        it.geosolutions.jaiext.range.Range tmp = (it.geosolutions.jaiext.range.Range) objValue;
        newValue = Range.create(tmp.getMin().doubleValue(), tmp.isMinIncluded(), tmp.getMax().doubleValue(), tmp.isMaxIncluded());
    }
    populateField(newValue);
}
Also used : Range(org.jaitools.numeric.Range)

Example 8 with Range

use of org.jaitools.numeric.Range in project sldeditor by robward-scisys.

the class FieldConfigRangeTest method testGenerateExpression.

/**
 * Test method for {@link com.sldeditor.ui.detail.config.FieldConfigRange#generateExpression()}. Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigRange#populateExpression(java.lang.Object, org.opengis.filter.expression.Expression)}. Test
 * method for {@link com.sldeditor.ui.detail.config.FieldConfigRange#populateField(java.lang.Double)}. Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigRange#setTestValue(com.sldeditor.ui.detail.config.FieldId, double)}. Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigRange#getDoubleValue()}.
 */
@SuppressWarnings("rawtypes")
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;
    FieldConfigRange field = new FieldConfigRange(new FieldConfigCommonData(Double.class, FieldIdEnum.NAME, "label", valueOnly), org.jaitools.numeric.Range.class);
    field.createUI();
    Range expectedValue = Range.create(3.0, false, 11.0, false);
    field.populateField(expectedValue);
    Range actualValueJAITools = field.getRange();
    assertTrue(Math.abs(actualValueJAITools.getMin().doubleValue() - expectedValue.getMin().doubleValue()) < 0.001);
    assertEquals(actualValueJAITools.isMinIncluded(), expectedValue.isMinIncluded());
    assertTrue(Math.abs(actualValueJAITools.getMax().doubleValue() - expectedValue.getMax().doubleValue()) < 0.001);
    assertEquals(actualValueJAITools.isMaxIncluded(), expectedValue.isMaxIncluded());
    field.populateExpression(null);
    actualValueJAITools = field.getRange();
    Range expectedDefaultValue = Range.create(0.0, true, 1.0, true);
    assertTrue(Math.abs(actualValueJAITools.getMin().doubleValue() - expectedDefaultValue.getMin().doubleValue()) < 0.001);
    assertEquals(actualValueJAITools.isMinIncluded(), expectedDefaultValue.isMinIncluded());
    assertTrue(Math.abs(actualValueJAITools.getMax().doubleValue() - expectedDefaultValue.getMax().doubleValue()) < 0.001);
    assertEquals(actualValueJAITools.isMaxIncluded(), expectedDefaultValue.isMaxIncluded());
    // Try using it.geosolutions.jaiext.range.Range
    field = new FieldConfigRange(new FieldConfigCommonData(Double.class, FieldIdEnum.NAME, "label", valueOnly), it.geosolutions.jaiext.range.Range.class);
    field.createUI();
    field.populateField(expectedValue);
    Range actualValueJAIExt = field.getRange();
    assertTrue(Math.abs(actualValueJAIExt.getMin().doubleValue() - expectedValue.getMin().doubleValue()) < 0.001);
    assertEquals(actualValueJAIExt.isMinIncluded(), expectedValue.isMinIncluded());
    assertTrue(Math.abs(actualValueJAIExt.getMax().doubleValue() - expectedValue.getMax().doubleValue()) < 0.001);
    assertEquals(actualValueJAIExt.isMaxIncluded(), expectedValue.isMaxIncluded());
    Expression rangeJAIToolsExpression = field.getExpression();
    field.populate(rangeJAIToolsExpression);
    actualValueJAITools = field.getRange();
    assertTrue(Math.abs(actualValueJAIExt.getMin().doubleValue() - expectedValue.getMin().doubleValue()) < 0.001);
    assertEquals(actualValueJAIExt.isMinIncluded(), expectedValue.isMinIncluded());
    assertTrue(Math.abs(actualValueJAIExt.getMax().doubleValue() - expectedValue.getMax().doubleValue()) < 0.001);
    assertEquals(actualValueJAIExt.isMaxIncluded(), expectedValue.isMaxIncluded());
}
Also used : FieldConfigRange(com.sldeditor.ui.detail.config.FieldConfigRange) Expression(org.opengis.filter.expression.Expression) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) Range(org.jaitools.numeric.Range) FieldConfigRange(com.sldeditor.ui.detail.config.FieldConfigRange) Test(org.junit.Test)

Example 9 with Range

use of org.jaitools.numeric.Range 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 10 with Range

use of org.jaitools.numeric.Range 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

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