Search in sources :

Example 1 with Range

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

the class FieldConfigRangeTest method testUndoAction.

/**
 * Test method for {@link com.sldeditor.ui.detail.config.FieldConfigRange#undoAction(com.sldeditor.common.undo.UndoInterface)}. Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigRange#redoAction(com.sldeditor.common.undo.UndoInterface)}.
 */
@SuppressWarnings("rawtypes")
@Test
public void testUndoAction() {
    boolean valueOnly = true;
    FieldConfigRange field = new FieldConfigRange(new FieldConfigCommonData(Double.class, FieldIdEnum.NAME, "label", valueOnly), org.jaitools.numeric.Range.class);
    field.undoAction(null);
    field.redoAction(null);
    Range expectedValue1 = Range.create(3.0, false, 11.0, false);
    field.createUI();
    field.populateField(expectedValue1);
    Range actualValue = field.getRange();
    assertTrue(Math.abs(actualValue.getMin().doubleValue() - expectedValue1.getMin().doubleValue()) < 0.001);
    assertEquals(actualValue.isMinIncluded(), expectedValue1.isMinIncluded());
    assertTrue(Math.abs(actualValue.getMax().doubleValue() - expectedValue1.getMax().doubleValue()) < 0.001);
    assertEquals(actualValue.isMaxIncluded(), expectedValue1.isMaxIncluded());
    Range expectedValue2 = Range.create(23.0, true, 51.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() - expectedValue2.getMax().doubleValue()) < 0.001);
    assertEquals(actualValue.isMaxIncluded(), expectedValue2.isMaxIncluded());
    UndoManager.getInstance().undo();
    actualValue = field.getRange();
    assertTrue(Math.abs(actualValue.getMin().doubleValue() - expectedValue1.getMin().doubleValue()) < 0.001);
    assertEquals(actualValue.isMinIncluded(), expectedValue1.isMinIncluded());
    assertTrue(Math.abs(actualValue.getMax().doubleValue() - expectedValue1.getMax().doubleValue()) < 0.001);
    assertEquals(actualValue.isMaxIncluded(), expectedValue1.isMaxIncluded());
    UndoManager.getInstance().redo();
    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() - expectedValue2.getMax().doubleValue()) < 0.001);
    assertEquals(actualValue.isMaxIncluded(), expectedValue2.isMaxIncluded());
    // Increase the code coverage
    field.undoAction(null);
    field.redoAction(null);
    field.undoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
    field.redoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent) 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 2 with Range

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

the class FieldConfigRange method getRangeValues.

/**
 * Gets the range.
 *
 * @return the range
 */
@SuppressWarnings("rawtypes")
private Range getRangeValues() {
    Range range = previousValue;
    if (!isPopulating() && (startRange != null) && (startRange.includedCheckBox != null)) {
        boolean minIncluded = startRange.includedCheckBox.isSelected();
        boolean maxIncluded = endRange.includedCheckBox.isSelected();
        Double minValue = startRange.spinner.getDoubleValue();
        Double maxValue = endRange.spinner.getDoubleValue();
        range = Range.create(minValue, minIncluded, maxValue, maxIncluded);
        previousValue = range;
    }
    return range;
}
Also used : Range(org.jaitools.numeric.Range)

Example 3 with Range

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

the class FieldConfigRange method undoAction.

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

Example 4 with Range

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

the class FieldConfigRange method uiInteraction.

/**
 * Ui interaction.
 *
 * @param parentObj the parent obj
 */
@SuppressWarnings("rawtypes")
protected void uiInteraction(final UndoActionInterface parentObj) {
    Range oldValueObj = previousValue;
    Range newValueObj = getRangeValues();
    if (oldValueObj != previousValue) {
        UndoManager.getInstance().addUndoEvent(new UndoEvent(parentObj, getFieldId(), oldValueObj, newValueObj));
    }
    valueUpdated();
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent) Range(org.jaitools.numeric.Range)

Example 5 with Range

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

the class FieldConfigRange method generateExpression.

/**
 * Generate expression.
 *
 * @return the expression
 */
@SuppressWarnings("rawtypes")
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.detail.config.FieldConfigBase#generateExpression()
     */
@Override
protected Expression generateExpression() {
    Expression expression = null;
    Range range = getRange();
    if (this.rangeClass == Range.class) {
        expression = getFilterFactory().literal(range);
    } else if (this.rangeClass == it.geosolutions.jaiext.range.Range.class) {
        it.geosolutions.jaiext.range.Range r = it.geosolutions.jaiext.range.RangeFactory.create(range.getMin().doubleValue(), range.isMinIncluded(), range.getMax().doubleValue(), range.isMaxIncluded(), false);
        expression = getFilterFactory().literal(r);
    }
    return expression;
}
Also used : Expression(org.opengis.filter.expression.Expression) Range(org.jaitools.numeric.Range)

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